Completed
Pull Request — master (#9488)
by John
18:54
created
settings/users.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 list($adminGroup, $groups) = $groupsInfo->get();
84 84
 
85 85
 $recoveryAdminEnabled = $appManager->isEnabledForUser('encryption') &&
86
-					    $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
86
+					    $config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
87 87
 
88 88
 if ($isAdmin) {
89 89
 	$subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 } else {
100 100
 	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
101 101
 	$gids = array();
102
-	foreach($groups as $group) {
102
+	foreach ($groups as $group) {
103 103
 		if (isset($group['id'])) {
104 104
 			$gids[] = $group['id'];
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 }
109 109
 
110 110
 // remove disabled from total count
111
-foreach($groups as $key => $group) {
111
+foreach ($groups as $key => $group) {
112 112
 	$groups[$key]['usercount'] -= $group['disabled'];
113 113
 }
114 114
 
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
 ];
121 121
 
122 122
 // load preset quotas
123
-$quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
124
-$quotaPreset=explode(',', $quotaPreset);
125
-foreach($quotaPreset as &$preset) {
126
-	$preset=trim($preset);
123
+$quotaPreset = $config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
124
+$quotaPreset = explode(',', $quotaPreset);
125
+foreach ($quotaPreset as &$preset) {
126
+	$preset = trim($preset);
127 127
 }
128
-$quotaPreset=array_diff($quotaPreset, array('default', 'none'));
128
+$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
129 129
 
130
-$defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
131
-$defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
132
-	&& array_search($defaultQuota, array('none', 'default'))===false;
130
+$defaultQuota = $config->getAppValue('files', 'default_quota', 'none');
131
+$defaultQuotaIsUserDefined = array_search($defaultQuota, $quotaPreset) === false
132
+	&& array_search($defaultQuota, array('none', 'default')) === false;
133 133
 
134 134
 \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
135 135
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 $tmpl->assign('sortGroups', $sortGroupsBy);
139 139
 $tmpl->assign('adminGroup', $adminGroup);
140 140
 $tmpl->assign('disabledUsersGroup', $disabledUsersGroup);
141
-$tmpl->assign('isAdmin', (int)$isAdmin);
141
+$tmpl->assign('isAdmin', (int) $isAdmin);
142 142
 $tmpl->assign('subadmins', $subAdmins);
143 143
 $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
144 144
 $tmpl->assign('quota_preset', $quotaPreset);
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
 $config = \OC::$server->getConfig();
49 49
 
50 50
 if ($config->getSystemValue('sort_groups_by_name', false)) {
51
-	$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
51
+    $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
52 52
 } else {
53
-	$isLDAPUsed = false;
54
-	if ($appManager->isEnabledForUser('user_ldap')) {
55
-		$isLDAPUsed =
56
-			$groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
57
-			|| $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
58
-		if ($isLDAPUsed) {
59
-			// LDAP user count can be slow, so we sort by group name here
60
-			$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
61
-		}
62
-	}
53
+    $isLDAPUsed = false;
54
+    if ($appManager->isEnabledForUser('user_ldap')) {
55
+        $isLDAPUsed =
56
+            $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
57
+            || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
58
+        if ($isLDAPUsed) {
59
+            // LDAP user count can be slow, so we sort by group name here
60
+            $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
61
+        }
62
+    }
63 63
 }
64 64
 
65 65
 $uid = \OC_User::getUser();
@@ -68,67 +68,67 @@  discard block
 block discarded – undo
68 68
 $isDisabled = true;
69 69
 $user = $userManager->get($uid);
70 70
 if ($user) {
71
-	$isDisabled = !$user->isEnabled();
71
+    $isDisabled = !$user->isEnabled();
72 72
 }
73 73
 
74 74
 $groupsInfo = new \OC\Group\MetaData(
75
-	$uid,
76
-	$isAdmin,
77
-	$groupManager,
78
-	\OC::$server->getUserSession()
75
+    $uid,
76
+    $isAdmin,
77
+    $groupManager,
78
+    \OC::$server->getUserSession()
79 79
 );
80 80
 
81 81
 $groupsInfo->setSorting($sortGroupsBy);
82 82
 list($adminGroup, $groups) = $groupsInfo->get();
83 83
 
84 84
 $recoveryAdminEnabled = $appManager->isEnabledForUser('encryption') &&
85
-					    $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
85
+                        $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
86 86
 
87 87
 if ($isAdmin) {
88
-	$subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
89
-	// New class returns IUser[] so convert back
90
-	$result = [];
91
-	foreach ($subAdmins as $subAdmin) {
92
-		$result[] = [
93
-			'gid' => $subAdmin['group']->getGID(),
94
-			'uid' => $subAdmin['user']->getUID(),
95
-		];
96
-	}
97
-	$subAdmins = $result;
88
+    $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
89
+    // New class returns IUser[] so convert back
90
+    $result = [];
91
+    foreach ($subAdmins as $subAdmin) {
92
+        $result[] = [
93
+            'gid' => $subAdmin['group']->getGID(),
94
+            'uid' => $subAdmin['user']->getUID(),
95
+        ];
96
+    }
97
+    $subAdmins = $result;
98 98
 } else {
99
-	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
100
-	$gids = array();
101
-	foreach($groups as $group) {
102
-		if (isset($group['id'])) {
103
-			$gids[] = $group['id'];
104
-		}
105
-	}
106
-	$subAdmins = false;
99
+    /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
100
+    $gids = array();
101
+    foreach($groups as $group) {
102
+        if (isset($group['id'])) {
103
+            $gids[] = $group['id'];
104
+        }
105
+    }
106
+    $subAdmins = false;
107 107
 }
108 108
 
109 109
 // remove disabled from total count
110 110
 foreach($groups as $key => $group) {
111
-	$groups[$key]['usercount'] -= $group['disabled'];
111
+    $groups[$key]['usercount'] -= $group['disabled'];
112 112
 }
113 113
 
114 114
 $disabledUsers = $isLDAPUsed ? 0 : $isAdmin ? $userManager->countDisabledUsers() : $userManager->countDisabledUsersOfGroups($gids);
115 115
 $disabledUsersGroup = [
116
-	'id' => '_disabledUsers',
117
-	'name' => '_disabledUsers',
118
-	'usercount' => $disabledUsers
116
+    'id' => '_disabledUsers',
117
+    'name' => '_disabledUsers',
118
+    'usercount' => $disabledUsers
119 119
 ];
120 120
 
121 121
 // load preset quotas
122 122
 $quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
123 123
 $quotaPreset=explode(',', $quotaPreset);
124 124
 foreach($quotaPreset as &$preset) {
125
-	$preset=trim($preset);
125
+    $preset=trim($preset);
126 126
 }
127 127
 $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
128 128
 
129 129
 $defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
130 130
 $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
131
-	&& array_search($defaultQuota, array('none', 'default'))===false;
131
+    && array_search($defaultQuota, array('none', 'default'))===false;
132 132
 
133 133
 \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
134 134
 
Please login to merge, or discard this patch.
lib/private/Group/MetaData.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,6 @@
 block discarded – undo
52 52
 	 * @param string $user the uid of the current user
53 53
 	 * @param bool $isAdmin whether the current users is an admin
54 54
 	 * @param IGroupManager $groupManager
55
-	 * @param IUserManager $userManager
56 55
 	 * @param IUserSession $userSession
57 56
 	 */
58 57
 	public function __construct(
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -31,174 +31,174 @@
 block discarded – undo
31 31
 use OCP\IGroupManager;
32 32
 
33 33
 class MetaData {
34
-	const SORT_NONE = 0;
35
-	const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends
36
-	const SORT_GROUPNAME = 2;
37
-
38
-	/** @var string */
39
-	protected $user;
40
-	/** @var bool */
41
-	protected $isAdmin;
42
-	/** @var array */
43
-	protected $metaData = array();
44
-	/** @var IGroupManager */
45
-	protected $groupManager;
46
-	/** @var bool */
47
-	protected $sorting = false;
48
-	/** @var IUserSession */
49
-	protected $userSession;
50
-
51
-	/**
52
-	 * @param string $user the uid of the current user
53
-	 * @param bool $isAdmin whether the current users is an admin
54
-	 * @param IGroupManager $groupManager
55
-	 * @param IUserManager $userManager
56
-	 * @param IUserSession $userSession
57
-	 */
58
-	public function __construct(
59
-			$user,
60
-			$isAdmin,
61
-			IGroupManager $groupManager,
62
-			IUserSession $userSession
63
-			) {
64
-		$this->user = $user;
65
-		$this->isAdmin = (bool)$isAdmin;
66
-		$this->groupManager = $groupManager;
67
-		$this->userSession = $userSession;
68
-	}
69
-
70
-	/**
71
-	 * returns an array with meta data about all available groups
72
-	 * the array is structured as follows:
73
-	 * [0] array containing meta data about admin groups
74
-	 * [1] array containing meta data about unprivileged groups
75
-	 * @param string $groupSearch only effective when instance was created with
76
-	 * isAdmin being true
77
-	 * @param string $userSearch the pattern users are search for
78
-	 * @return array
79
-	 */
80
-	public function get($groupSearch = '', $userSearch = '') {
81
-		$key = $groupSearch . '::' . $userSearch;
82
-		if(isset($this->metaData[$key])) {
83
-			return $this->metaData[$key];
84
-		}
85
-
86
-		$adminGroups = array();
87
-		$groups = array();
88
-		$sortGroupsIndex = 0;
89
-		$sortGroupsKeys = array();
90
-		$sortAdminGroupsIndex = 0;
91
-		$sortAdminGroupsKeys = array();
92
-
93
-		foreach($this->getGroups($groupSearch) as $group) {
94
-			$groupMetaData = $this->generateGroupMetaData($group, $userSearch);
95
-			if (strtolower($group->getGID()) !== 'admin') {
96
-				$this->addEntry(
97
-					$groups,
98
-					$sortGroupsKeys,
99
-					$sortGroupsIndex,
100
-					$groupMetaData);
101
-			} else {
102
-				//admin group is hard coded to 'admin' for now. In future,
103
-				//backends may define admin groups too. Then the if statement
104
-				//has to be adjusted accordingly.
105
-				$this->addEntry(
106
-					$adminGroups,
107
-					$sortAdminGroupsKeys,
108
-					$sortAdminGroupsIndex,
109
-					$groupMetaData);
110
-			}
111
-		}
112
-
113
-		//whether sorting is necessary is will be checked in sort()
114
-		$this->sort($groups, $sortGroupsKeys);
115
-		$this->sort($adminGroups, $sortAdminGroupsKeys);
116
-
117
-		$this->metaData[$key] = array($adminGroups, $groups);
118
-		return $this->metaData[$key];
119
-	}
120
-
121
-	/**
122
-	 * sets the sort mode, see SORT_* constants for supported modes
123
-	 *
124
-	 * @param int $sortMode
125
-	 */
126
-	public function setSorting($sortMode) {
127
-		switch ($sortMode) {
128
-			case self::SORT_USERCOUNT:
129
-			case self::SORT_GROUPNAME:
130
-				$this->sorting = $sortMode;
131
-				break;
132
-
133
-			default:
134
-				$this->sorting = self::SORT_NONE;
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * adds an group entry to the resulting array
140
-	 * @param array $entries the resulting array, by reference
141
-	 * @param array $sortKeys the sort key array, by reference
142
-	 * @param int $sortIndex the sort key index, by reference
143
-	 * @param array $data the group's meta data as returned by generateGroupMetaData()
144
-	 */
145
-	private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) {
146
-		$entries[] = $data;
147
-		if ($this->sorting === self::SORT_USERCOUNT) {
148
-			$sortKeys[$sortIndex] = $data['usercount'];
149
-			$sortIndex++;
150
-		} else if ($this->sorting === self::SORT_GROUPNAME) {
151
-			$sortKeys[$sortIndex] = $data['name'];
152
-			$sortIndex++;
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * creates an array containing the group meta data
158
-	 * @param \OCP\IGroup $group
159
-	 * @param string $userSearch
160
-	 * @return array with the keys 'id', 'name', 'usercount' and 'disabled'
161
-	 */
162
-	private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
163
-		return array(
164
-				'id' => $group->getGID(),
165
-				'name' => $group->getDisplayName(),
166
-				'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
167
-				'disabled' => $group->countDisabled()
168
-			);
169
-	}
170
-
171
-	/**
172
-	 * sorts the result array, if applicable
173
-	 * @param array $entries the result array, by reference
174
-	 * @param array $sortKeys the array containing the sort keys
175
-	 * @param return null
176
-	 */
177
-	private function sort(&$entries, $sortKeys) {
178
-		if ($this->sorting === self::SORT_USERCOUNT) {
179
-			array_multisort($sortKeys, SORT_DESC, $entries);
180
-		} else if ($this->sorting === self::SORT_GROUPNAME) {
181
-			array_multisort($sortKeys, SORT_ASC, $entries);
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * returns the available groups
187
-	 * @param string $search a search string
188
-	 * @return \OCP\IGroup[]
189
-	 */
190
-	protected function getGroups($search = '') {
191
-		if($this->isAdmin) {
192
-			return $this->groupManager->search($search);
193
-		} else {
194
-			$userObject = $this->userSession->getUser();
195
-			if($userObject !== null) {
196
-				$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
197
-			} else {
198
-				$groups = [];
199
-			}
200
-
201
-			return $groups;
202
-		}
203
-	}
34
+    const SORT_NONE = 0;
35
+    const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends
36
+    const SORT_GROUPNAME = 2;
37
+
38
+    /** @var string */
39
+    protected $user;
40
+    /** @var bool */
41
+    protected $isAdmin;
42
+    /** @var array */
43
+    protected $metaData = array();
44
+    /** @var IGroupManager */
45
+    protected $groupManager;
46
+    /** @var bool */
47
+    protected $sorting = false;
48
+    /** @var IUserSession */
49
+    protected $userSession;
50
+
51
+    /**
52
+     * @param string $user the uid of the current user
53
+     * @param bool $isAdmin whether the current users is an admin
54
+     * @param IGroupManager $groupManager
55
+     * @param IUserManager $userManager
56
+     * @param IUserSession $userSession
57
+     */
58
+    public function __construct(
59
+            $user,
60
+            $isAdmin,
61
+            IGroupManager $groupManager,
62
+            IUserSession $userSession
63
+            ) {
64
+        $this->user = $user;
65
+        $this->isAdmin = (bool)$isAdmin;
66
+        $this->groupManager = $groupManager;
67
+        $this->userSession = $userSession;
68
+    }
69
+
70
+    /**
71
+     * returns an array with meta data about all available groups
72
+     * the array is structured as follows:
73
+     * [0] array containing meta data about admin groups
74
+     * [1] array containing meta data about unprivileged groups
75
+     * @param string $groupSearch only effective when instance was created with
76
+     * isAdmin being true
77
+     * @param string $userSearch the pattern users are search for
78
+     * @return array
79
+     */
80
+    public function get($groupSearch = '', $userSearch = '') {
81
+        $key = $groupSearch . '::' . $userSearch;
82
+        if(isset($this->metaData[$key])) {
83
+            return $this->metaData[$key];
84
+        }
85
+
86
+        $adminGroups = array();
87
+        $groups = array();
88
+        $sortGroupsIndex = 0;
89
+        $sortGroupsKeys = array();
90
+        $sortAdminGroupsIndex = 0;
91
+        $sortAdminGroupsKeys = array();
92
+
93
+        foreach($this->getGroups($groupSearch) as $group) {
94
+            $groupMetaData = $this->generateGroupMetaData($group, $userSearch);
95
+            if (strtolower($group->getGID()) !== 'admin') {
96
+                $this->addEntry(
97
+                    $groups,
98
+                    $sortGroupsKeys,
99
+                    $sortGroupsIndex,
100
+                    $groupMetaData);
101
+            } else {
102
+                //admin group is hard coded to 'admin' for now. In future,
103
+                //backends may define admin groups too. Then the if statement
104
+                //has to be adjusted accordingly.
105
+                $this->addEntry(
106
+                    $adminGroups,
107
+                    $sortAdminGroupsKeys,
108
+                    $sortAdminGroupsIndex,
109
+                    $groupMetaData);
110
+            }
111
+        }
112
+
113
+        //whether sorting is necessary is will be checked in sort()
114
+        $this->sort($groups, $sortGroupsKeys);
115
+        $this->sort($adminGroups, $sortAdminGroupsKeys);
116
+
117
+        $this->metaData[$key] = array($adminGroups, $groups);
118
+        return $this->metaData[$key];
119
+    }
120
+
121
+    /**
122
+     * sets the sort mode, see SORT_* constants for supported modes
123
+     *
124
+     * @param int $sortMode
125
+     */
126
+    public function setSorting($sortMode) {
127
+        switch ($sortMode) {
128
+            case self::SORT_USERCOUNT:
129
+            case self::SORT_GROUPNAME:
130
+                $this->sorting = $sortMode;
131
+                break;
132
+
133
+            default:
134
+                $this->sorting = self::SORT_NONE;
135
+        }
136
+    }
137
+
138
+    /**
139
+     * adds an group entry to the resulting array
140
+     * @param array $entries the resulting array, by reference
141
+     * @param array $sortKeys the sort key array, by reference
142
+     * @param int $sortIndex the sort key index, by reference
143
+     * @param array $data the group's meta data as returned by generateGroupMetaData()
144
+     */
145
+    private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) {
146
+        $entries[] = $data;
147
+        if ($this->sorting === self::SORT_USERCOUNT) {
148
+            $sortKeys[$sortIndex] = $data['usercount'];
149
+            $sortIndex++;
150
+        } else if ($this->sorting === self::SORT_GROUPNAME) {
151
+            $sortKeys[$sortIndex] = $data['name'];
152
+            $sortIndex++;
153
+        }
154
+    }
155
+
156
+    /**
157
+     * creates an array containing the group meta data
158
+     * @param \OCP\IGroup $group
159
+     * @param string $userSearch
160
+     * @return array with the keys 'id', 'name', 'usercount' and 'disabled'
161
+     */
162
+    private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
163
+        return array(
164
+                'id' => $group->getGID(),
165
+                'name' => $group->getDisplayName(),
166
+                'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
167
+                'disabled' => $group->countDisabled()
168
+            );
169
+    }
170
+
171
+    /**
172
+     * sorts the result array, if applicable
173
+     * @param array $entries the result array, by reference
174
+     * @param array $sortKeys the array containing the sort keys
175
+     * @param return null
176
+     */
177
+    private function sort(&$entries, $sortKeys) {
178
+        if ($this->sorting === self::SORT_USERCOUNT) {
179
+            array_multisort($sortKeys, SORT_DESC, $entries);
180
+        } else if ($this->sorting === self::SORT_GROUPNAME) {
181
+            array_multisort($sortKeys, SORT_ASC, $entries);
182
+        }
183
+    }
184
+
185
+    /**
186
+     * returns the available groups
187
+     * @param string $search a search string
188
+     * @return \OCP\IGroup[]
189
+     */
190
+    protected function getGroups($search = '') {
191
+        if($this->isAdmin) {
192
+            return $this->groupManager->search($search);
193
+        } else {
194
+            $userObject = $this->userSession->getUser();
195
+            if($userObject !== null) {
196
+                $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
197
+            } else {
198
+                $groups = [];
199
+            }
200
+
201
+            return $groups;
202
+        }
203
+    }
204 204
 }
Please login to merge, or discard this patch.
lib/private/Group/Database.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -380,7 +380,6 @@
 block discarded – undo
380 380
 	/**
381 381
 	 * get the number of disabled users in a group
382 382
 	 *
383
-	 * @param string $search
384 383
 	 * @return int|bool
385 384
 	 */
386 385
 	public function countDisabledInGroup(string $gid): int {
Please login to merge, or discard this patch.
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -55,357 +55,357 @@
 block discarded – undo
55 55
  * Class for group management in a SQL Database (e.g. MySQL, SQLite)
56 56
  */
57 57
 class Database extends ABackend
58
-	implements IAddToGroupBackend,
59
-			   ICountDisabledInGroup,
60
-	           ICountUsersBackend,
61
-	           ICreateGroupBackend,
62
-	           IDeleteGroupBackend,
63
-	           IRemoveFromGroupBackend {
64
-
65
-	/** @var string[] */
66
-	private $groupCache = [];
67
-
68
-	/** @var IDBConnection */
69
-	private $dbConn;
70
-
71
-	/**
72
-	 * \OC\Group\Database constructor.
73
-	 *
74
-	 * @param IDBConnection|null $dbConn
75
-	 */
76
-	public function __construct(IDBConnection $dbConn = null) {
77
-		$this->dbConn = $dbConn;
78
-	}
79
-
80
-	/**
81
-	 * FIXME: This function should not be required!
82
-	 */
83
-	private function fixDI() {
84
-		if ($this->dbConn === null) {
85
-			$this->dbConn = \OC::$server->getDatabaseConnection();
86
-		}
87
-	}
88
-
89
-	/**
90
-	 * Try to create a new group
91
-	 * @param string $gid The name of the group to create
92
-	 * @return bool
93
-	 *
94
-	 * Tries to create a new group. If the group name already exists, false will
95
-	 * be returned.
96
-	 */
97
-	public function createGroup(string $gid): bool {
98
-		$this->fixDI();
99
-
100
-		// Add group
101
-		$result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [
102
-			'gid' => $gid,
103
-		]);
104
-
105
-		// Add to cache
106
-		$this->groupCache[$gid] = $gid;
107
-
108
-		return $result === 1;
109
-	}
110
-
111
-	/**
112
-	 * delete a group
113
-	 * @param string $gid gid of the group to delete
114
-	 * @return bool
115
-	 *
116
-	 * Deletes a group and removes it from the group_user-table
117
-	 */
118
-	public function deleteGroup(string $gid): bool {
119
-		$this->fixDI();
120
-
121
-		// Delete the group
122
-		$qb = $this->dbConn->getQueryBuilder();
123
-		$qb->delete('groups')
124
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
125
-			->execute();
126
-
127
-		// Delete the group-user relation
128
-		$qb = $this->dbConn->getQueryBuilder();
129
-		$qb->delete('group_user')
130
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
131
-			->execute();
132
-
133
-		// Delete the group-groupadmin relation
134
-		$qb = $this->dbConn->getQueryBuilder();
135
-		$qb->delete('group_admin')
136
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
137
-			->execute();
138
-
139
-		// Delete from cache
140
-		unset($this->groupCache[$gid]);
141
-
142
-		return true;
143
-	}
144
-
145
-	/**
146
-	 * is user in group?
147
-	 * @param string $uid uid of the user
148
-	 * @param string $gid gid of the group
149
-	 * @return bool
150
-	 *
151
-	 * Checks whether the user is member of a group or not.
152
-	 */
153
-	public function inGroup( $uid, $gid ) {
154
-		$this->fixDI();
155
-
156
-		// check
157
-		$qb = $this->dbConn->getQueryBuilder();
158
-		$cursor = $qb->select('uid')
159
-			->from('group_user')
160
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
161
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
162
-			->execute();
163
-
164
-		$result = $cursor->fetch();
165
-		$cursor->closeCursor();
166
-
167
-		return $result ? true : false;
168
-	}
169
-
170
-	/**
171
-	 * Add a user to a group
172
-	 * @param string $uid Name of the user to add to group
173
-	 * @param string $gid Name of the group in which add the user
174
-	 * @return bool
175
-	 *
176
-	 * Adds a user to a group.
177
-	 */
178
-	public function addToGroup(string $uid, string $gid): bool {
179
-		$this->fixDI();
180
-
181
-		// No duplicate entries!
182
-		if( !$this->inGroup( $uid, $gid )) {
183
-			$qb = $this->dbConn->getQueryBuilder();
184
-			$qb->insert('group_user')
185
-				->setValue('uid', $qb->createNamedParameter($uid))
186
-				->setValue('gid', $qb->createNamedParameter($gid))
187
-				->execute();
188
-			return true;
189
-		}else{
190
-			return false;
191
-		}
192
-	}
193
-
194
-	/**
195
-	 * Removes a user from a group
196
-	 * @param string $uid Name of the user to remove from group
197
-	 * @param string $gid Name of the group from which remove the user
198
-	 * @return bool
199
-	 *
200
-	 * removes the user from a group.
201
-	 */
202
-	public function removeFromGroup(string $uid, string $gid): bool {
203
-		$this->fixDI();
204
-
205
-		$qb = $this->dbConn->getQueryBuilder();
206
-		$qb->delete('group_user')
207
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
208
-			->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
209
-			->execute();
210
-
211
-		return true;
212
-	}
213
-
214
-	/**
215
-	 * Get all groups a user belongs to
216
-	 * @param string $uid Name of the user
217
-	 * @return array an array of group names
218
-	 *
219
-	 * This function fetches all groups a user belongs to. It does not check
220
-	 * if the user exists at all.
221
-	 */
222
-	public function getUserGroups( $uid ) {
223
-		//guests has empty or null $uid
224
-		if ($uid === null || $uid === '') {
225
-			return [];
226
-		}
227
-
228
-		$this->fixDI();
229
-
230
-		// No magic!
231
-		$qb = $this->dbConn->getQueryBuilder();
232
-		$cursor = $qb->select('gid')
233
-			->from('group_user')
234
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
235
-			->execute();
236
-
237
-		$groups = [];
238
-		while( $row = $cursor->fetch()) {
239
-			$groups[] = $row['gid'];
240
-			$this->groupCache[$row['gid']] = $row['gid'];
241
-		}
242
-		$cursor->closeCursor();
243
-
244
-		return $groups;
245
-	}
246
-
247
-	/**
248
-	 * get a list of all groups
249
-	 * @param string $search
250
-	 * @param int $limit
251
-	 * @param int $offset
252
-	 * @return array an array of group names
253
-	 *
254
-	 * Returns a list with all groups
255
-	 */
256
-	public function getGroups($search = '', $limit = null, $offset = null) {
257
-		$this->fixDI();
258
-
259
-		$query = $this->dbConn->getQueryBuilder();
260
-		$query->select('gid')
261
-			->from('groups')
262
-			->orderBy('gid', 'ASC');
263
-
264
-		if ($search !== '') {
265
-			$query->where($query->expr()->iLike('gid', $query->createNamedParameter(
266
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
267
-			)));
268
-		}
269
-
270
-		$query->setMaxResults($limit)
271
-			->setFirstResult($offset);
272
-		$result = $query->execute();
273
-
274
-		$groups = [];
275
-		while ($row = $result->fetch()) {
276
-			$groups[] = $row['gid'];
277
-		}
278
-		$result->closeCursor();
279
-
280
-		return $groups;
281
-	}
282
-
283
-	/**
284
-	 * check if a group exists
285
-	 * @param string $gid
286
-	 * @return bool
287
-	 */
288
-	public function groupExists($gid) {
289
-		$this->fixDI();
290
-
291
-		// Check cache first
292
-		if (isset($this->groupCache[$gid])) {
293
-			return true;
294
-		}
295
-
296
-		$qb = $this->dbConn->getQueryBuilder();
297
-		$cursor = $qb->select('gid')
298
-			->from('groups')
299
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
300
-			->execute();
301
-		$result = $cursor->fetch();
302
-		$cursor->closeCursor();
303
-
304
-		if ($result !== false) {
305
-			$this->groupCache[$gid] = $gid;
306
-			return true;
307
-		}
308
-		return false;
309
-	}
310
-
311
-	/**
312
-	 * get a list of all users in a group
313
-	 * @param string $gid
314
-	 * @param string $search
315
-	 * @param int $limit
316
-	 * @param int $offset
317
-	 * @return array an array of user ids
318
-	 */
319
-	public function usersInGroup($gid, $search = '', $limit = null, $offset = null) {
320
-		$this->fixDI();
321
-
322
-		$query = $this->dbConn->getQueryBuilder();
323
-		$query->select('uid')
324
-			->from('group_user')
325
-			->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
326
-			->orderBy('uid', 'ASC');
327
-
328
-		if ($search !== '') {
329
-			$query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
330
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
331
-			)));
332
-		}
333
-
334
-		$query->setMaxResults($limit)
335
-			->setFirstResult($offset);
336
-		$result = $query->execute();
337
-
338
-		$users = [];
339
-		while ($row = $result->fetch()) {
340
-			$users[] = $row['uid'];
341
-		}
342
-		$result->closeCursor();
343
-
344
-		return $users;
345
-	}
346
-
347
-	/**
348
-	 * get the number of all users matching the search string in a group
349
-	 * @param string $gid
350
-	 * @param string $search
351
-	 * @return int
352
-	 */
353
-	public function countUsersInGroup(string $gid, string $search = ''): int {
354
-		$this->fixDI();
355
-
356
-		$query = $this->dbConn->getQueryBuilder();
357
-		$query->selectAlias($query->createFunction('COUNT(*)'), 'num_users')
358
-			->from('group_user')
359
-			->where($query->expr()->eq('gid', $query->createNamedParameter($gid)));
360
-
361
-		if ($search !== '') {
362
-			$query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
363
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
364
-			)));
365
-		}
366
-
367
-		$result = $query->execute();
368
-		$count = $result->fetchColumn();
369
-		$result->closeCursor();
370
-
371
-		if ($count !== false) {
372
-			$count = (int)$count;
373
-		} else {
374
-			$count = 0;
375
-		}
376
-
377
-		return $count;
378
-	}
379
-
380
-	/**
381
-	 * get the number of disabled users in a group
382
-	 *
383
-	 * @param string $search
384
-	 * @return int|bool
385
-	 */
386
-	public function countDisabledInGroup(string $gid): int {
387
-		$this->fixDI();
58
+    implements IAddToGroupBackend,
59
+                ICountDisabledInGroup,
60
+                ICountUsersBackend,
61
+                ICreateGroupBackend,
62
+                IDeleteGroupBackend,
63
+                IRemoveFromGroupBackend {
64
+
65
+    /** @var string[] */
66
+    private $groupCache = [];
67
+
68
+    /** @var IDBConnection */
69
+    private $dbConn;
70
+
71
+    /**
72
+     * \OC\Group\Database constructor.
73
+     *
74
+     * @param IDBConnection|null $dbConn
75
+     */
76
+    public function __construct(IDBConnection $dbConn = null) {
77
+        $this->dbConn = $dbConn;
78
+    }
79
+
80
+    /**
81
+     * FIXME: This function should not be required!
82
+     */
83
+    private function fixDI() {
84
+        if ($this->dbConn === null) {
85
+            $this->dbConn = \OC::$server->getDatabaseConnection();
86
+        }
87
+    }
88
+
89
+    /**
90
+     * Try to create a new group
91
+     * @param string $gid The name of the group to create
92
+     * @return bool
93
+     *
94
+     * Tries to create a new group. If the group name already exists, false will
95
+     * be returned.
96
+     */
97
+    public function createGroup(string $gid): bool {
98
+        $this->fixDI();
99
+
100
+        // Add group
101
+        $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [
102
+            'gid' => $gid,
103
+        ]);
104
+
105
+        // Add to cache
106
+        $this->groupCache[$gid] = $gid;
107
+
108
+        return $result === 1;
109
+    }
110
+
111
+    /**
112
+     * delete a group
113
+     * @param string $gid gid of the group to delete
114
+     * @return bool
115
+     *
116
+     * Deletes a group and removes it from the group_user-table
117
+     */
118
+    public function deleteGroup(string $gid): bool {
119
+        $this->fixDI();
120
+
121
+        // Delete the group
122
+        $qb = $this->dbConn->getQueryBuilder();
123
+        $qb->delete('groups')
124
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
125
+            ->execute();
126
+
127
+        // Delete the group-user relation
128
+        $qb = $this->dbConn->getQueryBuilder();
129
+        $qb->delete('group_user')
130
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
131
+            ->execute();
132
+
133
+        // Delete the group-groupadmin relation
134
+        $qb = $this->dbConn->getQueryBuilder();
135
+        $qb->delete('group_admin')
136
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
137
+            ->execute();
138
+
139
+        // Delete from cache
140
+        unset($this->groupCache[$gid]);
141
+
142
+        return true;
143
+    }
144
+
145
+    /**
146
+     * is user in group?
147
+     * @param string $uid uid of the user
148
+     * @param string $gid gid of the group
149
+     * @return bool
150
+     *
151
+     * Checks whether the user is member of a group or not.
152
+     */
153
+    public function inGroup( $uid, $gid ) {
154
+        $this->fixDI();
155
+
156
+        // check
157
+        $qb = $this->dbConn->getQueryBuilder();
158
+        $cursor = $qb->select('uid')
159
+            ->from('group_user')
160
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
161
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
162
+            ->execute();
163
+
164
+        $result = $cursor->fetch();
165
+        $cursor->closeCursor();
166
+
167
+        return $result ? true : false;
168
+    }
169
+
170
+    /**
171
+     * Add a user to a group
172
+     * @param string $uid Name of the user to add to group
173
+     * @param string $gid Name of the group in which add the user
174
+     * @return bool
175
+     *
176
+     * Adds a user to a group.
177
+     */
178
+    public function addToGroup(string $uid, string $gid): bool {
179
+        $this->fixDI();
180
+
181
+        // No duplicate entries!
182
+        if( !$this->inGroup( $uid, $gid )) {
183
+            $qb = $this->dbConn->getQueryBuilder();
184
+            $qb->insert('group_user')
185
+                ->setValue('uid', $qb->createNamedParameter($uid))
186
+                ->setValue('gid', $qb->createNamedParameter($gid))
187
+                ->execute();
188
+            return true;
189
+        }else{
190
+            return false;
191
+        }
192
+    }
193
+
194
+    /**
195
+     * Removes a user from a group
196
+     * @param string $uid Name of the user to remove from group
197
+     * @param string $gid Name of the group from which remove the user
198
+     * @return bool
199
+     *
200
+     * removes the user from a group.
201
+     */
202
+    public function removeFromGroup(string $uid, string $gid): bool {
203
+        $this->fixDI();
204
+
205
+        $qb = $this->dbConn->getQueryBuilder();
206
+        $qb->delete('group_user')
207
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
208
+            ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
209
+            ->execute();
210
+
211
+        return true;
212
+    }
213
+
214
+    /**
215
+     * Get all groups a user belongs to
216
+     * @param string $uid Name of the user
217
+     * @return array an array of group names
218
+     *
219
+     * This function fetches all groups a user belongs to. It does not check
220
+     * if the user exists at all.
221
+     */
222
+    public function getUserGroups( $uid ) {
223
+        //guests has empty or null $uid
224
+        if ($uid === null || $uid === '') {
225
+            return [];
226
+        }
227
+
228
+        $this->fixDI();
229
+
230
+        // No magic!
231
+        $qb = $this->dbConn->getQueryBuilder();
232
+        $cursor = $qb->select('gid')
233
+            ->from('group_user')
234
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
235
+            ->execute();
236
+
237
+        $groups = [];
238
+        while( $row = $cursor->fetch()) {
239
+            $groups[] = $row['gid'];
240
+            $this->groupCache[$row['gid']] = $row['gid'];
241
+        }
242
+        $cursor->closeCursor();
243
+
244
+        return $groups;
245
+    }
246
+
247
+    /**
248
+     * get a list of all groups
249
+     * @param string $search
250
+     * @param int $limit
251
+     * @param int $offset
252
+     * @return array an array of group names
253
+     *
254
+     * Returns a list with all groups
255
+     */
256
+    public function getGroups($search = '', $limit = null, $offset = null) {
257
+        $this->fixDI();
258
+
259
+        $query = $this->dbConn->getQueryBuilder();
260
+        $query->select('gid')
261
+            ->from('groups')
262
+            ->orderBy('gid', 'ASC');
263
+
264
+        if ($search !== '') {
265
+            $query->where($query->expr()->iLike('gid', $query->createNamedParameter(
266
+                '%' . $this->dbConn->escapeLikeParameter($search) . '%'
267
+            )));
268
+        }
269
+
270
+        $query->setMaxResults($limit)
271
+            ->setFirstResult($offset);
272
+        $result = $query->execute();
273
+
274
+        $groups = [];
275
+        while ($row = $result->fetch()) {
276
+            $groups[] = $row['gid'];
277
+        }
278
+        $result->closeCursor();
279
+
280
+        return $groups;
281
+    }
282
+
283
+    /**
284
+     * check if a group exists
285
+     * @param string $gid
286
+     * @return bool
287
+     */
288
+    public function groupExists($gid) {
289
+        $this->fixDI();
290
+
291
+        // Check cache first
292
+        if (isset($this->groupCache[$gid])) {
293
+            return true;
294
+        }
295
+
296
+        $qb = $this->dbConn->getQueryBuilder();
297
+        $cursor = $qb->select('gid')
298
+            ->from('groups')
299
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
300
+            ->execute();
301
+        $result = $cursor->fetch();
302
+        $cursor->closeCursor();
303
+
304
+        if ($result !== false) {
305
+            $this->groupCache[$gid] = $gid;
306
+            return true;
307
+        }
308
+        return false;
309
+    }
310
+
311
+    /**
312
+     * get a list of all users in a group
313
+     * @param string $gid
314
+     * @param string $search
315
+     * @param int $limit
316
+     * @param int $offset
317
+     * @return array an array of user ids
318
+     */
319
+    public function usersInGroup($gid, $search = '', $limit = null, $offset = null) {
320
+        $this->fixDI();
321
+
322
+        $query = $this->dbConn->getQueryBuilder();
323
+        $query->select('uid')
324
+            ->from('group_user')
325
+            ->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
326
+            ->orderBy('uid', 'ASC');
327
+
328
+        if ($search !== '') {
329
+            $query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
330
+                '%' . $this->dbConn->escapeLikeParameter($search) . '%'
331
+            )));
332
+        }
333
+
334
+        $query->setMaxResults($limit)
335
+            ->setFirstResult($offset);
336
+        $result = $query->execute();
337
+
338
+        $users = [];
339
+        while ($row = $result->fetch()) {
340
+            $users[] = $row['uid'];
341
+        }
342
+        $result->closeCursor();
343
+
344
+        return $users;
345
+    }
346
+
347
+    /**
348
+     * get the number of all users matching the search string in a group
349
+     * @param string $gid
350
+     * @param string $search
351
+     * @return int
352
+     */
353
+    public function countUsersInGroup(string $gid, string $search = ''): int {
354
+        $this->fixDI();
355
+
356
+        $query = $this->dbConn->getQueryBuilder();
357
+        $query->selectAlias($query->createFunction('COUNT(*)'), 'num_users')
358
+            ->from('group_user')
359
+            ->where($query->expr()->eq('gid', $query->createNamedParameter($gid)));
360
+
361
+        if ($search !== '') {
362
+            $query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
363
+                '%' . $this->dbConn->escapeLikeParameter($search) . '%'
364
+            )));
365
+        }
366
+
367
+        $result = $query->execute();
368
+        $count = $result->fetchColumn();
369
+        $result->closeCursor();
370
+
371
+        if ($count !== false) {
372
+            $count = (int)$count;
373
+        } else {
374
+            $count = 0;
375
+        }
376
+
377
+        return $count;
378
+    }
379
+
380
+    /**
381
+     * get the number of disabled users in a group
382
+     *
383
+     * @param string $search
384
+     * @return int|bool
385
+     */
386
+    public function countDisabledInGroup(string $gid): int {
387
+        $this->fixDI();
388 388
 		
389
-		$query = $this->dbConn->getQueryBuilder();
390
-		$query->select($query->createFunction('COUNT(Distinct uid)'))
391
-			->from('preferences', 'p')
392
-			->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
393
-			->where($query->expr()->eq('appid', $query->createNamedParameter('core')))
394
-			->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled')))
395
-			->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
396
-			->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR));
389
+        $query = $this->dbConn->getQueryBuilder();
390
+        $query->select($query->createFunction('COUNT(Distinct uid)'))
391
+            ->from('preferences', 'p')
392
+            ->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
393
+            ->where($query->expr()->eq('appid', $query->createNamedParameter('core')))
394
+            ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled')))
395
+            ->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
396
+            ->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR));
397 397
 		
398
-		$result = $query->execute();
399
-		$count = $result->fetchColumn();
400
-		$result->closeCursor();
398
+        $result = $query->execute();
399
+        $count = $result->fetchColumn();
400
+        $result->closeCursor();
401 401
 		
402
-		if ($count !== false) {
403
-			$count = (int)$count;
404
-		} else {
405
-			$count = 0;
406
-		}
407
-
408
-		return $count;
409
-	}
402
+        if ($count !== false) {
403
+            $count = (int)$count;
404
+        } else {
405
+            $count = 0;
406
+        }
407
+
408
+        return $count;
409
+    }
410 410
 
411 411
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * Checks whether the user is member of a group or not.
152 152
 	 */
153
-	public function inGroup( $uid, $gid ) {
153
+	public function inGroup($uid, $gid) {
154 154
 		$this->fixDI();
155 155
 
156 156
 		// check
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 		$this->fixDI();
180 180
 
181 181
 		// No duplicate entries!
182
-		if( !$this->inGroup( $uid, $gid )) {
182
+		if (!$this->inGroup($uid, $gid)) {
183 183
 			$qb = $this->dbConn->getQueryBuilder();
184 184
 			$qb->insert('group_user')
185 185
 				->setValue('uid', $qb->createNamedParameter($uid))
186 186
 				->setValue('gid', $qb->createNamedParameter($gid))
187 187
 				->execute();
188 188
 			return true;
189
-		}else{
189
+		} else {
190 190
 			return false;
191 191
 		}
192 192
 	}
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * This function fetches all groups a user belongs to. It does not check
220 220
 	 * if the user exists at all.
221 221
 	 */
222
-	public function getUserGroups( $uid ) {
222
+	public function getUserGroups($uid) {
223 223
 		//guests has empty or null $uid
224 224
 		if ($uid === null || $uid === '') {
225 225
 			return [];
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 			->execute();
236 236
 
237 237
 		$groups = [];
238
-		while( $row = $cursor->fetch()) {
238
+		while ($row = $cursor->fetch()) {
239 239
 			$groups[] = $row['gid'];
240 240
 			$this->groupCache[$row['gid']] = $row['gid'];
241 241
 		}
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 
264 264
 		if ($search !== '') {
265 265
 			$query->where($query->expr()->iLike('gid', $query->createNamedParameter(
266
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
266
+				'%'.$this->dbConn->escapeLikeParameter($search).'%'
267 267
 			)));
268 268
 		}
269 269
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 		if ($search !== '') {
329 329
 			$query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
330
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
330
+				'%'.$this->dbConn->escapeLikeParameter($search).'%'
331 331
 			)));
332 332
 		}
333 333
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 
361 361
 		if ($search !== '') {
362 362
 			$query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
363
-				'%' . $this->dbConn->escapeLikeParameter($search) . '%'
363
+				'%'.$this->dbConn->escapeLikeParameter($search).'%'
364 364
 			)));
365 365
 		}
366 366
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 		$result->closeCursor();
370 370
 
371 371
 		if ($count !== false) {
372
-			$count = (int)$count;
372
+			$count = (int) $count;
373 373
 		} else {
374 374
 			$count = 0;
375 375
 		}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		$result->closeCursor();
401 401
 		
402 402
 		if ($count !== false) {
403
-			$count = (int)$count;
403
+			$count = (int) $count;
404 404
 		} else {
405 405
 			$count = 0;
406 406
 		}
Please login to merge, or discard this patch.
lib/private/Group/Group.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -35,292 +35,292 @@
 block discarded – undo
35 35
 use OCP\Group\Backend\ICountDisabledInGroup;
36 36
 
37 37
 class Group implements IGroup {
38
-	/** @var null|string  */
39
-	protected $displayName;
38
+    /** @var null|string  */
39
+    protected $displayName;
40 40
 
41
-	/**
42
-	 * @var string $id
43
-	 */
44
-	private $gid;
41
+    /**
42
+     * @var string $id
43
+     */
44
+    private $gid;
45 45
 
46
-	/**
47
-	 * @var \OC\User\User[] $users
48
-	 */
49
-	private $users = array();
46
+    /**
47
+     * @var \OC\User\User[] $users
48
+     */
49
+    private $users = array();
50 50
 
51
-	/**
52
-	 * @var bool $usersLoaded
53
-	 */
54
-	private $usersLoaded;
51
+    /**
52
+     * @var bool $usersLoaded
53
+     */
54
+    private $usersLoaded;
55 55
 
56
-	/**
57
-	 * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend
58
-	 */
59
-	private $backends;
56
+    /**
57
+     * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend
58
+     */
59
+    private $backends;
60 60
 
61
-	/**
62
-	 * @var \OC\Hooks\PublicEmitter $emitter
63
-	 */
64
-	private $emitter;
61
+    /**
62
+     * @var \OC\Hooks\PublicEmitter $emitter
63
+     */
64
+    private $emitter;
65 65
 
66
-	/**
67
-	 * @var \OC\User\Manager $userManager
68
-	 */
69
-	private $userManager;
66
+    /**
67
+     * @var \OC\User\Manager $userManager
68
+     */
69
+    private $userManager;
70 70
 
71
-	/**
72
-	 * @param string $gid
73
-	 * @param \OC\Group\Backend[] $backends
74
-	 * @param \OC\User\Manager $userManager
75
-	 * @param \OC\Hooks\PublicEmitter $emitter
76
-	 * @param string $displayName
77
-	 */
78
-	public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
79
-		$this->gid = $gid;
80
-		$this->backends = $backends;
81
-		$this->userManager = $userManager;
82
-		$this->emitter = $emitter;
83
-		$this->displayName = $displayName;
84
-	}
71
+    /**
72
+     * @param string $gid
73
+     * @param \OC\Group\Backend[] $backends
74
+     * @param \OC\User\Manager $userManager
75
+     * @param \OC\Hooks\PublicEmitter $emitter
76
+     * @param string $displayName
77
+     */
78
+    public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
79
+        $this->gid = $gid;
80
+        $this->backends = $backends;
81
+        $this->userManager = $userManager;
82
+        $this->emitter = $emitter;
83
+        $this->displayName = $displayName;
84
+    }
85 85
 
86
-	public function getGID() {
87
-		return $this->gid;
88
-	}
86
+    public function getGID() {
87
+        return $this->gid;
88
+    }
89 89
 
90
-	public function getDisplayName() {
91
-		if (is_null($this->displayName)) {
92
-			return $this->gid;
93
-		}
94
-		return $this->displayName;
95
-	}
90
+    public function getDisplayName() {
91
+        if (is_null($this->displayName)) {
92
+            return $this->gid;
93
+        }
94
+        return $this->displayName;
95
+    }
96 96
 
97
-	/**
98
-	 * get all users in the group
99
-	 *
100
-	 * @return \OC\User\User[]
101
-	 */
102
-	public function getUsers() {
103
-		if ($this->usersLoaded) {
104
-			return $this->users;
105
-		}
97
+    /**
98
+     * get all users in the group
99
+     *
100
+     * @return \OC\User\User[]
101
+     */
102
+    public function getUsers() {
103
+        if ($this->usersLoaded) {
104
+            return $this->users;
105
+        }
106 106
 
107
-		$userIds = array();
108
-		foreach ($this->backends as $backend) {
109
-			$diff = array_diff(
110
-				$backend->usersInGroup($this->gid),
111
-				$userIds
112
-			);
113
-			if ($diff) {
114
-				$userIds = array_merge($userIds, $diff);
115
-			}
116
-		}
107
+        $userIds = array();
108
+        foreach ($this->backends as $backend) {
109
+            $diff = array_diff(
110
+                $backend->usersInGroup($this->gid),
111
+                $userIds
112
+            );
113
+            if ($diff) {
114
+                $userIds = array_merge($userIds, $diff);
115
+            }
116
+        }
117 117
 
118
-		$this->users = $this->getVerifiedUsers($userIds);
119
-		$this->usersLoaded = true;
120
-		return $this->users;
121
-	}
118
+        $this->users = $this->getVerifiedUsers($userIds);
119
+        $this->usersLoaded = true;
120
+        return $this->users;
121
+    }
122 122
 
123
-	/**
124
-	 * check if a user is in the group
125
-	 *
126
-	 * @param IUser $user
127
-	 * @return bool
128
-	 */
129
-	public function inGroup(IUser $user) {
130
-		if (isset($this->users[$user->getUID()])) {
131
-			return true;
132
-		}
133
-		foreach ($this->backends as $backend) {
134
-			if ($backend->inGroup($user->getUID(), $this->gid)) {
135
-				$this->users[$user->getUID()] = $user;
136
-				return true;
137
-			}
138
-		}
139
-		return false;
140
-	}
123
+    /**
124
+     * check if a user is in the group
125
+     *
126
+     * @param IUser $user
127
+     * @return bool
128
+     */
129
+    public function inGroup(IUser $user) {
130
+        if (isset($this->users[$user->getUID()])) {
131
+            return true;
132
+        }
133
+        foreach ($this->backends as $backend) {
134
+            if ($backend->inGroup($user->getUID(), $this->gid)) {
135
+                $this->users[$user->getUID()] = $user;
136
+                return true;
137
+            }
138
+        }
139
+        return false;
140
+    }
141 141
 
142
-	/**
143
-	 * add a user to the group
144
-	 *
145
-	 * @param IUser $user
146
-	 */
147
-	public function addUser(IUser $user) {
148
-		if ($this->inGroup($user)) {
149
-			return;
150
-		}
142
+    /**
143
+     * add a user to the group
144
+     *
145
+     * @param IUser $user
146
+     */
147
+    public function addUser(IUser $user) {
148
+        if ($this->inGroup($user)) {
149
+            return;
150
+        }
151 151
 
152
-		if ($this->emitter) {
153
-			$this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
154
-		}
155
-		foreach ($this->backends as $backend) {
156
-			if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) {
157
-				$backend->addToGroup($user->getUID(), $this->gid);
158
-				if ($this->users) {
159
-					$this->users[$user->getUID()] = $user;
160
-				}
161
-				if ($this->emitter) {
162
-					$this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
163
-				}
164
-				return;
165
-			}
166
-		}
167
-	}
152
+        if ($this->emitter) {
153
+            $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
154
+        }
155
+        foreach ($this->backends as $backend) {
156
+            if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) {
157
+                $backend->addToGroup($user->getUID(), $this->gid);
158
+                if ($this->users) {
159
+                    $this->users[$user->getUID()] = $user;
160
+                }
161
+                if ($this->emitter) {
162
+                    $this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
163
+                }
164
+                return;
165
+            }
166
+        }
167
+    }
168 168
 
169
-	/**
170
-	 * remove a user from the group
171
-	 *
172
-	 * @param \OC\User\User $user
173
-	 */
174
-	public function removeUser($user) {
175
-		$result = false;
176
-		if ($this->emitter) {
177
-			$this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
178
-		}
179
-		foreach ($this->backends as $backend) {
180
-			if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
181
-				$backend->removeFromGroup($user->getUID(), $this->gid);
182
-				$result = true;
183
-			}
184
-		}
185
-		if ($result) {
186
-			if ($this->emitter) {
187
-				$this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
188
-			}
189
-			if ($this->users) {
190
-				foreach ($this->users as $index => $groupUser) {
191
-					if ($groupUser->getUID() === $user->getUID()) {
192
-						unset($this->users[$index]);
193
-						return;
194
-					}
195
-				}
196
-			}
197
-		}
198
-	}
169
+    /**
170
+     * remove a user from the group
171
+     *
172
+     * @param \OC\User\User $user
173
+     */
174
+    public function removeUser($user) {
175
+        $result = false;
176
+        if ($this->emitter) {
177
+            $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
178
+        }
179
+        foreach ($this->backends as $backend) {
180
+            if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
181
+                $backend->removeFromGroup($user->getUID(), $this->gid);
182
+                $result = true;
183
+            }
184
+        }
185
+        if ($result) {
186
+            if ($this->emitter) {
187
+                $this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
188
+            }
189
+            if ($this->users) {
190
+                foreach ($this->users as $index => $groupUser) {
191
+                    if ($groupUser->getUID() === $user->getUID()) {
192
+                        unset($this->users[$index]);
193
+                        return;
194
+                    }
195
+                }
196
+            }
197
+        }
198
+    }
199 199
 
200
-	/**
201
-	 * search for users in the group by userid
202
-	 *
203
-	 * @param string $search
204
-	 * @param int $limit
205
-	 * @param int $offset
206
-	 * @return \OC\User\User[]
207
-	 */
208
-	public function searchUsers($search, $limit = null, $offset = null) {
209
-		$users = array();
210
-		foreach ($this->backends as $backend) {
211
-			$userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
212
-			$users += $this->getVerifiedUsers($userIds);
213
-			if (!is_null($limit) and $limit <= 0) {
214
-				return array_values($users);
215
-			}
216
-		}
217
-		return array_values($users);
218
-	}
200
+    /**
201
+     * search for users in the group by userid
202
+     *
203
+     * @param string $search
204
+     * @param int $limit
205
+     * @param int $offset
206
+     * @return \OC\User\User[]
207
+     */
208
+    public function searchUsers($search, $limit = null, $offset = null) {
209
+        $users = array();
210
+        foreach ($this->backends as $backend) {
211
+            $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
212
+            $users += $this->getVerifiedUsers($userIds);
213
+            if (!is_null($limit) and $limit <= 0) {
214
+                return array_values($users);
215
+            }
216
+        }
217
+        return array_values($users);
218
+    }
219 219
 
220
-	/**
221
-	 * returns the number of users matching the search string
222
-	 *
223
-	 * @param string $search
224
-	 * @return int|bool
225
-	 */
226
-	public function count($search = '') {
227
-		$users = false;
228
-		foreach ($this->backends as $backend) {
229
-			if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
230
-				if($users === false) {
231
-					//we could directly add to a bool variable, but this would
232
-					//be ugly
233
-					$users = 0;
234
-				}
235
-				$users += $backend->countUsersInGroup($this->gid, $search);
236
-			}
237
-		}
238
-		return $users;
239
-	}
220
+    /**
221
+     * returns the number of users matching the search string
222
+     *
223
+     * @param string $search
224
+     * @return int|bool
225
+     */
226
+    public function count($search = '') {
227
+        $users = false;
228
+        foreach ($this->backends as $backend) {
229
+            if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
230
+                if($users === false) {
231
+                    //we could directly add to a bool variable, but this would
232
+                    //be ugly
233
+                    $users = 0;
234
+                }
235
+                $users += $backend->countUsersInGroup($this->gid, $search);
236
+            }
237
+        }
238
+        return $users;
239
+    }
240 240
 
241
-	/**
242
-	 * returns the number of disabled users
243
-	 *
244
-	 * @return int|bool
245
-	 */
246
-	public function countDisabled() {
247
-		$users = false;
248
-		foreach ($this->backends as $backend) {
249
-			if($backend instanceOf ICountDisabledInGroup) {
250
-				if($users === false) {
251
-					//we could directly add to a bool variable, but this would
252
-					//be ugly
253
-					$users = 0;
254
-				}
255
-				$users += $backend->countDisabledInGroup($this->gid);
256
-			}
257
-		}
258
-		return $users;
259
-	}
241
+    /**
242
+     * returns the number of disabled users
243
+     *
244
+     * @return int|bool
245
+     */
246
+    public function countDisabled() {
247
+        $users = false;
248
+        foreach ($this->backends as $backend) {
249
+            if($backend instanceOf ICountDisabledInGroup) {
250
+                if($users === false) {
251
+                    //we could directly add to a bool variable, but this would
252
+                    //be ugly
253
+                    $users = 0;
254
+                }
255
+                $users += $backend->countDisabledInGroup($this->gid);
256
+            }
257
+        }
258
+        return $users;
259
+    }
260 260
 
261
-	/**
262
-	 * search for users in the group by displayname
263
-	 *
264
-	 * @param string $search
265
-	 * @param int $limit
266
-	 * @param int $offset
267
-	 * @return \OC\User\User[]
268
-	 */
269
-	public function searchDisplayName($search, $limit = null, $offset = null) {
270
-		$users = array();
271
-		foreach ($this->backends as $backend) {
272
-			$userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
273
-			$users = $this->getVerifiedUsers($userIds);
274
-			if (!is_null($limit) and $limit <= 0) {
275
-				return array_values($users);
276
-			}
277
-		}
278
-		return array_values($users);
279
-	}
261
+    /**
262
+     * search for users in the group by displayname
263
+     *
264
+     * @param string $search
265
+     * @param int $limit
266
+     * @param int $offset
267
+     * @return \OC\User\User[]
268
+     */
269
+    public function searchDisplayName($search, $limit = null, $offset = null) {
270
+        $users = array();
271
+        foreach ($this->backends as $backend) {
272
+            $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
273
+            $users = $this->getVerifiedUsers($userIds);
274
+            if (!is_null($limit) and $limit <= 0) {
275
+                return array_values($users);
276
+            }
277
+        }
278
+        return array_values($users);
279
+    }
280 280
 
281
-	/**
282
-	 * delete the group
283
-	 *
284
-	 * @return bool
285
-	 */
286
-	public function delete() {
287
-		// Prevent users from deleting group admin
288
-		if ($this->getGID() === 'admin') {
289
-			return false;
290
-		}
281
+    /**
282
+     * delete the group
283
+     *
284
+     * @return bool
285
+     */
286
+    public function delete() {
287
+        // Prevent users from deleting group admin
288
+        if ($this->getGID() === 'admin') {
289
+            return false;
290
+        }
291 291
 
292
-		$result = false;
293
-		if ($this->emitter) {
294
-			$this->emitter->emit('\OC\Group', 'preDelete', array($this));
295
-		}
296
-		foreach ($this->backends as $backend) {
297
-			if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) {
298
-				$result = true;
299
-				$backend->deleteGroup($this->gid);
300
-			}
301
-		}
302
-		if ($result and $this->emitter) {
303
-			$this->emitter->emit('\OC\Group', 'postDelete', array($this));
304
-		}
305
-		return $result;
306
-	}
292
+        $result = false;
293
+        if ($this->emitter) {
294
+            $this->emitter->emit('\OC\Group', 'preDelete', array($this));
295
+        }
296
+        foreach ($this->backends as $backend) {
297
+            if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) {
298
+                $result = true;
299
+                $backend->deleteGroup($this->gid);
300
+            }
301
+        }
302
+        if ($result and $this->emitter) {
303
+            $this->emitter->emit('\OC\Group', 'postDelete', array($this));
304
+        }
305
+        return $result;
306
+    }
307 307
 
308
-	/**
309
-	 * returns all the Users from an array that really exists
310
-	 * @param string[] $userIds an array containing user IDs
311
-	 * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
312
-	 */
313
-	private function getVerifiedUsers($userIds) {
314
-		if (!is_array($userIds)) {
315
-			return array();
316
-		}
317
-		$users = array();
318
-		foreach ($userIds as $userId) {
319
-			$user = $this->userManager->get($userId);
320
-			if (!is_null($user)) {
321
-				$users[$userId] = $user;
322
-			}
323
-		}
324
-		return $users;
325
-	}
308
+    /**
309
+     * returns all the Users from an array that really exists
310
+     * @param string[] $userIds an array containing user IDs
311
+     * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
312
+     */
313
+    private function getVerifiedUsers($userIds) {
314
+        if (!is_array($userIds)) {
315
+            return array();
316
+        }
317
+        $users = array();
318
+        foreach ($userIds as $userId) {
319
+            $user = $this->userManager->get($userId);
320
+            if (!is_null($user)) {
321
+                $users[$userId] = $user;
322
+            }
323
+        }
324
+        return $users;
325
+    }
326 326
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	public function count($search = '') {
227 227
 		$users = false;
228 228
 		foreach ($this->backends as $backend) {
229
-			if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
230
-				if($users === false) {
229
+			if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
230
+				if ($users === false) {
231 231
 					//we could directly add to a bool variable, but this would
232 232
 					//be ugly
233 233
 					$users = 0;
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	public function countDisabled() {
247 247
 		$users = false;
248 248
 		foreach ($this->backends as $backend) {
249
-			if($backend instanceOf ICountDisabledInGroup) {
250
-				if($users === false) {
249
+			if ($backend instanceOf ICountDisabledInGroup) {
250
+				if ($users === false) {
251 251
 					//we could directly add to a bool variable, but this would
252 252
 					//be ugly
253 253
 					$users = 0;
Please login to merge, or discard this patch.
lib/private/User/Manager.php 2 patches
Indentation   +515 added lines, -515 removed lines patch added patch discarded remove patch
@@ -57,523 +57,523 @@
 block discarded – undo
57 57
  * @package OC\User
58 58
  */
59 59
 class Manager extends PublicEmitter implements IUserManager {
60
-	/**
61
-	 * @var \OCP\UserInterface[] $backends
62
-	 */
63
-	private $backends = array();
64
-
65
-	/**
66
-	 * @var \OC\User\User[] $cachedUsers
67
-	 */
68
-	private $cachedUsers = array();
69
-
70
-	/**
71
-	 * @var \OCP\IConfig $config
72
-	 */
73
-	private $config;
74
-
75
-	/**
76
-	 * @param \OCP\IConfig $config
77
-	 */
78
-	public function __construct(IConfig $config) {
79
-		$this->config = $config;
80
-		$cachedUsers = &$this->cachedUsers;
81
-		$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
82
-			/** @var \OC\User\User $user */
83
-			unset($cachedUsers[$user->getUID()]);
84
-		});
85
-	}
86
-
87
-	/**
88
-	 * Get the active backends
89
-	 * @return \OCP\UserInterface[]
90
-	 */
91
-	public function getBackends() {
92
-		return $this->backends;
93
-	}
94
-
95
-	/**
96
-	 * register a user backend
97
-	 *
98
-	 * @param \OCP\UserInterface $backend
99
-	 */
100
-	public function registerBackend($backend) {
101
-		$this->backends[] = $backend;
102
-	}
103
-
104
-	/**
105
-	 * remove a user backend
106
-	 *
107
-	 * @param \OCP\UserInterface $backend
108
-	 */
109
-	public function removeBackend($backend) {
110
-		$this->cachedUsers = array();
111
-		if (($i = array_search($backend, $this->backends)) !== false) {
112
-			unset($this->backends[$i]);
113
-		}
114
-	}
115
-
116
-	/**
117
-	 * remove all user backends
118
-	 */
119
-	public function clearBackends() {
120
-		$this->cachedUsers = array();
121
-		$this->backends = array();
122
-	}
123
-
124
-	/**
125
-	 * get a user by user id
126
-	 *
127
-	 * @param string $uid
128
-	 * @return \OC\User\User|null Either the user or null if the specified user does not exist
129
-	 */
130
-	public function get($uid) {
131
-		if (is_null($uid) || $uid === '' || $uid === false) {
132
-			return null;
133
-		}
134
-		if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends
135
-			return $this->cachedUsers[$uid];
136
-		}
137
-		foreach ($this->backends as $backend) {
138
-			if ($backend->userExists($uid)) {
139
-				return $this->getUserObject($uid, $backend);
140
-			}
141
-		}
142
-		return null;
143
-	}
144
-
145
-	/**
146
-	 * get or construct the user object
147
-	 *
148
-	 * @param string $uid
149
-	 * @param \OCP\UserInterface $backend
150
-	 * @param bool $cacheUser If false the newly created user object will not be cached
151
-	 * @return \OC\User\User
152
-	 */
153
-	protected function getUserObject($uid, $backend, $cacheUser = true) {
154
-		if (isset($this->cachedUsers[$uid])) {
155
-			return $this->cachedUsers[$uid];
156
-		}
157
-
158
-		$user = new User($uid, $backend, $this, $this->config);
159
-		if ($cacheUser) {
160
-			$this->cachedUsers[$uid] = $user;
161
-		}
162
-		return $user;
163
-	}
164
-
165
-	/**
166
-	 * check if a user exists
167
-	 *
168
-	 * @param string $uid
169
-	 * @return bool
170
-	 */
171
-	public function userExists($uid) {
172
-		$user = $this->get($uid);
173
-		return ($user !== null);
174
-	}
175
-
176
-	/**
177
-	 * Check if the password is valid for the user
178
-	 *
179
-	 * @param string $loginName
180
-	 * @param string $password
181
-	 * @return mixed the User object on success, false otherwise
182
-	 */
183
-	public function checkPassword($loginName, $password) {
184
-		$result = $this->checkPasswordNoLogging($loginName, $password);
185
-
186
-		if ($result === false) {
187
-			\OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
188
-		}
189
-
190
-		return $result;
191
-	}
192
-
193
-	/**
194
-	 * Check if the password is valid for the user
195
-	 *
196
-	 * @internal
197
-	 * @param string $loginName
198
-	 * @param string $password
199
-	 * @return mixed the User object on success, false otherwise
200
-	 */
201
-	public function checkPasswordNoLogging($loginName, $password) {
202
-		$loginName = str_replace("\0", '', $loginName);
203
-		$password = str_replace("\0", '', $password);
204
-
205
-		foreach ($this->backends as $backend) {
206
-			if ($backend->implementsActions(Backend::CHECK_PASSWORD)) {
207
-				$uid = $backend->checkPassword($loginName, $password);
208
-				if ($uid !== false) {
209
-					return $this->getUserObject($uid, $backend);
210
-				}
211
-			}
212
-		}
213
-
214
-		return false;
215
-	}
216
-
217
-	/**
218
-	 * search by user id
219
-	 *
220
-	 * @param string $pattern
221
-	 * @param int $limit
222
-	 * @param int $offset
223
-	 * @return \OC\User\User[]
224
-	 */
225
-	public function search($pattern, $limit = null, $offset = null) {
226
-		$users = array();
227
-		foreach ($this->backends as $backend) {
228
-			$backendUsers = $backend->getUsers($pattern, $limit, $offset);
229
-			if (is_array($backendUsers)) {
230
-				foreach ($backendUsers as $uid) {
231
-					$users[$uid] = $this->getUserObject($uid, $backend);
232
-				}
233
-			}
234
-		}
235
-
236
-		uasort($users, function ($a, $b) {
237
-			/**
238
-			 * @var \OC\User\User $a
239
-			 * @var \OC\User\User $b
240
-			 */
241
-			return strcmp($a->getUID(), $b->getUID());
242
-		});
243
-		return $users;
244
-	}
245
-
246
-	/**
247
-	 * search by displayName
248
-	 *
249
-	 * @param string $pattern
250
-	 * @param int $limit
251
-	 * @param int $offset
252
-	 * @return \OC\User\User[]
253
-	 */
254
-	public function searchDisplayName($pattern, $limit = null, $offset = null) {
255
-		$users = array();
256
-		foreach ($this->backends as $backend) {
257
-			$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
258
-			if (is_array($backendUsers)) {
259
-				foreach ($backendUsers as $uid => $displayName) {
260
-					$users[] = $this->getUserObject($uid, $backend);
261
-				}
262
-			}
263
-		}
264
-
265
-		usort($users, function ($a, $b) {
266
-			/**
267
-			 * @var \OC\User\User $a
268
-			 * @var \OC\User\User $b
269
-			 */
270
-			return strcmp(strtolower($a->getDisplayName()), strtolower($b->getDisplayName()));
271
-		});
272
-		return $users;
273
-	}
274
-
275
-	/**
276
-	 * @param string $uid
277
-	 * @param string $password
278
-	 * @throws \InvalidArgumentException
279
-	 * @return bool|IUser the created user or false
280
-	 */
281
-	public function createUser($uid, $password) {
282
-		$localBackends = [];
283
-		foreach ($this->backends as $backend) {
284
-			if ($backend instanceof Database) {
285
-				// First check if there is another user backend
286
-				$localBackends[] = $backend;
287
-				continue;
288
-			}
289
-
290
-			if ($backend->implementsActions(Backend::CREATE_USER)) {
291
-				return $this->createUserFromBackend($uid, $password, $backend);
292
-			}
293
-		}
294
-
295
-		foreach ($localBackends as $backend) {
296
-			if ($backend->implementsActions(Backend::CREATE_USER)) {
297
-				return $this->createUserFromBackend($uid, $password, $backend);
298
-			}
299
-		}
300
-
301
-		return false;
302
-	}
303
-
304
-	/**
305
-	 * @param string $uid
306
-	 * @param string $password
307
-	 * @param UserInterface $backend
308
-	 * @return IUser|null
309
-	 * @throws \InvalidArgumentException
310
-	 */
311
-	public function createUserFromBackend($uid, $password, UserInterface $backend) {
312
-		$l = \OC::$server->getL10N('lib');
313
-
314
-		// Check the name for bad characters
315
-		// Allowed are: "a-z", "A-Z", "0-9" and "_.@-'"
316
-		if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $uid)) {
317
-			throw new \InvalidArgumentException($l->t('Only the following characters are allowed in a username:'
318
-				. ' "a-z", "A-Z", "0-9", and "_.@-\'"'));
319
-		}
320
-		// No empty username
321
-		if (trim($uid) === '') {
322
-			throw new \InvalidArgumentException($l->t('A valid username must be provided'));
323
-		}
324
-		// No whitespace at the beginning or at the end
325
-		if (trim($uid) !== $uid) {
326
-			throw new \InvalidArgumentException($l->t('Username contains whitespace at the beginning or at the end'));
327
-		}
328
-		// Username only consists of 1 or 2 dots (directory traversal)
329
-		if ($uid === '.' || $uid === '..') {
330
-			throw new \InvalidArgumentException($l->t('Username must not consist of dots only'));
331
-		}
332
-		// No empty password
333
-		if (trim($password) === '') {
334
-			throw new \InvalidArgumentException($l->t('A valid password must be provided'));
335
-		}
336
-
337
-		// Check if user already exists
338
-		if ($this->userExists($uid)) {
339
-			throw new \InvalidArgumentException($l->t('The username is already being used'));
340
-		}
341
-
342
-		$this->emit('\OC\User', 'preCreateUser', [$uid, $password]);
343
-		$state = $backend->createUser($uid, $password);
344
-		if($state === false) {
345
-			throw new \InvalidArgumentException($l->t('Could not create user'));
346
-		}
347
-		$user = $this->getUserObject($uid, $backend);
348
-		if ($user instanceof IUser) {
349
-			$this->emit('\OC\User', 'postCreateUser', [$user, $password]);
350
-		}
351
-		return $user;
352
-	}
353
-
354
-	/**
355
-	 * returns how many users per backend exist (if supported by backend)
356
-	 *
357
-	 * @param boolean $hasLoggedIn when true only users that have a lastLogin
358
-	 *                entry in the preferences table will be affected
359
-	 * @return array|int an array of backend class as key and count number as value
360
-	 *                if $hasLoggedIn is true only an int is returned
361
-	 */
362
-	public function countUsers($hasLoggedIn = false) {
363
-		if ($hasLoggedIn) {
364
-			return $this->countSeenUsers();
365
-		}
366
-		$userCountStatistics = [];
367
-		foreach ($this->backends as $backend) {
368
-			if ($backend->implementsActions(Backend::COUNT_USERS)) {
369
-				$backendUsers = $backend->countUsers();
370
-				if($backendUsers !== false) {
371
-					if($backend instanceof IUserBackend) {
372
-						$name = $backend->getBackendName();
373
-					} else {
374
-						$name = get_class($backend);
375
-					}
376
-					if(isset($userCountStatistics[$name])) {
377
-						$userCountStatistics[$name] += $backendUsers;
378
-					} else {
379
-						$userCountStatistics[$name] = $backendUsers;
380
-					}
381
-				}
382
-			}
383
-		}
384
-		return $userCountStatistics;
385
-	}
386
-
387
-	/**
388
-	 * The callback is executed for each user on each backend.
389
-	 * If the callback returns false no further users will be retrieved.
390
-	 *
391
-	 * @param \Closure $callback
392
-	 * @param string $search
393
-	 * @param boolean $onlySeen when true only users that have a lastLogin entry
394
-	 *                in the preferences table will be affected
395
-	 * @since 9.0.0
396
-	 */
397
-	public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = false) {
398
-		if ($onlySeen) {
399
-			$this->callForSeenUsers($callback);
400
-		} else {
401
-			foreach ($this->getBackends() as $backend) {
402
-				$limit = 500;
403
-				$offset = 0;
404
-				do {
405
-					$users = $backend->getUsers($search, $limit, $offset);
406
-					foreach ($users as $uid) {
407
-						if (!$backend->userExists($uid)) {
408
-							continue;
409
-						}
410
-						$user = $this->getUserObject($uid, $backend, false);
411
-						$return = $callback($user);
412
-						if ($return === false) {
413
-							break;
414
-						}
415
-					}
416
-					$offset += $limit;
417
-				} while (count($users) >= $limit);
418
-			}
419
-		}
420
-	}
421
-
422
-	/**
423
-	 * returns how many users are disabled
424
-	 *
425
-	 * @return int
426
-	 * @since 12.0.0
427
-	 */
428
-	public function countDisabledUsers(): int {
429
-		$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
430
-		$queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
431
-			->from('preferences')
432
-			->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
433
-			->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
434
-			->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR));
60
+    /**
61
+     * @var \OCP\UserInterface[] $backends
62
+     */
63
+    private $backends = array();
64
+
65
+    /**
66
+     * @var \OC\User\User[] $cachedUsers
67
+     */
68
+    private $cachedUsers = array();
69
+
70
+    /**
71
+     * @var \OCP\IConfig $config
72
+     */
73
+    private $config;
74
+
75
+    /**
76
+     * @param \OCP\IConfig $config
77
+     */
78
+    public function __construct(IConfig $config) {
79
+        $this->config = $config;
80
+        $cachedUsers = &$this->cachedUsers;
81
+        $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
82
+            /** @var \OC\User\User $user */
83
+            unset($cachedUsers[$user->getUID()]);
84
+        });
85
+    }
86
+
87
+    /**
88
+     * Get the active backends
89
+     * @return \OCP\UserInterface[]
90
+     */
91
+    public function getBackends() {
92
+        return $this->backends;
93
+    }
94
+
95
+    /**
96
+     * register a user backend
97
+     *
98
+     * @param \OCP\UserInterface $backend
99
+     */
100
+    public function registerBackend($backend) {
101
+        $this->backends[] = $backend;
102
+    }
103
+
104
+    /**
105
+     * remove a user backend
106
+     *
107
+     * @param \OCP\UserInterface $backend
108
+     */
109
+    public function removeBackend($backend) {
110
+        $this->cachedUsers = array();
111
+        if (($i = array_search($backend, $this->backends)) !== false) {
112
+            unset($this->backends[$i]);
113
+        }
114
+    }
115
+
116
+    /**
117
+     * remove all user backends
118
+     */
119
+    public function clearBackends() {
120
+        $this->cachedUsers = array();
121
+        $this->backends = array();
122
+    }
123
+
124
+    /**
125
+     * get a user by user id
126
+     *
127
+     * @param string $uid
128
+     * @return \OC\User\User|null Either the user or null if the specified user does not exist
129
+     */
130
+    public function get($uid) {
131
+        if (is_null($uid) || $uid === '' || $uid === false) {
132
+            return null;
133
+        }
134
+        if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends
135
+            return $this->cachedUsers[$uid];
136
+        }
137
+        foreach ($this->backends as $backend) {
138
+            if ($backend->userExists($uid)) {
139
+                return $this->getUserObject($uid, $backend);
140
+            }
141
+        }
142
+        return null;
143
+    }
144
+
145
+    /**
146
+     * get or construct the user object
147
+     *
148
+     * @param string $uid
149
+     * @param \OCP\UserInterface $backend
150
+     * @param bool $cacheUser If false the newly created user object will not be cached
151
+     * @return \OC\User\User
152
+     */
153
+    protected function getUserObject($uid, $backend, $cacheUser = true) {
154
+        if (isset($this->cachedUsers[$uid])) {
155
+            return $this->cachedUsers[$uid];
156
+        }
157
+
158
+        $user = new User($uid, $backend, $this, $this->config);
159
+        if ($cacheUser) {
160
+            $this->cachedUsers[$uid] = $user;
161
+        }
162
+        return $user;
163
+    }
164
+
165
+    /**
166
+     * check if a user exists
167
+     *
168
+     * @param string $uid
169
+     * @return bool
170
+     */
171
+    public function userExists($uid) {
172
+        $user = $this->get($uid);
173
+        return ($user !== null);
174
+    }
175
+
176
+    /**
177
+     * Check if the password is valid for the user
178
+     *
179
+     * @param string $loginName
180
+     * @param string $password
181
+     * @return mixed the User object on success, false otherwise
182
+     */
183
+    public function checkPassword($loginName, $password) {
184
+        $result = $this->checkPasswordNoLogging($loginName, $password);
185
+
186
+        if ($result === false) {
187
+            \OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
188
+        }
189
+
190
+        return $result;
191
+    }
192
+
193
+    /**
194
+     * Check if the password is valid for the user
195
+     *
196
+     * @internal
197
+     * @param string $loginName
198
+     * @param string $password
199
+     * @return mixed the User object on success, false otherwise
200
+     */
201
+    public function checkPasswordNoLogging($loginName, $password) {
202
+        $loginName = str_replace("\0", '', $loginName);
203
+        $password = str_replace("\0", '', $password);
204
+
205
+        foreach ($this->backends as $backend) {
206
+            if ($backend->implementsActions(Backend::CHECK_PASSWORD)) {
207
+                $uid = $backend->checkPassword($loginName, $password);
208
+                if ($uid !== false) {
209
+                    return $this->getUserObject($uid, $backend);
210
+                }
211
+            }
212
+        }
213
+
214
+        return false;
215
+    }
216
+
217
+    /**
218
+     * search by user id
219
+     *
220
+     * @param string $pattern
221
+     * @param int $limit
222
+     * @param int $offset
223
+     * @return \OC\User\User[]
224
+     */
225
+    public function search($pattern, $limit = null, $offset = null) {
226
+        $users = array();
227
+        foreach ($this->backends as $backend) {
228
+            $backendUsers = $backend->getUsers($pattern, $limit, $offset);
229
+            if (is_array($backendUsers)) {
230
+                foreach ($backendUsers as $uid) {
231
+                    $users[$uid] = $this->getUserObject($uid, $backend);
232
+                }
233
+            }
234
+        }
235
+
236
+        uasort($users, function ($a, $b) {
237
+            /**
238
+             * @var \OC\User\User $a
239
+             * @var \OC\User\User $b
240
+             */
241
+            return strcmp($a->getUID(), $b->getUID());
242
+        });
243
+        return $users;
244
+    }
245
+
246
+    /**
247
+     * search by displayName
248
+     *
249
+     * @param string $pattern
250
+     * @param int $limit
251
+     * @param int $offset
252
+     * @return \OC\User\User[]
253
+     */
254
+    public function searchDisplayName($pattern, $limit = null, $offset = null) {
255
+        $users = array();
256
+        foreach ($this->backends as $backend) {
257
+            $backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
258
+            if (is_array($backendUsers)) {
259
+                foreach ($backendUsers as $uid => $displayName) {
260
+                    $users[] = $this->getUserObject($uid, $backend);
261
+                }
262
+            }
263
+        }
264
+
265
+        usort($users, function ($a, $b) {
266
+            /**
267
+             * @var \OC\User\User $a
268
+             * @var \OC\User\User $b
269
+             */
270
+            return strcmp(strtolower($a->getDisplayName()), strtolower($b->getDisplayName()));
271
+        });
272
+        return $users;
273
+    }
274
+
275
+    /**
276
+     * @param string $uid
277
+     * @param string $password
278
+     * @throws \InvalidArgumentException
279
+     * @return bool|IUser the created user or false
280
+     */
281
+    public function createUser($uid, $password) {
282
+        $localBackends = [];
283
+        foreach ($this->backends as $backend) {
284
+            if ($backend instanceof Database) {
285
+                // First check if there is another user backend
286
+                $localBackends[] = $backend;
287
+                continue;
288
+            }
289
+
290
+            if ($backend->implementsActions(Backend::CREATE_USER)) {
291
+                return $this->createUserFromBackend($uid, $password, $backend);
292
+            }
293
+        }
294
+
295
+        foreach ($localBackends as $backend) {
296
+            if ($backend->implementsActions(Backend::CREATE_USER)) {
297
+                return $this->createUserFromBackend($uid, $password, $backend);
298
+            }
299
+        }
300
+
301
+        return false;
302
+    }
303
+
304
+    /**
305
+     * @param string $uid
306
+     * @param string $password
307
+     * @param UserInterface $backend
308
+     * @return IUser|null
309
+     * @throws \InvalidArgumentException
310
+     */
311
+    public function createUserFromBackend($uid, $password, UserInterface $backend) {
312
+        $l = \OC::$server->getL10N('lib');
313
+
314
+        // Check the name for bad characters
315
+        // Allowed are: "a-z", "A-Z", "0-9" and "_.@-'"
316
+        if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $uid)) {
317
+            throw new \InvalidArgumentException($l->t('Only the following characters are allowed in a username:'
318
+                . ' "a-z", "A-Z", "0-9", and "_.@-\'"'));
319
+        }
320
+        // No empty username
321
+        if (trim($uid) === '') {
322
+            throw new \InvalidArgumentException($l->t('A valid username must be provided'));
323
+        }
324
+        // No whitespace at the beginning or at the end
325
+        if (trim($uid) !== $uid) {
326
+            throw new \InvalidArgumentException($l->t('Username contains whitespace at the beginning or at the end'));
327
+        }
328
+        // Username only consists of 1 or 2 dots (directory traversal)
329
+        if ($uid === '.' || $uid === '..') {
330
+            throw new \InvalidArgumentException($l->t('Username must not consist of dots only'));
331
+        }
332
+        // No empty password
333
+        if (trim($password) === '') {
334
+            throw new \InvalidArgumentException($l->t('A valid password must be provided'));
335
+        }
336
+
337
+        // Check if user already exists
338
+        if ($this->userExists($uid)) {
339
+            throw new \InvalidArgumentException($l->t('The username is already being used'));
340
+        }
341
+
342
+        $this->emit('\OC\User', 'preCreateUser', [$uid, $password]);
343
+        $state = $backend->createUser($uid, $password);
344
+        if($state === false) {
345
+            throw new \InvalidArgumentException($l->t('Could not create user'));
346
+        }
347
+        $user = $this->getUserObject($uid, $backend);
348
+        if ($user instanceof IUser) {
349
+            $this->emit('\OC\User', 'postCreateUser', [$user, $password]);
350
+        }
351
+        return $user;
352
+    }
353
+
354
+    /**
355
+     * returns how many users per backend exist (if supported by backend)
356
+     *
357
+     * @param boolean $hasLoggedIn when true only users that have a lastLogin
358
+     *                entry in the preferences table will be affected
359
+     * @return array|int an array of backend class as key and count number as value
360
+     *                if $hasLoggedIn is true only an int is returned
361
+     */
362
+    public function countUsers($hasLoggedIn = false) {
363
+        if ($hasLoggedIn) {
364
+            return $this->countSeenUsers();
365
+        }
366
+        $userCountStatistics = [];
367
+        foreach ($this->backends as $backend) {
368
+            if ($backend->implementsActions(Backend::COUNT_USERS)) {
369
+                $backendUsers = $backend->countUsers();
370
+                if($backendUsers !== false) {
371
+                    if($backend instanceof IUserBackend) {
372
+                        $name = $backend->getBackendName();
373
+                    } else {
374
+                        $name = get_class($backend);
375
+                    }
376
+                    if(isset($userCountStatistics[$name])) {
377
+                        $userCountStatistics[$name] += $backendUsers;
378
+                    } else {
379
+                        $userCountStatistics[$name] = $backendUsers;
380
+                    }
381
+                }
382
+            }
383
+        }
384
+        return $userCountStatistics;
385
+    }
386
+
387
+    /**
388
+     * The callback is executed for each user on each backend.
389
+     * If the callback returns false no further users will be retrieved.
390
+     *
391
+     * @param \Closure $callback
392
+     * @param string $search
393
+     * @param boolean $onlySeen when true only users that have a lastLogin entry
394
+     *                in the preferences table will be affected
395
+     * @since 9.0.0
396
+     */
397
+    public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = false) {
398
+        if ($onlySeen) {
399
+            $this->callForSeenUsers($callback);
400
+        } else {
401
+            foreach ($this->getBackends() as $backend) {
402
+                $limit = 500;
403
+                $offset = 0;
404
+                do {
405
+                    $users = $backend->getUsers($search, $limit, $offset);
406
+                    foreach ($users as $uid) {
407
+                        if (!$backend->userExists($uid)) {
408
+                            continue;
409
+                        }
410
+                        $user = $this->getUserObject($uid, $backend, false);
411
+                        $return = $callback($user);
412
+                        if ($return === false) {
413
+                            break;
414
+                        }
415
+                    }
416
+                    $offset += $limit;
417
+                } while (count($users) >= $limit);
418
+            }
419
+        }
420
+    }
421
+
422
+    /**
423
+     * returns how many users are disabled
424
+     *
425
+     * @return int
426
+     * @since 12.0.0
427
+     */
428
+    public function countDisabledUsers(): int {
429
+        $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
430
+        $queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
431
+            ->from('preferences')
432
+            ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
433
+            ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
434
+            ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR));
435 435
 
436 436
 		
437
-		$result = $queryBuilder->execute();
438
-		$count = $result->fetchColumn();
439
-		$result->closeCursor();
437
+        $result = $queryBuilder->execute();
438
+        $count = $result->fetchColumn();
439
+        $result->closeCursor();
440 440
 		
441
-		if ($count !== false) {
442
-			$count = (int)$count;
443
-		} else {
444
-			$count = 0;
445
-		}
446
-
447
-		return $count;
448
-	}
449
-
450
-	/**
451
-	 * returns how many users are disabled in the requested groups
452
-	 *
453
-	 * @param array $groups groupids to search
454
-	 * @return int
455
-	 * @since 14.0.0
456
-	 */
457
-	public function countDisabledUsersOfGroups(array $groups): int {
458
-		$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
459
-		$queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)'))
460
-			->from('preferences', 'p')
461
-			->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
462
-			->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
463
-			->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
464
-			->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
465
-			->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY)));
466
-
467
-		$result = $queryBuilder->execute();
468
-		$count = $result->fetchColumn();
469
-		$result->closeCursor();
441
+        if ($count !== false) {
442
+            $count = (int)$count;
443
+        } else {
444
+            $count = 0;
445
+        }
446
+
447
+        return $count;
448
+    }
449
+
450
+    /**
451
+     * returns how many users are disabled in the requested groups
452
+     *
453
+     * @param array $groups groupids to search
454
+     * @return int
455
+     * @since 14.0.0
456
+     */
457
+    public function countDisabledUsersOfGroups(array $groups): int {
458
+        $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
459
+        $queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)'))
460
+            ->from('preferences', 'p')
461
+            ->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
462
+            ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
463
+            ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
464
+            ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
465
+            ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY)));
466
+
467
+        $result = $queryBuilder->execute();
468
+        $count = $result->fetchColumn();
469
+        $result->closeCursor();
470 470
 		
471
-		if ($count !== false) {
472
-			$count = (int)$count;
473
-		} else {
474
-			$count = 0;
475
-		}
476
-
477
-		return $count;
478
-	}
479
-
480
-	/**
481
-	 * returns how many users have logged in once
482
-	 *
483
-	 * @return int
484
-	 * @since 11.0.0
485
-	 */
486
-	public function countSeenUsers() {
487
-		$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
488
-		$queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
489
-			->from('preferences')
490
-			->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login')))
491
-			->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin')))
492
-			->andWhere($queryBuilder->expr()->isNotNull('configvalue'));
493
-
494
-		$query = $queryBuilder->execute();
495
-
496
-		$result = (int)$query->fetchColumn();
497
-		$query->closeCursor();
498
-
499
-		return $result;
500
-	}
501
-
502
-	/**
503
-	 * @param \Closure $callback
504
-	 * @since 11.0.0
505
-	 */
506
-	public function callForSeenUsers(\Closure $callback) {
507
-		$limit = 1000;
508
-		$offset = 0;
509
-		do {
510
-			$userIds = $this->getSeenUserIds($limit, $offset);
511
-			$offset += $limit;
512
-			foreach ($userIds as $userId) {
513
-				foreach ($this->backends as $backend) {
514
-					if ($backend->userExists($userId)) {
515
-						$user = $this->getUserObject($userId, $backend, false);
516
-						$return = $callback($user);
517
-						if ($return === false) {
518
-							return;
519
-						}
520
-						break;
521
-					}
522
-				}
523
-			}
524
-		} while (count($userIds) >= $limit);
525
-	}
526
-
527
-	/**
528
-	 * Getting all userIds that have a listLogin value requires checking the
529
-	 * value in php because on oracle you cannot use a clob in a where clause,
530
-	 * preventing us from doing a not null or length(value) > 0 check.
531
-	 *
532
-	 * @param int $limit
533
-	 * @param int $offset
534
-	 * @return string[] with user ids
535
-	 */
536
-	private function getSeenUserIds($limit = null, $offset = null) {
537
-		$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
538
-		$queryBuilder->select(['userid'])
539
-			->from('preferences')
540
-			->where($queryBuilder->expr()->eq(
541
-				'appid', $queryBuilder->createNamedParameter('login'))
542
-			)
543
-			->andWhere($queryBuilder->expr()->eq(
544
-				'configkey', $queryBuilder->createNamedParameter('lastLogin'))
545
-			)
546
-			->andWhere($queryBuilder->expr()->isNotNull('configvalue')
547
-			);
548
-
549
-		if ($limit !== null) {
550
-			$queryBuilder->setMaxResults($limit);
551
-		}
552
-		if ($offset !== null) {
553
-			$queryBuilder->setFirstResult($offset);
554
-		}
555
-		$query = $queryBuilder->execute();
556
-		$result = [];
557
-
558
-		while ($row = $query->fetch()) {
559
-			$result[] = $row['userid'];
560
-		}
561
-
562
-		$query->closeCursor();
563
-
564
-		return $result;
565
-	}
566
-
567
-	/**
568
-	 * @param string $email
569
-	 * @return IUser[]
570
-	 * @since 9.1.0
571
-	 */
572
-	public function getByEmail($email) {
573
-		$userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
574
-
575
-		return array_map(function($uid) {
576
-			return $this->get($uid);
577
-		}, $userIds);
578
-	}
471
+        if ($count !== false) {
472
+            $count = (int)$count;
473
+        } else {
474
+            $count = 0;
475
+        }
476
+
477
+        return $count;
478
+    }
479
+
480
+    /**
481
+     * returns how many users have logged in once
482
+     *
483
+     * @return int
484
+     * @since 11.0.0
485
+     */
486
+    public function countSeenUsers() {
487
+        $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
488
+        $queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
489
+            ->from('preferences')
490
+            ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login')))
491
+            ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin')))
492
+            ->andWhere($queryBuilder->expr()->isNotNull('configvalue'));
493
+
494
+        $query = $queryBuilder->execute();
495
+
496
+        $result = (int)$query->fetchColumn();
497
+        $query->closeCursor();
498
+
499
+        return $result;
500
+    }
501
+
502
+    /**
503
+     * @param \Closure $callback
504
+     * @since 11.0.0
505
+     */
506
+    public function callForSeenUsers(\Closure $callback) {
507
+        $limit = 1000;
508
+        $offset = 0;
509
+        do {
510
+            $userIds = $this->getSeenUserIds($limit, $offset);
511
+            $offset += $limit;
512
+            foreach ($userIds as $userId) {
513
+                foreach ($this->backends as $backend) {
514
+                    if ($backend->userExists($userId)) {
515
+                        $user = $this->getUserObject($userId, $backend, false);
516
+                        $return = $callback($user);
517
+                        if ($return === false) {
518
+                            return;
519
+                        }
520
+                        break;
521
+                    }
522
+                }
523
+            }
524
+        } while (count($userIds) >= $limit);
525
+    }
526
+
527
+    /**
528
+     * Getting all userIds that have a listLogin value requires checking the
529
+     * value in php because on oracle you cannot use a clob in a where clause,
530
+     * preventing us from doing a not null or length(value) > 0 check.
531
+     *
532
+     * @param int $limit
533
+     * @param int $offset
534
+     * @return string[] with user ids
535
+     */
536
+    private function getSeenUserIds($limit = null, $offset = null) {
537
+        $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
538
+        $queryBuilder->select(['userid'])
539
+            ->from('preferences')
540
+            ->where($queryBuilder->expr()->eq(
541
+                'appid', $queryBuilder->createNamedParameter('login'))
542
+            )
543
+            ->andWhere($queryBuilder->expr()->eq(
544
+                'configkey', $queryBuilder->createNamedParameter('lastLogin'))
545
+            )
546
+            ->andWhere($queryBuilder->expr()->isNotNull('configvalue')
547
+            );
548
+
549
+        if ($limit !== null) {
550
+            $queryBuilder->setMaxResults($limit);
551
+        }
552
+        if ($offset !== null) {
553
+            $queryBuilder->setFirstResult($offset);
554
+        }
555
+        $query = $queryBuilder->execute();
556
+        $result = [];
557
+
558
+        while ($row = $query->fetch()) {
559
+            $result[] = $row['userid'];
560
+        }
561
+
562
+        $query->closeCursor();
563
+
564
+        return $result;
565
+    }
566
+
567
+    /**
568
+     * @param string $email
569
+     * @return IUser[]
570
+     * @since 9.1.0
571
+     */
572
+    public function getByEmail($email) {
573
+        $userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
574
+
575
+        return array_map(function($uid) {
576
+            return $this->get($uid);
577
+        }, $userIds);
578
+    }
579 579
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	public function __construct(IConfig $config) {
79 79
 		$this->config = $config;
80 80
 		$cachedUsers = &$this->cachedUsers;
81
-		$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
81
+		$this->listen('\OC\User', 'postDelete', function($user) use (&$cachedUsers) {
82 82
 			/** @var \OC\User\User $user */
83 83
 			unset($cachedUsers[$user->getUID()]);
84 84
 		});
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		$result = $this->checkPasswordNoLogging($loginName, $password);
185 185
 
186 186
 		if ($result === false) {
187
-			\OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
187
+			\OC::$server->getLogger()->warning('Login failed: \''.$loginName.'\' (Remote IP: \''.\OC::$server->getRequest()->getRemoteAddress().'\')', ['app' => 'core']);
188 188
 		}
189 189
 
190 190
 		return $result;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 			}
234 234
 		}
235 235
 
236
-		uasort($users, function ($a, $b) {
236
+		uasort($users, function($a, $b) {
237 237
 			/**
238 238
 			 * @var \OC\User\User $a
239 239
 			 * @var \OC\User\User $b
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			}
263 263
 		}
264 264
 
265
-		usort($users, function ($a, $b) {
265
+		usort($users, function($a, $b) {
266 266
 			/**
267 267
 			 * @var \OC\User\User $a
268 268
 			 * @var \OC\User\User $b
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$this->emit('\OC\User', 'preCreateUser', [$uid, $password]);
343 343
 		$state = $backend->createUser($uid, $password);
344
-		if($state === false) {
344
+		if ($state === false) {
345 345
 			throw new \InvalidArgumentException($l->t('Could not create user'));
346 346
 		}
347 347
 		$user = $this->getUserObject($uid, $backend);
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 		foreach ($this->backends as $backend) {
368 368
 			if ($backend->implementsActions(Backend::COUNT_USERS)) {
369 369
 				$backendUsers = $backend->countUsers();
370
-				if($backendUsers !== false) {
371
-					if($backend instanceof IUserBackend) {
370
+				if ($backendUsers !== false) {
371
+					if ($backend instanceof IUserBackend) {
372 372
 						$name = $backend->getBackendName();
373 373
 					} else {
374 374
 						$name = get_class($backend);
375 375
 					}
376
-					if(isset($userCountStatistics[$name])) {
376
+					if (isset($userCountStatistics[$name])) {
377 377
 						$userCountStatistics[$name] += $backendUsers;
378 378
 					} else {
379 379
 						$userCountStatistics[$name] = $backendUsers;
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 		$result->closeCursor();
440 440
 		
441 441
 		if ($count !== false) {
442
-			$count = (int)$count;
442
+			$count = (int) $count;
443 443
 		} else {
444 444
 			$count = 0;
445 445
 		}
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
 		$result->closeCursor();
470 470
 		
471 471
 		if ($count !== false) {
472
-			$count = (int)$count;
472
+			$count = (int) $count;
473 473
 		} else {
474 474
 			$count = 0;
475 475
 		}
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
 		$query = $queryBuilder->execute();
495 495
 
496
-		$result = (int)$query->fetchColumn();
496
+		$result = (int) $query->fetchColumn();
497 497
 		$query->closeCursor();
498 498
 
499 499
 		return $result;
Please login to merge, or discard this patch.
lib/public/Group/Backend/ICountDisabledInGroup.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
  */
30 30
 interface ICountDisabledInGroup {
31 31
 
32
-	/**
33
-	 * @since 14.0.0
34
-	 */
35
-	public function countDisabledInGroup(string $gid): int;
32
+    /**
33
+     * @since 14.0.0
34
+     */
35
+    public function countDisabledInGroup(string $gid): int;
36 36
 }
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/GroupsController.php 1 patch
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -44,240 +44,240 @@
 block discarded – undo
44 44
 
45 45
 class GroupsController extends AUserData {
46 46
 
47
-	/** @var ILogger */
48
-	private $logger;
47
+    /** @var ILogger */
48
+    private $logger;
49 49
 
50
-	/**
51
-	 * @param string $appName
52
-	 * @param IRequest $request
53
-	 * @param IUserManager $userManager
54
-	 * @param IConfig $config
55
-	 * @param IGroupManager $groupManager
56
-	 * @param IUserSession $userSession
57
-	 * @param AccountManager $accountManager
58
-	 * @param ILogger $logger
59
-	 * @param UsersController $userController
60
-	 */
61
-	public function __construct(string $appName,
62
-								IRequest $request,
63
-								IUserManager $userManager,
64
-								IConfig $config,
65
-								IGroupManager $groupManager,
66
-								IUserSession $userSession,
67
-								AccountManager $accountManager,
68
-								ILogger $logger) {
69
-		parent::__construct($appName,
70
-			$request,
71
-			$userManager,
72
-			$config,
73
-			$groupManager,
74
-			$userSession,
75
-			$accountManager);
50
+    /**
51
+     * @param string $appName
52
+     * @param IRequest $request
53
+     * @param IUserManager $userManager
54
+     * @param IConfig $config
55
+     * @param IGroupManager $groupManager
56
+     * @param IUserSession $userSession
57
+     * @param AccountManager $accountManager
58
+     * @param ILogger $logger
59
+     * @param UsersController $userController
60
+     */
61
+    public function __construct(string $appName,
62
+                                IRequest $request,
63
+                                IUserManager $userManager,
64
+                                IConfig $config,
65
+                                IGroupManager $groupManager,
66
+                                IUserSession $userSession,
67
+                                AccountManager $accountManager,
68
+                                ILogger $logger) {
69
+        parent::__construct($appName,
70
+            $request,
71
+            $userManager,
72
+            $config,
73
+            $groupManager,
74
+            $userSession,
75
+            $accountManager);
76 76
 
77
-		$this->logger = $logger;
78
-	}
77
+        $this->logger = $logger;
78
+    }
79 79
 
80
-	/**
81
-	 * returns a list of groups
82
-	 *
83
-	 * @NoAdminRequired
84
-	 *
85
-	 * @param string $search
86
-	 * @param int $limit
87
-	 * @param int $offset
88
-	 * @return DataResponse
89
-	 */
90
-	public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
91
-		$groups = $this->groupManager->search($search, $limit, $offset);
92
-		$groups = array_map(function($group) {
93
-			/** @var IGroup $group */
94
-			return $group->getGID();
95
-		}, $groups);
80
+    /**
81
+     * returns a list of groups
82
+     *
83
+     * @NoAdminRequired
84
+     *
85
+     * @param string $search
86
+     * @param int $limit
87
+     * @param int $offset
88
+     * @return DataResponse
89
+     */
90
+    public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
91
+        $groups = $this->groupManager->search($search, $limit, $offset);
92
+        $groups = array_map(function($group) {
93
+            /** @var IGroup $group */
94
+            return $group->getGID();
95
+        }, $groups);
96 96
 
97
-		return new DataResponse(['groups' => $groups]);
98
-	}
97
+        return new DataResponse(['groups' => $groups]);
98
+    }
99 99
 
100
-	/**
101
-	 * returns a list of groups details with ids and displaynames
102
-	 *
103
-	 * @NoAdminRequired
104
-	 *
105
-	 * @param string $search
106
-	 * @param int $limit
107
-	 * @param int $offset
108
-	 * @return DataResponse
109
-	 */
110
-	public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
111
-		$groups = $this->groupManager->search($search, $limit, $offset);
112
-		$groups = array_map(function($group) {
113
-			/** @var IGroup $group */
114
-			return [
115
-				'id' => $group->getGID(),
116
-				'displayname' => $group->getDisplayName(),
117
-				'usercount' => $group->count(),
118
-				'disabled' => $group->countDisabled()
119
-			];
120
-		}, $groups);
100
+    /**
101
+     * returns a list of groups details with ids and displaynames
102
+     *
103
+     * @NoAdminRequired
104
+     *
105
+     * @param string $search
106
+     * @param int $limit
107
+     * @param int $offset
108
+     * @return DataResponse
109
+     */
110
+    public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
111
+        $groups = $this->groupManager->search($search, $limit, $offset);
112
+        $groups = array_map(function($group) {
113
+            /** @var IGroup $group */
114
+            return [
115
+                'id' => $group->getGID(),
116
+                'displayname' => $group->getDisplayName(),
117
+                'usercount' => $group->count(),
118
+                'disabled' => $group->countDisabled()
119
+            ];
120
+        }, $groups);
121 121
 
122
-		return new DataResponse(['groups' => $groups]);
123
-	}
122
+        return new DataResponse(['groups' => $groups]);
123
+    }
124 124
 
125
-	/**
126
-	 * @NoAdminRequired
127
-	 *
128
-	 * @param string $groupId
129
-	 * @return DataResponse
130
-	 * @throws OCSException	
131
-	 *
132
-	 * @deprecated 14 Use getGroupUsers
133
-	 */
134
-	public function getGroup(string $groupId): DataResponse {
135
-		return $this->getGroupUsers($groupId);
136
-	}
125
+    /**
126
+     * @NoAdminRequired
127
+     *
128
+     * @param string $groupId
129
+     * @return DataResponse
130
+     * @throws OCSException	
131
+     *
132
+     * @deprecated 14 Use getGroupUsers
133
+     */
134
+    public function getGroup(string $groupId): DataResponse {
135
+        return $this->getGroupUsers($groupId);
136
+    }
137 137
 
138
-	/**
139
-	 * returns an array of users in the specified group
140
-	 *
141
-	 * @NoAdminRequired
142
-	 *
143
-	 * @param string $groupId
144
-	 * @return DataResponse
145
-	 * @throws OCSException
146
-	 */
147
-	public function getGroupUsers(string $groupId): DataResponse {
148
-		$user = $this->userSession->getUser();
149
-		$isSubadminOfGroup = false;
138
+    /**
139
+     * returns an array of users in the specified group
140
+     *
141
+     * @NoAdminRequired
142
+     *
143
+     * @param string $groupId
144
+     * @return DataResponse
145
+     * @throws OCSException
146
+     */
147
+    public function getGroupUsers(string $groupId): DataResponse {
148
+        $user = $this->userSession->getUser();
149
+        $isSubadminOfGroup = false;
150 150
 
151
-		// Check the group exists
152
-		$group = $this->groupManager->get($groupId);
153
-		if ($group !== null) {
154
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
155
-		} else {
156
-			throw new OCSNotFoundException('The requested group could not be found');
157
-		}
151
+        // Check the group exists
152
+        $group = $this->groupManager->get($groupId);
153
+        if ($group !== null) {
154
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
155
+        } else {
156
+            throw new OCSNotFoundException('The requested group could not be found');
157
+        }
158 158
 
159
-		// Check subadmin has access to this group
160
-		if($this->groupManager->isAdmin($user->getUID())
161
-		   || $isSubadminOfGroup) {
162
-			$users = $this->groupManager->get($groupId)->getUsers();
163
-			$users =  array_map(function($user) {
164
-				/** @var IUser $user */
165
-				return $user->getUID();
166
-			}, $users);
167
-			$users = array_values($users);
168
-			return new DataResponse(['users' => $users]);
169
-		}
159
+        // Check subadmin has access to this group
160
+        if($this->groupManager->isAdmin($user->getUID())
161
+           || $isSubadminOfGroup) {
162
+            $users = $this->groupManager->get($groupId)->getUsers();
163
+            $users =  array_map(function($user) {
164
+                /** @var IUser $user */
165
+                return $user->getUID();
166
+            }, $users);
167
+            $users = array_values($users);
168
+            return new DataResponse(['users' => $users]);
169
+        }
170 170
 
171
-		throw new OCSForbiddenException();
172
-	}
171
+        throw new OCSForbiddenException();
172
+    }
173 173
 
174
-	/**
175
-	 * returns an array of users details in the specified group
176
-	 *
177
-	 * @NoAdminRequired
178
-	 *
179
-	 * @param string $groupId
180
-	 * @param int $limit
181
-	 * @param int $offset
182
-	 * @return DataResponse
183
-	 * @throws OCSException
184
-	 */
185
-	public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
186
-		$user = $this->userSession->getUser();
187
-		$isSubadminOfGroup = false;
174
+    /**
175
+     * returns an array of users details in the specified group
176
+     *
177
+     * @NoAdminRequired
178
+     *
179
+     * @param string $groupId
180
+     * @param int $limit
181
+     * @param int $offset
182
+     * @return DataResponse
183
+     * @throws OCSException
184
+     */
185
+    public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
186
+        $user = $this->userSession->getUser();
187
+        $isSubadminOfGroup = false;
188 188
 
189
-		// Check the group exists
190
-		$group = $this->groupManager->get($groupId);
191
-		if ($group !== null) {
192
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
193
-		} else {
194
-			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
195
-		}
189
+        // Check the group exists
190
+        $group = $this->groupManager->get($groupId);
191
+        if ($group !== null) {
192
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
193
+        } else {
194
+            throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
195
+        }
196 196
 
197
-		// Check subadmin has access to this group
198
-		if($this->groupManager->isAdmin($user->getUID())
199
-		   || $isSubadminOfGroup) {
200
-			$users = $this->groupManager->get($groupId)->getUsers();
201
-			// Extract required number
202
-			$users = array_slice($users, $offset, $limit);
203
-			$users = array_keys($users);
204
-			$usersDetails = [];
205
-			foreach ($users as $userId) {
206
-				$userData = $this->getUserData($userId);
207
-				// Do not insert empty entry
208
-				if(!empty($userData)) {
209
-					$usersDetails[$userId] = $userData;
210
-				}
211
-			}
212
-			return new DataResponse(['users' => $usersDetails]);
213
-		}
197
+        // Check subadmin has access to this group
198
+        if($this->groupManager->isAdmin($user->getUID())
199
+           || $isSubadminOfGroup) {
200
+            $users = $this->groupManager->get($groupId)->getUsers();
201
+            // Extract required number
202
+            $users = array_slice($users, $offset, $limit);
203
+            $users = array_keys($users);
204
+            $usersDetails = [];
205
+            foreach ($users as $userId) {
206
+                $userData = $this->getUserData($userId);
207
+                // Do not insert empty entry
208
+                if(!empty($userData)) {
209
+                    $usersDetails[$userId] = $userData;
210
+                }
211
+            }
212
+            return new DataResponse(['users' => $usersDetails]);
213
+        }
214 214
 
215
-		throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
216
-	}
215
+        throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
216
+    }
217 217
 
218
-	/**
219
-	 * creates a new group
220
-	 *
221
-	 * @PasswordConfirmationRequired
222
-	 *
223
-	 * @param string $groupid
224
-	 * @return DataResponse
225
-	 * @throws OCSException
226
-	 */
227
-	public function addGroup(string $groupid): DataResponse {
228
-		// Validate name
229
-		if(empty($groupid)) {
230
-			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
231
-			throw new OCSException('Invalid group name', 101);
232
-		}
233
-		// Check if it exists
234
-		if($this->groupManager->groupExists($groupid)){
235
-			throw new OCSException('', 102);
236
-		}
237
-		$this->groupManager->createGroup($groupid);
238
-		return new DataResponse();
239
-	}
218
+    /**
219
+     * creates a new group
220
+     *
221
+     * @PasswordConfirmationRequired
222
+     *
223
+     * @param string $groupid
224
+     * @return DataResponse
225
+     * @throws OCSException
226
+     */
227
+    public function addGroup(string $groupid): DataResponse {
228
+        // Validate name
229
+        if(empty($groupid)) {
230
+            $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
231
+            throw new OCSException('Invalid group name', 101);
232
+        }
233
+        // Check if it exists
234
+        if($this->groupManager->groupExists($groupid)){
235
+            throw new OCSException('', 102);
236
+        }
237
+        $this->groupManager->createGroup($groupid);
238
+        return new DataResponse();
239
+    }
240 240
 
241
-	/**
242
-	 * @PasswordConfirmationRequired
243
-	 *
244
-	 * @param string $groupId
245
-	 * @return DataResponse
246
-	 * @throws OCSException
247
-	 */
248
-	public function deleteGroup(string $groupId): DataResponse {
249
-		// Check it exists
250
-		if(!$this->groupManager->groupExists($groupId)){
251
-			throw new OCSException('', 101);
252
-		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
253
-			// Cannot delete admin group
254
-			throw new OCSException('', 102);
255
-		}
241
+    /**
242
+     * @PasswordConfirmationRequired
243
+     *
244
+     * @param string $groupId
245
+     * @return DataResponse
246
+     * @throws OCSException
247
+     */
248
+    public function deleteGroup(string $groupId): DataResponse {
249
+        // Check it exists
250
+        if(!$this->groupManager->groupExists($groupId)){
251
+            throw new OCSException('', 101);
252
+        } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
253
+            // Cannot delete admin group
254
+            throw new OCSException('', 102);
255
+        }
256 256
 
257
-		return new DataResponse();
258
-	}
257
+        return new DataResponse();
258
+    }
259 259
 
260
-	/**
261
-	 * @param string $groupId
262
-	 * @return DataResponse
263
-	 * @throws OCSException
264
-	 */
265
-	public function getSubAdminsOfGroup(string $groupId): DataResponse {
266
-		// Check group exists
267
-		$targetGroup = $this->groupManager->get($groupId);
268
-		if($targetGroup === null) {
269
-			throw new OCSException('Group does not exist', 101);
270
-		}
260
+    /**
261
+     * @param string $groupId
262
+     * @return DataResponse
263
+     * @throws OCSException
264
+     */
265
+    public function getSubAdminsOfGroup(string $groupId): DataResponse {
266
+        // Check group exists
267
+        $targetGroup = $this->groupManager->get($groupId);
268
+        if($targetGroup === null) {
269
+            throw new OCSException('Group does not exist', 101);
270
+        }
271 271
 
272
-		/** @var IUser[] $subadmins */
273
-		$subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
274
-		// New class returns IUser[] so convert back
275
-		$uids = [];
276
-		foreach ($subadmins as $user) {
277
-			$uids[] = $user->getUID();
278
-		}
272
+        /** @var IUser[] $subadmins */
273
+        $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
274
+        // New class returns IUser[] so convert back
275
+        $uids = [];
276
+        foreach ($subadmins as $user) {
277
+            $uids[] = $user->getUID();
278
+        }
279 279
 
280
-		return new DataResponse($uids);
281
-	}
280
+        return new DataResponse($uids);
281
+    }
282 282
 
283 283
 }
Please login to merge, or discard this patch.