Passed
Push — master ( 1366b3...59f0fc )
by Julius
17:36 queued 11s
created
lib/private/Collaboration/Collaborators/GroupPlugin.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -37,115 +37,115 @@
 block discarded – undo
37 37
 use OCP\Share\IShare;
38 38
 
39 39
 class GroupPlugin implements ISearchPlugin {
40
-	/** @var bool */
41
-	protected $shareeEnumeration;
42
-	/** @var bool */
43
-	protected $shareWithGroupOnly;
44
-	/** @var bool */
45
-	protected $shareeEnumerationInGroupOnly;
46
-	/** @var bool */
47
-	protected $groupSharingDisabled;
48
-
49
-	/** @var IGroupManager */
50
-	private $groupManager;
51
-	/** @var IConfig */
52
-	private $config;
53
-	/** @var IUserSession */
54
-	private $userSession;
55
-
56
-	public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
57
-		$this->groupManager = $groupManager;
58
-		$this->config = $config;
59
-		$this->userSession = $userSession;
60
-
61
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
62
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
63
-		$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
64
-		$this->groupSharingDisabled = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'no';
65
-	}
66
-
67
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
68
-		if ($this->groupSharingDisabled) {
69
-			return false;
70
-		}
71
-
72
-		$hasMoreResults = false;
73
-		$result = ['wide' => [], 'exact' => []];
74
-
75
-		$groups = $this->groupManager->search($search, $limit, $offset);
76
-		$groupIds = array_map(function (IGroup $group) {
77
-			return $group->getGID();
78
-		}, $groups);
79
-
80
-		if (!$this->shareeEnumeration || count($groups) < $limit) {
81
-			$hasMoreResults = true;
82
-		}
83
-
84
-		$userGroups = [];
85
-		if (!empty($groups) && ($this->shareWithGroupOnly || $this->shareeEnumerationInGroupOnly)) {
86
-			// Intersect all the groups that match with the groups this user is a member of
87
-			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
88
-			$userGroups = array_map(function (IGroup $group) {
89
-				return $group->getGID();
90
-			}, $userGroups);
91
-			$groupIds = array_intersect($groupIds, $userGroups);
92
-		}
93
-
94
-		$lowerSearch = strtolower($search);
95
-		foreach ($groups as $group) {
96
-			if ($group->hideFromCollaboration()) {
97
-				continue;
98
-			}
99
-
100
-			// FIXME: use a more efficient approach
101
-			$gid = $group->getGID();
102
-			if (!in_array($gid, $groupIds)) {
103
-				continue;
104
-			}
105
-			if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
106
-				$result['exact'][] = [
107
-					'label' => $group->getDisplayName(),
108
-					'value' => [
109
-						'shareType' => IShare::TYPE_GROUP,
110
-						'shareWith' => $gid,
111
-					],
112
-				];
113
-			} else {
114
-				if ($this->shareeEnumerationInGroupOnly && !in_array($group->getGID(), $userGroups, true)) {
115
-					continue;
116
-				}
117
-				$result['wide'][] = [
118
-					'label' => $group->getDisplayName(),
119
-					'value' => [
120
-						'shareType' => IShare::TYPE_GROUP,
121
-						'shareWith' => $gid,
122
-					],
123
-				];
124
-			}
125
-		}
126
-
127
-		if ($offset === 0 && empty($result['exact'])) {
128
-			// On page one we try if the search result has a direct hit on the
129
-			// user id and if so, we add that to the exact match list
130
-			$group = $this->groupManager->get($search);
131
-			if ($group instanceof IGroup && !$group->hideFromCollaboration() && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
132
-				$result['exact'][] = [
133
-					'label' => $group->getDisplayName(),
134
-					'value' => [
135
-						'shareType' => IShare::TYPE_GROUP,
136
-						'shareWith' => $group->getGID(),
137
-					],
138
-				];
139
-			}
140
-		}
141
-
142
-		if (!$this->shareeEnumeration) {
143
-			$result['wide'] = [];
144
-		}
145
-
146
-		$type = new SearchResultType('groups');
147
-		$searchResult->addResultSet($type, $result['wide'], $result['exact']);
148
-
149
-		return $hasMoreResults;
150
-	}
40
+    /** @var bool */
41
+    protected $shareeEnumeration;
42
+    /** @var bool */
43
+    protected $shareWithGroupOnly;
44
+    /** @var bool */
45
+    protected $shareeEnumerationInGroupOnly;
46
+    /** @var bool */
47
+    protected $groupSharingDisabled;
48
+
49
+    /** @var IGroupManager */
50
+    private $groupManager;
51
+    /** @var IConfig */
52
+    private $config;
53
+    /** @var IUserSession */
54
+    private $userSession;
55
+
56
+    public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
57
+        $this->groupManager = $groupManager;
58
+        $this->config = $config;
59
+        $this->userSession = $userSession;
60
+
61
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
62
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
63
+        $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
64
+        $this->groupSharingDisabled = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'no';
65
+    }
66
+
67
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
68
+        if ($this->groupSharingDisabled) {
69
+            return false;
70
+        }
71
+
72
+        $hasMoreResults = false;
73
+        $result = ['wide' => [], 'exact' => []];
74
+
75
+        $groups = $this->groupManager->search($search, $limit, $offset);
76
+        $groupIds = array_map(function (IGroup $group) {
77
+            return $group->getGID();
78
+        }, $groups);
79
+
80
+        if (!$this->shareeEnumeration || count($groups) < $limit) {
81
+            $hasMoreResults = true;
82
+        }
83
+
84
+        $userGroups = [];
85
+        if (!empty($groups) && ($this->shareWithGroupOnly || $this->shareeEnumerationInGroupOnly)) {
86
+            // Intersect all the groups that match with the groups this user is a member of
87
+            $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
88
+            $userGroups = array_map(function (IGroup $group) {
89
+                return $group->getGID();
90
+            }, $userGroups);
91
+            $groupIds = array_intersect($groupIds, $userGroups);
92
+        }
93
+
94
+        $lowerSearch = strtolower($search);
95
+        foreach ($groups as $group) {
96
+            if ($group->hideFromCollaboration()) {
97
+                continue;
98
+            }
99
+
100
+            // FIXME: use a more efficient approach
101
+            $gid = $group->getGID();
102
+            if (!in_array($gid, $groupIds)) {
103
+                continue;
104
+            }
105
+            if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
106
+                $result['exact'][] = [
107
+                    'label' => $group->getDisplayName(),
108
+                    'value' => [
109
+                        'shareType' => IShare::TYPE_GROUP,
110
+                        'shareWith' => $gid,
111
+                    ],
112
+                ];
113
+            } else {
114
+                if ($this->shareeEnumerationInGroupOnly && !in_array($group->getGID(), $userGroups, true)) {
115
+                    continue;
116
+                }
117
+                $result['wide'][] = [
118
+                    'label' => $group->getDisplayName(),
119
+                    'value' => [
120
+                        'shareType' => IShare::TYPE_GROUP,
121
+                        'shareWith' => $gid,
122
+                    ],
123
+                ];
124
+            }
125
+        }
126
+
127
+        if ($offset === 0 && empty($result['exact'])) {
128
+            // On page one we try if the search result has a direct hit on the
129
+            // user id and if so, we add that to the exact match list
130
+            $group = $this->groupManager->get($search);
131
+            if ($group instanceof IGroup && !$group->hideFromCollaboration() && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
132
+                $result['exact'][] = [
133
+                    'label' => $group->getDisplayName(),
134
+                    'value' => [
135
+                        'shareType' => IShare::TYPE_GROUP,
136
+                        'shareWith' => $group->getGID(),
137
+                    ],
138
+                ];
139
+            }
140
+        }
141
+
142
+        if (!$this->shareeEnumeration) {
143
+            $result['wide'] = [];
144
+        }
145
+
146
+        $type = new SearchResultType('groups');
147
+        $searchResult->addResultSet($type, $result['wide'], $result['exact']);
148
+
149
+        return $hasMoreResults;
150
+    }
151 151
 }
Please login to merge, or discard this patch.