@@ -27,66 +27,66 @@ |
||
27 | 27 | |
28 | 28 | class SystemTag implements ISystemTag { |
29 | 29 | |
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private $id; |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private $id; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $name; |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $name; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - private $userVisible; |
|
40 | + /** |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + private $userVisible; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var bool |
|
47 | - */ |
|
48 | - private $userAssignable; |
|
45 | + /** |
|
46 | + * @var bool |
|
47 | + */ |
|
48 | + private $userAssignable; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Constructor. |
|
52 | - * |
|
53 | - * @param string $id tag id |
|
54 | - * @param string $name tag name |
|
55 | - * @param bool $userVisible whether the tag is user visible |
|
56 | - * @param bool $userAssignable whether the tag is user assignable |
|
57 | - */ |
|
58 | - public function __construct($id, $name, $userVisible, $userAssignable) { |
|
59 | - $this->id = $id; |
|
60 | - $this->name = $name; |
|
61 | - $this->userVisible = $userVisible; |
|
62 | - $this->userAssignable = $userAssignable; |
|
63 | - } |
|
50 | + /** |
|
51 | + * Constructor. |
|
52 | + * |
|
53 | + * @param string $id tag id |
|
54 | + * @param string $name tag name |
|
55 | + * @param bool $userVisible whether the tag is user visible |
|
56 | + * @param bool $userAssignable whether the tag is user assignable |
|
57 | + */ |
|
58 | + public function __construct($id, $name, $userVisible, $userAssignable) { |
|
59 | + $this->id = $id; |
|
60 | + $this->name = $name; |
|
61 | + $this->userVisible = $userVisible; |
|
62 | + $this->userAssignable = $userAssignable; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function getId() { |
|
69 | - return $this->id; |
|
70 | - } |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function getId() { |
|
69 | + return $this->id; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * {@inheritdoc} |
|
74 | - */ |
|
75 | - public function getName() { |
|
76 | - return $this->name; |
|
77 | - } |
|
72 | + /** |
|
73 | + * {@inheritdoc} |
|
74 | + */ |
|
75 | + public function getName() { |
|
76 | + return $this->name; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * {@inheritdoc} |
|
81 | - */ |
|
82 | - public function isUserVisible() { |
|
83 | - return $this->userVisible; |
|
84 | - } |
|
79 | + /** |
|
80 | + * {@inheritdoc} |
|
81 | + */ |
|
82 | + public function isUserVisible() { |
|
83 | + return $this->userVisible; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * {@inheritdoc} |
|
88 | - */ |
|
89 | - public function isUserAssignable() { |
|
90 | - return $this->userAssignable; |
|
91 | - } |
|
86 | + /** |
|
87 | + * {@inheritdoc} |
|
88 | + */ |
|
89 | + public function isUserAssignable() { |
|
90 | + return $this->userAssignable; |
|
91 | + } |
|
92 | 92 | } |
@@ -44,291 +44,291 @@ |
||
44 | 44 | */ |
45 | 45 | class Database extends \OC\Group\Backend { |
46 | 46 | |
47 | - /** @var string[] */ |
|
48 | - private $groupCache = []; |
|
49 | - |
|
50 | - /** @var \OCP\IDBConnection */ |
|
51 | - private $dbConn; |
|
52 | - |
|
53 | - /** |
|
54 | - * \OC\Group\Database constructor. |
|
55 | - * |
|
56 | - * @param \OCP\IDBConnection|null $dbConn |
|
57 | - */ |
|
58 | - public function __construct(\OCP\IDBConnection $dbConn = null) { |
|
59 | - $this->dbConn = $dbConn; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * FIXME: This function should not be required! |
|
64 | - */ |
|
65 | - private function fixDI() { |
|
66 | - if ($this->dbConn === null) { |
|
67 | - $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Try to create a new group |
|
73 | - * @param string $gid The name of the group to create |
|
74 | - * @return bool |
|
75 | - * |
|
76 | - * Tries to create a new group. If the group name already exists, false will |
|
77 | - * be returned. |
|
78 | - */ |
|
79 | - public function createGroup( $gid ) { |
|
80 | - $this->fixDI(); |
|
81 | - |
|
82 | - // Add group |
|
83 | - $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [ |
|
84 | - 'gid' => $gid, |
|
85 | - ]); |
|
86 | - |
|
87 | - // Add to cache |
|
88 | - $this->groupCache[$gid] = $gid; |
|
89 | - |
|
90 | - return $result === 1; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * delete a group |
|
95 | - * @param string $gid gid of the group to delete |
|
96 | - * @return bool |
|
97 | - * |
|
98 | - * Deletes a group and removes it from the group_user-table |
|
99 | - */ |
|
100 | - public function deleteGroup( $gid ) { |
|
101 | - $this->fixDI(); |
|
102 | - |
|
103 | - // Delete the group |
|
104 | - $qb = $this->dbConn->getQueryBuilder(); |
|
105 | - $qb->delete('groups') |
|
106 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
107 | - ->execute(); |
|
108 | - |
|
109 | - // Delete the group-user relation |
|
110 | - $qb = $this->dbConn->getQueryBuilder(); |
|
111 | - $qb->delete('group_user') |
|
112 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
113 | - ->execute(); |
|
114 | - |
|
115 | - // Delete the group-groupadmin relation |
|
116 | - $qb = $this->dbConn->getQueryBuilder(); |
|
117 | - $qb->delete('group_admin') |
|
118 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
119 | - ->execute(); |
|
120 | - |
|
121 | - // Delete from cache |
|
122 | - unset($this->groupCache[$gid]); |
|
123 | - |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * is user in group? |
|
129 | - * @param string $uid uid of the user |
|
130 | - * @param string $gid gid of the group |
|
131 | - * @return bool |
|
132 | - * |
|
133 | - * Checks whether the user is member of a group or not. |
|
134 | - */ |
|
135 | - public function inGroup( $uid, $gid ) { |
|
136 | - $this->fixDI(); |
|
137 | - |
|
138 | - // check |
|
139 | - $qb = $this->dbConn->getQueryBuilder(); |
|
140 | - $cursor = $qb->select('uid') |
|
141 | - ->from('group_user') |
|
142 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
143 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
144 | - ->execute(); |
|
145 | - |
|
146 | - $result = $cursor->fetch(); |
|
147 | - $cursor->closeCursor(); |
|
148 | - |
|
149 | - return $result ? true : false; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Add a user to a group |
|
154 | - * @param string $uid Name of the user to add to group |
|
155 | - * @param string $gid Name of the group in which add the user |
|
156 | - * @return bool |
|
157 | - * |
|
158 | - * Adds a user to a group. |
|
159 | - */ |
|
160 | - public function addToGroup( $uid, $gid ) { |
|
161 | - $this->fixDI(); |
|
162 | - |
|
163 | - // No duplicate entries! |
|
164 | - if( !$this->inGroup( $uid, $gid )) { |
|
165 | - $qb = $this->dbConn->getQueryBuilder(); |
|
166 | - $qb->insert('group_user') |
|
167 | - ->setValue('uid', $qb->createNamedParameter($uid)) |
|
168 | - ->setValue('gid', $qb->createNamedParameter($gid)) |
|
169 | - ->execute(); |
|
170 | - return true; |
|
171 | - }else{ |
|
172 | - return false; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Removes a user from a group |
|
178 | - * @param string $uid Name of the user to remove from group |
|
179 | - * @param string $gid Name of the group from which remove the user |
|
180 | - * @return bool |
|
181 | - * |
|
182 | - * removes the user from a group. |
|
183 | - */ |
|
184 | - public function removeFromGroup( $uid, $gid ) { |
|
185 | - $this->fixDI(); |
|
186 | - |
|
187 | - $qb = $this->dbConn->getQueryBuilder(); |
|
188 | - $qb->delete('group_user') |
|
189 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
190 | - ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
191 | - ->execute(); |
|
192 | - |
|
193 | - return true; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Get all groups a user belongs to |
|
198 | - * @param string $uid Name of the user |
|
199 | - * @return array an array of group names |
|
200 | - * |
|
201 | - * This function fetches all groups a user belongs to. It does not check |
|
202 | - * if the user exists at all. |
|
203 | - */ |
|
204 | - public function getUserGroups( $uid ) { |
|
205 | - //guests has empty or null $uid |
|
206 | - if ($uid === null || $uid === '') { |
|
207 | - return []; |
|
208 | - } |
|
209 | - |
|
210 | - $this->fixDI(); |
|
211 | - |
|
212 | - // No magic! |
|
213 | - $qb = $this->dbConn->getQueryBuilder(); |
|
214 | - $cursor = $qb->select('gid') |
|
215 | - ->from('group_user') |
|
216 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
217 | - ->execute(); |
|
218 | - |
|
219 | - $groups = []; |
|
220 | - while( $row = $cursor->fetch()) { |
|
221 | - $groups[] = $row["gid"]; |
|
222 | - $this->groupCache[$row['gid']] = $row['gid']; |
|
223 | - } |
|
224 | - $cursor->closeCursor(); |
|
225 | - |
|
226 | - return $groups; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * get a list of all groups |
|
231 | - * @param string $search |
|
232 | - * @param int $limit |
|
233 | - * @param int $offset |
|
234 | - * @return array an array of group names |
|
235 | - * |
|
236 | - * Returns a list with all groups |
|
237 | - */ |
|
238 | - public function getGroups($search = '', $limit = null, $offset = null) { |
|
239 | - $parameters = []; |
|
240 | - $searchLike = ''; |
|
241 | - if ($search !== '') { |
|
242 | - $parameters[] = '%' . $search . '%'; |
|
243 | - $searchLike = ' WHERE LOWER(`gid`) LIKE LOWER(?)'; |
|
244 | - } |
|
245 | - |
|
246 | - $stmt = \OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups`' . $searchLike . ' ORDER BY `gid` ASC', $limit, $offset); |
|
247 | - $result = $stmt->execute($parameters); |
|
248 | - $groups = array(); |
|
249 | - while ($row = $result->fetchRow()) { |
|
250 | - $groups[] = $row['gid']; |
|
251 | - } |
|
252 | - return $groups; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * check if a group exists |
|
257 | - * @param string $gid |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public function groupExists($gid) { |
|
261 | - $this->fixDI(); |
|
262 | - |
|
263 | - // Check cache first |
|
264 | - if (isset($this->groupCache[$gid])) { |
|
265 | - return true; |
|
266 | - } |
|
267 | - |
|
268 | - $qb = $this->dbConn->getQueryBuilder(); |
|
269 | - $cursor = $qb->select('gid') |
|
270 | - ->from('groups') |
|
271 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
272 | - ->execute(); |
|
273 | - $result = $cursor->fetch(); |
|
274 | - $cursor->closeCursor(); |
|
275 | - |
|
276 | - if ($result !== false) { |
|
277 | - $this->groupCache[$gid] = $gid; |
|
278 | - return true; |
|
279 | - } |
|
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * get a list of all users in a group |
|
285 | - * @param string $gid |
|
286 | - * @param string $search |
|
287 | - * @param int $limit |
|
288 | - * @param int $offset |
|
289 | - * @return array an array of user ids |
|
290 | - */ |
|
291 | - public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { |
|
292 | - $parameters = [$gid]; |
|
293 | - $searchLike = ''; |
|
294 | - if ($search !== '') { |
|
295 | - $parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%'; |
|
296 | - $searchLike = ' AND `uid` LIKE ?'; |
|
297 | - } |
|
298 | - |
|
299 | - $stmt = \OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike . ' ORDER BY `uid` ASC', |
|
300 | - $limit, |
|
301 | - $offset); |
|
302 | - $result = $stmt->execute($parameters); |
|
303 | - $users = array(); |
|
304 | - while ($row = $result->fetchRow()) { |
|
305 | - $users[] = $row['uid']; |
|
306 | - } |
|
307 | - return $users; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * get the number of all users matching the search string in a group |
|
312 | - * @param string $gid |
|
313 | - * @param string $search |
|
314 | - * @return int|false |
|
315 | - * @throws \OC\DatabaseException |
|
316 | - */ |
|
317 | - public function countUsersInGroup($gid, $search = '') { |
|
318 | - $parameters = [$gid]; |
|
319 | - $searchLike = ''; |
|
320 | - if ($search !== '') { |
|
321 | - $parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%'; |
|
322 | - $searchLike = ' AND `uid` LIKE ?'; |
|
323 | - } |
|
324 | - |
|
325 | - $stmt = \OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike); |
|
326 | - $result = $stmt->execute($parameters); |
|
327 | - $count = $result->fetchOne(); |
|
328 | - if($count !== false) { |
|
329 | - $count = intval($count); |
|
330 | - } |
|
331 | - return $count; |
|
332 | - } |
|
47 | + /** @var string[] */ |
|
48 | + private $groupCache = []; |
|
49 | + |
|
50 | + /** @var \OCP\IDBConnection */ |
|
51 | + private $dbConn; |
|
52 | + |
|
53 | + /** |
|
54 | + * \OC\Group\Database constructor. |
|
55 | + * |
|
56 | + * @param \OCP\IDBConnection|null $dbConn |
|
57 | + */ |
|
58 | + public function __construct(\OCP\IDBConnection $dbConn = null) { |
|
59 | + $this->dbConn = $dbConn; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * FIXME: This function should not be required! |
|
64 | + */ |
|
65 | + private function fixDI() { |
|
66 | + if ($this->dbConn === null) { |
|
67 | + $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Try to create a new group |
|
73 | + * @param string $gid The name of the group to create |
|
74 | + * @return bool |
|
75 | + * |
|
76 | + * Tries to create a new group. If the group name already exists, false will |
|
77 | + * be returned. |
|
78 | + */ |
|
79 | + public function createGroup( $gid ) { |
|
80 | + $this->fixDI(); |
|
81 | + |
|
82 | + // Add group |
|
83 | + $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [ |
|
84 | + 'gid' => $gid, |
|
85 | + ]); |
|
86 | + |
|
87 | + // Add to cache |
|
88 | + $this->groupCache[$gid] = $gid; |
|
89 | + |
|
90 | + return $result === 1; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * delete a group |
|
95 | + * @param string $gid gid of the group to delete |
|
96 | + * @return bool |
|
97 | + * |
|
98 | + * Deletes a group and removes it from the group_user-table |
|
99 | + */ |
|
100 | + public function deleteGroup( $gid ) { |
|
101 | + $this->fixDI(); |
|
102 | + |
|
103 | + // Delete the group |
|
104 | + $qb = $this->dbConn->getQueryBuilder(); |
|
105 | + $qb->delete('groups') |
|
106 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
107 | + ->execute(); |
|
108 | + |
|
109 | + // Delete the group-user relation |
|
110 | + $qb = $this->dbConn->getQueryBuilder(); |
|
111 | + $qb->delete('group_user') |
|
112 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
113 | + ->execute(); |
|
114 | + |
|
115 | + // Delete the group-groupadmin relation |
|
116 | + $qb = $this->dbConn->getQueryBuilder(); |
|
117 | + $qb->delete('group_admin') |
|
118 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
119 | + ->execute(); |
|
120 | + |
|
121 | + // Delete from cache |
|
122 | + unset($this->groupCache[$gid]); |
|
123 | + |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * is user in group? |
|
129 | + * @param string $uid uid of the user |
|
130 | + * @param string $gid gid of the group |
|
131 | + * @return bool |
|
132 | + * |
|
133 | + * Checks whether the user is member of a group or not. |
|
134 | + */ |
|
135 | + public function inGroup( $uid, $gid ) { |
|
136 | + $this->fixDI(); |
|
137 | + |
|
138 | + // check |
|
139 | + $qb = $this->dbConn->getQueryBuilder(); |
|
140 | + $cursor = $qb->select('uid') |
|
141 | + ->from('group_user') |
|
142 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
143 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
144 | + ->execute(); |
|
145 | + |
|
146 | + $result = $cursor->fetch(); |
|
147 | + $cursor->closeCursor(); |
|
148 | + |
|
149 | + return $result ? true : false; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Add a user to a group |
|
154 | + * @param string $uid Name of the user to add to group |
|
155 | + * @param string $gid Name of the group in which add the user |
|
156 | + * @return bool |
|
157 | + * |
|
158 | + * Adds a user to a group. |
|
159 | + */ |
|
160 | + public function addToGroup( $uid, $gid ) { |
|
161 | + $this->fixDI(); |
|
162 | + |
|
163 | + // No duplicate entries! |
|
164 | + if( !$this->inGroup( $uid, $gid )) { |
|
165 | + $qb = $this->dbConn->getQueryBuilder(); |
|
166 | + $qb->insert('group_user') |
|
167 | + ->setValue('uid', $qb->createNamedParameter($uid)) |
|
168 | + ->setValue('gid', $qb->createNamedParameter($gid)) |
|
169 | + ->execute(); |
|
170 | + return true; |
|
171 | + }else{ |
|
172 | + return false; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Removes a user from a group |
|
178 | + * @param string $uid Name of the user to remove from group |
|
179 | + * @param string $gid Name of the group from which remove the user |
|
180 | + * @return bool |
|
181 | + * |
|
182 | + * removes the user from a group. |
|
183 | + */ |
|
184 | + public function removeFromGroup( $uid, $gid ) { |
|
185 | + $this->fixDI(); |
|
186 | + |
|
187 | + $qb = $this->dbConn->getQueryBuilder(); |
|
188 | + $qb->delete('group_user') |
|
189 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
190 | + ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
191 | + ->execute(); |
|
192 | + |
|
193 | + return true; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Get all groups a user belongs to |
|
198 | + * @param string $uid Name of the user |
|
199 | + * @return array an array of group names |
|
200 | + * |
|
201 | + * This function fetches all groups a user belongs to. It does not check |
|
202 | + * if the user exists at all. |
|
203 | + */ |
|
204 | + public function getUserGroups( $uid ) { |
|
205 | + //guests has empty or null $uid |
|
206 | + if ($uid === null || $uid === '') { |
|
207 | + return []; |
|
208 | + } |
|
209 | + |
|
210 | + $this->fixDI(); |
|
211 | + |
|
212 | + // No magic! |
|
213 | + $qb = $this->dbConn->getQueryBuilder(); |
|
214 | + $cursor = $qb->select('gid') |
|
215 | + ->from('group_user') |
|
216 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
217 | + ->execute(); |
|
218 | + |
|
219 | + $groups = []; |
|
220 | + while( $row = $cursor->fetch()) { |
|
221 | + $groups[] = $row["gid"]; |
|
222 | + $this->groupCache[$row['gid']] = $row['gid']; |
|
223 | + } |
|
224 | + $cursor->closeCursor(); |
|
225 | + |
|
226 | + return $groups; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * get a list of all groups |
|
231 | + * @param string $search |
|
232 | + * @param int $limit |
|
233 | + * @param int $offset |
|
234 | + * @return array an array of group names |
|
235 | + * |
|
236 | + * Returns a list with all groups |
|
237 | + */ |
|
238 | + public function getGroups($search = '', $limit = null, $offset = null) { |
|
239 | + $parameters = []; |
|
240 | + $searchLike = ''; |
|
241 | + if ($search !== '') { |
|
242 | + $parameters[] = '%' . $search . '%'; |
|
243 | + $searchLike = ' WHERE LOWER(`gid`) LIKE LOWER(?)'; |
|
244 | + } |
|
245 | + |
|
246 | + $stmt = \OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups`' . $searchLike . ' ORDER BY `gid` ASC', $limit, $offset); |
|
247 | + $result = $stmt->execute($parameters); |
|
248 | + $groups = array(); |
|
249 | + while ($row = $result->fetchRow()) { |
|
250 | + $groups[] = $row['gid']; |
|
251 | + } |
|
252 | + return $groups; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * check if a group exists |
|
257 | + * @param string $gid |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public function groupExists($gid) { |
|
261 | + $this->fixDI(); |
|
262 | + |
|
263 | + // Check cache first |
|
264 | + if (isset($this->groupCache[$gid])) { |
|
265 | + return true; |
|
266 | + } |
|
267 | + |
|
268 | + $qb = $this->dbConn->getQueryBuilder(); |
|
269 | + $cursor = $qb->select('gid') |
|
270 | + ->from('groups') |
|
271 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) |
|
272 | + ->execute(); |
|
273 | + $result = $cursor->fetch(); |
|
274 | + $cursor->closeCursor(); |
|
275 | + |
|
276 | + if ($result !== false) { |
|
277 | + $this->groupCache[$gid] = $gid; |
|
278 | + return true; |
|
279 | + } |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * get a list of all users in a group |
|
285 | + * @param string $gid |
|
286 | + * @param string $search |
|
287 | + * @param int $limit |
|
288 | + * @param int $offset |
|
289 | + * @return array an array of user ids |
|
290 | + */ |
|
291 | + public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { |
|
292 | + $parameters = [$gid]; |
|
293 | + $searchLike = ''; |
|
294 | + if ($search !== '') { |
|
295 | + $parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%'; |
|
296 | + $searchLike = ' AND `uid` LIKE ?'; |
|
297 | + } |
|
298 | + |
|
299 | + $stmt = \OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike . ' ORDER BY `uid` ASC', |
|
300 | + $limit, |
|
301 | + $offset); |
|
302 | + $result = $stmt->execute($parameters); |
|
303 | + $users = array(); |
|
304 | + while ($row = $result->fetchRow()) { |
|
305 | + $users[] = $row['uid']; |
|
306 | + } |
|
307 | + return $users; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * get the number of all users matching the search string in a group |
|
312 | + * @param string $gid |
|
313 | + * @param string $search |
|
314 | + * @return int|false |
|
315 | + * @throws \OC\DatabaseException |
|
316 | + */ |
|
317 | + public function countUsersInGroup($gid, $search = '') { |
|
318 | + $parameters = [$gid]; |
|
319 | + $searchLike = ''; |
|
320 | + if ($search !== '') { |
|
321 | + $parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%'; |
|
322 | + $searchLike = ' AND `uid` LIKE ?'; |
|
323 | + } |
|
324 | + |
|
325 | + $stmt = \OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike); |
|
326 | + $result = $stmt->execute($parameters); |
|
327 | + $count = $result->fetchOne(); |
|
328 | + if($count !== false) { |
|
329 | + $count = intval($count); |
|
330 | + } |
|
331 | + return $count; |
|
332 | + } |
|
333 | 333 | |
334 | 334 | } |
@@ -26,8 +26,8 @@ |
||
26 | 26 | $server = \OC::$server; |
27 | 27 | |
28 | 28 | $controller = new \OC\OCS\Provider( |
29 | - 'ocs_provider', |
|
30 | - $server->getRequest(), |
|
31 | - $server->getAppManager() |
|
29 | + 'ocs_provider', |
|
30 | + $server->getRequest(), |
|
31 | + $server->getAppManager() |
|
32 | 32 | ); |
33 | 33 | echo $controller->buildProviderList()->render(); |
@@ -4,7 +4,7 @@ |
||
4 | 4 | <h2 class="title"><?php p($l->t('App update required')); ?></h2> |
5 | 5 | <?php } else { ?> |
6 | 6 | <h2 class="title"><?php p($l->t('%s will be updated to version %s', |
7 | - array($_['productName'], $_['version']))); ?></h2> |
|
7 | + array($_['productName'], $_['version']))); ?></h2> |
|
8 | 8 | <?php } ?> |
9 | 9 | <?php if (!empty($_['appsToUpgrade'])) { ?> |
10 | 10 | <div class="infogroup"> |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | - /** @var array $_ */ |
|
3 | - /** @var \OCP\IL10N $l */ |
|
2 | + /** @var array $_ */ |
|
3 | + /** @var \OCP\IL10N $l */ |
|
4 | 4 | |
5 | 5 | style('core', ['styles', 'header']); |
6 | 6 | ?> |
@@ -31,32 +31,32 @@ |
||
31 | 31 | \OC::$server->getSession()->close(); |
32 | 32 | |
33 | 33 | if (isset($_GET['query'])) { |
34 | - $query = $_GET['query']; |
|
34 | + $query = $_GET['query']; |
|
35 | 35 | } else { |
36 | - $query = ''; |
|
36 | + $query = ''; |
|
37 | 37 | } |
38 | 38 | if (isset($_GET['inApps'])) { |
39 | - $inApps = $_GET['inApps']; |
|
40 | - if (is_string($inApps)) { |
|
41 | - $inApps = array($inApps); |
|
42 | - } |
|
39 | + $inApps = $_GET['inApps']; |
|
40 | + if (is_string($inApps)) { |
|
41 | + $inApps = array($inApps); |
|
42 | + } |
|
43 | 43 | } else { |
44 | - $inApps = array(); |
|
44 | + $inApps = array(); |
|
45 | 45 | } |
46 | 46 | if (isset($_GET['page'])) { |
47 | - $page = (int)$_GET['page']; |
|
47 | + $page = (int)$_GET['page']; |
|
48 | 48 | } else { |
49 | - $page = 1; |
|
49 | + $page = 1; |
|
50 | 50 | } |
51 | 51 | if (isset($_GET['size'])) { |
52 | - $size = (int)$_GET['size']; |
|
52 | + $size = (int)$_GET['size']; |
|
53 | 53 | } else { |
54 | - $size = 30; |
|
54 | + $size = 30; |
|
55 | 55 | } |
56 | 56 | if($query) { |
57 | - $result = \OC::$server->getSearch()->searchPaged($query, $inApps, $page, $size); |
|
58 | - OC_JSON::encodedPrint($result); |
|
57 | + $result = \OC::$server->getSearch()->searchPaged($query, $inApps, $page, $size); |
|
58 | + OC_JSON::encodedPrint($result); |
|
59 | 59 | } |
60 | 60 | else { |
61 | - echo 'false'; |
|
61 | + echo 'false'; |
|
62 | 62 | } |
@@ -31,97 +31,97 @@ |
||
31 | 31 | use OC\Setup; |
32 | 32 | |
33 | 33 | class SetupController { |
34 | - /** @var Setup */ |
|
35 | - protected $setupHelper; |
|
36 | - /** @var string */ |
|
37 | - private $autoConfigFile; |
|
34 | + /** @var Setup */ |
|
35 | + protected $setupHelper; |
|
36 | + /** @var string */ |
|
37 | + private $autoConfigFile; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Setup $setupHelper |
|
41 | - */ |
|
42 | - function __construct(Setup $setupHelper) { |
|
43 | - $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
44 | - $this->setupHelper = $setupHelper; |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param Setup $setupHelper |
|
41 | + */ |
|
42 | + function __construct(Setup $setupHelper) { |
|
43 | + $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
44 | + $this->setupHelper = $setupHelper; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param $post |
|
49 | - */ |
|
50 | - public function run($post) { |
|
51 | - // Check for autosetup: |
|
52 | - $post = $this->loadAutoConfig($post); |
|
53 | - $opts = $this->setupHelper->getSystemInfo(); |
|
47 | + /** |
|
48 | + * @param $post |
|
49 | + */ |
|
50 | + public function run($post) { |
|
51 | + // Check for autosetup: |
|
52 | + $post = $this->loadAutoConfig($post); |
|
53 | + $opts = $this->setupHelper->getSystemInfo(); |
|
54 | 54 | |
55 | - // convert 'abcpassword' to 'abcpass' |
|
56 | - if (isset($post['adminpassword'])) { |
|
57 | - $post['adminpass'] = $post['adminpassword']; |
|
58 | - } |
|
59 | - if (isset($post['dbpassword'])) { |
|
60 | - $post['dbpass'] = $post['dbpassword']; |
|
61 | - } |
|
55 | + // convert 'abcpassword' to 'abcpass' |
|
56 | + if (isset($post['adminpassword'])) { |
|
57 | + $post['adminpass'] = $post['adminpassword']; |
|
58 | + } |
|
59 | + if (isset($post['dbpassword'])) { |
|
60 | + $post['dbpass'] = $post['dbpassword']; |
|
61 | + } |
|
62 | 62 | |
63 | - if(isset($post['install']) AND $post['install']=='true') { |
|
64 | - // We have to launch the installation process : |
|
65 | - $e = $this->setupHelper->install($post); |
|
66 | - $errors = array('errors' => $e); |
|
63 | + if(isset($post['install']) AND $post['install']=='true') { |
|
64 | + // We have to launch the installation process : |
|
65 | + $e = $this->setupHelper->install($post); |
|
66 | + $errors = array('errors' => $e); |
|
67 | 67 | |
68 | - if(count($e) > 0) { |
|
69 | - $options = array_merge($opts, $post, $errors); |
|
70 | - $this->display($options); |
|
71 | - } else { |
|
72 | - $this->finishSetup(); |
|
73 | - } |
|
74 | - } else { |
|
75 | - $options = array_merge($opts, $post); |
|
76 | - $this->display($options); |
|
77 | - } |
|
78 | - } |
|
68 | + if(count($e) > 0) { |
|
69 | + $options = array_merge($opts, $post, $errors); |
|
70 | + $this->display($options); |
|
71 | + } else { |
|
72 | + $this->finishSetup(); |
|
73 | + } |
|
74 | + } else { |
|
75 | + $options = array_merge($opts, $post); |
|
76 | + $this->display($options); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - public function display($post) { |
|
81 | - $defaults = array( |
|
82 | - 'adminlogin' => '', |
|
83 | - 'adminpass' => '', |
|
84 | - 'dbuser' => '', |
|
85 | - 'dbpass' => '', |
|
86 | - 'dbname' => '', |
|
87 | - 'dbtablespace' => '', |
|
88 | - 'dbhost' => 'localhost', |
|
89 | - 'dbtype' => '', |
|
90 | - ); |
|
91 | - $parameters = array_merge($defaults, $post); |
|
80 | + public function display($post) { |
|
81 | + $defaults = array( |
|
82 | + 'adminlogin' => '', |
|
83 | + 'adminpass' => '', |
|
84 | + 'dbuser' => '', |
|
85 | + 'dbpass' => '', |
|
86 | + 'dbname' => '', |
|
87 | + 'dbtablespace' => '', |
|
88 | + 'dbhost' => 'localhost', |
|
89 | + 'dbtype' => '', |
|
90 | + ); |
|
91 | + $parameters = array_merge($defaults, $post); |
|
92 | 92 | |
93 | - \OC_Util::addVendorScript('strengthify/jquery.strengthify'); |
|
94 | - \OC_Util::addVendorStyle('strengthify/strengthify'); |
|
95 | - \OC_Util::addScript('setup'); |
|
96 | - \OC_Template::printGuestPage('', 'installation', $parameters); |
|
97 | - } |
|
93 | + \OC_Util::addVendorScript('strengthify/jquery.strengthify'); |
|
94 | + \OC_Util::addVendorStyle('strengthify/strengthify'); |
|
95 | + \OC_Util::addScript('setup'); |
|
96 | + \OC_Template::printGuestPage('', 'installation', $parameters); |
|
97 | + } |
|
98 | 98 | |
99 | - public function finishSetup() { |
|
100 | - if( file_exists( $this->autoConfigFile )) { |
|
101 | - unlink($this->autoConfigFile); |
|
102 | - } |
|
103 | - \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
104 | - \OC_Util::redirectToDefaultPage(); |
|
105 | - } |
|
99 | + public function finishSetup() { |
|
100 | + if( file_exists( $this->autoConfigFile )) { |
|
101 | + unlink($this->autoConfigFile); |
|
102 | + } |
|
103 | + \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
104 | + \OC_Util::redirectToDefaultPage(); |
|
105 | + } |
|
106 | 106 | |
107 | - public function loadAutoConfig($post) { |
|
108 | - if( file_exists($this->autoConfigFile)) { |
|
109 | - \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', \OCP\Util::INFO); |
|
110 | - $AUTOCONFIG = array(); |
|
111 | - include $this->autoConfigFile; |
|
112 | - $post = array_merge ($post, $AUTOCONFIG); |
|
113 | - } |
|
107 | + public function loadAutoConfig($post) { |
|
108 | + if( file_exists($this->autoConfigFile)) { |
|
109 | + \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', \OCP\Util::INFO); |
|
110 | + $AUTOCONFIG = array(); |
|
111 | + include $this->autoConfigFile; |
|
112 | + $post = array_merge ($post, $AUTOCONFIG); |
|
113 | + } |
|
114 | 114 | |
115 | - $dbIsSet = isset($post['dbtype']); |
|
116 | - $directoryIsSet = isset($post['directory']); |
|
117 | - $adminAccountIsSet = isset($post['adminlogin']); |
|
115 | + $dbIsSet = isset($post['dbtype']); |
|
116 | + $directoryIsSet = isset($post['directory']); |
|
117 | + $adminAccountIsSet = isset($post['adminlogin']); |
|
118 | 118 | |
119 | - if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) { |
|
120 | - $post['install'] = 'true'; |
|
121 | - } |
|
122 | - $post['dbIsSet'] = $dbIsSet; |
|
123 | - $post['directoryIsSet'] = $directoryIsSet; |
|
119 | + if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) { |
|
120 | + $post['install'] = 'true'; |
|
121 | + } |
|
122 | + $post['dbIsSet'] = $dbIsSet; |
|
123 | + $post['directoryIsSet'] = $directoryIsSet; |
|
124 | 124 | |
125 | - return $post; |
|
126 | - } |
|
125 | + return $post; |
|
126 | + } |
|
127 | 127 | } |
@@ -29,46 +29,46 @@ |
||
29 | 29 | use \OCP\IUserManager; |
30 | 30 | |
31 | 31 | class UserController extends Controller { |
32 | - /** |
|
33 | - * @var IUserManager |
|
34 | - */ |
|
35 | - protected $userManager; |
|
32 | + /** |
|
33 | + * @var IUserManager |
|
34 | + */ |
|
35 | + protected $userManager; |
|
36 | 36 | |
37 | - public function __construct($appName, |
|
38 | - IRequest $request, |
|
39 | - IUserManager $userManager |
|
40 | - ) { |
|
41 | - parent::__construct($appName, $request); |
|
42 | - $this->userManager = $userManager; |
|
43 | - } |
|
37 | + public function __construct($appName, |
|
38 | + IRequest $request, |
|
39 | + IUserManager $userManager |
|
40 | + ) { |
|
41 | + parent::__construct($appName, $request); |
|
42 | + $this->userManager = $userManager; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Lookup user display names |
|
47 | - * |
|
48 | - * @NoAdminRequired |
|
49 | - * |
|
50 | - * @param array $users |
|
51 | - * |
|
52 | - * @return JSONResponse |
|
53 | - */ |
|
54 | - public function getDisplayNames($users) { |
|
55 | - $result = array(); |
|
45 | + /** |
|
46 | + * Lookup user display names |
|
47 | + * |
|
48 | + * @NoAdminRequired |
|
49 | + * |
|
50 | + * @param array $users |
|
51 | + * |
|
52 | + * @return JSONResponse |
|
53 | + */ |
|
54 | + public function getDisplayNames($users) { |
|
55 | + $result = array(); |
|
56 | 56 | |
57 | - foreach ($users as $user) { |
|
58 | - $userObject = $this->userManager->get($user); |
|
59 | - if (is_object($userObject)) { |
|
60 | - $result[$user] = $userObject->getDisplayName(); |
|
61 | - } else { |
|
62 | - $result[$user] = $user; |
|
63 | - } |
|
64 | - } |
|
57 | + foreach ($users as $user) { |
|
58 | + $userObject = $this->userManager->get($user); |
|
59 | + if (is_object($userObject)) { |
|
60 | + $result[$user] = $userObject->getDisplayName(); |
|
61 | + } else { |
|
62 | + $result[$user] = $user; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - $json = array( |
|
67 | - 'users' => $result, |
|
68 | - 'status' => 'success' |
|
69 | - ); |
|
66 | + $json = array( |
|
67 | + 'users' => $result, |
|
68 | + 'status' => 'success' |
|
69 | + ); |
|
70 | 70 | |
71 | - return new JSONResponse($json); |
|
71 | + return new JSONResponse($json); |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | } |
@@ -34,28 +34,28 @@ |
||
34 | 34 | |
35 | 35 | class RemoveCertificate extends Base { |
36 | 36 | |
37 | - /** @var ICertificateManager */ |
|
38 | - protected $certificateManager; |
|
39 | - |
|
40 | - public function __construct(ICertificateManager $certificateManager) { |
|
41 | - $this->certificateManager = $certificateManager; |
|
42 | - parent::__construct(); |
|
43 | - } |
|
44 | - |
|
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('security:certificates:remove') |
|
48 | - ->setDescription('remove trusted certificate') |
|
49 | - ->addArgument( |
|
50 | - 'name', |
|
51 | - InputArgument::REQUIRED, |
|
52 | - 'the file name of the certificate to remove' |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | - $name = $input->getArgument('name'); |
|
58 | - |
|
59 | - $this->certificateManager->removeCertificate($name); |
|
60 | - } |
|
37 | + /** @var ICertificateManager */ |
|
38 | + protected $certificateManager; |
|
39 | + |
|
40 | + public function __construct(ICertificateManager $certificateManager) { |
|
41 | + $this->certificateManager = $certificateManager; |
|
42 | + parent::__construct(); |
|
43 | + } |
|
44 | + |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('security:certificates:remove') |
|
48 | + ->setDescription('remove trusted certificate') |
|
49 | + ->addArgument( |
|
50 | + 'name', |
|
51 | + InputArgument::REQUIRED, |
|
52 | + 'the file name of the certificate to remove' |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | + $name = $input->getArgument('name'); |
|
58 | + |
|
59 | + $this->certificateManager->removeCertificate($name); |
|
60 | + } |
|
61 | 61 | } |