@@ -48,272 +48,272 @@ |
||
48 | 48 | |
49 | 49 | class GroupsController extends AUserData { |
50 | 50 | |
51 | - /** @var ILogger */ |
|
52 | - private $logger; |
|
51 | + /** @var ILogger */ |
|
52 | + private $logger; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $appName |
|
56 | - * @param IRequest $request |
|
57 | - * @param IUserManager $userManager |
|
58 | - * @param IConfig $config |
|
59 | - * @param IGroupManager $groupManager |
|
60 | - * @param IUserSession $userSession |
|
61 | - * @param AccountManager $accountManager |
|
62 | - * @param ILogger $logger |
|
63 | - * @param UsersController $userController |
|
64 | - */ |
|
65 | - public function __construct(string $appName, |
|
66 | - IRequest $request, |
|
67 | - IUserManager $userManager, |
|
68 | - IConfig $config, |
|
69 | - IGroupManager $groupManager, |
|
70 | - IUserSession $userSession, |
|
71 | - AccountManager $accountManager, |
|
72 | - ILogger $logger) { |
|
73 | - parent::__construct($appName, |
|
74 | - $request, |
|
75 | - $userManager, |
|
76 | - $config, |
|
77 | - $groupManager, |
|
78 | - $userSession, |
|
79 | - $accountManager); |
|
54 | + /** |
|
55 | + * @param string $appName |
|
56 | + * @param IRequest $request |
|
57 | + * @param IUserManager $userManager |
|
58 | + * @param IConfig $config |
|
59 | + * @param IGroupManager $groupManager |
|
60 | + * @param IUserSession $userSession |
|
61 | + * @param AccountManager $accountManager |
|
62 | + * @param ILogger $logger |
|
63 | + * @param UsersController $userController |
|
64 | + */ |
|
65 | + public function __construct(string $appName, |
|
66 | + IRequest $request, |
|
67 | + IUserManager $userManager, |
|
68 | + IConfig $config, |
|
69 | + IGroupManager $groupManager, |
|
70 | + IUserSession $userSession, |
|
71 | + AccountManager $accountManager, |
|
72 | + ILogger $logger) { |
|
73 | + parent::__construct($appName, |
|
74 | + $request, |
|
75 | + $userManager, |
|
76 | + $config, |
|
77 | + $groupManager, |
|
78 | + $userSession, |
|
79 | + $accountManager); |
|
80 | 80 | |
81 | - $this->logger = $logger; |
|
82 | - } |
|
81 | + $this->logger = $logger; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * returns a list of groups |
|
86 | - * |
|
87 | - * @NoAdminRequired |
|
88 | - * |
|
89 | - * @param string $search |
|
90 | - * @param int $limit |
|
91 | - * @param int $offset |
|
92 | - * @return DataResponse |
|
93 | - */ |
|
94 | - public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
95 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
96 | - $groups = array_map(function ($group) { |
|
97 | - /** @var IGroup $group */ |
|
98 | - return $group->getGID(); |
|
99 | - }, $groups); |
|
84 | + /** |
|
85 | + * returns a list of groups |
|
86 | + * |
|
87 | + * @NoAdminRequired |
|
88 | + * |
|
89 | + * @param string $search |
|
90 | + * @param int $limit |
|
91 | + * @param int $offset |
|
92 | + * @return DataResponse |
|
93 | + */ |
|
94 | + public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
95 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
96 | + $groups = array_map(function ($group) { |
|
97 | + /** @var IGroup $group */ |
|
98 | + return $group->getGID(); |
|
99 | + }, $groups); |
|
100 | 100 | |
101 | - return new DataResponse(['groups' => $groups]); |
|
102 | - } |
|
101 | + return new DataResponse(['groups' => $groups]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * returns a list of groups details with ids and displaynames |
|
106 | - * |
|
107 | - * @NoAdminRequired |
|
108 | - * |
|
109 | - * @param string $search |
|
110 | - * @param int $limit |
|
111 | - * @param int $offset |
|
112 | - * @return DataResponse |
|
113 | - */ |
|
114 | - public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
115 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
116 | - $groups = array_map(function ($group) { |
|
117 | - /** @var IGroup $group */ |
|
118 | - return [ |
|
119 | - 'id' => $group->getGID(), |
|
120 | - 'displayname' => $group->getDisplayName(), |
|
121 | - 'usercount' => $group->count(), |
|
122 | - 'disabled' => $group->countDisabled(), |
|
123 | - 'canAdd' => $group->canAddUser(), |
|
124 | - 'canRemove' => $group->canRemoveUser(), |
|
125 | - ]; |
|
126 | - }, $groups); |
|
104 | + /** |
|
105 | + * returns a list of groups details with ids and displaynames |
|
106 | + * |
|
107 | + * @NoAdminRequired |
|
108 | + * |
|
109 | + * @param string $search |
|
110 | + * @param int $limit |
|
111 | + * @param int $offset |
|
112 | + * @return DataResponse |
|
113 | + */ |
|
114 | + public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
115 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
116 | + $groups = array_map(function ($group) { |
|
117 | + /** @var IGroup $group */ |
|
118 | + return [ |
|
119 | + 'id' => $group->getGID(), |
|
120 | + 'displayname' => $group->getDisplayName(), |
|
121 | + 'usercount' => $group->count(), |
|
122 | + 'disabled' => $group->countDisabled(), |
|
123 | + 'canAdd' => $group->canAddUser(), |
|
124 | + 'canRemove' => $group->canRemoveUser(), |
|
125 | + ]; |
|
126 | + }, $groups); |
|
127 | 127 | |
128 | - return new DataResponse(['groups' => $groups]); |
|
129 | - } |
|
128 | + return new DataResponse(['groups' => $groups]); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @NoAdminRequired |
|
133 | - * |
|
134 | - * @param string $groupId |
|
135 | - * @return DataResponse |
|
136 | - * @throws OCSException |
|
137 | - * |
|
138 | - * @deprecated 14 Use getGroupUsers |
|
139 | - */ |
|
140 | - public function getGroup(string $groupId): DataResponse { |
|
141 | - return $this->getGroupUsers($groupId); |
|
142 | - } |
|
131 | + /** |
|
132 | + * @NoAdminRequired |
|
133 | + * |
|
134 | + * @param string $groupId |
|
135 | + * @return DataResponse |
|
136 | + * @throws OCSException |
|
137 | + * |
|
138 | + * @deprecated 14 Use getGroupUsers |
|
139 | + */ |
|
140 | + public function getGroup(string $groupId): DataResponse { |
|
141 | + return $this->getGroupUsers($groupId); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * returns an array of users in the specified group |
|
146 | - * |
|
147 | - * @NoAdminRequired |
|
148 | - * |
|
149 | - * @param string $groupId |
|
150 | - * @return DataResponse |
|
151 | - * @throws OCSException |
|
152 | - */ |
|
153 | - public function getGroupUsers(string $groupId): DataResponse { |
|
154 | - $user = $this->userSession->getUser(); |
|
155 | - $isSubadminOfGroup = false; |
|
144 | + /** |
|
145 | + * returns an array of users in the specified group |
|
146 | + * |
|
147 | + * @NoAdminRequired |
|
148 | + * |
|
149 | + * @param string $groupId |
|
150 | + * @return DataResponse |
|
151 | + * @throws OCSException |
|
152 | + */ |
|
153 | + public function getGroupUsers(string $groupId): DataResponse { |
|
154 | + $user = $this->userSession->getUser(); |
|
155 | + $isSubadminOfGroup = false; |
|
156 | 156 | |
157 | - // Check the group exists |
|
158 | - $group = $this->groupManager->get($groupId); |
|
159 | - if ($group !== null) { |
|
160 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
161 | - } else { |
|
162 | - throw new OCSNotFoundException('The requested group could not be found'); |
|
163 | - } |
|
157 | + // Check the group exists |
|
158 | + $group = $this->groupManager->get($groupId); |
|
159 | + if ($group !== null) { |
|
160 | + $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
161 | + } else { |
|
162 | + throw new OCSNotFoundException('The requested group could not be found'); |
|
163 | + } |
|
164 | 164 | |
165 | - // Check subadmin has access to this group |
|
166 | - if($this->groupManager->isAdmin($user->getUID()) |
|
167 | - || $isSubadminOfGroup) { |
|
168 | - $users = $this->groupManager->get($groupId)->getUsers(); |
|
169 | - $users = array_map(function ($user) { |
|
170 | - /** @var IUser $user */ |
|
171 | - return $user->getUID(); |
|
172 | - }, $users); |
|
173 | - $users = array_values($users); |
|
174 | - return new DataResponse(['users' => $users]); |
|
175 | - } |
|
165 | + // Check subadmin has access to this group |
|
166 | + if($this->groupManager->isAdmin($user->getUID()) |
|
167 | + || $isSubadminOfGroup) { |
|
168 | + $users = $this->groupManager->get($groupId)->getUsers(); |
|
169 | + $users = array_map(function ($user) { |
|
170 | + /** @var IUser $user */ |
|
171 | + return $user->getUID(); |
|
172 | + }, $users); |
|
173 | + $users = array_values($users); |
|
174 | + return new DataResponse(['users' => $users]); |
|
175 | + } |
|
176 | 176 | |
177 | - throw new OCSForbiddenException(); |
|
178 | - } |
|
177 | + throw new OCSForbiddenException(); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * returns an array of users details in the specified group |
|
182 | - * |
|
183 | - * @NoAdminRequired |
|
184 | - * |
|
185 | - * @param string $groupId |
|
186 | - * @param string $search |
|
187 | - * @param int $limit |
|
188 | - * @param int $offset |
|
189 | - * @return DataResponse |
|
190 | - * @throws OCSException |
|
191 | - */ |
|
192 | - public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
193 | - $currentUser = $this->userSession->getUser(); |
|
180 | + /** |
|
181 | + * returns an array of users details in the specified group |
|
182 | + * |
|
183 | + * @NoAdminRequired |
|
184 | + * |
|
185 | + * @param string $groupId |
|
186 | + * @param string $search |
|
187 | + * @param int $limit |
|
188 | + * @param int $offset |
|
189 | + * @return DataResponse |
|
190 | + * @throws OCSException |
|
191 | + */ |
|
192 | + public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
193 | + $currentUser = $this->userSession->getUser(); |
|
194 | 194 | |
195 | - // Check the group exists |
|
196 | - $group = $this->groupManager->get($groupId); |
|
197 | - if ($group !== null) { |
|
198 | - $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); |
|
199 | - } else { |
|
200 | - throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
201 | - } |
|
195 | + // Check the group exists |
|
196 | + $group = $this->groupManager->get($groupId); |
|
197 | + if ($group !== null) { |
|
198 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); |
|
199 | + } else { |
|
200 | + throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
201 | + } |
|
202 | 202 | |
203 | - // Check subadmin has access to this group |
|
204 | - if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
205 | - $users = $group->searchUsers($search, $limit, $offset); |
|
203 | + // Check subadmin has access to this group |
|
204 | + if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
205 | + $users = $group->searchUsers($search, $limit, $offset); |
|
206 | 206 | |
207 | - // Extract required number |
|
208 | - $usersDetails = []; |
|
209 | - foreach ($users as $user) { |
|
210 | - try { |
|
211 | - /** @var IUser $user */ |
|
212 | - $userId = (string)$user->getUID(); |
|
213 | - $userData = $this->getUserData($userId); |
|
214 | - // Do not insert empty entry |
|
215 | - if (!empty($userData)) { |
|
216 | - $usersDetails[$userId] = $userData; |
|
217 | - } else { |
|
218 | - // Logged user does not have permissions to see this user |
|
219 | - // only showing its id |
|
220 | - $usersDetails[$userId] = ['id' => $userId]; |
|
221 | - } |
|
222 | - } catch(OCSNotFoundException $e) { |
|
223 | - // continue if a users ceased to exist. |
|
224 | - } |
|
225 | - } |
|
226 | - return new DataResponse(['users' => $usersDetails]); |
|
227 | - } |
|
207 | + // Extract required number |
|
208 | + $usersDetails = []; |
|
209 | + foreach ($users as $user) { |
|
210 | + try { |
|
211 | + /** @var IUser $user */ |
|
212 | + $userId = (string)$user->getUID(); |
|
213 | + $userData = $this->getUserData($userId); |
|
214 | + // Do not insert empty entry |
|
215 | + if (!empty($userData)) { |
|
216 | + $usersDetails[$userId] = $userData; |
|
217 | + } else { |
|
218 | + // Logged user does not have permissions to see this user |
|
219 | + // only showing its id |
|
220 | + $usersDetails[$userId] = ['id' => $userId]; |
|
221 | + } |
|
222 | + } catch(OCSNotFoundException $e) { |
|
223 | + // continue if a users ceased to exist. |
|
224 | + } |
|
225 | + } |
|
226 | + return new DataResponse(['users' => $usersDetails]); |
|
227 | + } |
|
228 | 228 | |
229 | - throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
230 | - } |
|
229 | + throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * creates a new group |
|
234 | - * |
|
235 | - * @PasswordConfirmationRequired |
|
236 | - * |
|
237 | - * @param string $groupid |
|
238 | - * @return DataResponse |
|
239 | - * @throws OCSException |
|
240 | - */ |
|
241 | - public function addGroup(string $groupid): DataResponse { |
|
242 | - // Validate name |
|
243 | - if(empty($groupid)) { |
|
244 | - $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
245 | - throw new OCSException('Invalid group name', 101); |
|
246 | - } |
|
247 | - // Check if it exists |
|
248 | - if($this->groupManager->groupExists($groupid)){ |
|
249 | - throw new OCSException('group exists', 102); |
|
250 | - } |
|
251 | - $this->groupManager->createGroup($groupid); |
|
252 | - return new DataResponse(); |
|
253 | - } |
|
232 | + /** |
|
233 | + * creates a new group |
|
234 | + * |
|
235 | + * @PasswordConfirmationRequired |
|
236 | + * |
|
237 | + * @param string $groupid |
|
238 | + * @return DataResponse |
|
239 | + * @throws OCSException |
|
240 | + */ |
|
241 | + public function addGroup(string $groupid): DataResponse { |
|
242 | + // Validate name |
|
243 | + if(empty($groupid)) { |
|
244 | + $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
245 | + throw new OCSException('Invalid group name', 101); |
|
246 | + } |
|
247 | + // Check if it exists |
|
248 | + if($this->groupManager->groupExists($groupid)){ |
|
249 | + throw new OCSException('group exists', 102); |
|
250 | + } |
|
251 | + $this->groupManager->createGroup($groupid); |
|
252 | + return new DataResponse(); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @PasswordConfirmationRequired |
|
257 | - * |
|
258 | - * @param string $groupId |
|
259 | - * @param string $key |
|
260 | - * @param string $value |
|
261 | - * @return DataResponse |
|
262 | - * @throws OCSException |
|
263 | - */ |
|
264 | - public function updateGroup(string $groupId, string $key, string $value): DataResponse { |
|
265 | - if ($key === 'displayname') { |
|
266 | - $group = $this->groupManager->get($groupId); |
|
267 | - if ($group->setDisplayName($value)) { |
|
268 | - return new DataResponse(); |
|
269 | - } |
|
255 | + /** |
|
256 | + * @PasswordConfirmationRequired |
|
257 | + * |
|
258 | + * @param string $groupId |
|
259 | + * @param string $key |
|
260 | + * @param string $value |
|
261 | + * @return DataResponse |
|
262 | + * @throws OCSException |
|
263 | + */ |
|
264 | + public function updateGroup(string $groupId, string $key, string $value): DataResponse { |
|
265 | + if ($key === 'displayname') { |
|
266 | + $group = $this->groupManager->get($groupId); |
|
267 | + if ($group->setDisplayName($value)) { |
|
268 | + return new DataResponse(); |
|
269 | + } |
|
270 | 270 | |
271 | - throw new OCSException('Not supported by backend', 101); |
|
272 | - } else { |
|
273 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
274 | - } |
|
275 | - } |
|
271 | + throw new OCSException('Not supported by backend', 101); |
|
272 | + } else { |
|
273 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @PasswordConfirmationRequired |
|
279 | - * |
|
280 | - * @param string $groupId |
|
281 | - * @return DataResponse |
|
282 | - * @throws OCSException |
|
283 | - */ |
|
284 | - public function deleteGroup(string $groupId): DataResponse { |
|
285 | - // Check it exists |
|
286 | - if(!$this->groupManager->groupExists($groupId)){ |
|
287 | - throw new OCSException('', 101); |
|
288 | - } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
289 | - // Cannot delete admin group |
|
290 | - throw new OCSException('', 102); |
|
291 | - } |
|
277 | + /** |
|
278 | + * @PasswordConfirmationRequired |
|
279 | + * |
|
280 | + * @param string $groupId |
|
281 | + * @return DataResponse |
|
282 | + * @throws OCSException |
|
283 | + */ |
|
284 | + public function deleteGroup(string $groupId): DataResponse { |
|
285 | + // Check it exists |
|
286 | + if(!$this->groupManager->groupExists($groupId)){ |
|
287 | + throw new OCSException('', 101); |
|
288 | + } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
289 | + // Cannot delete admin group |
|
290 | + throw new OCSException('', 102); |
|
291 | + } |
|
292 | 292 | |
293 | - return new DataResponse(); |
|
294 | - } |
|
293 | + return new DataResponse(); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * @param string $groupId |
|
298 | - * @return DataResponse |
|
299 | - * @throws OCSException |
|
300 | - */ |
|
301 | - public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
302 | - // Check group exists |
|
303 | - $targetGroup = $this->groupManager->get($groupId); |
|
304 | - if($targetGroup === null) { |
|
305 | - throw new OCSException('Group does not exist', 101); |
|
306 | - } |
|
296 | + /** |
|
297 | + * @param string $groupId |
|
298 | + * @return DataResponse |
|
299 | + * @throws OCSException |
|
300 | + */ |
|
301 | + public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
302 | + // Check group exists |
|
303 | + $targetGroup = $this->groupManager->get($groupId); |
|
304 | + if($targetGroup === null) { |
|
305 | + throw new OCSException('Group does not exist', 101); |
|
306 | + } |
|
307 | 307 | |
308 | - /** @var IUser[] $subadmins */ |
|
309 | - $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
310 | - // New class returns IUser[] so convert back |
|
311 | - $uids = []; |
|
312 | - foreach ($subadmins as $user) { |
|
313 | - $uids[] = $user->getUID(); |
|
314 | - } |
|
308 | + /** @var IUser[] $subadmins */ |
|
309 | + $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
310 | + // New class returns IUser[] so convert back |
|
311 | + $uids = []; |
|
312 | + foreach ($subadmins as $user) { |
|
313 | + $uids[] = $user->getUID(); |
|
314 | + } |
|
315 | 315 | |
316 | - return new DataResponse($uids); |
|
317 | - } |
|
316 | + return new DataResponse($uids); |
|
317 | + } |
|
318 | 318 | |
319 | 319 | } |
@@ -43,55 +43,55 @@ |
||
43 | 43 | |
44 | 44 | class Application extends App { |
45 | 45 | |
46 | - const APP_ID = 'comments'; |
|
46 | + const APP_ID = 'comments'; |
|
47 | 47 | |
48 | - public function __construct(array $urlParams = []) { |
|
49 | - parent::__construct(self::APP_ID, $urlParams); |
|
50 | - $container = $this->getContainer(); |
|
48 | + public function __construct(array $urlParams = []) { |
|
49 | + parent::__construct(self::APP_ID, $urlParams); |
|
50 | + $container = $this->getContainer(); |
|
51 | 51 | |
52 | - $container->registerAlias('NotificationsController', Notifications::class); |
|
52 | + $container->registerAlias('NotificationsController', Notifications::class); |
|
53 | 53 | |
54 | - $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
55 | - Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
54 | + $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
55 | + Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
56 | 56 | |
57 | - $this->register(); |
|
58 | - } |
|
57 | + $this->register(); |
|
58 | + } |
|
59 | 59 | |
60 | - private function register() { |
|
61 | - $server = $this->getContainer()->getServer(); |
|
60 | + private function register() { |
|
61 | + $server = $this->getContainer()->getServer(); |
|
62 | 62 | |
63 | - /** @var IEventDispatcher $newDispatcher */ |
|
64 | - $dispatcher = $server->query(IEventDispatcher::class); |
|
63 | + /** @var IEventDispatcher $newDispatcher */ |
|
64 | + $dispatcher = $server->query(IEventDispatcher::class); |
|
65 | 65 | |
66 | - $this->registerEventsScripts($dispatcher); |
|
67 | - $this->registerDavEntity($dispatcher); |
|
68 | - $this->registerNotifier(); |
|
69 | - $this->registerCommentsEventHandler(); |
|
66 | + $this->registerEventsScripts($dispatcher); |
|
67 | + $this->registerDavEntity($dispatcher); |
|
68 | + $this->registerNotifier(); |
|
69 | + $this->registerCommentsEventHandler(); |
|
70 | 70 | |
71 | - $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
72 | - } |
|
71 | + $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
72 | + } |
|
73 | 73 | |
74 | - protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
75 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); |
|
76 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class); |
|
77 | - } |
|
74 | + protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
75 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); |
|
76 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class); |
|
77 | + } |
|
78 | 78 | |
79 | - protected function registerDavEntity(IEventDispatcher $dispatcher) { |
|
80 | - $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { |
|
81 | - $event->addEntityCollection('files', function ($name) { |
|
82 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
83 | - return !empty($nodes); |
|
84 | - }); |
|
85 | - }); |
|
86 | - } |
|
79 | + protected function registerDavEntity(IEventDispatcher $dispatcher) { |
|
80 | + $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { |
|
81 | + $event->addEntityCollection('files', function ($name) { |
|
82 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
83 | + return !empty($nodes); |
|
84 | + }); |
|
85 | + }); |
|
86 | + } |
|
87 | 87 | |
88 | - protected function registerNotifier() { |
|
89 | - $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
90 | - } |
|
88 | + protected function registerNotifier() { |
|
89 | + $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
90 | + } |
|
91 | 91 | |
92 | - protected function registerCommentsEventHandler() { |
|
93 | - $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
94 | - return $this->getContainer()->query(EventHandler::class); |
|
95 | - }); |
|
96 | - } |
|
92 | + protected function registerCommentsEventHandler() { |
|
93 | + $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
94 | + return $this->getContainer()->query(EventHandler::class); |
|
95 | + }); |
|
96 | + } |
|
97 | 97 | } |
@@ -28,87 +28,87 @@ |
||
28 | 28 | |
29 | 29 | class CommentersSorter implements ISorter { |
30 | 30 | |
31 | - /** @var ICommentsManager */ |
|
32 | - private $commentsManager; |
|
33 | - |
|
34 | - public function __construct(ICommentsManager $commentsManager) { |
|
35 | - $this->commentsManager = $commentsManager; |
|
36 | - } |
|
37 | - |
|
38 | - public function getId() { |
|
39 | - return 'commenters'; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Sorts people who commented on the given item atop (descelating) of the |
|
44 | - * others |
|
45 | - * |
|
46 | - * @param array $sortArray |
|
47 | - * @param array $context |
|
48 | - */ |
|
49 | - public function sort(array &$sortArray, array $context) { |
|
50 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
51 | - if(count($commenters) === 0) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - foreach ($sortArray as $type => &$byType) { |
|
56 | - if(!isset($commenters[$type])) { |
|
57 | - continue; |
|
58 | - } |
|
59 | - |
|
60 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
61 | - // the current index to the value and compare it on a draw |
|
62 | - $i = 0; |
|
63 | - $workArray = array_map(function ($element) use (&$i) { |
|
64 | - return [$i++, $element]; |
|
65 | - }, $byType); |
|
66 | - |
|
67 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
68 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
69 | - if($r === 0) { |
|
70 | - $r = $a[0] - $b[0]; |
|
71 | - } |
|
72 | - return $r; |
|
73 | - }); |
|
74 | - |
|
75 | - // and remove the index values again |
|
76 | - $byType = array_column($workArray, 1); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param $type |
|
82 | - * @param $id |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function retrieveCommentsInformation($type, $id) { |
|
86 | - $comments = $this->commentsManager->getForObject($type, $id); |
|
87 | - if(count($comments) === 0) { |
|
88 | - return []; |
|
89 | - } |
|
90 | - |
|
91 | - $actors = []; |
|
92 | - foreach ($comments as $comment) { |
|
93 | - if(!isset($actors[$comment->getActorType()])) { |
|
94 | - $actors[$comment->getActorType()] = []; |
|
95 | - } |
|
96 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
97 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
98 | - } else { |
|
99 | - $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
100 | - } |
|
101 | - } |
|
102 | - return $actors; |
|
103 | - } |
|
104 | - |
|
105 | - protected function compare(array $a, array $b, array $commenters) { |
|
106 | - $a = $a['value']['shareWith']; |
|
107 | - $b = $b['value']['shareWith']; |
|
108 | - |
|
109 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
110 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
111 | - |
|
112 | - return $valueB - $valueA; |
|
113 | - } |
|
31 | + /** @var ICommentsManager */ |
|
32 | + private $commentsManager; |
|
33 | + |
|
34 | + public function __construct(ICommentsManager $commentsManager) { |
|
35 | + $this->commentsManager = $commentsManager; |
|
36 | + } |
|
37 | + |
|
38 | + public function getId() { |
|
39 | + return 'commenters'; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Sorts people who commented on the given item atop (descelating) of the |
|
44 | + * others |
|
45 | + * |
|
46 | + * @param array $sortArray |
|
47 | + * @param array $context |
|
48 | + */ |
|
49 | + public function sort(array &$sortArray, array $context) { |
|
50 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
51 | + if(count($commenters) === 0) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + foreach ($sortArray as $type => &$byType) { |
|
56 | + if(!isset($commenters[$type])) { |
|
57 | + continue; |
|
58 | + } |
|
59 | + |
|
60 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
61 | + // the current index to the value and compare it on a draw |
|
62 | + $i = 0; |
|
63 | + $workArray = array_map(function ($element) use (&$i) { |
|
64 | + return [$i++, $element]; |
|
65 | + }, $byType); |
|
66 | + |
|
67 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
68 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
69 | + if($r === 0) { |
|
70 | + $r = $a[0] - $b[0]; |
|
71 | + } |
|
72 | + return $r; |
|
73 | + }); |
|
74 | + |
|
75 | + // and remove the index values again |
|
76 | + $byType = array_column($workArray, 1); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param $type |
|
82 | + * @param $id |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function retrieveCommentsInformation($type, $id) { |
|
86 | + $comments = $this->commentsManager->getForObject($type, $id); |
|
87 | + if(count($comments) === 0) { |
|
88 | + return []; |
|
89 | + } |
|
90 | + |
|
91 | + $actors = []; |
|
92 | + foreach ($comments as $comment) { |
|
93 | + if(!isset($actors[$comment->getActorType()])) { |
|
94 | + $actors[$comment->getActorType()] = []; |
|
95 | + } |
|
96 | + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
97 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
98 | + } else { |
|
99 | + $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
100 | + } |
|
101 | + } |
|
102 | + return $actors; |
|
103 | + } |
|
104 | + |
|
105 | + protected function compare(array $a, array $b, array $commenters) { |
|
106 | + $a = $a['value']['shareWith']; |
|
107 | + $b = $b['value']['shareWith']; |
|
108 | + |
|
109 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
110 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
111 | + |
|
112 | + return $valueB - $valueA; |
|
113 | + } |
|
114 | 114 | } |
@@ -47,247 +47,247 @@ |
||
47 | 47 | |
48 | 48 | class PersonalInfo implements ISettings { |
49 | 49 | |
50 | - /** @var IConfig */ |
|
51 | - private $config; |
|
52 | - /** @var IUserManager */ |
|
53 | - private $userManager; |
|
54 | - /** @var AccountManager */ |
|
55 | - private $accountManager; |
|
56 | - /** @var IGroupManager */ |
|
57 | - private $groupManager; |
|
58 | - /** @var IAppManager */ |
|
59 | - private $appManager; |
|
60 | - /** @var IFactory */ |
|
61 | - private $l10nFactory; |
|
62 | - /** @var IL10N */ |
|
63 | - private $l; |
|
64 | - |
|
65 | - /** |
|
66 | - * @param IConfig $config |
|
67 | - * @param IUserManager $userManager |
|
68 | - * @param IGroupManager $groupManager |
|
69 | - * @param AccountManager $accountManager |
|
70 | - * @param IFactory $l10nFactory |
|
71 | - * @param IL10N $l |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - IConfig $config, |
|
75 | - IUserManager $userManager, |
|
76 | - IGroupManager $groupManager, |
|
77 | - AccountManager $accountManager, |
|
78 | - IAppManager $appManager, |
|
79 | - IFactory $l10nFactory, |
|
80 | - IL10N $l |
|
81 | - ) { |
|
82 | - $this->config = $config; |
|
83 | - $this->userManager = $userManager; |
|
84 | - $this->accountManager = $accountManager; |
|
85 | - $this->groupManager = $groupManager; |
|
86 | - $this->appManager = $appManager; |
|
87 | - $this->l10nFactory = $l10nFactory; |
|
88 | - $this->l = $l; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
93 | - * @since 9.1 |
|
94 | - */ |
|
95 | - public function getForm() { |
|
96 | - $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
97 | - $lookupServerUploadEnabled = false; |
|
98 | - if($federatedFileSharingEnabled) { |
|
99 | - $federatedFileSharing = \OC::$server->query(Application::class); |
|
100 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
101 | - $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
102 | - } |
|
103 | - |
|
104 | - $uid = \OC_User::getUser(); |
|
105 | - $user = $this->userManager->get($uid); |
|
106 | - $userData = $this->accountManager->getUser($user); |
|
107 | - |
|
108 | - $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
109 | - if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
110 | - $totalSpace = $this->l->t('Unlimited'); |
|
111 | - } else { |
|
112 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
113 | - } |
|
114 | - |
|
115 | - $languageParameters = $this->getLanguages($user); |
|
116 | - $localeParameters = $this->getLocales($user); |
|
117 | - $messageParameters = $this->getMessageParameters($userData); |
|
118 | - |
|
119 | - $parameters = [ |
|
120 | - 'total_space' => $totalSpace, |
|
121 | - 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
122 | - 'usage_relative' => round($storageInfo['relative']), |
|
123 | - 'quota' => $storageInfo['quota'], |
|
124 | - 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
125 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
126 | - 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
127 | - 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
128 | - 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
129 | - 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
130 | - 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
131 | - 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
132 | - 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
133 | - 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
134 | - 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
135 | - 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
136 | - 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
137 | - 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
138 | - 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
139 | - 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
140 | - 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
141 | - 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
142 | - 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
143 | - 'groups' => $this->getGroups($user), |
|
144 | - ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | - |
|
146 | - |
|
147 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string the section ID, e.g. 'sharing' |
|
152 | - * @since 9.1 |
|
153 | - */ |
|
154 | - public function getSection() { |
|
155 | - return 'personal-info'; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int whether the form should be rather on the top or bottom of |
|
160 | - * the admin section. The forms are arranged in ascending order of the |
|
161 | - * priority values. It is required to return a value between 0 and 100. |
|
162 | - * |
|
163 | - * E.g.: 70 |
|
164 | - * @since 9.1 |
|
165 | - */ |
|
166 | - public function getPriority() { |
|
167 | - return 10; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * returns a sorted list of the user's group GIDs |
|
172 | - * |
|
173 | - * @param IUser $user |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - private function getGroups(IUser $user) { |
|
177 | - $groups = array_map( |
|
178 | - function (IGroup $group) { |
|
179 | - return $group->getDisplayName(); |
|
180 | - }, |
|
181 | - $this->groupManager->getUserGroups($user) |
|
182 | - ); |
|
183 | - sort($groups); |
|
184 | - |
|
185 | - return $groups; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * returns the user language, common language and other languages in an |
|
190 | - * associative array |
|
191 | - * |
|
192 | - * @param IUser $user |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - private function getLanguages(IUser $user) { |
|
196 | - $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | - if($forceLanguage !== false) { |
|
198 | - return []; |
|
199 | - } |
|
200 | - |
|
201 | - $uid = $user->getUID(); |
|
202 | - |
|
203 | - $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | - $languages = $this->l10nFactory->getLanguages(); |
|
205 | - |
|
206 | - // associate the user language with the proper array |
|
207 | - $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
208 | - $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
209 | - // search in the other languages |
|
210 | - if ($userLangIndex === false) { |
|
211 | - $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
212 | - $userLang = $languages['languages'][$userLangIndex]; |
|
213 | - } |
|
214 | - // if user language is not available but set somehow: show the actual code as name |
|
215 | - if (!is_array($userLang)) { |
|
216 | - $userLang = [ |
|
217 | - 'code' => $userConfLang, |
|
218 | - 'name' => $userConfLang, |
|
219 | - ]; |
|
220 | - } |
|
221 | - |
|
222 | - return array_merge( |
|
223 | - ['activelanguage' => $userLang], |
|
224 | - $languages |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - private function getLocales(IUser $user) { |
|
229 | - $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
230 | - if($forceLanguage !== false) { |
|
231 | - return []; |
|
232 | - } |
|
233 | - |
|
234 | - $uid = $user->getUID(); |
|
235 | - |
|
236 | - $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
237 | - |
|
238 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
239 | - |
|
240 | - $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
241 | - |
|
242 | - $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
243 | - return $userLocaleString === $value['code']; |
|
244 | - }); |
|
245 | - |
|
246 | - if (!empty($userLocale)) |
|
247 | - { |
|
248 | - $userLocale = reset($userLocale); |
|
249 | - } |
|
250 | - |
|
251 | - $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
252 | - return 0 === strpos($localeCode['code'], $userLang); |
|
253 | - }); |
|
254 | - |
|
255 | - if (!$userLocale) { |
|
256 | - $userLocale = [ |
|
257 | - 'code' => 'en', |
|
258 | - 'name' => 'English' |
|
259 | - ]; |
|
260 | - } |
|
261 | - |
|
262 | - return [ |
|
263 | - 'activelocaleLang' => $userLocaleString, |
|
264 | - 'activelocale' => $userLocale, |
|
265 | - 'locales' => $localeCodes, |
|
266 | - 'localesForLanguage' => $localesForLanguage, |
|
267 | - ]; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @param array $userData |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - private function getMessageParameters(array $userData) { |
|
275 | - $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
276 | - $messageParameters = []; |
|
277 | - foreach ($needVerifyMessage as $property) { |
|
278 | - switch ($userData[$property]['verified']) { |
|
279 | - case AccountManager::VERIFIED: |
|
280 | - $message = $this->l->t('Verifying'); |
|
281 | - break; |
|
282 | - case AccountManager::VERIFICATION_IN_PROGRESS: |
|
283 | - $message = $this->l->t('Verifying …'); |
|
284 | - break; |
|
285 | - default: |
|
286 | - $message = $this->l->t('Verify'); |
|
287 | - } |
|
288 | - $messageParameters[$property . 'Message'] = $message; |
|
289 | - } |
|
290 | - return $messageParameters; |
|
291 | - } |
|
50 | + /** @var IConfig */ |
|
51 | + private $config; |
|
52 | + /** @var IUserManager */ |
|
53 | + private $userManager; |
|
54 | + /** @var AccountManager */ |
|
55 | + private $accountManager; |
|
56 | + /** @var IGroupManager */ |
|
57 | + private $groupManager; |
|
58 | + /** @var IAppManager */ |
|
59 | + private $appManager; |
|
60 | + /** @var IFactory */ |
|
61 | + private $l10nFactory; |
|
62 | + /** @var IL10N */ |
|
63 | + private $l; |
|
64 | + |
|
65 | + /** |
|
66 | + * @param IConfig $config |
|
67 | + * @param IUserManager $userManager |
|
68 | + * @param IGroupManager $groupManager |
|
69 | + * @param AccountManager $accountManager |
|
70 | + * @param IFactory $l10nFactory |
|
71 | + * @param IL10N $l |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + IConfig $config, |
|
75 | + IUserManager $userManager, |
|
76 | + IGroupManager $groupManager, |
|
77 | + AccountManager $accountManager, |
|
78 | + IAppManager $appManager, |
|
79 | + IFactory $l10nFactory, |
|
80 | + IL10N $l |
|
81 | + ) { |
|
82 | + $this->config = $config; |
|
83 | + $this->userManager = $userManager; |
|
84 | + $this->accountManager = $accountManager; |
|
85 | + $this->groupManager = $groupManager; |
|
86 | + $this->appManager = $appManager; |
|
87 | + $this->l10nFactory = $l10nFactory; |
|
88 | + $this->l = $l; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
93 | + * @since 9.1 |
|
94 | + */ |
|
95 | + public function getForm() { |
|
96 | + $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
97 | + $lookupServerUploadEnabled = false; |
|
98 | + if($federatedFileSharingEnabled) { |
|
99 | + $federatedFileSharing = \OC::$server->query(Application::class); |
|
100 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
101 | + $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
102 | + } |
|
103 | + |
|
104 | + $uid = \OC_User::getUser(); |
|
105 | + $user = $this->userManager->get($uid); |
|
106 | + $userData = $this->accountManager->getUser($user); |
|
107 | + |
|
108 | + $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
109 | + if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
110 | + $totalSpace = $this->l->t('Unlimited'); |
|
111 | + } else { |
|
112 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
113 | + } |
|
114 | + |
|
115 | + $languageParameters = $this->getLanguages($user); |
|
116 | + $localeParameters = $this->getLocales($user); |
|
117 | + $messageParameters = $this->getMessageParameters($userData); |
|
118 | + |
|
119 | + $parameters = [ |
|
120 | + 'total_space' => $totalSpace, |
|
121 | + 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
122 | + 'usage_relative' => round($storageInfo['relative']), |
|
123 | + 'quota' => $storageInfo['quota'], |
|
124 | + 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
125 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
126 | + 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
127 | + 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
128 | + 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
129 | + 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
130 | + 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
131 | + 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
132 | + 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
133 | + 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
134 | + 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
135 | + 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
136 | + 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
137 | + 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
138 | + 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
139 | + 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
140 | + 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
141 | + 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
142 | + 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
143 | + 'groups' => $this->getGroups($user), |
|
144 | + ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | + |
|
146 | + |
|
147 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string the section ID, e.g. 'sharing' |
|
152 | + * @since 9.1 |
|
153 | + */ |
|
154 | + public function getSection() { |
|
155 | + return 'personal-info'; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int whether the form should be rather on the top or bottom of |
|
160 | + * the admin section. The forms are arranged in ascending order of the |
|
161 | + * priority values. It is required to return a value between 0 and 100. |
|
162 | + * |
|
163 | + * E.g.: 70 |
|
164 | + * @since 9.1 |
|
165 | + */ |
|
166 | + public function getPriority() { |
|
167 | + return 10; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * returns a sorted list of the user's group GIDs |
|
172 | + * |
|
173 | + * @param IUser $user |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + private function getGroups(IUser $user) { |
|
177 | + $groups = array_map( |
|
178 | + function (IGroup $group) { |
|
179 | + return $group->getDisplayName(); |
|
180 | + }, |
|
181 | + $this->groupManager->getUserGroups($user) |
|
182 | + ); |
|
183 | + sort($groups); |
|
184 | + |
|
185 | + return $groups; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * returns the user language, common language and other languages in an |
|
190 | + * associative array |
|
191 | + * |
|
192 | + * @param IUser $user |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + private function getLanguages(IUser $user) { |
|
196 | + $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | + if($forceLanguage !== false) { |
|
198 | + return []; |
|
199 | + } |
|
200 | + |
|
201 | + $uid = $user->getUID(); |
|
202 | + |
|
203 | + $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | + $languages = $this->l10nFactory->getLanguages(); |
|
205 | + |
|
206 | + // associate the user language with the proper array |
|
207 | + $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
208 | + $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
209 | + // search in the other languages |
|
210 | + if ($userLangIndex === false) { |
|
211 | + $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
212 | + $userLang = $languages['languages'][$userLangIndex]; |
|
213 | + } |
|
214 | + // if user language is not available but set somehow: show the actual code as name |
|
215 | + if (!is_array($userLang)) { |
|
216 | + $userLang = [ |
|
217 | + 'code' => $userConfLang, |
|
218 | + 'name' => $userConfLang, |
|
219 | + ]; |
|
220 | + } |
|
221 | + |
|
222 | + return array_merge( |
|
223 | + ['activelanguage' => $userLang], |
|
224 | + $languages |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + private function getLocales(IUser $user) { |
|
229 | + $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
230 | + if($forceLanguage !== false) { |
|
231 | + return []; |
|
232 | + } |
|
233 | + |
|
234 | + $uid = $user->getUID(); |
|
235 | + |
|
236 | + $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
237 | + |
|
238 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
239 | + |
|
240 | + $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
241 | + |
|
242 | + $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
243 | + return $userLocaleString === $value['code']; |
|
244 | + }); |
|
245 | + |
|
246 | + if (!empty($userLocale)) |
|
247 | + { |
|
248 | + $userLocale = reset($userLocale); |
|
249 | + } |
|
250 | + |
|
251 | + $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
252 | + return 0 === strpos($localeCode['code'], $userLang); |
|
253 | + }); |
|
254 | + |
|
255 | + if (!$userLocale) { |
|
256 | + $userLocale = [ |
|
257 | + 'code' => 'en', |
|
258 | + 'name' => 'English' |
|
259 | + ]; |
|
260 | + } |
|
261 | + |
|
262 | + return [ |
|
263 | + 'activelocaleLang' => $userLocaleString, |
|
264 | + 'activelocale' => $userLocale, |
|
265 | + 'locales' => $localeCodes, |
|
266 | + 'localesForLanguage' => $localesForLanguage, |
|
267 | + ]; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @param array $userData |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + private function getMessageParameters(array $userData) { |
|
275 | + $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
276 | + $messageParameters = []; |
|
277 | + foreach ($needVerifyMessage as $property) { |
|
278 | + switch ($userData[$property]['verified']) { |
|
279 | + case AccountManager::VERIFIED: |
|
280 | + $message = $this->l->t('Verifying'); |
|
281 | + break; |
|
282 | + case AccountManager::VERIFICATION_IN_PROGRESS: |
|
283 | + $message = $this->l->t('Verifying …'); |
|
284 | + break; |
|
285 | + default: |
|
286 | + $message = $this->l->t('Verify'); |
|
287 | + } |
|
288 | + $messageParameters[$property . 'Message'] = $message; |
|
289 | + } |
|
290 | + return $messageParameters; |
|
291 | + } |
|
292 | 292 | |
293 | 293 | } |
@@ -55,165 +55,165 @@ |
||
55 | 55 | |
56 | 56 | class Application extends App { |
57 | 57 | |
58 | - const APP_ID = 'settings'; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array $urlParams |
|
62 | - */ |
|
63 | - public function __construct(array $urlParams=[]) { |
|
64 | - parent::__construct(self::APP_ID, $urlParams); |
|
65 | - |
|
66 | - $container = $this->getContainer(); |
|
67 | - |
|
68 | - // Register Middleware |
|
69 | - $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
70 | - $container->registerMiddleWare('SubadminMiddleware'); |
|
71 | - |
|
72 | - /** |
|
73 | - * Core class wrappers |
|
74 | - */ |
|
75 | - /** FIXME: Remove once OC_User is non-static and mockable */ |
|
76 | - $container->registerService('isAdmin', function () { |
|
77 | - return \OC_User::isAdminUser(\OC_User::getUser()); |
|
78 | - }); |
|
79 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
80 | - $container->registerService('isSubAdmin', function (IContainer $c) { |
|
81 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
82 | - $isSubAdmin = false; |
|
83 | - if($userObject !== null) { |
|
84 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
85 | - } |
|
86 | - return $isSubAdmin; |
|
87 | - }); |
|
88 | - $container->registerService('userCertificateManager', function (IContainer $c) { |
|
89 | - return $c->query('ServerContainer')->getCertificateManager(); |
|
90 | - }, false); |
|
91 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
92 | - return $c->query('ServerContainer')->getCertificateManager(null); |
|
93 | - }, false); |
|
94 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
95 | - return $c->query('ServerContainer')->query(IProvider::class); |
|
96 | - }); |
|
97 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
98 | - return $c->query('ServerContainer')->getSettingsManager(); |
|
99 | - }); |
|
100 | - |
|
101 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
102 | - /** @var Server $server */ |
|
103 | - $server = $c->query('ServerContainer'); |
|
104 | - /** @var Defaults $defaults */ |
|
105 | - $defaults = $server->query(Defaults::class); |
|
106 | - |
|
107 | - return new NewUserMailHelper( |
|
108 | - $defaults, |
|
109 | - $server->getURLGenerator(), |
|
110 | - $server->getL10NFactory(), |
|
111 | - $server->getMailer(), |
|
112 | - $server->getSecureRandom(), |
|
113 | - new TimeFactory(), |
|
114 | - $server->getConfig(), |
|
115 | - $server->getCrypto(), |
|
116 | - Util::getDefaultEmailAddress('no-reply') |
|
117 | - ); |
|
118 | - }); |
|
119 | - |
|
120 | - /** @var EventDispatcherInterface $eventDispatcher */ |
|
121 | - $eventDispatcher = $container->getServer()->getEventDispatcher(); |
|
122 | - $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
123 | - if (($token = $event->getSubject()) instanceof IToken) { |
|
124 | - /** @var IActivityManager $activityManager */ |
|
125 | - $activityManager = $container->query(IActivityManager::class); |
|
126 | - /** @var ILogger $logger */ |
|
127 | - $logger = $container->query(ILogger::class); |
|
128 | - |
|
129 | - $activity = $activityManager->generateEvent(); |
|
130 | - $activity->setApp('settings') |
|
131 | - ->setType('security') |
|
132 | - ->setAffectedUser($token->getUID()) |
|
133 | - ->setAuthor($token->getUID()) |
|
134 | - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
135 | - ->setObject('app_token', $token->getId()); |
|
136 | - |
|
137 | - try { |
|
138 | - $activityManager->publish($activity); |
|
139 | - } catch (BadMethodCallException $e) { |
|
140 | - $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
141 | - } |
|
142 | - } |
|
143 | - }); |
|
144 | - } |
|
145 | - |
|
146 | - public function register() { |
|
147 | - Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
148 | - Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
149 | - |
|
150 | - $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
|
151 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | - $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
153 | - |
|
154 | - Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
155 | - } |
|
156 | - |
|
157 | - public function addUserToGroup(IGroup $group, IUser $user): void { |
|
158 | - /** @var Hooks $hooks */ |
|
159 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
160 | - $hooks->addUserToGroup($group, $user); |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
165 | - /** @var Hooks $hooks */ |
|
166 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
167 | - $hooks->removeUserFromGroup($group, $user); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param array $parameters |
|
173 | - * @throws \InvalidArgumentException |
|
174 | - * @throws \BadMethodCallException |
|
175 | - * @throws \Exception |
|
176 | - * @throws \OCP\AppFramework\QueryException |
|
177 | - */ |
|
178 | - public function onChangePassword(array $parameters) { |
|
179 | - /** @var Hooks $hooks */ |
|
180 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
181 | - $hooks->onChangePassword($parameters['uid']); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @param array $parameters |
|
186 | - * @throws \InvalidArgumentException |
|
187 | - * @throws \BadMethodCallException |
|
188 | - * @throws \Exception |
|
189 | - * @throws \OCP\AppFramework\QueryException |
|
190 | - */ |
|
191 | - public function onChangeInfo(array $parameters) { |
|
192 | - if ($parameters['feature'] !== 'eMailAddress') { |
|
193 | - return; |
|
194 | - } |
|
195 | - |
|
196 | - /** @var Hooks $hooks */ |
|
197 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
198 | - $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param array $settings |
|
203 | - */ |
|
204 | - public function extendJsConfig(array $settings) { |
|
205 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
206 | - |
|
207 | - $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
208 | - if (!empty($publicWebFinger)) { |
|
209 | - $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
210 | - } |
|
211 | - |
|
212 | - $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
213 | - if (!empty($publicNodeInfo)) { |
|
214 | - $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
215 | - } |
|
216 | - |
|
217 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
218 | - } |
|
58 | + const APP_ID = 'settings'; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array $urlParams |
|
62 | + */ |
|
63 | + public function __construct(array $urlParams=[]) { |
|
64 | + parent::__construct(self::APP_ID, $urlParams); |
|
65 | + |
|
66 | + $container = $this->getContainer(); |
|
67 | + |
|
68 | + // Register Middleware |
|
69 | + $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
70 | + $container->registerMiddleWare('SubadminMiddleware'); |
|
71 | + |
|
72 | + /** |
|
73 | + * Core class wrappers |
|
74 | + */ |
|
75 | + /** FIXME: Remove once OC_User is non-static and mockable */ |
|
76 | + $container->registerService('isAdmin', function () { |
|
77 | + return \OC_User::isAdminUser(\OC_User::getUser()); |
|
78 | + }); |
|
79 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
80 | + $container->registerService('isSubAdmin', function (IContainer $c) { |
|
81 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
82 | + $isSubAdmin = false; |
|
83 | + if($userObject !== null) { |
|
84 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
85 | + } |
|
86 | + return $isSubAdmin; |
|
87 | + }); |
|
88 | + $container->registerService('userCertificateManager', function (IContainer $c) { |
|
89 | + return $c->query('ServerContainer')->getCertificateManager(); |
|
90 | + }, false); |
|
91 | + $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
92 | + return $c->query('ServerContainer')->getCertificateManager(null); |
|
93 | + }, false); |
|
94 | + $container->registerService(IProvider::class, function (IContainer $c) { |
|
95 | + return $c->query('ServerContainer')->query(IProvider::class); |
|
96 | + }); |
|
97 | + $container->registerService(IManager::class, function (IContainer $c) { |
|
98 | + return $c->query('ServerContainer')->getSettingsManager(); |
|
99 | + }); |
|
100 | + |
|
101 | + $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
102 | + /** @var Server $server */ |
|
103 | + $server = $c->query('ServerContainer'); |
|
104 | + /** @var Defaults $defaults */ |
|
105 | + $defaults = $server->query(Defaults::class); |
|
106 | + |
|
107 | + return new NewUserMailHelper( |
|
108 | + $defaults, |
|
109 | + $server->getURLGenerator(), |
|
110 | + $server->getL10NFactory(), |
|
111 | + $server->getMailer(), |
|
112 | + $server->getSecureRandom(), |
|
113 | + new TimeFactory(), |
|
114 | + $server->getConfig(), |
|
115 | + $server->getCrypto(), |
|
116 | + Util::getDefaultEmailAddress('no-reply') |
|
117 | + ); |
|
118 | + }); |
|
119 | + |
|
120 | + /** @var EventDispatcherInterface $eventDispatcher */ |
|
121 | + $eventDispatcher = $container->getServer()->getEventDispatcher(); |
|
122 | + $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
123 | + if (($token = $event->getSubject()) instanceof IToken) { |
|
124 | + /** @var IActivityManager $activityManager */ |
|
125 | + $activityManager = $container->query(IActivityManager::class); |
|
126 | + /** @var ILogger $logger */ |
|
127 | + $logger = $container->query(ILogger::class); |
|
128 | + |
|
129 | + $activity = $activityManager->generateEvent(); |
|
130 | + $activity->setApp('settings') |
|
131 | + ->setType('security') |
|
132 | + ->setAffectedUser($token->getUID()) |
|
133 | + ->setAuthor($token->getUID()) |
|
134 | + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
135 | + ->setObject('app_token', $token->getId()); |
|
136 | + |
|
137 | + try { |
|
138 | + $activityManager->publish($activity); |
|
139 | + } catch (BadMethodCallException $e) { |
|
140 | + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
141 | + } |
|
142 | + } |
|
143 | + }); |
|
144 | + } |
|
145 | + |
|
146 | + public function register() { |
|
147 | + Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
148 | + Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
149 | + |
|
150 | + $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
|
151 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | + $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
153 | + |
|
154 | + Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
155 | + } |
|
156 | + |
|
157 | + public function addUserToGroup(IGroup $group, IUser $user): void { |
|
158 | + /** @var Hooks $hooks */ |
|
159 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
160 | + $hooks->addUserToGroup($group, $user); |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
165 | + /** @var Hooks $hooks */ |
|
166 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
167 | + $hooks->removeUserFromGroup($group, $user); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param array $parameters |
|
173 | + * @throws \InvalidArgumentException |
|
174 | + * @throws \BadMethodCallException |
|
175 | + * @throws \Exception |
|
176 | + * @throws \OCP\AppFramework\QueryException |
|
177 | + */ |
|
178 | + public function onChangePassword(array $parameters) { |
|
179 | + /** @var Hooks $hooks */ |
|
180 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
181 | + $hooks->onChangePassword($parameters['uid']); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @param array $parameters |
|
186 | + * @throws \InvalidArgumentException |
|
187 | + * @throws \BadMethodCallException |
|
188 | + * @throws \Exception |
|
189 | + * @throws \OCP\AppFramework\QueryException |
|
190 | + */ |
|
191 | + public function onChangeInfo(array $parameters) { |
|
192 | + if ($parameters['feature'] !== 'eMailAddress') { |
|
193 | + return; |
|
194 | + } |
|
195 | + |
|
196 | + /** @var Hooks $hooks */ |
|
197 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
198 | + $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param array $settings |
|
203 | + */ |
|
204 | + public function extendJsConfig(array $settings) { |
|
205 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
206 | + |
|
207 | + $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
208 | + if (!empty($publicWebFinger)) { |
|
209 | + $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
210 | + } |
|
211 | + |
|
212 | + $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
213 | + if (!empty($publicNodeInfo)) { |
|
214 | + $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
215 | + } |
|
216 | + |
|
217 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
218 | + } |
|
219 | 219 | } |
@@ -57,469 +57,469 @@ |
||
57 | 57 | use function in_array; |
58 | 58 | |
59 | 59 | class UsersController extends Controller { |
60 | - /** @var IUserManager */ |
|
61 | - private $userManager; |
|
62 | - /** @var IGroupManager */ |
|
63 | - private $groupManager; |
|
64 | - /** @var IUserSession */ |
|
65 | - private $userSession; |
|
66 | - /** @var IConfig */ |
|
67 | - private $config; |
|
68 | - /** @var bool */ |
|
69 | - private $isAdmin; |
|
70 | - /** @var IL10N */ |
|
71 | - private $l10n; |
|
72 | - /** @var IMailer */ |
|
73 | - private $mailer; |
|
74 | - /** @var IFactory */ |
|
75 | - private $l10nFactory; |
|
76 | - /** @var IAppManager */ |
|
77 | - private $appManager; |
|
78 | - /** @var AccountManager */ |
|
79 | - private $accountManager; |
|
80 | - /** @var Manager */ |
|
81 | - private $keyManager; |
|
82 | - /** @var IJobList */ |
|
83 | - private $jobList; |
|
84 | - /** @var IManager */ |
|
85 | - private $encryptionManager; |
|
86 | - |
|
87 | - |
|
88 | - public function __construct(string $appName, |
|
89 | - IRequest $request, |
|
90 | - IUserManager $userManager, |
|
91 | - IGroupManager $groupManager, |
|
92 | - IUserSession $userSession, |
|
93 | - IConfig $config, |
|
94 | - bool $isAdmin, |
|
95 | - IL10N $l10n, |
|
96 | - IMailer $mailer, |
|
97 | - IFactory $l10nFactory, |
|
98 | - IAppManager $appManager, |
|
99 | - AccountManager $accountManager, |
|
100 | - Manager $keyManager, |
|
101 | - IJobList $jobList, |
|
102 | - IManager $encryptionManager) { |
|
103 | - parent::__construct($appName, $request); |
|
104 | - $this->userManager = $userManager; |
|
105 | - $this->groupManager = $groupManager; |
|
106 | - $this->userSession = $userSession; |
|
107 | - $this->config = $config; |
|
108 | - $this->isAdmin = $isAdmin; |
|
109 | - $this->l10n = $l10n; |
|
110 | - $this->mailer = $mailer; |
|
111 | - $this->l10nFactory = $l10nFactory; |
|
112 | - $this->appManager = $appManager; |
|
113 | - $this->accountManager = $accountManager; |
|
114 | - $this->keyManager = $keyManager; |
|
115 | - $this->jobList = $jobList; |
|
116 | - $this->encryptionManager = $encryptionManager; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @NoCSRFRequired |
|
122 | - * @NoAdminRequired |
|
123 | - * |
|
124 | - * Display users list template |
|
125 | - * |
|
126 | - * @return TemplateResponse |
|
127 | - */ |
|
128 | - public function usersListByGroup() { |
|
129 | - return $this->usersList(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @NoCSRFRequired |
|
134 | - * @NoAdminRequired |
|
135 | - * |
|
136 | - * Display users list template |
|
137 | - * |
|
138 | - * @return TemplateResponse |
|
139 | - */ |
|
140 | - public function usersList() { |
|
141 | - $user = $this->userSession->getUser(); |
|
142 | - $uid = $user->getUID(); |
|
143 | - |
|
144 | - \OC::$server->getNavigationManager()->setActiveEntry('core_users'); |
|
145 | - |
|
146 | - /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */ |
|
147 | - $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT; |
|
148 | - $isLDAPUsed = false; |
|
149 | - if ($this->config->getSystemValue('sort_groups_by_name', false)) { |
|
150 | - $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; |
|
151 | - } else { |
|
152 | - if ($this->appManager->isEnabledForUser('user_ldap')) { |
|
153 | - $isLDAPUsed = |
|
154 | - $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy'); |
|
155 | - if ($isLDAPUsed) { |
|
156 | - // LDAP user count can be slow, so we sort by group name here |
|
157 | - $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - $canChangePassword = $this->canAdminChangeUserPasswords(); |
|
163 | - |
|
164 | - /* GROUPS */ |
|
165 | - $groupsInfo = new \OC\Group\MetaData( |
|
166 | - $uid, |
|
167 | - $this->isAdmin, |
|
168 | - $this->groupManager, |
|
169 | - $this->userSession |
|
170 | - ); |
|
171 | - |
|
172 | - $groupsInfo->setSorting($sortGroupsBy); |
|
173 | - list($adminGroup, $groups) = $groupsInfo->get(); |
|
174 | - |
|
175 | - if(!$isLDAPUsed && $this->appManager->isEnabledForUser('user_ldap')) { |
|
176 | - $isLDAPUsed = (bool)array_reduce($this->userManager->getBackends(), function ($ldapFound, $backend) { |
|
177 | - return $ldapFound || $backend instanceof User_Proxy; |
|
178 | - }); |
|
179 | - } |
|
180 | - |
|
181 | - $disabledUsers = -1; |
|
182 | - $userCount = 0; |
|
183 | - |
|
184 | - if(!$isLDAPUsed) { |
|
185 | - if ($this->isAdmin) { |
|
186 | - $disabledUsers = $this->userManager->countDisabledUsers(); |
|
187 | - $userCount = array_reduce($this->userManager->countUsers(), function ($v, $w) { |
|
188 | - return $v + (int)$w; |
|
189 | - }, 0); |
|
190 | - } else { |
|
191 | - // User is subadmin ! |
|
192 | - // Map group list to names to retrieve the countDisabledUsersOfGroups |
|
193 | - $userGroups = $this->groupManager->getUserGroups($user); |
|
194 | - $groupsNames = []; |
|
195 | - |
|
196 | - foreach($groups as $key => $group) { |
|
197 | - // $userCount += (int)$group['usercount']; |
|
198 | - array_push($groupsNames, $group['name']); |
|
199 | - // we prevent subadmins from looking up themselves |
|
200 | - // so we lower the count of the groups he belongs to |
|
201 | - if (array_key_exists($group['id'], $userGroups)) { |
|
202 | - $groups[$key]['usercount']--; |
|
203 | - $userCount -= 1; // we also lower from one the total count |
|
204 | - } |
|
205 | - }; |
|
206 | - $userCount += $this->userManager->countUsersOfGroups($groupsInfo->getGroups()); |
|
207 | - $disabledUsers = $this->userManager->countDisabledUsersOfGroups($groupsNames); |
|
208 | - } |
|
209 | - |
|
210 | - $userCount -= $disabledUsers; |
|
211 | - } |
|
212 | - |
|
213 | - $disabledUsersGroup = [ |
|
214 | - 'id' => 'disabled', |
|
215 | - 'name' => 'Disabled users', |
|
216 | - 'usercount' => $disabledUsers |
|
217 | - ]; |
|
218 | - |
|
219 | - /* QUOTAS PRESETS */ |
|
220 | - $quotaPreset = $this->parseQuotaPreset($this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB')); |
|
221 | - $defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
222 | - |
|
223 | - \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts'); |
|
224 | - |
|
225 | - /* LANGUAGES */ |
|
226 | - $languages = $this->l10nFactory->getLanguages(); |
|
227 | - |
|
228 | - /* FINAL DATA */ |
|
229 | - $serverData = []; |
|
230 | - // groups |
|
231 | - $serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups); |
|
232 | - // Various data |
|
233 | - $serverData['isAdmin'] = $this->isAdmin; |
|
234 | - $serverData['sortGroups'] = $sortGroupsBy; |
|
235 | - $serverData['quotaPreset'] = $quotaPreset; |
|
236 | - $serverData['userCount'] = $userCount; |
|
237 | - $serverData['languages'] = $languages; |
|
238 | - $serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en'); |
|
239 | - // Settings |
|
240 | - $serverData['defaultQuota'] = $defaultQuota; |
|
241 | - $serverData['canChangePassword'] = $canChangePassword; |
|
242 | - $serverData['newUserGenerateUserID'] = $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes'; |
|
243 | - $serverData['newUserRequireEmail'] = $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes'; |
|
244 | - $serverData['newUserSendEmail'] = $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes'; |
|
245 | - |
|
246 | - return new TemplateResponse('settings', 'settings-vue', ['serverData' => $serverData]); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @param string $key |
|
251 | - * @param string $value |
|
252 | - * |
|
253 | - * @return JSONResponse |
|
254 | - */ |
|
255 | - public function setPreference(string $key, string $value): JSONResponse { |
|
256 | - $allowed = ['newUser.sendEmail']; |
|
257 | - if (!in_array($key, $allowed, true)) { |
|
258 | - return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
259 | - } |
|
260 | - |
|
261 | - $this->config->setAppValue('core', $key, $value); |
|
262 | - |
|
263 | - return new JSONResponse([]); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Parse the app value for quota_present |
|
268 | - * |
|
269 | - * @param string $quotaPreset |
|
270 | - * @return array |
|
271 | - */ |
|
272 | - protected function parseQuotaPreset(string $quotaPreset): array { |
|
273 | - // 1 GB, 5 GB, 10 GB => [1 GB, 5 GB, 10 GB] |
|
274 | - $presets = array_filter(array_map('trim', explode(',', $quotaPreset))); |
|
275 | - // Drop default and none, Make array indexes numerically |
|
276 | - return array_values(array_diff($presets, ['default', 'none'])); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * check if the admin can change the users password |
|
281 | - * |
|
282 | - * The admin can change the passwords if: |
|
283 | - * |
|
284 | - * - no encryption module is loaded and encryption is disabled |
|
285 | - * - encryption module is loaded but it doesn't require per user keys |
|
286 | - * |
|
287 | - * The admin can not change the passwords if: |
|
288 | - * |
|
289 | - * - an encryption module is loaded and it uses per-user keys |
|
290 | - * - encryption is enabled but no encryption modules are loaded |
|
291 | - * |
|
292 | - * @return bool |
|
293 | - */ |
|
294 | - protected function canAdminChangeUserPasswords() { |
|
295 | - $isEncryptionEnabled = $this->encryptionManager->isEnabled(); |
|
296 | - try { |
|
297 | - $noUserSpecificEncryptionKeys =!$this->encryptionManager->getEncryptionModule()->needDetailedAccessList(); |
|
298 | - $isEncryptionModuleLoaded = true; |
|
299 | - } catch (ModuleDoesNotExistsException $e) { |
|
300 | - $noUserSpecificEncryptionKeys = true; |
|
301 | - $isEncryptionModuleLoaded = false; |
|
302 | - } |
|
303 | - |
|
304 | - $canChangePassword = ($isEncryptionEnabled && $isEncryptionModuleLoaded && $noUserSpecificEncryptionKeys) |
|
305 | - || (!$isEncryptionEnabled && !$isEncryptionModuleLoaded) |
|
306 | - || (!$isEncryptionEnabled && $isEncryptionModuleLoaded && $noUserSpecificEncryptionKeys); |
|
307 | - |
|
308 | - return $canChangePassword; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @NoAdminRequired |
|
313 | - * @NoSubadminRequired |
|
314 | - * @PasswordConfirmationRequired |
|
315 | - * |
|
316 | - * @param string $avatarScope |
|
317 | - * @param string $displayname |
|
318 | - * @param string $displaynameScope |
|
319 | - * @param string $phone |
|
320 | - * @param string $phoneScope |
|
321 | - * @param string $email |
|
322 | - * @param string $emailScope |
|
323 | - * @param string $website |
|
324 | - * @param string $websiteScope |
|
325 | - * @param string $address |
|
326 | - * @param string $addressScope |
|
327 | - * @param string $twitter |
|
328 | - * @param string $twitterScope |
|
329 | - * @return DataResponse |
|
330 | - */ |
|
331 | - public function setUserSettings($avatarScope, |
|
332 | - $displayname, |
|
333 | - $displaynameScope, |
|
334 | - $phone, |
|
335 | - $phoneScope, |
|
336 | - $email, |
|
337 | - $emailScope, |
|
338 | - $website, |
|
339 | - $websiteScope, |
|
340 | - $address, |
|
341 | - $addressScope, |
|
342 | - $twitter, |
|
343 | - $twitterScope |
|
344 | - ) { |
|
345 | - if (!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
346 | - return new DataResponse( |
|
347 | - [ |
|
348 | - 'status' => 'error', |
|
349 | - 'data' => [ |
|
350 | - 'message' => $this->l10n->t('Invalid mail address') |
|
351 | - ] |
|
352 | - ], |
|
353 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
354 | - ); |
|
355 | - } |
|
356 | - $user = $this->userSession->getUser(); |
|
357 | - $data = $this->accountManager->getUser($user); |
|
358 | - $data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope]; |
|
359 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
360 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope]; |
|
361 | - $data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope]; |
|
362 | - } |
|
363 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
364 | - $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
365 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
366 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
367 | - $data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope]; |
|
368 | - $data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope]; |
|
369 | - $data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope]; |
|
370 | - $data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope]; |
|
371 | - } |
|
372 | - } |
|
373 | - try { |
|
374 | - $this->saveUserSettings($user, $data); |
|
375 | - return new DataResponse( |
|
376 | - [ |
|
377 | - 'status' => 'success', |
|
378 | - 'data' => [ |
|
379 | - 'userId' => $user->getUID(), |
|
380 | - 'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'], |
|
381 | - 'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
382 | - 'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
383 | - 'email' => $data[AccountManager::PROPERTY_EMAIL]['value'], |
|
384 | - 'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'], |
|
385 | - 'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'], |
|
386 | - 'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
387 | - 'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'], |
|
388 | - 'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
389 | - 'message' => $this->l10n->t('Settings saved') |
|
390 | - ] |
|
391 | - ], |
|
392 | - Http::STATUS_OK |
|
393 | - ); |
|
394 | - } catch (ForbiddenException $e) { |
|
395 | - return new DataResponse([ |
|
396 | - 'status' => 'error', |
|
397 | - 'data' => [ |
|
398 | - 'message' => $e->getMessage() |
|
399 | - ], |
|
400 | - ]); |
|
401 | - } |
|
402 | - } |
|
403 | - /** |
|
404 | - * update account manager with new user data |
|
405 | - * |
|
406 | - * @param IUser $user |
|
407 | - * @param array $data |
|
408 | - * @throws ForbiddenException |
|
409 | - */ |
|
410 | - protected function saveUserSettings(IUser $user, array $data) { |
|
411 | - // keep the user back-end up-to-date with the latest display name and email |
|
412 | - // address |
|
413 | - $oldDisplayName = $user->getDisplayName(); |
|
414 | - $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
415 | - if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
416 | - && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
417 | - ) { |
|
418 | - $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
419 | - if ($result === false) { |
|
420 | - throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
421 | - } |
|
422 | - } |
|
423 | - $oldEmailAddress = $user->getEMailAddress(); |
|
424 | - $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
425 | - if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
426 | - && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
427 | - ) { |
|
428 | - // this is the only permission a backend provides and is also used |
|
429 | - // for the permission of setting a email address |
|
430 | - if (!$user->canChangeDisplayName()) { |
|
431 | - throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
432 | - } |
|
433 | - $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
434 | - } |
|
435 | - $this->accountManager->updateUser($user, $data); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Set the mail address of a user |
|
440 | - * |
|
441 | - * @NoAdminRequired |
|
442 | - * @NoSubadminRequired |
|
443 | - * @PasswordConfirmationRequired |
|
444 | - * |
|
445 | - * @param string $account |
|
446 | - * @param bool $onlyVerificationCode only return verification code without updating the data |
|
447 | - * @return DataResponse |
|
448 | - */ |
|
449 | - public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse { |
|
450 | - |
|
451 | - $user = $this->userSession->getUser(); |
|
452 | - |
|
453 | - if ($user === null) { |
|
454 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
455 | - } |
|
456 | - |
|
457 | - $accountData = $this->accountManager->getUser($user); |
|
458 | - $cloudId = $user->getCloudId(); |
|
459 | - $message = 'Use my Federated Cloud ID to share with me: ' . $cloudId; |
|
460 | - $signature = $this->signMessage($user, $message); |
|
461 | - |
|
462 | - $code = $message . ' ' . $signature; |
|
463 | - $codeMd5 = $message . ' ' . md5($signature); |
|
464 | - |
|
465 | - switch ($account) { |
|
466 | - case 'verify-twitter': |
|
467 | - $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
468 | - $msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):'); |
|
469 | - $code = $codeMd5; |
|
470 | - $type = AccountManager::PROPERTY_TWITTER; |
|
471 | - $data = $accountData[AccountManager::PROPERTY_TWITTER]['value']; |
|
472 | - $accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature; |
|
473 | - break; |
|
474 | - case 'verify-website': |
|
475 | - $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
476 | - $msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):'); |
|
477 | - $type = AccountManager::PROPERTY_WEBSITE; |
|
478 | - $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value']; |
|
479 | - $accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature; |
|
480 | - break; |
|
481 | - default: |
|
482 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
483 | - } |
|
484 | - |
|
485 | - if ($onlyVerificationCode === false) { |
|
486 | - $this->accountManager->updateUser($user, $accountData); |
|
487 | - |
|
488 | - $this->jobList->add(VerifyUserData::class, |
|
489 | - [ |
|
490 | - 'verificationCode' => $code, |
|
491 | - 'data' => $data, |
|
492 | - 'type' => $type, |
|
493 | - 'uid' => $user->getUID(), |
|
494 | - 'try' => 0, |
|
495 | - 'lastRun' => $this->getCurrentTime() |
|
496 | - ] |
|
497 | - ); |
|
498 | - } |
|
499 | - |
|
500 | - return new DataResponse(['msg' => $msg, 'code' => $code]); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * get current timestamp |
|
505 | - * |
|
506 | - * @return int |
|
507 | - */ |
|
508 | - protected function getCurrentTime(): int { |
|
509 | - return time(); |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * sign message with users private key |
|
514 | - * |
|
515 | - * @param IUser $user |
|
516 | - * @param string $message |
|
517 | - * |
|
518 | - * @return string base64 encoded signature |
|
519 | - */ |
|
520 | - protected function signMessage(IUser $user, string $message): string { |
|
521 | - $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
522 | - openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
523 | - return base64_encode($signature); |
|
524 | - } |
|
60 | + /** @var IUserManager */ |
|
61 | + private $userManager; |
|
62 | + /** @var IGroupManager */ |
|
63 | + private $groupManager; |
|
64 | + /** @var IUserSession */ |
|
65 | + private $userSession; |
|
66 | + /** @var IConfig */ |
|
67 | + private $config; |
|
68 | + /** @var bool */ |
|
69 | + private $isAdmin; |
|
70 | + /** @var IL10N */ |
|
71 | + private $l10n; |
|
72 | + /** @var IMailer */ |
|
73 | + private $mailer; |
|
74 | + /** @var IFactory */ |
|
75 | + private $l10nFactory; |
|
76 | + /** @var IAppManager */ |
|
77 | + private $appManager; |
|
78 | + /** @var AccountManager */ |
|
79 | + private $accountManager; |
|
80 | + /** @var Manager */ |
|
81 | + private $keyManager; |
|
82 | + /** @var IJobList */ |
|
83 | + private $jobList; |
|
84 | + /** @var IManager */ |
|
85 | + private $encryptionManager; |
|
86 | + |
|
87 | + |
|
88 | + public function __construct(string $appName, |
|
89 | + IRequest $request, |
|
90 | + IUserManager $userManager, |
|
91 | + IGroupManager $groupManager, |
|
92 | + IUserSession $userSession, |
|
93 | + IConfig $config, |
|
94 | + bool $isAdmin, |
|
95 | + IL10N $l10n, |
|
96 | + IMailer $mailer, |
|
97 | + IFactory $l10nFactory, |
|
98 | + IAppManager $appManager, |
|
99 | + AccountManager $accountManager, |
|
100 | + Manager $keyManager, |
|
101 | + IJobList $jobList, |
|
102 | + IManager $encryptionManager) { |
|
103 | + parent::__construct($appName, $request); |
|
104 | + $this->userManager = $userManager; |
|
105 | + $this->groupManager = $groupManager; |
|
106 | + $this->userSession = $userSession; |
|
107 | + $this->config = $config; |
|
108 | + $this->isAdmin = $isAdmin; |
|
109 | + $this->l10n = $l10n; |
|
110 | + $this->mailer = $mailer; |
|
111 | + $this->l10nFactory = $l10nFactory; |
|
112 | + $this->appManager = $appManager; |
|
113 | + $this->accountManager = $accountManager; |
|
114 | + $this->keyManager = $keyManager; |
|
115 | + $this->jobList = $jobList; |
|
116 | + $this->encryptionManager = $encryptionManager; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @NoCSRFRequired |
|
122 | + * @NoAdminRequired |
|
123 | + * |
|
124 | + * Display users list template |
|
125 | + * |
|
126 | + * @return TemplateResponse |
|
127 | + */ |
|
128 | + public function usersListByGroup() { |
|
129 | + return $this->usersList(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @NoCSRFRequired |
|
134 | + * @NoAdminRequired |
|
135 | + * |
|
136 | + * Display users list template |
|
137 | + * |
|
138 | + * @return TemplateResponse |
|
139 | + */ |
|
140 | + public function usersList() { |
|
141 | + $user = $this->userSession->getUser(); |
|
142 | + $uid = $user->getUID(); |
|
143 | + |
|
144 | + \OC::$server->getNavigationManager()->setActiveEntry('core_users'); |
|
145 | + |
|
146 | + /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */ |
|
147 | + $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT; |
|
148 | + $isLDAPUsed = false; |
|
149 | + if ($this->config->getSystemValue('sort_groups_by_name', false)) { |
|
150 | + $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; |
|
151 | + } else { |
|
152 | + if ($this->appManager->isEnabledForUser('user_ldap')) { |
|
153 | + $isLDAPUsed = |
|
154 | + $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy'); |
|
155 | + if ($isLDAPUsed) { |
|
156 | + // LDAP user count can be slow, so we sort by group name here |
|
157 | + $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + $canChangePassword = $this->canAdminChangeUserPasswords(); |
|
163 | + |
|
164 | + /* GROUPS */ |
|
165 | + $groupsInfo = new \OC\Group\MetaData( |
|
166 | + $uid, |
|
167 | + $this->isAdmin, |
|
168 | + $this->groupManager, |
|
169 | + $this->userSession |
|
170 | + ); |
|
171 | + |
|
172 | + $groupsInfo->setSorting($sortGroupsBy); |
|
173 | + list($adminGroup, $groups) = $groupsInfo->get(); |
|
174 | + |
|
175 | + if(!$isLDAPUsed && $this->appManager->isEnabledForUser('user_ldap')) { |
|
176 | + $isLDAPUsed = (bool)array_reduce($this->userManager->getBackends(), function ($ldapFound, $backend) { |
|
177 | + return $ldapFound || $backend instanceof User_Proxy; |
|
178 | + }); |
|
179 | + } |
|
180 | + |
|
181 | + $disabledUsers = -1; |
|
182 | + $userCount = 0; |
|
183 | + |
|
184 | + if(!$isLDAPUsed) { |
|
185 | + if ($this->isAdmin) { |
|
186 | + $disabledUsers = $this->userManager->countDisabledUsers(); |
|
187 | + $userCount = array_reduce($this->userManager->countUsers(), function ($v, $w) { |
|
188 | + return $v + (int)$w; |
|
189 | + }, 0); |
|
190 | + } else { |
|
191 | + // User is subadmin ! |
|
192 | + // Map group list to names to retrieve the countDisabledUsersOfGroups |
|
193 | + $userGroups = $this->groupManager->getUserGroups($user); |
|
194 | + $groupsNames = []; |
|
195 | + |
|
196 | + foreach($groups as $key => $group) { |
|
197 | + // $userCount += (int)$group['usercount']; |
|
198 | + array_push($groupsNames, $group['name']); |
|
199 | + // we prevent subadmins from looking up themselves |
|
200 | + // so we lower the count of the groups he belongs to |
|
201 | + if (array_key_exists($group['id'], $userGroups)) { |
|
202 | + $groups[$key]['usercount']--; |
|
203 | + $userCount -= 1; // we also lower from one the total count |
|
204 | + } |
|
205 | + }; |
|
206 | + $userCount += $this->userManager->countUsersOfGroups($groupsInfo->getGroups()); |
|
207 | + $disabledUsers = $this->userManager->countDisabledUsersOfGroups($groupsNames); |
|
208 | + } |
|
209 | + |
|
210 | + $userCount -= $disabledUsers; |
|
211 | + } |
|
212 | + |
|
213 | + $disabledUsersGroup = [ |
|
214 | + 'id' => 'disabled', |
|
215 | + 'name' => 'Disabled users', |
|
216 | + 'usercount' => $disabledUsers |
|
217 | + ]; |
|
218 | + |
|
219 | + /* QUOTAS PRESETS */ |
|
220 | + $quotaPreset = $this->parseQuotaPreset($this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB')); |
|
221 | + $defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
222 | + |
|
223 | + \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts'); |
|
224 | + |
|
225 | + /* LANGUAGES */ |
|
226 | + $languages = $this->l10nFactory->getLanguages(); |
|
227 | + |
|
228 | + /* FINAL DATA */ |
|
229 | + $serverData = []; |
|
230 | + // groups |
|
231 | + $serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups); |
|
232 | + // Various data |
|
233 | + $serverData['isAdmin'] = $this->isAdmin; |
|
234 | + $serverData['sortGroups'] = $sortGroupsBy; |
|
235 | + $serverData['quotaPreset'] = $quotaPreset; |
|
236 | + $serverData['userCount'] = $userCount; |
|
237 | + $serverData['languages'] = $languages; |
|
238 | + $serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en'); |
|
239 | + // Settings |
|
240 | + $serverData['defaultQuota'] = $defaultQuota; |
|
241 | + $serverData['canChangePassword'] = $canChangePassword; |
|
242 | + $serverData['newUserGenerateUserID'] = $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes'; |
|
243 | + $serverData['newUserRequireEmail'] = $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes'; |
|
244 | + $serverData['newUserSendEmail'] = $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes'; |
|
245 | + |
|
246 | + return new TemplateResponse('settings', 'settings-vue', ['serverData' => $serverData]); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @param string $key |
|
251 | + * @param string $value |
|
252 | + * |
|
253 | + * @return JSONResponse |
|
254 | + */ |
|
255 | + public function setPreference(string $key, string $value): JSONResponse { |
|
256 | + $allowed = ['newUser.sendEmail']; |
|
257 | + if (!in_array($key, $allowed, true)) { |
|
258 | + return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
259 | + } |
|
260 | + |
|
261 | + $this->config->setAppValue('core', $key, $value); |
|
262 | + |
|
263 | + return new JSONResponse([]); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Parse the app value for quota_present |
|
268 | + * |
|
269 | + * @param string $quotaPreset |
|
270 | + * @return array |
|
271 | + */ |
|
272 | + protected function parseQuotaPreset(string $quotaPreset): array { |
|
273 | + // 1 GB, 5 GB, 10 GB => [1 GB, 5 GB, 10 GB] |
|
274 | + $presets = array_filter(array_map('trim', explode(',', $quotaPreset))); |
|
275 | + // Drop default and none, Make array indexes numerically |
|
276 | + return array_values(array_diff($presets, ['default', 'none'])); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * check if the admin can change the users password |
|
281 | + * |
|
282 | + * The admin can change the passwords if: |
|
283 | + * |
|
284 | + * - no encryption module is loaded and encryption is disabled |
|
285 | + * - encryption module is loaded but it doesn't require per user keys |
|
286 | + * |
|
287 | + * The admin can not change the passwords if: |
|
288 | + * |
|
289 | + * - an encryption module is loaded and it uses per-user keys |
|
290 | + * - encryption is enabled but no encryption modules are loaded |
|
291 | + * |
|
292 | + * @return bool |
|
293 | + */ |
|
294 | + protected function canAdminChangeUserPasswords() { |
|
295 | + $isEncryptionEnabled = $this->encryptionManager->isEnabled(); |
|
296 | + try { |
|
297 | + $noUserSpecificEncryptionKeys =!$this->encryptionManager->getEncryptionModule()->needDetailedAccessList(); |
|
298 | + $isEncryptionModuleLoaded = true; |
|
299 | + } catch (ModuleDoesNotExistsException $e) { |
|
300 | + $noUserSpecificEncryptionKeys = true; |
|
301 | + $isEncryptionModuleLoaded = false; |
|
302 | + } |
|
303 | + |
|
304 | + $canChangePassword = ($isEncryptionEnabled && $isEncryptionModuleLoaded && $noUserSpecificEncryptionKeys) |
|
305 | + || (!$isEncryptionEnabled && !$isEncryptionModuleLoaded) |
|
306 | + || (!$isEncryptionEnabled && $isEncryptionModuleLoaded && $noUserSpecificEncryptionKeys); |
|
307 | + |
|
308 | + return $canChangePassword; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @NoAdminRequired |
|
313 | + * @NoSubadminRequired |
|
314 | + * @PasswordConfirmationRequired |
|
315 | + * |
|
316 | + * @param string $avatarScope |
|
317 | + * @param string $displayname |
|
318 | + * @param string $displaynameScope |
|
319 | + * @param string $phone |
|
320 | + * @param string $phoneScope |
|
321 | + * @param string $email |
|
322 | + * @param string $emailScope |
|
323 | + * @param string $website |
|
324 | + * @param string $websiteScope |
|
325 | + * @param string $address |
|
326 | + * @param string $addressScope |
|
327 | + * @param string $twitter |
|
328 | + * @param string $twitterScope |
|
329 | + * @return DataResponse |
|
330 | + */ |
|
331 | + public function setUserSettings($avatarScope, |
|
332 | + $displayname, |
|
333 | + $displaynameScope, |
|
334 | + $phone, |
|
335 | + $phoneScope, |
|
336 | + $email, |
|
337 | + $emailScope, |
|
338 | + $website, |
|
339 | + $websiteScope, |
|
340 | + $address, |
|
341 | + $addressScope, |
|
342 | + $twitter, |
|
343 | + $twitterScope |
|
344 | + ) { |
|
345 | + if (!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
346 | + return new DataResponse( |
|
347 | + [ |
|
348 | + 'status' => 'error', |
|
349 | + 'data' => [ |
|
350 | + 'message' => $this->l10n->t('Invalid mail address') |
|
351 | + ] |
|
352 | + ], |
|
353 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
354 | + ); |
|
355 | + } |
|
356 | + $user = $this->userSession->getUser(); |
|
357 | + $data = $this->accountManager->getUser($user); |
|
358 | + $data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope]; |
|
359 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
360 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope]; |
|
361 | + $data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope]; |
|
362 | + } |
|
363 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
364 | + $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
365 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
366 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
367 | + $data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope]; |
|
368 | + $data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope]; |
|
369 | + $data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope]; |
|
370 | + $data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope]; |
|
371 | + } |
|
372 | + } |
|
373 | + try { |
|
374 | + $this->saveUserSettings($user, $data); |
|
375 | + return new DataResponse( |
|
376 | + [ |
|
377 | + 'status' => 'success', |
|
378 | + 'data' => [ |
|
379 | + 'userId' => $user->getUID(), |
|
380 | + 'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'], |
|
381 | + 'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
382 | + 'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
383 | + 'email' => $data[AccountManager::PROPERTY_EMAIL]['value'], |
|
384 | + 'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'], |
|
385 | + 'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'], |
|
386 | + 'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
387 | + 'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'], |
|
388 | + 'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
389 | + 'message' => $this->l10n->t('Settings saved') |
|
390 | + ] |
|
391 | + ], |
|
392 | + Http::STATUS_OK |
|
393 | + ); |
|
394 | + } catch (ForbiddenException $e) { |
|
395 | + return new DataResponse([ |
|
396 | + 'status' => 'error', |
|
397 | + 'data' => [ |
|
398 | + 'message' => $e->getMessage() |
|
399 | + ], |
|
400 | + ]); |
|
401 | + } |
|
402 | + } |
|
403 | + /** |
|
404 | + * update account manager with new user data |
|
405 | + * |
|
406 | + * @param IUser $user |
|
407 | + * @param array $data |
|
408 | + * @throws ForbiddenException |
|
409 | + */ |
|
410 | + protected function saveUserSettings(IUser $user, array $data) { |
|
411 | + // keep the user back-end up-to-date with the latest display name and email |
|
412 | + // address |
|
413 | + $oldDisplayName = $user->getDisplayName(); |
|
414 | + $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
415 | + if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
416 | + && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
417 | + ) { |
|
418 | + $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
419 | + if ($result === false) { |
|
420 | + throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
421 | + } |
|
422 | + } |
|
423 | + $oldEmailAddress = $user->getEMailAddress(); |
|
424 | + $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
425 | + if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
426 | + && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
427 | + ) { |
|
428 | + // this is the only permission a backend provides and is also used |
|
429 | + // for the permission of setting a email address |
|
430 | + if (!$user->canChangeDisplayName()) { |
|
431 | + throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
432 | + } |
|
433 | + $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
434 | + } |
|
435 | + $this->accountManager->updateUser($user, $data); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Set the mail address of a user |
|
440 | + * |
|
441 | + * @NoAdminRequired |
|
442 | + * @NoSubadminRequired |
|
443 | + * @PasswordConfirmationRequired |
|
444 | + * |
|
445 | + * @param string $account |
|
446 | + * @param bool $onlyVerificationCode only return verification code without updating the data |
|
447 | + * @return DataResponse |
|
448 | + */ |
|
449 | + public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse { |
|
450 | + |
|
451 | + $user = $this->userSession->getUser(); |
|
452 | + |
|
453 | + if ($user === null) { |
|
454 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
455 | + } |
|
456 | + |
|
457 | + $accountData = $this->accountManager->getUser($user); |
|
458 | + $cloudId = $user->getCloudId(); |
|
459 | + $message = 'Use my Federated Cloud ID to share with me: ' . $cloudId; |
|
460 | + $signature = $this->signMessage($user, $message); |
|
461 | + |
|
462 | + $code = $message . ' ' . $signature; |
|
463 | + $codeMd5 = $message . ' ' . md5($signature); |
|
464 | + |
|
465 | + switch ($account) { |
|
466 | + case 'verify-twitter': |
|
467 | + $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
468 | + $msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):'); |
|
469 | + $code = $codeMd5; |
|
470 | + $type = AccountManager::PROPERTY_TWITTER; |
|
471 | + $data = $accountData[AccountManager::PROPERTY_TWITTER]['value']; |
|
472 | + $accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature; |
|
473 | + break; |
|
474 | + case 'verify-website': |
|
475 | + $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
476 | + $msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):'); |
|
477 | + $type = AccountManager::PROPERTY_WEBSITE; |
|
478 | + $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value']; |
|
479 | + $accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature; |
|
480 | + break; |
|
481 | + default: |
|
482 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
483 | + } |
|
484 | + |
|
485 | + if ($onlyVerificationCode === false) { |
|
486 | + $this->accountManager->updateUser($user, $accountData); |
|
487 | + |
|
488 | + $this->jobList->add(VerifyUserData::class, |
|
489 | + [ |
|
490 | + 'verificationCode' => $code, |
|
491 | + 'data' => $data, |
|
492 | + 'type' => $type, |
|
493 | + 'uid' => $user->getUID(), |
|
494 | + 'try' => 0, |
|
495 | + 'lastRun' => $this->getCurrentTime() |
|
496 | + ] |
|
497 | + ); |
|
498 | + } |
|
499 | + |
|
500 | + return new DataResponse(['msg' => $msg, 'code' => $code]); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * get current timestamp |
|
505 | + * |
|
506 | + * @return int |
|
507 | + */ |
|
508 | + protected function getCurrentTime(): int { |
|
509 | + return time(); |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * sign message with users private key |
|
514 | + * |
|
515 | + * @param IUser $user |
|
516 | + * @param string $message |
|
517 | + * |
|
518 | + * @return string base64 encoded signature |
|
519 | + */ |
|
520 | + protected function signMessage(IUser $user, string $message): string { |
|
521 | + $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
522 | + openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
523 | + return base64_encode($signature); |
|
524 | + } |
|
525 | 525 | } |
@@ -56,507 +56,507 @@ |
||
56 | 56 | |
57 | 57 | class AppSettingsController extends Controller { |
58 | 58 | |
59 | - /** @var \OCP\IL10N */ |
|
60 | - private $l10n; |
|
61 | - /** @var IConfig */ |
|
62 | - private $config; |
|
63 | - /** @var INavigationManager */ |
|
64 | - private $navigationManager; |
|
65 | - /** @var IAppManager */ |
|
66 | - private $appManager; |
|
67 | - /** @var CategoryFetcher */ |
|
68 | - private $categoryFetcher; |
|
69 | - /** @var AppFetcher */ |
|
70 | - private $appFetcher; |
|
71 | - /** @var IFactory */ |
|
72 | - private $l10nFactory; |
|
73 | - /** @var BundleFetcher */ |
|
74 | - private $bundleFetcher; |
|
75 | - /** @var Installer */ |
|
76 | - private $installer; |
|
77 | - /** @var IURLGenerator */ |
|
78 | - private $urlGenerator; |
|
79 | - /** @var ILogger */ |
|
80 | - private $logger; |
|
81 | - |
|
82 | - /** @var array */ |
|
83 | - private $allApps = []; |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $appName |
|
87 | - * @param IRequest $request |
|
88 | - * @param IL10N $l10n |
|
89 | - * @param IConfig $config |
|
90 | - * @param INavigationManager $navigationManager |
|
91 | - * @param IAppManager $appManager |
|
92 | - * @param CategoryFetcher $categoryFetcher |
|
93 | - * @param AppFetcher $appFetcher |
|
94 | - * @param IFactory $l10nFactory |
|
95 | - * @param BundleFetcher $bundleFetcher |
|
96 | - * @param Installer $installer |
|
97 | - * @param IURLGenerator $urlGenerator |
|
98 | - * @param ILogger $logger |
|
99 | - */ |
|
100 | - public function __construct(string $appName, |
|
101 | - IRequest $request, |
|
102 | - IL10N $l10n, |
|
103 | - IConfig $config, |
|
104 | - INavigationManager $navigationManager, |
|
105 | - IAppManager $appManager, |
|
106 | - CategoryFetcher $categoryFetcher, |
|
107 | - AppFetcher $appFetcher, |
|
108 | - IFactory $l10nFactory, |
|
109 | - BundleFetcher $bundleFetcher, |
|
110 | - Installer $installer, |
|
111 | - IURLGenerator $urlGenerator, |
|
112 | - ILogger $logger) { |
|
113 | - parent::__construct($appName, $request); |
|
114 | - $this->l10n = $l10n; |
|
115 | - $this->config = $config; |
|
116 | - $this->navigationManager = $navigationManager; |
|
117 | - $this->appManager = $appManager; |
|
118 | - $this->categoryFetcher = $categoryFetcher; |
|
119 | - $this->appFetcher = $appFetcher; |
|
120 | - $this->l10nFactory = $l10nFactory; |
|
121 | - $this->bundleFetcher = $bundleFetcher; |
|
122 | - $this->installer = $installer; |
|
123 | - $this->urlGenerator = $urlGenerator; |
|
124 | - $this->logger = $logger; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @NoCSRFRequired |
|
129 | - * |
|
130 | - * @return TemplateResponse |
|
131 | - */ |
|
132 | - public function viewApps(): TemplateResponse { |
|
133 | - \OC_Util::addScript('settings', 'apps'); |
|
134 | - $params = []; |
|
135 | - $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
136 | - $params['updateCount'] = count($this->getAppsWithUpdates()); |
|
137 | - $params['developerDocumentation'] = $this->urlGenerator->linkToDocs('developer-manual'); |
|
138 | - $params['bundles'] = $this->getBundles(); |
|
139 | - $this->navigationManager->setActiveEntry('core_apps'); |
|
140 | - |
|
141 | - $templateResponse = new TemplateResponse('settings', 'settings-vue', ['serverData' => $params]); |
|
142 | - $policy = new ContentSecurityPolicy(); |
|
143 | - $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
144 | - $templateResponse->setContentSecurityPolicy($policy); |
|
145 | - |
|
146 | - return $templateResponse; |
|
147 | - } |
|
148 | - |
|
149 | - private function getAppsWithUpdates() { |
|
150 | - $appClass = new \OC_App(); |
|
151 | - $apps = $appClass->listAllApps(); |
|
152 | - foreach($apps as $key => $app) { |
|
153 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
154 | - if($newVersion === false) { |
|
155 | - unset($apps[$key]); |
|
156 | - } |
|
157 | - } |
|
158 | - return $apps; |
|
159 | - } |
|
160 | - |
|
161 | - private function getBundles() { |
|
162 | - $result = []; |
|
163 | - $bundles = $this->bundleFetcher->getBundles(); |
|
164 | - foreach ($bundles as $bundle) { |
|
165 | - $result[] = [ |
|
166 | - 'name' => $bundle->getName(), |
|
167 | - 'id' => $bundle->getIdentifier(), |
|
168 | - 'appIdentifiers' => $bundle->getAppIdentifiers() |
|
169 | - ]; |
|
170 | - } |
|
171 | - return $result; |
|
172 | - |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get all available categories |
|
177 | - * |
|
178 | - * @return JSONResponse |
|
179 | - */ |
|
180 | - public function listCategories(): JSONResponse { |
|
181 | - return new JSONResponse($this->getAllCategories()); |
|
182 | - } |
|
183 | - |
|
184 | - private function getAllCategories() { |
|
185 | - $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
186 | - |
|
187 | - $formattedCategories = []; |
|
188 | - $categories = $this->categoryFetcher->get(); |
|
189 | - foreach($categories as $category) { |
|
190 | - $formattedCategories[] = [ |
|
191 | - 'id' => $category['id'], |
|
192 | - 'ident' => $category['id'], |
|
193 | - 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
194 | - ]; |
|
195 | - } |
|
196 | - |
|
197 | - return $formattedCategories; |
|
198 | - } |
|
199 | - |
|
200 | - private function fetchApps() { |
|
201 | - $appClass = new \OC_App(); |
|
202 | - $apps = $appClass->listAllApps(); |
|
203 | - foreach ($apps as $app) { |
|
204 | - $app['installed'] = true; |
|
205 | - $this->allApps[$app['id']] = $app; |
|
206 | - } |
|
207 | - |
|
208 | - $apps = $this->getAppsForCategory(''); |
|
209 | - foreach ($apps as $app) { |
|
210 | - $app['appstore'] = true; |
|
211 | - if (!array_key_exists($app['id'], $this->allApps)) { |
|
212 | - $this->allApps[$app['id']] = $app; |
|
213 | - } else { |
|
214 | - $this->allApps[$app['id']] = array_merge($app, $this->allApps[$app['id']]); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // add bundle information |
|
219 | - $bundles = $this->bundleFetcher->getBundles(); |
|
220 | - foreach($bundles as $bundle) { |
|
221 | - foreach($bundle->getAppIdentifiers() as $identifier) { |
|
222 | - foreach($this->allApps as &$app) { |
|
223 | - if($app['id'] === $identifier) { |
|
224 | - $app['bundleIds'][] = $bundle->getIdentifier(); |
|
225 | - continue; |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - private function getAllApps() { |
|
233 | - return $this->allApps; |
|
234 | - } |
|
235 | - /** |
|
236 | - * Get all available apps in a category |
|
237 | - * |
|
238 | - * @param string $category |
|
239 | - * @return JSONResponse |
|
240 | - * @throws \Exception |
|
241 | - */ |
|
242 | - public function listApps(): JSONResponse { |
|
243 | - |
|
244 | - $this->fetchApps(); |
|
245 | - $apps = $this->getAllApps(); |
|
246 | - |
|
247 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
248 | - |
|
249 | - // Extend existing app details |
|
250 | - $apps = array_map(function ($appData) use ($dependencyAnalyzer) { |
|
251 | - if (isset($appData['appstoreData'])) { |
|
252 | - $appstoreData = $appData['appstoreData']; |
|
253 | - $appData['screenshot'] = isset($appstoreData['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/' . base64_encode($appstoreData['screenshots'][0]['url']) : ''; |
|
254 | - $appData['category'] = $appstoreData['categories']; |
|
255 | - } |
|
256 | - |
|
257 | - $newVersion = $this->installer->isUpdateAvailable($appData['id']); |
|
258 | - if($newVersion) { |
|
259 | - $appData['update'] = $newVersion; |
|
260 | - } |
|
261 | - |
|
262 | - // fix groups to be an array |
|
263 | - $groups = []; |
|
264 | - if (is_string($appData['groups'])) { |
|
265 | - $groups = json_decode($appData['groups']); |
|
266 | - } |
|
267 | - $appData['groups'] = $groups; |
|
268 | - $appData['canUnInstall'] = !$appData['active'] && $appData['removable']; |
|
269 | - |
|
270 | - // fix licence vs license |
|
271 | - if (isset($appData['license']) && !isset($appData['licence'])) { |
|
272 | - $appData['licence'] = $appData['license']; |
|
273 | - } |
|
274 | - |
|
275 | - $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []); |
|
276 | - if (!is_array($ignoreMaxApps)) { |
|
277 | - $this->logger->warning('The value given for app_install_overwrite is not an array. Ignoring...'); |
|
278 | - $ignoreMaxApps = []; |
|
279 | - } |
|
280 | - $ignoreMax = in_array($appData['id'], $ignoreMaxApps); |
|
281 | - |
|
282 | - // analyse dependencies |
|
283 | - $missing = $dependencyAnalyzer->analyze($appData, $ignoreMax); |
|
284 | - $appData['canInstall'] = empty($missing); |
|
285 | - $appData['missingDependencies'] = $missing; |
|
286 | - |
|
287 | - $appData['missingMinOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['min-version']); |
|
288 | - $appData['missingMaxOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['max-version']); |
|
289 | - $appData['isCompatible'] = $dependencyAnalyzer->isMarkedCompatible($appData); |
|
290 | - |
|
291 | - return $appData; |
|
292 | - }, $apps); |
|
293 | - |
|
294 | - usort($apps, [$this, 'sortApps']); |
|
295 | - |
|
296 | - return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Get all apps for a category from the app store |
|
301 | - * |
|
302 | - * @param string $requestedCategory |
|
303 | - * @return array |
|
304 | - * @throws \Exception |
|
305 | - */ |
|
306 | - private function getAppsForCategory($requestedCategory = ''): array { |
|
307 | - $versionParser = new VersionParser(); |
|
308 | - $formattedApps = []; |
|
309 | - $apps = $this->appFetcher->get(); |
|
310 | - foreach($apps as $app) { |
|
311 | - // Skip all apps not in the requested category |
|
312 | - if ($requestedCategory !== '') { |
|
313 | - $isInCategory = false; |
|
314 | - foreach($app['categories'] as $category) { |
|
315 | - if($category === $requestedCategory) { |
|
316 | - $isInCategory = true; |
|
317 | - } |
|
318 | - } |
|
319 | - if(!$isInCategory) { |
|
320 | - continue; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - if (!isset($app['releases'][0]['rawPlatformVersionSpec'])) { |
|
325 | - continue; |
|
326 | - } |
|
327 | - $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
328 | - $nextCloudVersionDependencies = []; |
|
329 | - if($nextCloudVersion->getMinimumVersion() !== '') { |
|
330 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
331 | - } |
|
332 | - if($nextCloudVersion->getMaximumVersion() !== '') { |
|
333 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
334 | - } |
|
335 | - $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
336 | - $existsLocally = \OC_App::getAppPath($app['id']) !== false; |
|
337 | - $phpDependencies = []; |
|
338 | - if($phpVersion->getMinimumVersion() !== '') { |
|
339 | - $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
340 | - } |
|
341 | - if($phpVersion->getMaximumVersion() !== '') { |
|
342 | - $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
343 | - } |
|
344 | - if(isset($app['releases'][0]['minIntSize'])) { |
|
345 | - $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
346 | - } |
|
347 | - $authors = ''; |
|
348 | - foreach($app['authors'] as $key => $author) { |
|
349 | - $authors .= $author['name']; |
|
350 | - if($key !== count($app['authors']) - 1) { |
|
351 | - $authors .= ', '; |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
356 | - $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
357 | - $groups = null; |
|
358 | - if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
359 | - $groups = $enabledValue; |
|
360 | - } |
|
361 | - |
|
362 | - $currentVersion = ''; |
|
363 | - if($this->appManager->isInstalled($app['id'])) { |
|
364 | - $currentVersion = $this->appManager->getAppVersion($app['id']); |
|
365 | - } else { |
|
366 | - $currentLanguage = $app['releases'][0]['version']; |
|
367 | - } |
|
368 | - |
|
369 | - $formattedApps[] = [ |
|
370 | - 'id' => $app['id'], |
|
371 | - 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
372 | - 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
373 | - 'summary' => isset($app['translations'][$currentLanguage]['summary']) ? $app['translations'][$currentLanguage]['summary'] : $app['translations']['en']['summary'], |
|
374 | - 'license' => $app['releases'][0]['licenses'], |
|
375 | - 'author' => $authors, |
|
376 | - 'shipped' => false, |
|
377 | - 'version' => $currentVersion, |
|
378 | - 'default_enable' => '', |
|
379 | - 'types' => [], |
|
380 | - 'documentation' => [ |
|
381 | - 'admin' => $app['adminDocs'], |
|
382 | - 'user' => $app['userDocs'], |
|
383 | - 'developer' => $app['developerDocs'] |
|
384 | - ], |
|
385 | - 'website' => $app['website'], |
|
386 | - 'bugs' => $app['issueTracker'], |
|
387 | - 'detailpage' => $app['website'], |
|
388 | - 'dependencies' => array_merge( |
|
389 | - $nextCloudVersionDependencies, |
|
390 | - $phpDependencies |
|
391 | - ), |
|
392 | - 'level' => ($app['isFeatured'] === true) ? 200 : 100, |
|
393 | - 'missingMaxOwnCloudVersion' => false, |
|
394 | - 'missingMinOwnCloudVersion' => false, |
|
395 | - 'canInstall' => true, |
|
396 | - 'screenshot' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
397 | - 'score' => $app['ratingOverall'], |
|
398 | - 'ratingNumOverall' => $app['ratingNumOverall'], |
|
399 | - 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5, |
|
400 | - 'removable' => $existsLocally, |
|
401 | - 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
402 | - 'needsDownload' => !$existsLocally, |
|
403 | - 'groups' => $groups, |
|
404 | - 'fromAppStore' => true, |
|
405 | - 'appstoreData' => $app, |
|
406 | - ]; |
|
407 | - } |
|
408 | - |
|
409 | - return $formattedApps; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * @PasswordConfirmationRequired |
|
414 | - * |
|
415 | - * @param string $appId |
|
416 | - * @param array $groups |
|
417 | - * @return JSONResponse |
|
418 | - */ |
|
419 | - public function enableApp(string $appId, array $groups = []): JSONResponse { |
|
420 | - return $this->enableApps([$appId], $groups); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Enable one or more apps |
|
425 | - * |
|
426 | - * apps will be enabled for specific groups only if $groups is defined |
|
427 | - * |
|
428 | - * @PasswordConfirmationRequired |
|
429 | - * @param array $appIds |
|
430 | - * @param array $groups |
|
431 | - * @return JSONResponse |
|
432 | - */ |
|
433 | - public function enableApps(array $appIds, array $groups = []): JSONResponse { |
|
434 | - try { |
|
435 | - $updateRequired = false; |
|
436 | - |
|
437 | - foreach ($appIds as $appId) { |
|
438 | - $appId = OC_App::cleanAppId($appId); |
|
439 | - |
|
440 | - // Check if app is already downloaded |
|
441 | - /** @var Installer $installer */ |
|
442 | - $installer = \OC::$server->query(Installer::class); |
|
443 | - $isDownloaded = $installer->isDownloaded($appId); |
|
444 | - |
|
445 | - if(!$isDownloaded) { |
|
446 | - $installer->downloadApp($appId); |
|
447 | - } |
|
448 | - |
|
449 | - $installer->installApp($appId); |
|
450 | - |
|
451 | - if (count($groups) > 0) { |
|
452 | - $this->appManager->enableAppForGroups($appId, $this->getGroupList($groups)); |
|
453 | - } else { |
|
454 | - $this->appManager->enableApp($appId); |
|
455 | - } |
|
456 | - if (\OC_App::shouldUpgrade($appId)) { |
|
457 | - $updateRequired = true; |
|
458 | - } |
|
459 | - } |
|
460 | - return new JSONResponse(['data' => ['update_required' => $updateRequired]]); |
|
461 | - |
|
462 | - } catch (\Exception $e) { |
|
463 | - $this->logger->logException($e); |
|
464 | - return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
465 | - } |
|
466 | - } |
|
467 | - |
|
468 | - private function getGroupList(array $groups) { |
|
469 | - $groupManager = \OC::$server->getGroupManager(); |
|
470 | - $groupsList = []; |
|
471 | - foreach ($groups as $group) { |
|
472 | - $groupItem = $groupManager->get($group); |
|
473 | - if ($groupItem instanceof \OCP\IGroup) { |
|
474 | - $groupsList[] = $groupManager->get($group); |
|
475 | - } |
|
476 | - } |
|
477 | - return $groupsList; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @PasswordConfirmationRequired |
|
482 | - * |
|
483 | - * @param string $appId |
|
484 | - * @return JSONResponse |
|
485 | - */ |
|
486 | - public function disableApp(string $appId): JSONResponse { |
|
487 | - return $this->disableApps([$appId]); |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * @PasswordConfirmationRequired |
|
492 | - * |
|
493 | - * @param array $appIds |
|
494 | - * @return JSONResponse |
|
495 | - */ |
|
496 | - public function disableApps(array $appIds): JSONResponse { |
|
497 | - try { |
|
498 | - foreach ($appIds as $appId) { |
|
499 | - $appId = OC_App::cleanAppId($appId); |
|
500 | - $this->appManager->disableApp($appId); |
|
501 | - } |
|
502 | - return new JSONResponse([]); |
|
503 | - } catch (\Exception $e) { |
|
504 | - $this->logger->logException($e); |
|
505 | - return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * @PasswordConfirmationRequired |
|
511 | - * |
|
512 | - * @param string $appId |
|
513 | - * @return JSONResponse |
|
514 | - */ |
|
515 | - public function uninstallApp(string $appId): JSONResponse { |
|
516 | - $appId = OC_App::cleanAppId($appId); |
|
517 | - $result = $this->installer->removeApp($appId); |
|
518 | - if($result !== false) { |
|
519 | - $this->appManager->clearAppsCache(); |
|
520 | - return new JSONResponse(['data' => ['appid' => $appId]]); |
|
521 | - } |
|
522 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t remove app.')]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * @param string $appId |
|
527 | - * @return JSONResponse |
|
528 | - */ |
|
529 | - public function updateApp(string $appId): JSONResponse { |
|
530 | - $appId = OC_App::cleanAppId($appId); |
|
531 | - |
|
532 | - $this->config->setSystemValue('maintenance', true); |
|
533 | - try { |
|
534 | - $result = $this->installer->updateAppstoreApp($appId); |
|
535 | - $this->config->setSystemValue('maintenance', false); |
|
536 | - } catch (\Exception $ex) { |
|
537 | - $this->config->setSystemValue('maintenance', false); |
|
538 | - return new JSONResponse(['data' => ['message' => $ex->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
539 | - } |
|
540 | - |
|
541 | - if ($result !== false) { |
|
542 | - return new JSONResponse(['data' => ['appid' => $appId]]); |
|
543 | - } |
|
544 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t update app.')]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
545 | - } |
|
546 | - |
|
547 | - private function sortApps($a, $b) { |
|
548 | - $a = (string)$a['name']; |
|
549 | - $b = (string)$b['name']; |
|
550 | - if ($a === $b) { |
|
551 | - return 0; |
|
552 | - } |
|
553 | - return ($a < $b) ? -1 : 1; |
|
554 | - } |
|
555 | - |
|
556 | - public function force(string $appId): JSONResponse { |
|
557 | - $appId = OC_App::cleanAppId($appId); |
|
558 | - $this->appManager->ignoreNextcloudRequirementForApp($appId); |
|
559 | - return new JSONResponse(); |
|
560 | - } |
|
59 | + /** @var \OCP\IL10N */ |
|
60 | + private $l10n; |
|
61 | + /** @var IConfig */ |
|
62 | + private $config; |
|
63 | + /** @var INavigationManager */ |
|
64 | + private $navigationManager; |
|
65 | + /** @var IAppManager */ |
|
66 | + private $appManager; |
|
67 | + /** @var CategoryFetcher */ |
|
68 | + private $categoryFetcher; |
|
69 | + /** @var AppFetcher */ |
|
70 | + private $appFetcher; |
|
71 | + /** @var IFactory */ |
|
72 | + private $l10nFactory; |
|
73 | + /** @var BundleFetcher */ |
|
74 | + private $bundleFetcher; |
|
75 | + /** @var Installer */ |
|
76 | + private $installer; |
|
77 | + /** @var IURLGenerator */ |
|
78 | + private $urlGenerator; |
|
79 | + /** @var ILogger */ |
|
80 | + private $logger; |
|
81 | + |
|
82 | + /** @var array */ |
|
83 | + private $allApps = []; |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $appName |
|
87 | + * @param IRequest $request |
|
88 | + * @param IL10N $l10n |
|
89 | + * @param IConfig $config |
|
90 | + * @param INavigationManager $navigationManager |
|
91 | + * @param IAppManager $appManager |
|
92 | + * @param CategoryFetcher $categoryFetcher |
|
93 | + * @param AppFetcher $appFetcher |
|
94 | + * @param IFactory $l10nFactory |
|
95 | + * @param BundleFetcher $bundleFetcher |
|
96 | + * @param Installer $installer |
|
97 | + * @param IURLGenerator $urlGenerator |
|
98 | + * @param ILogger $logger |
|
99 | + */ |
|
100 | + public function __construct(string $appName, |
|
101 | + IRequest $request, |
|
102 | + IL10N $l10n, |
|
103 | + IConfig $config, |
|
104 | + INavigationManager $navigationManager, |
|
105 | + IAppManager $appManager, |
|
106 | + CategoryFetcher $categoryFetcher, |
|
107 | + AppFetcher $appFetcher, |
|
108 | + IFactory $l10nFactory, |
|
109 | + BundleFetcher $bundleFetcher, |
|
110 | + Installer $installer, |
|
111 | + IURLGenerator $urlGenerator, |
|
112 | + ILogger $logger) { |
|
113 | + parent::__construct($appName, $request); |
|
114 | + $this->l10n = $l10n; |
|
115 | + $this->config = $config; |
|
116 | + $this->navigationManager = $navigationManager; |
|
117 | + $this->appManager = $appManager; |
|
118 | + $this->categoryFetcher = $categoryFetcher; |
|
119 | + $this->appFetcher = $appFetcher; |
|
120 | + $this->l10nFactory = $l10nFactory; |
|
121 | + $this->bundleFetcher = $bundleFetcher; |
|
122 | + $this->installer = $installer; |
|
123 | + $this->urlGenerator = $urlGenerator; |
|
124 | + $this->logger = $logger; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @NoCSRFRequired |
|
129 | + * |
|
130 | + * @return TemplateResponse |
|
131 | + */ |
|
132 | + public function viewApps(): TemplateResponse { |
|
133 | + \OC_Util::addScript('settings', 'apps'); |
|
134 | + $params = []; |
|
135 | + $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
136 | + $params['updateCount'] = count($this->getAppsWithUpdates()); |
|
137 | + $params['developerDocumentation'] = $this->urlGenerator->linkToDocs('developer-manual'); |
|
138 | + $params['bundles'] = $this->getBundles(); |
|
139 | + $this->navigationManager->setActiveEntry('core_apps'); |
|
140 | + |
|
141 | + $templateResponse = new TemplateResponse('settings', 'settings-vue', ['serverData' => $params]); |
|
142 | + $policy = new ContentSecurityPolicy(); |
|
143 | + $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
144 | + $templateResponse->setContentSecurityPolicy($policy); |
|
145 | + |
|
146 | + return $templateResponse; |
|
147 | + } |
|
148 | + |
|
149 | + private function getAppsWithUpdates() { |
|
150 | + $appClass = new \OC_App(); |
|
151 | + $apps = $appClass->listAllApps(); |
|
152 | + foreach($apps as $key => $app) { |
|
153 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
154 | + if($newVersion === false) { |
|
155 | + unset($apps[$key]); |
|
156 | + } |
|
157 | + } |
|
158 | + return $apps; |
|
159 | + } |
|
160 | + |
|
161 | + private function getBundles() { |
|
162 | + $result = []; |
|
163 | + $bundles = $this->bundleFetcher->getBundles(); |
|
164 | + foreach ($bundles as $bundle) { |
|
165 | + $result[] = [ |
|
166 | + 'name' => $bundle->getName(), |
|
167 | + 'id' => $bundle->getIdentifier(), |
|
168 | + 'appIdentifiers' => $bundle->getAppIdentifiers() |
|
169 | + ]; |
|
170 | + } |
|
171 | + return $result; |
|
172 | + |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get all available categories |
|
177 | + * |
|
178 | + * @return JSONResponse |
|
179 | + */ |
|
180 | + public function listCategories(): JSONResponse { |
|
181 | + return new JSONResponse($this->getAllCategories()); |
|
182 | + } |
|
183 | + |
|
184 | + private function getAllCategories() { |
|
185 | + $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
186 | + |
|
187 | + $formattedCategories = []; |
|
188 | + $categories = $this->categoryFetcher->get(); |
|
189 | + foreach($categories as $category) { |
|
190 | + $formattedCategories[] = [ |
|
191 | + 'id' => $category['id'], |
|
192 | + 'ident' => $category['id'], |
|
193 | + 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
194 | + ]; |
|
195 | + } |
|
196 | + |
|
197 | + return $formattedCategories; |
|
198 | + } |
|
199 | + |
|
200 | + private function fetchApps() { |
|
201 | + $appClass = new \OC_App(); |
|
202 | + $apps = $appClass->listAllApps(); |
|
203 | + foreach ($apps as $app) { |
|
204 | + $app['installed'] = true; |
|
205 | + $this->allApps[$app['id']] = $app; |
|
206 | + } |
|
207 | + |
|
208 | + $apps = $this->getAppsForCategory(''); |
|
209 | + foreach ($apps as $app) { |
|
210 | + $app['appstore'] = true; |
|
211 | + if (!array_key_exists($app['id'], $this->allApps)) { |
|
212 | + $this->allApps[$app['id']] = $app; |
|
213 | + } else { |
|
214 | + $this->allApps[$app['id']] = array_merge($app, $this->allApps[$app['id']]); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // add bundle information |
|
219 | + $bundles = $this->bundleFetcher->getBundles(); |
|
220 | + foreach($bundles as $bundle) { |
|
221 | + foreach($bundle->getAppIdentifiers() as $identifier) { |
|
222 | + foreach($this->allApps as &$app) { |
|
223 | + if($app['id'] === $identifier) { |
|
224 | + $app['bundleIds'][] = $bundle->getIdentifier(); |
|
225 | + continue; |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + private function getAllApps() { |
|
233 | + return $this->allApps; |
|
234 | + } |
|
235 | + /** |
|
236 | + * Get all available apps in a category |
|
237 | + * |
|
238 | + * @param string $category |
|
239 | + * @return JSONResponse |
|
240 | + * @throws \Exception |
|
241 | + */ |
|
242 | + public function listApps(): JSONResponse { |
|
243 | + |
|
244 | + $this->fetchApps(); |
|
245 | + $apps = $this->getAllApps(); |
|
246 | + |
|
247 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
248 | + |
|
249 | + // Extend existing app details |
|
250 | + $apps = array_map(function ($appData) use ($dependencyAnalyzer) { |
|
251 | + if (isset($appData['appstoreData'])) { |
|
252 | + $appstoreData = $appData['appstoreData']; |
|
253 | + $appData['screenshot'] = isset($appstoreData['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/' . base64_encode($appstoreData['screenshots'][0]['url']) : ''; |
|
254 | + $appData['category'] = $appstoreData['categories']; |
|
255 | + } |
|
256 | + |
|
257 | + $newVersion = $this->installer->isUpdateAvailable($appData['id']); |
|
258 | + if($newVersion) { |
|
259 | + $appData['update'] = $newVersion; |
|
260 | + } |
|
261 | + |
|
262 | + // fix groups to be an array |
|
263 | + $groups = []; |
|
264 | + if (is_string($appData['groups'])) { |
|
265 | + $groups = json_decode($appData['groups']); |
|
266 | + } |
|
267 | + $appData['groups'] = $groups; |
|
268 | + $appData['canUnInstall'] = !$appData['active'] && $appData['removable']; |
|
269 | + |
|
270 | + // fix licence vs license |
|
271 | + if (isset($appData['license']) && !isset($appData['licence'])) { |
|
272 | + $appData['licence'] = $appData['license']; |
|
273 | + } |
|
274 | + |
|
275 | + $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []); |
|
276 | + if (!is_array($ignoreMaxApps)) { |
|
277 | + $this->logger->warning('The value given for app_install_overwrite is not an array. Ignoring...'); |
|
278 | + $ignoreMaxApps = []; |
|
279 | + } |
|
280 | + $ignoreMax = in_array($appData['id'], $ignoreMaxApps); |
|
281 | + |
|
282 | + // analyse dependencies |
|
283 | + $missing = $dependencyAnalyzer->analyze($appData, $ignoreMax); |
|
284 | + $appData['canInstall'] = empty($missing); |
|
285 | + $appData['missingDependencies'] = $missing; |
|
286 | + |
|
287 | + $appData['missingMinOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['min-version']); |
|
288 | + $appData['missingMaxOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['max-version']); |
|
289 | + $appData['isCompatible'] = $dependencyAnalyzer->isMarkedCompatible($appData); |
|
290 | + |
|
291 | + return $appData; |
|
292 | + }, $apps); |
|
293 | + |
|
294 | + usort($apps, [$this, 'sortApps']); |
|
295 | + |
|
296 | + return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Get all apps for a category from the app store |
|
301 | + * |
|
302 | + * @param string $requestedCategory |
|
303 | + * @return array |
|
304 | + * @throws \Exception |
|
305 | + */ |
|
306 | + private function getAppsForCategory($requestedCategory = ''): array { |
|
307 | + $versionParser = new VersionParser(); |
|
308 | + $formattedApps = []; |
|
309 | + $apps = $this->appFetcher->get(); |
|
310 | + foreach($apps as $app) { |
|
311 | + // Skip all apps not in the requested category |
|
312 | + if ($requestedCategory !== '') { |
|
313 | + $isInCategory = false; |
|
314 | + foreach($app['categories'] as $category) { |
|
315 | + if($category === $requestedCategory) { |
|
316 | + $isInCategory = true; |
|
317 | + } |
|
318 | + } |
|
319 | + if(!$isInCategory) { |
|
320 | + continue; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + if (!isset($app['releases'][0]['rawPlatformVersionSpec'])) { |
|
325 | + continue; |
|
326 | + } |
|
327 | + $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
328 | + $nextCloudVersionDependencies = []; |
|
329 | + if($nextCloudVersion->getMinimumVersion() !== '') { |
|
330 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
331 | + } |
|
332 | + if($nextCloudVersion->getMaximumVersion() !== '') { |
|
333 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
334 | + } |
|
335 | + $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
336 | + $existsLocally = \OC_App::getAppPath($app['id']) !== false; |
|
337 | + $phpDependencies = []; |
|
338 | + if($phpVersion->getMinimumVersion() !== '') { |
|
339 | + $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
340 | + } |
|
341 | + if($phpVersion->getMaximumVersion() !== '') { |
|
342 | + $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
343 | + } |
|
344 | + if(isset($app['releases'][0]['minIntSize'])) { |
|
345 | + $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
346 | + } |
|
347 | + $authors = ''; |
|
348 | + foreach($app['authors'] as $key => $author) { |
|
349 | + $authors .= $author['name']; |
|
350 | + if($key !== count($app['authors']) - 1) { |
|
351 | + $authors .= ', '; |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
356 | + $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
357 | + $groups = null; |
|
358 | + if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
359 | + $groups = $enabledValue; |
|
360 | + } |
|
361 | + |
|
362 | + $currentVersion = ''; |
|
363 | + if($this->appManager->isInstalled($app['id'])) { |
|
364 | + $currentVersion = $this->appManager->getAppVersion($app['id']); |
|
365 | + } else { |
|
366 | + $currentLanguage = $app['releases'][0]['version']; |
|
367 | + } |
|
368 | + |
|
369 | + $formattedApps[] = [ |
|
370 | + 'id' => $app['id'], |
|
371 | + 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
372 | + 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
373 | + 'summary' => isset($app['translations'][$currentLanguage]['summary']) ? $app['translations'][$currentLanguage]['summary'] : $app['translations']['en']['summary'], |
|
374 | + 'license' => $app['releases'][0]['licenses'], |
|
375 | + 'author' => $authors, |
|
376 | + 'shipped' => false, |
|
377 | + 'version' => $currentVersion, |
|
378 | + 'default_enable' => '', |
|
379 | + 'types' => [], |
|
380 | + 'documentation' => [ |
|
381 | + 'admin' => $app['adminDocs'], |
|
382 | + 'user' => $app['userDocs'], |
|
383 | + 'developer' => $app['developerDocs'] |
|
384 | + ], |
|
385 | + 'website' => $app['website'], |
|
386 | + 'bugs' => $app['issueTracker'], |
|
387 | + 'detailpage' => $app['website'], |
|
388 | + 'dependencies' => array_merge( |
|
389 | + $nextCloudVersionDependencies, |
|
390 | + $phpDependencies |
|
391 | + ), |
|
392 | + 'level' => ($app['isFeatured'] === true) ? 200 : 100, |
|
393 | + 'missingMaxOwnCloudVersion' => false, |
|
394 | + 'missingMinOwnCloudVersion' => false, |
|
395 | + 'canInstall' => true, |
|
396 | + 'screenshot' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
397 | + 'score' => $app['ratingOverall'], |
|
398 | + 'ratingNumOverall' => $app['ratingNumOverall'], |
|
399 | + 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5, |
|
400 | + 'removable' => $existsLocally, |
|
401 | + 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
402 | + 'needsDownload' => !$existsLocally, |
|
403 | + 'groups' => $groups, |
|
404 | + 'fromAppStore' => true, |
|
405 | + 'appstoreData' => $app, |
|
406 | + ]; |
|
407 | + } |
|
408 | + |
|
409 | + return $formattedApps; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * @PasswordConfirmationRequired |
|
414 | + * |
|
415 | + * @param string $appId |
|
416 | + * @param array $groups |
|
417 | + * @return JSONResponse |
|
418 | + */ |
|
419 | + public function enableApp(string $appId, array $groups = []): JSONResponse { |
|
420 | + return $this->enableApps([$appId], $groups); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Enable one or more apps |
|
425 | + * |
|
426 | + * apps will be enabled for specific groups only if $groups is defined |
|
427 | + * |
|
428 | + * @PasswordConfirmationRequired |
|
429 | + * @param array $appIds |
|
430 | + * @param array $groups |
|
431 | + * @return JSONResponse |
|
432 | + */ |
|
433 | + public function enableApps(array $appIds, array $groups = []): JSONResponse { |
|
434 | + try { |
|
435 | + $updateRequired = false; |
|
436 | + |
|
437 | + foreach ($appIds as $appId) { |
|
438 | + $appId = OC_App::cleanAppId($appId); |
|
439 | + |
|
440 | + // Check if app is already downloaded |
|
441 | + /** @var Installer $installer */ |
|
442 | + $installer = \OC::$server->query(Installer::class); |
|
443 | + $isDownloaded = $installer->isDownloaded($appId); |
|
444 | + |
|
445 | + if(!$isDownloaded) { |
|
446 | + $installer->downloadApp($appId); |
|
447 | + } |
|
448 | + |
|
449 | + $installer->installApp($appId); |
|
450 | + |
|
451 | + if (count($groups) > 0) { |
|
452 | + $this->appManager->enableAppForGroups($appId, $this->getGroupList($groups)); |
|
453 | + } else { |
|
454 | + $this->appManager->enableApp($appId); |
|
455 | + } |
|
456 | + if (\OC_App::shouldUpgrade($appId)) { |
|
457 | + $updateRequired = true; |
|
458 | + } |
|
459 | + } |
|
460 | + return new JSONResponse(['data' => ['update_required' => $updateRequired]]); |
|
461 | + |
|
462 | + } catch (\Exception $e) { |
|
463 | + $this->logger->logException($e); |
|
464 | + return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
465 | + } |
|
466 | + } |
|
467 | + |
|
468 | + private function getGroupList(array $groups) { |
|
469 | + $groupManager = \OC::$server->getGroupManager(); |
|
470 | + $groupsList = []; |
|
471 | + foreach ($groups as $group) { |
|
472 | + $groupItem = $groupManager->get($group); |
|
473 | + if ($groupItem instanceof \OCP\IGroup) { |
|
474 | + $groupsList[] = $groupManager->get($group); |
|
475 | + } |
|
476 | + } |
|
477 | + return $groupsList; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @PasswordConfirmationRequired |
|
482 | + * |
|
483 | + * @param string $appId |
|
484 | + * @return JSONResponse |
|
485 | + */ |
|
486 | + public function disableApp(string $appId): JSONResponse { |
|
487 | + return $this->disableApps([$appId]); |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * @PasswordConfirmationRequired |
|
492 | + * |
|
493 | + * @param array $appIds |
|
494 | + * @return JSONResponse |
|
495 | + */ |
|
496 | + public function disableApps(array $appIds): JSONResponse { |
|
497 | + try { |
|
498 | + foreach ($appIds as $appId) { |
|
499 | + $appId = OC_App::cleanAppId($appId); |
|
500 | + $this->appManager->disableApp($appId); |
|
501 | + } |
|
502 | + return new JSONResponse([]); |
|
503 | + } catch (\Exception $e) { |
|
504 | + $this->logger->logException($e); |
|
505 | + return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * @PasswordConfirmationRequired |
|
511 | + * |
|
512 | + * @param string $appId |
|
513 | + * @return JSONResponse |
|
514 | + */ |
|
515 | + public function uninstallApp(string $appId): JSONResponse { |
|
516 | + $appId = OC_App::cleanAppId($appId); |
|
517 | + $result = $this->installer->removeApp($appId); |
|
518 | + if($result !== false) { |
|
519 | + $this->appManager->clearAppsCache(); |
|
520 | + return new JSONResponse(['data' => ['appid' => $appId]]); |
|
521 | + } |
|
522 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t remove app.')]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * @param string $appId |
|
527 | + * @return JSONResponse |
|
528 | + */ |
|
529 | + public function updateApp(string $appId): JSONResponse { |
|
530 | + $appId = OC_App::cleanAppId($appId); |
|
531 | + |
|
532 | + $this->config->setSystemValue('maintenance', true); |
|
533 | + try { |
|
534 | + $result = $this->installer->updateAppstoreApp($appId); |
|
535 | + $this->config->setSystemValue('maintenance', false); |
|
536 | + } catch (\Exception $ex) { |
|
537 | + $this->config->setSystemValue('maintenance', false); |
|
538 | + return new JSONResponse(['data' => ['message' => $ex->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
539 | + } |
|
540 | + |
|
541 | + if ($result !== false) { |
|
542 | + return new JSONResponse(['data' => ['appid' => $appId]]); |
|
543 | + } |
|
544 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t update app.')]], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
545 | + } |
|
546 | + |
|
547 | + private function sortApps($a, $b) { |
|
548 | + $a = (string)$a['name']; |
|
549 | + $b = (string)$b['name']; |
|
550 | + if ($a === $b) { |
|
551 | + return 0; |
|
552 | + } |
|
553 | + return ($a < $b) ? -1 : 1; |
|
554 | + } |
|
555 | + |
|
556 | + public function force(string $appId): JSONResponse { |
|
557 | + $appId = OC_App::cleanAppId($appId); |
|
558 | + $this->appManager->ignoreNextcloudRequirementForApp($appId); |
|
559 | + return new JSONResponse(); |
|
560 | + } |
|
561 | 561 | |
562 | 562 | } |
@@ -27,96 +27,96 @@ |
||
27 | 27 | |
28 | 28 | abstract class AbstractStringCheck implements ICheck { |
29 | 29 | |
30 | - /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ |
|
31 | - protected $matches; |
|
30 | + /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ |
|
31 | + protected $matches; |
|
32 | 32 | |
33 | - /** @var IL10N */ |
|
34 | - protected $l; |
|
33 | + /** @var IL10N */ |
|
34 | + protected $l; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param IL10N $l |
|
38 | - */ |
|
39 | - public function __construct(IL10N $l) { |
|
40 | - $this->l = $l; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param IL10N $l |
|
38 | + */ |
|
39 | + public function __construct(IL10N $l) { |
|
40 | + $this->l = $l; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - abstract protected function getActualValue(); |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + abstract protected function getActualValue(); |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $operator |
|
50 | - * @param string $value |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function executeCheck($operator, $value) { |
|
54 | - $actualValue = $this->getActualValue(); |
|
55 | - return $this->executeStringCheck($operator, $value, $actualValue); |
|
56 | - } |
|
48 | + /** |
|
49 | + * @param string $operator |
|
50 | + * @param string $value |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function executeCheck($operator, $value) { |
|
54 | + $actualValue = $this->getActualValue(); |
|
55 | + return $this->executeStringCheck($operator, $value, $actualValue); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $operator |
|
60 | - * @param string $checkValue |
|
61 | - * @param string $actualValue |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - protected function executeStringCheck($operator, $checkValue, $actualValue) { |
|
65 | - if ($operator === 'is') { |
|
66 | - return $checkValue === $actualValue; |
|
67 | - } else if ($operator === '!is') { |
|
68 | - return $checkValue !== $actualValue; |
|
69 | - } else { |
|
70 | - $match = $this->match($checkValue, $actualValue); |
|
71 | - if ($operator === 'matches') { |
|
72 | - return $match === 1; |
|
73 | - } else { |
|
74 | - return $match === 0; |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
58 | + /** |
|
59 | + * @param string $operator |
|
60 | + * @param string $checkValue |
|
61 | + * @param string $actualValue |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + protected function executeStringCheck($operator, $checkValue, $actualValue) { |
|
65 | + if ($operator === 'is') { |
|
66 | + return $checkValue === $actualValue; |
|
67 | + } else if ($operator === '!is') { |
|
68 | + return $checkValue !== $actualValue; |
|
69 | + } else { |
|
70 | + $match = $this->match($checkValue, $actualValue); |
|
71 | + if ($operator === 'matches') { |
|
72 | + return $match === 1; |
|
73 | + } else { |
|
74 | + return $match === 0; |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $operator |
|
81 | - * @param string $value |
|
82 | - * @throws \UnexpectedValueException |
|
83 | - */ |
|
84 | - public function validateCheck($operator, $value) { |
|
85 | - if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) { |
|
86 | - throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
87 | - } |
|
79 | + /** |
|
80 | + * @param string $operator |
|
81 | + * @param string $value |
|
82 | + * @throws \UnexpectedValueException |
|
83 | + */ |
|
84 | + public function validateCheck($operator, $value) { |
|
85 | + if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) { |
|
86 | + throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
87 | + } |
|
88 | 88 | |
89 | - if (in_array($operator, ['matches', '!matches']) && |
|
90 | - @preg_match($value, null) === false) { |
|
91 | - throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); |
|
92 | - } |
|
93 | - } |
|
89 | + if (in_array($operator, ['matches', '!matches']) && |
|
90 | + @preg_match($value, null) === false) { |
|
91 | + throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - public function supportedEntities(): array { |
|
96 | - // universal by default |
|
97 | - return []; |
|
98 | - } |
|
95 | + public function supportedEntities(): array { |
|
96 | + // universal by default |
|
97 | + return []; |
|
98 | + } |
|
99 | 99 | |
100 | - public function isAvailableForScope(int $scope): bool { |
|
101 | - // admin only by default |
|
102 | - return $scope === IManager::SCOPE_ADMIN; |
|
103 | - } |
|
100 | + public function isAvailableForScope(int $scope): bool { |
|
101 | + // admin only by default |
|
102 | + return $scope === IManager::SCOPE_ADMIN; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @param string $pattern |
|
107 | - * @param string $subject |
|
108 | - * @return int|bool |
|
109 | - */ |
|
110 | - protected function match($pattern, $subject) { |
|
111 | - $patternHash = md5($pattern); |
|
112 | - $subjectHash = md5($subject); |
|
113 | - if (isset($this->matches[$patternHash][$subjectHash])) { |
|
114 | - return $this->matches[$patternHash][$subjectHash]; |
|
115 | - } |
|
116 | - if (!isset($this->matches[$patternHash])) { |
|
117 | - $this->matches[$patternHash] = []; |
|
118 | - } |
|
119 | - $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject); |
|
120 | - return $this->matches[$patternHash][$subjectHash]; |
|
121 | - } |
|
105 | + /** |
|
106 | + * @param string $pattern |
|
107 | + * @param string $subject |
|
108 | + * @return int|bool |
|
109 | + */ |
|
110 | + protected function match($pattern, $subject) { |
|
111 | + $patternHash = md5($pattern); |
|
112 | + $subjectHash = md5($subject); |
|
113 | + if (isset($this->matches[$patternHash][$subjectHash])) { |
|
114 | + return $this->matches[$patternHash][$subjectHash]; |
|
115 | + } |
|
116 | + if (!isset($this->matches[$patternHash])) { |
|
117 | + $this->matches[$patternHash] = []; |
|
118 | + } |
|
119 | + $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject); |
|
120 | + return $this->matches[$patternHash][$subjectHash]; |
|
121 | + } |
|
122 | 122 | } |
@@ -41,156 +41,156 @@ |
||
41 | 41 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
42 | 42 | |
43 | 43 | abstract class ASettings implements ISettings { |
44 | - /** @var IL10N */ |
|
45 | - private $l10n; |
|
46 | - |
|
47 | - /** @var string */ |
|
48 | - private $appName; |
|
49 | - |
|
50 | - /** @var EventDispatcherInterface */ |
|
51 | - private $eventDispatcher; |
|
52 | - |
|
53 | - /** @var Manager */ |
|
54 | - protected $manager; |
|
55 | - |
|
56 | - /** @var IInitialStateService */ |
|
57 | - private $initialStateService; |
|
58 | - |
|
59 | - /** @var IConfig */ |
|
60 | - private $config; |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $appName |
|
64 | - * @param IL10N $l |
|
65 | - * @param EventDispatcherInterface $eventDispatcher |
|
66 | - * @param Manager $manager |
|
67 | - * @param IInitialStateService $initialStateService |
|
68 | - * @param IConfig $config |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - $appName, |
|
72 | - IL10N $l, |
|
73 | - EventDispatcherInterface $eventDispatcher, |
|
74 | - Manager $manager, |
|
75 | - IInitialStateService $initialStateService, |
|
76 | - IConfig $config |
|
77 | - ) { |
|
78 | - $this->appName = $appName; |
|
79 | - $this->l10n = $l; |
|
80 | - $this->eventDispatcher = $eventDispatcher; |
|
81 | - $this->manager = $manager; |
|
82 | - $this->initialStateService = $initialStateService; |
|
83 | - $this->config = $config; |
|
84 | - } |
|
85 | - |
|
86 | - abstract function getScope(): int; |
|
87 | - |
|
88 | - /** |
|
89 | - * @return TemplateResponse |
|
90 | - */ |
|
91 | - public function getForm() { |
|
92 | - $this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts'); |
|
93 | - |
|
94 | - $entities = $this->manager->getEntitiesList(); |
|
95 | - $this->initialStateService->provideInitialState( |
|
96 | - Application::APP_ID, |
|
97 | - 'entities', |
|
98 | - $this->entitiesToArray($entities) |
|
99 | - ); |
|
100 | - |
|
101 | - $operators = $this->manager->getOperatorList(); |
|
102 | - $this->initialStateService->provideInitialState( |
|
103 | - Application::APP_ID, |
|
104 | - 'operators', |
|
105 | - $this->operatorsToArray($operators) |
|
106 | - ); |
|
107 | - |
|
108 | - $checks = $this->manager->getCheckList(); |
|
109 | - $this->initialStateService->provideInitialState( |
|
110 | - Application::APP_ID, |
|
111 | - 'checks', |
|
112 | - $this->checksToArray($checks) |
|
113 | - ); |
|
114 | - |
|
115 | - $this->initialStateService->provideInitialState( |
|
116 | - Application::APP_ID, |
|
117 | - 'scope', |
|
118 | - $this->getScope() |
|
119 | - ); |
|
120 | - |
|
121 | - $this->initialStateService->provideInitialState( |
|
122 | - Application::APP_ID, |
|
123 | - 'appstoreenabled', |
|
124 | - $this->config->getSystemValueBool('appstoreenabled', true) |
|
125 | - ); |
|
126 | - |
|
127 | - return new TemplateResponse(Application::APP_ID, 'settings', [], 'blank'); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string the section ID, e.g. 'sharing' |
|
132 | - */ |
|
133 | - public function getSection() { |
|
134 | - return 'workflow'; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return int whether the form should be rather on the top or bottom of |
|
139 | - * the admin section. The forms are arranged in ascending order of the |
|
140 | - * priority values. It is required to return a value between 0 and 100. |
|
141 | - * |
|
142 | - * E.g.: 70 |
|
143 | - */ |
|
144 | - public function getPriority() { |
|
145 | - return 0; |
|
146 | - } |
|
147 | - |
|
148 | - private function entitiesToArray(array $entities) { |
|
149 | - return array_map(function (IEntity $entity) { |
|
150 | - $events = array_map(function (IEntityEvent $entityEvent) { |
|
151 | - return [ |
|
152 | - 'eventName' => $entityEvent->getEventName(), |
|
153 | - 'displayName' => $entityEvent->getDisplayName() |
|
154 | - ]; |
|
155 | - }, $entity->getEvents()); |
|
156 | - |
|
157 | - return [ |
|
158 | - 'id' => get_class($entity), |
|
159 | - 'icon' => $entity->getIcon(), |
|
160 | - 'name' => $entity->getName(), |
|
161 | - 'events' => $events, |
|
162 | - ]; |
|
163 | - }, $entities); |
|
164 | - } |
|
165 | - |
|
166 | - private function operatorsToArray(array $operators) { |
|
167 | - $operators = array_filter($operators, function (IOperation $operator) { |
|
168 | - return $operator->isAvailableForScope($this->getScope()); |
|
169 | - }); |
|
170 | - |
|
171 | - return array_map(function (IOperation $operator) { |
|
172 | - return [ |
|
173 | - 'id' => get_class($operator), |
|
174 | - 'icon' => $operator->getIcon(), |
|
175 | - 'name' => $operator->getDisplayName(), |
|
176 | - 'description' => $operator->getDescription(), |
|
177 | - 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
178 | - 'isComplex' => $operator instanceof IComplexOperation, |
|
179 | - 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
180 | - ]; |
|
181 | - }, $operators); |
|
182 | - } |
|
183 | - |
|
184 | - private function checksToArray(array $checks) { |
|
185 | - $checks = array_filter($checks, function (ICheck $check) { |
|
186 | - return $check->isAvailableForScope($this->getScope()); |
|
187 | - }); |
|
188 | - |
|
189 | - return array_map(function (ICheck $check) { |
|
190 | - return [ |
|
191 | - 'id' => get_class($check), |
|
192 | - 'supportedEntities' => $check->supportedEntities(), |
|
193 | - ]; |
|
194 | - }, $checks); |
|
195 | - } |
|
44 | + /** @var IL10N */ |
|
45 | + private $l10n; |
|
46 | + |
|
47 | + /** @var string */ |
|
48 | + private $appName; |
|
49 | + |
|
50 | + /** @var EventDispatcherInterface */ |
|
51 | + private $eventDispatcher; |
|
52 | + |
|
53 | + /** @var Manager */ |
|
54 | + protected $manager; |
|
55 | + |
|
56 | + /** @var IInitialStateService */ |
|
57 | + private $initialStateService; |
|
58 | + |
|
59 | + /** @var IConfig */ |
|
60 | + private $config; |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $appName |
|
64 | + * @param IL10N $l |
|
65 | + * @param EventDispatcherInterface $eventDispatcher |
|
66 | + * @param Manager $manager |
|
67 | + * @param IInitialStateService $initialStateService |
|
68 | + * @param IConfig $config |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + $appName, |
|
72 | + IL10N $l, |
|
73 | + EventDispatcherInterface $eventDispatcher, |
|
74 | + Manager $manager, |
|
75 | + IInitialStateService $initialStateService, |
|
76 | + IConfig $config |
|
77 | + ) { |
|
78 | + $this->appName = $appName; |
|
79 | + $this->l10n = $l; |
|
80 | + $this->eventDispatcher = $eventDispatcher; |
|
81 | + $this->manager = $manager; |
|
82 | + $this->initialStateService = $initialStateService; |
|
83 | + $this->config = $config; |
|
84 | + } |
|
85 | + |
|
86 | + abstract function getScope(): int; |
|
87 | + |
|
88 | + /** |
|
89 | + * @return TemplateResponse |
|
90 | + */ |
|
91 | + public function getForm() { |
|
92 | + $this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts'); |
|
93 | + |
|
94 | + $entities = $this->manager->getEntitiesList(); |
|
95 | + $this->initialStateService->provideInitialState( |
|
96 | + Application::APP_ID, |
|
97 | + 'entities', |
|
98 | + $this->entitiesToArray($entities) |
|
99 | + ); |
|
100 | + |
|
101 | + $operators = $this->manager->getOperatorList(); |
|
102 | + $this->initialStateService->provideInitialState( |
|
103 | + Application::APP_ID, |
|
104 | + 'operators', |
|
105 | + $this->operatorsToArray($operators) |
|
106 | + ); |
|
107 | + |
|
108 | + $checks = $this->manager->getCheckList(); |
|
109 | + $this->initialStateService->provideInitialState( |
|
110 | + Application::APP_ID, |
|
111 | + 'checks', |
|
112 | + $this->checksToArray($checks) |
|
113 | + ); |
|
114 | + |
|
115 | + $this->initialStateService->provideInitialState( |
|
116 | + Application::APP_ID, |
|
117 | + 'scope', |
|
118 | + $this->getScope() |
|
119 | + ); |
|
120 | + |
|
121 | + $this->initialStateService->provideInitialState( |
|
122 | + Application::APP_ID, |
|
123 | + 'appstoreenabled', |
|
124 | + $this->config->getSystemValueBool('appstoreenabled', true) |
|
125 | + ); |
|
126 | + |
|
127 | + return new TemplateResponse(Application::APP_ID, 'settings', [], 'blank'); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string the section ID, e.g. 'sharing' |
|
132 | + */ |
|
133 | + public function getSection() { |
|
134 | + return 'workflow'; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return int whether the form should be rather on the top or bottom of |
|
139 | + * the admin section. The forms are arranged in ascending order of the |
|
140 | + * priority values. It is required to return a value between 0 and 100. |
|
141 | + * |
|
142 | + * E.g.: 70 |
|
143 | + */ |
|
144 | + public function getPriority() { |
|
145 | + return 0; |
|
146 | + } |
|
147 | + |
|
148 | + private function entitiesToArray(array $entities) { |
|
149 | + return array_map(function (IEntity $entity) { |
|
150 | + $events = array_map(function (IEntityEvent $entityEvent) { |
|
151 | + return [ |
|
152 | + 'eventName' => $entityEvent->getEventName(), |
|
153 | + 'displayName' => $entityEvent->getDisplayName() |
|
154 | + ]; |
|
155 | + }, $entity->getEvents()); |
|
156 | + |
|
157 | + return [ |
|
158 | + 'id' => get_class($entity), |
|
159 | + 'icon' => $entity->getIcon(), |
|
160 | + 'name' => $entity->getName(), |
|
161 | + 'events' => $events, |
|
162 | + ]; |
|
163 | + }, $entities); |
|
164 | + } |
|
165 | + |
|
166 | + private function operatorsToArray(array $operators) { |
|
167 | + $operators = array_filter($operators, function (IOperation $operator) { |
|
168 | + return $operator->isAvailableForScope($this->getScope()); |
|
169 | + }); |
|
170 | + |
|
171 | + return array_map(function (IOperation $operator) { |
|
172 | + return [ |
|
173 | + 'id' => get_class($operator), |
|
174 | + 'icon' => $operator->getIcon(), |
|
175 | + 'name' => $operator->getDisplayName(), |
|
176 | + 'description' => $operator->getDescription(), |
|
177 | + 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
178 | + 'isComplex' => $operator instanceof IComplexOperation, |
|
179 | + 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
180 | + ]; |
|
181 | + }, $operators); |
|
182 | + } |
|
183 | + |
|
184 | + private function checksToArray(array $checks) { |
|
185 | + $checks = array_filter($checks, function (ICheck $check) { |
|
186 | + return $check->isAvailableForScope($this->getScope()); |
|
187 | + }); |
|
188 | + |
|
189 | + return array_map(function (ICheck $check) { |
|
190 | + return [ |
|
191 | + 'id' => get_class($check), |
|
192 | + 'supportedEntities' => $check->supportedEntities(), |
|
193 | + ]; |
|
194 | + }, $checks); |
|
195 | + } |
|
196 | 196 | } |