@@ -38,218 +38,218 @@ |
||
38 | 38 | use OCP\Share\IShare; |
39 | 39 | |
40 | 40 | class File implements \OCP\Share_Backend_File_Dependent { |
41 | - public const FORMAT_SHARED_STORAGE = 0; |
|
42 | - public const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
43 | - public const FORMAT_FILE_APP_ROOT = 2; |
|
44 | - public const FORMAT_OPENDIR = 3; |
|
45 | - public const FORMAT_GET_ALL = 4; |
|
46 | - public const FORMAT_PERMISSIONS = 5; |
|
47 | - public const FORMAT_TARGET_NAMES = 6; |
|
48 | - |
|
49 | - private $path; |
|
50 | - |
|
51 | - /** @var FederatedShareProvider */ |
|
52 | - private $federatedShareProvider; |
|
53 | - |
|
54 | - public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
55 | - if ($federatedShareProvider) { |
|
56 | - $this->federatedShareProvider = $federatedShareProvider; |
|
57 | - } else { |
|
58 | - $this->federatedShareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - public function isValidSource($itemSource, $uidOwner) { |
|
63 | - try { |
|
64 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
65 | - // FIXME: attributes should not be set here, |
|
66 | - // keeping this pattern for now to avoid unexpected |
|
67 | - // regressions |
|
68 | - $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
69 | - return true; |
|
70 | - } catch (\OCP\Files\NotFoundException $e) { |
|
71 | - return false; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - public function getFilePath($itemSource, $uidOwner) { |
|
76 | - if (isset($this->path)) { |
|
77 | - $path = $this->path; |
|
78 | - $this->path = null; |
|
79 | - return $path; |
|
80 | - } else { |
|
81 | - try { |
|
82 | - $path = \OC\Files\Filesystem::getPath($itemSource); |
|
83 | - return $path; |
|
84 | - } catch (\OCP\Files\NotFoundException $e) { |
|
85 | - return false; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * create unique target |
|
92 | - * @param string $filePath |
|
93 | - * @param string $shareWith |
|
94 | - * @param array $exclude (optional) |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
98 | - $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
99 | - $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
100 | - |
|
101 | - // for group shares we return the target right away |
|
102 | - if ($shareWith === false) { |
|
103 | - return $target; |
|
104 | - } |
|
105 | - |
|
106 | - \OC\Files\Filesystem::initMountPoints($shareWith); |
|
107 | - $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
108 | - |
|
109 | - if (!$view->is_dir($shareFolder)) { |
|
110 | - $dir = ''; |
|
111 | - $subdirs = explode('/', $shareFolder); |
|
112 | - foreach ($subdirs as $subdir) { |
|
113 | - $dir = $dir . '/' . $subdir; |
|
114 | - if (!$view->is_dir($dir)) { |
|
115 | - $view->mkdir($dir); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - $excludeList = is_array($exclude) ? $exclude : []; |
|
121 | - |
|
122 | - return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
123 | - } |
|
124 | - |
|
125 | - public function formatItems($items, $format, $parameters = null) { |
|
126 | - if ($format === self::FORMAT_SHARED_STORAGE) { |
|
127 | - // Only 1 item should come through for this format call |
|
128 | - $item = array_shift($items); |
|
129 | - return [ |
|
130 | - 'parent' => $item['parent'], |
|
131 | - 'path' => $item['path'], |
|
132 | - 'storage' => $item['storage'], |
|
133 | - 'permissions' => $item['permissions'], |
|
134 | - 'uid_owner' => $item['uid_owner'], |
|
135 | - ]; |
|
136 | - } elseif ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
137 | - $files = []; |
|
138 | - foreach ($items as $item) { |
|
139 | - $file = []; |
|
140 | - $file['fileid'] = $item['file_source']; |
|
141 | - $file['storage'] = $item['storage']; |
|
142 | - $file['path'] = $item['file_target']; |
|
143 | - $file['parent'] = $item['file_parent']; |
|
144 | - $file['name'] = basename($item['file_target']); |
|
145 | - $file['mimetype'] = $item['mimetype']; |
|
146 | - $file['mimepart'] = $item['mimepart']; |
|
147 | - $file['mtime'] = $item['mtime']; |
|
148 | - $file['encrypted'] = $item['encrypted']; |
|
149 | - $file['etag'] = $item['etag']; |
|
150 | - $file['uid_owner'] = $item['uid_owner']; |
|
151 | - $file['displayname_owner'] = $item['displayname_owner']; |
|
152 | - |
|
153 | - $storage = \OC\Files\Filesystem::getStorage('/'); |
|
154 | - $cache = $storage->getCache(); |
|
155 | - $file['size'] = $item['size']; |
|
156 | - $files[] = $file; |
|
157 | - } |
|
158 | - return $files; |
|
159 | - } elseif ($format === self::FORMAT_OPENDIR) { |
|
160 | - $files = []; |
|
161 | - foreach ($items as $item) { |
|
162 | - $files[] = basename($item['file_target']); |
|
163 | - } |
|
164 | - return $files; |
|
165 | - } elseif ($format === self::FORMAT_GET_ALL) { |
|
166 | - $ids = []; |
|
167 | - foreach ($items as $item) { |
|
168 | - $ids[] = $item['file_source']; |
|
169 | - } |
|
170 | - return $ids; |
|
171 | - } elseif ($format === self::FORMAT_PERMISSIONS) { |
|
172 | - $filePermissions = []; |
|
173 | - foreach ($items as $item) { |
|
174 | - $filePermissions[$item['file_source']] = $item['permissions']; |
|
175 | - } |
|
176 | - return $filePermissions; |
|
177 | - } elseif ($format === self::FORMAT_TARGET_NAMES) { |
|
178 | - $targets = []; |
|
179 | - foreach ($items as $item) { |
|
180 | - $targets[] = $item['file_target']; |
|
181 | - } |
|
182 | - return $targets; |
|
183 | - } |
|
184 | - return []; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * check if server2server share is enabled |
|
189 | - * |
|
190 | - * @param int $shareType |
|
191 | - * @return boolean |
|
192 | - */ |
|
193 | - public function isShareTypeAllowed($shareType) { |
|
194 | - if ($shareType === IShare::TYPE_REMOTE) { |
|
195 | - return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
196 | - } |
|
197 | - |
|
198 | - if ($shareType === IShare::TYPE_REMOTE_GROUP) { |
|
199 | - return $this->federatedShareProvider->isOutgoingServer2serverGroupShareEnabled(); |
|
200 | - } |
|
201 | - |
|
202 | - return true; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * resolve reshares to return the correct source item |
|
207 | - * @param array $source |
|
208 | - * @return array source item |
|
209 | - */ |
|
210 | - protected static function resolveReshares($source) { |
|
211 | - if (isset($source['parent'])) { |
|
212 | - $parent = $source['parent']; |
|
213 | - while (isset($parent)) { |
|
214 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
215 | - $qb->select('parent', 'uid_owner') |
|
216 | - ->from('share') |
|
217 | - ->where( |
|
218 | - $qb->expr()->eq('id', $qb->createNamedParameter($parent)) |
|
219 | - ); |
|
220 | - $result = $qb->execute(); |
|
221 | - $item = $result->fetch(); |
|
222 | - $result->closeCursor(); |
|
223 | - if (isset($item['parent'])) { |
|
224 | - $parent = $item['parent']; |
|
225 | - } else { |
|
226 | - $fileOwner = $item['uid_owner']; |
|
227 | - break; |
|
228 | - } |
|
229 | - } |
|
230 | - } else { |
|
231 | - $fileOwner = $source['uid_owner']; |
|
232 | - } |
|
233 | - if (isset($fileOwner)) { |
|
234 | - $source['fileOwner'] = $fileOwner; |
|
235 | - } else { |
|
236 | - \OC::$server->getLogger()->error('No owner found for reshare', ['app' => 'files_sharing']); |
|
237 | - } |
|
238 | - |
|
239 | - return $source; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $target |
|
244 | - * @param array $share |
|
245 | - * @return array|false source item |
|
246 | - */ |
|
247 | - public static function getSource($target, $share) { |
|
248 | - if ($share['item_type'] === 'folder' && $target !== '') { |
|
249 | - // note: in case of ext storage mount points the path might be empty |
|
250 | - // which would cause a leading slash to appear |
|
251 | - $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
252 | - } |
|
253 | - return self::resolveReshares($share); |
|
254 | - } |
|
41 | + public const FORMAT_SHARED_STORAGE = 0; |
|
42 | + public const FORMAT_GET_FOLDER_CONTENTS = 1; |
|
43 | + public const FORMAT_FILE_APP_ROOT = 2; |
|
44 | + public const FORMAT_OPENDIR = 3; |
|
45 | + public const FORMAT_GET_ALL = 4; |
|
46 | + public const FORMAT_PERMISSIONS = 5; |
|
47 | + public const FORMAT_TARGET_NAMES = 6; |
|
48 | + |
|
49 | + private $path; |
|
50 | + |
|
51 | + /** @var FederatedShareProvider */ |
|
52 | + private $federatedShareProvider; |
|
53 | + |
|
54 | + public function __construct(FederatedShareProvider $federatedShareProvider = null) { |
|
55 | + if ($federatedShareProvider) { |
|
56 | + $this->federatedShareProvider = $federatedShareProvider; |
|
57 | + } else { |
|
58 | + $this->federatedShareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + public function isValidSource($itemSource, $uidOwner) { |
|
63 | + try { |
|
64 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
65 | + // FIXME: attributes should not be set here, |
|
66 | + // keeping this pattern for now to avoid unexpected |
|
67 | + // regressions |
|
68 | + $this->path = \OC\Files\Filesystem::normalizePath(basename($path)); |
|
69 | + return true; |
|
70 | + } catch (\OCP\Files\NotFoundException $e) { |
|
71 | + return false; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + public function getFilePath($itemSource, $uidOwner) { |
|
76 | + if (isset($this->path)) { |
|
77 | + $path = $this->path; |
|
78 | + $this->path = null; |
|
79 | + return $path; |
|
80 | + } else { |
|
81 | + try { |
|
82 | + $path = \OC\Files\Filesystem::getPath($itemSource); |
|
83 | + return $path; |
|
84 | + } catch (\OCP\Files\NotFoundException $e) { |
|
85 | + return false; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * create unique target |
|
92 | + * @param string $filePath |
|
93 | + * @param string $shareWith |
|
94 | + * @param array $exclude (optional) |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function generateTarget($filePath, $shareWith, $exclude = null) { |
|
98 | + $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); |
|
99 | + $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); |
|
100 | + |
|
101 | + // for group shares we return the target right away |
|
102 | + if ($shareWith === false) { |
|
103 | + return $target; |
|
104 | + } |
|
105 | + |
|
106 | + \OC\Files\Filesystem::initMountPoints($shareWith); |
|
107 | + $view = new \OC\Files\View('/' . $shareWith . '/files'); |
|
108 | + |
|
109 | + if (!$view->is_dir($shareFolder)) { |
|
110 | + $dir = ''; |
|
111 | + $subdirs = explode('/', $shareFolder); |
|
112 | + foreach ($subdirs as $subdir) { |
|
113 | + $dir = $dir . '/' . $subdir; |
|
114 | + if (!$view->is_dir($dir)) { |
|
115 | + $view->mkdir($dir); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + $excludeList = is_array($exclude) ? $exclude : []; |
|
121 | + |
|
122 | + return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view); |
|
123 | + } |
|
124 | + |
|
125 | + public function formatItems($items, $format, $parameters = null) { |
|
126 | + if ($format === self::FORMAT_SHARED_STORAGE) { |
|
127 | + // Only 1 item should come through for this format call |
|
128 | + $item = array_shift($items); |
|
129 | + return [ |
|
130 | + 'parent' => $item['parent'], |
|
131 | + 'path' => $item['path'], |
|
132 | + 'storage' => $item['storage'], |
|
133 | + 'permissions' => $item['permissions'], |
|
134 | + 'uid_owner' => $item['uid_owner'], |
|
135 | + ]; |
|
136 | + } elseif ($format === self::FORMAT_GET_FOLDER_CONTENTS) { |
|
137 | + $files = []; |
|
138 | + foreach ($items as $item) { |
|
139 | + $file = []; |
|
140 | + $file['fileid'] = $item['file_source']; |
|
141 | + $file['storage'] = $item['storage']; |
|
142 | + $file['path'] = $item['file_target']; |
|
143 | + $file['parent'] = $item['file_parent']; |
|
144 | + $file['name'] = basename($item['file_target']); |
|
145 | + $file['mimetype'] = $item['mimetype']; |
|
146 | + $file['mimepart'] = $item['mimepart']; |
|
147 | + $file['mtime'] = $item['mtime']; |
|
148 | + $file['encrypted'] = $item['encrypted']; |
|
149 | + $file['etag'] = $item['etag']; |
|
150 | + $file['uid_owner'] = $item['uid_owner']; |
|
151 | + $file['displayname_owner'] = $item['displayname_owner']; |
|
152 | + |
|
153 | + $storage = \OC\Files\Filesystem::getStorage('/'); |
|
154 | + $cache = $storage->getCache(); |
|
155 | + $file['size'] = $item['size']; |
|
156 | + $files[] = $file; |
|
157 | + } |
|
158 | + return $files; |
|
159 | + } elseif ($format === self::FORMAT_OPENDIR) { |
|
160 | + $files = []; |
|
161 | + foreach ($items as $item) { |
|
162 | + $files[] = basename($item['file_target']); |
|
163 | + } |
|
164 | + return $files; |
|
165 | + } elseif ($format === self::FORMAT_GET_ALL) { |
|
166 | + $ids = []; |
|
167 | + foreach ($items as $item) { |
|
168 | + $ids[] = $item['file_source']; |
|
169 | + } |
|
170 | + return $ids; |
|
171 | + } elseif ($format === self::FORMAT_PERMISSIONS) { |
|
172 | + $filePermissions = []; |
|
173 | + foreach ($items as $item) { |
|
174 | + $filePermissions[$item['file_source']] = $item['permissions']; |
|
175 | + } |
|
176 | + return $filePermissions; |
|
177 | + } elseif ($format === self::FORMAT_TARGET_NAMES) { |
|
178 | + $targets = []; |
|
179 | + foreach ($items as $item) { |
|
180 | + $targets[] = $item['file_target']; |
|
181 | + } |
|
182 | + return $targets; |
|
183 | + } |
|
184 | + return []; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * check if server2server share is enabled |
|
189 | + * |
|
190 | + * @param int $shareType |
|
191 | + * @return boolean |
|
192 | + */ |
|
193 | + public function isShareTypeAllowed($shareType) { |
|
194 | + if ($shareType === IShare::TYPE_REMOTE) { |
|
195 | + return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
196 | + } |
|
197 | + |
|
198 | + if ($shareType === IShare::TYPE_REMOTE_GROUP) { |
|
199 | + return $this->federatedShareProvider->isOutgoingServer2serverGroupShareEnabled(); |
|
200 | + } |
|
201 | + |
|
202 | + return true; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * resolve reshares to return the correct source item |
|
207 | + * @param array $source |
|
208 | + * @return array source item |
|
209 | + */ |
|
210 | + protected static function resolveReshares($source) { |
|
211 | + if (isset($source['parent'])) { |
|
212 | + $parent = $source['parent']; |
|
213 | + while (isset($parent)) { |
|
214 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
215 | + $qb->select('parent', 'uid_owner') |
|
216 | + ->from('share') |
|
217 | + ->where( |
|
218 | + $qb->expr()->eq('id', $qb->createNamedParameter($parent)) |
|
219 | + ); |
|
220 | + $result = $qb->execute(); |
|
221 | + $item = $result->fetch(); |
|
222 | + $result->closeCursor(); |
|
223 | + if (isset($item['parent'])) { |
|
224 | + $parent = $item['parent']; |
|
225 | + } else { |
|
226 | + $fileOwner = $item['uid_owner']; |
|
227 | + break; |
|
228 | + } |
|
229 | + } |
|
230 | + } else { |
|
231 | + $fileOwner = $source['uid_owner']; |
|
232 | + } |
|
233 | + if (isset($fileOwner)) { |
|
234 | + $source['fileOwner'] = $fileOwner; |
|
235 | + } else { |
|
236 | + \OC::$server->getLogger()->error('No owner found for reshare', ['app' => 'files_sharing']); |
|
237 | + } |
|
238 | + |
|
239 | + return $source; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $target |
|
244 | + * @param array $share |
|
245 | + * @return array|false source item |
|
246 | + */ |
|
247 | + public static function getSource($target, $share) { |
|
248 | + if ($share['item_type'] === 'folder' && $target !== '') { |
|
249 | + // note: in case of ext storage mount points the path might be empty |
|
250 | + // which would cause a leading slash to appear |
|
251 | + $share['path'] = ltrim($share['path'] . '/' . $target, '/'); |
|
252 | + } |
|
253 | + return self::resolveReshares($share); |
|
254 | + } |
|
255 | 255 | } |
@@ -62,906 +62,906 @@ |
||
62 | 62 | |
63 | 63 | class UsersController extends AUserData { |
64 | 64 | |
65 | - /** @var IAppManager */ |
|
66 | - private $appManager; |
|
67 | - /** @var ILogger */ |
|
68 | - private $logger; |
|
69 | - /** @var IFactory */ |
|
70 | - protected $l10nFactory; |
|
71 | - /** @var NewUserMailHelper */ |
|
72 | - private $newUserMailHelper; |
|
73 | - /** @var FederatedShareProviderFactory */ |
|
74 | - private $federatedShareProviderFactory; |
|
75 | - /** @var ISecureRandom */ |
|
76 | - private $secureRandom; |
|
77 | - /** @var RemoteWipe */ |
|
78 | - private $remoteWipe; |
|
79 | - |
|
80 | - public function __construct(string $appName, |
|
81 | - IRequest $request, |
|
82 | - IUserManager $userManager, |
|
83 | - IConfig $config, |
|
84 | - IAppManager $appManager, |
|
85 | - IGroupManager $groupManager, |
|
86 | - IUserSession $userSession, |
|
87 | - AccountManager $accountManager, |
|
88 | - ILogger $logger, |
|
89 | - IFactory $l10nFactory, |
|
90 | - NewUserMailHelper $newUserMailHelper, |
|
91 | - FederatedShareProviderFactory $federatedShareProviderFactory, |
|
92 | - ISecureRandom $secureRandom, |
|
93 | - RemoteWipe $remoteWipe) { |
|
94 | - parent::__construct($appName, |
|
95 | - $request, |
|
96 | - $userManager, |
|
97 | - $config, |
|
98 | - $groupManager, |
|
99 | - $userSession, |
|
100 | - $accountManager, |
|
101 | - $l10nFactory); |
|
102 | - |
|
103 | - $this->appManager = $appManager; |
|
104 | - $this->logger = $logger; |
|
105 | - $this->l10nFactory = $l10nFactory; |
|
106 | - $this->newUserMailHelper = $newUserMailHelper; |
|
107 | - $this->federatedShareProviderFactory = $federatedShareProviderFactory; |
|
108 | - $this->secureRandom = $secureRandom; |
|
109 | - $this->remoteWipe = $remoteWipe; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @NoAdminRequired |
|
114 | - * |
|
115 | - * returns a list of users |
|
116 | - * |
|
117 | - * @param string $search |
|
118 | - * @param int $limit |
|
119 | - * @param int $offset |
|
120 | - * @return DataResponse |
|
121 | - */ |
|
122 | - public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
123 | - $user = $this->userSession->getUser(); |
|
124 | - $users = []; |
|
125 | - |
|
126 | - // Admin? Or SubAdmin? |
|
127 | - $uid = $user->getUID(); |
|
128 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
129 | - if ($this->groupManager->isAdmin($uid)) { |
|
130 | - $users = $this->userManager->search($search, $limit, $offset); |
|
131 | - } elseif ($subAdminManager->isSubAdmin($user)) { |
|
132 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
133 | - foreach ($subAdminOfGroups as $key => $group) { |
|
134 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
135 | - } |
|
136 | - |
|
137 | - $users = []; |
|
138 | - foreach ($subAdminOfGroups as $group) { |
|
139 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $users = array_keys($users); |
|
144 | - |
|
145 | - return new DataResponse([ |
|
146 | - 'users' => $users |
|
147 | - ]); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @NoAdminRequired |
|
152 | - * |
|
153 | - * returns a list of users and their data |
|
154 | - */ |
|
155 | - public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
156 | - $currentUser = $this->userSession->getUser(); |
|
157 | - $users = []; |
|
158 | - |
|
159 | - // Admin? Or SubAdmin? |
|
160 | - $uid = $currentUser->getUID(); |
|
161 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
162 | - if ($this->groupManager->isAdmin($uid)) { |
|
163 | - $users = $this->userManager->search($search, $limit, $offset); |
|
164 | - $users = array_keys($users); |
|
165 | - } elseif ($subAdminManager->isSubAdmin($currentUser)) { |
|
166 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser); |
|
167 | - foreach ($subAdminOfGroups as $key => $group) { |
|
168 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
169 | - } |
|
170 | - |
|
171 | - $users = []; |
|
172 | - foreach ($subAdminOfGroups as $group) { |
|
173 | - $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
174 | - } |
|
175 | - $users = array_merge(...$users); |
|
176 | - } |
|
177 | - |
|
178 | - $usersDetails = []; |
|
179 | - foreach ($users as $userId) { |
|
180 | - $userId = (string) $userId; |
|
181 | - $userData = $this->getUserData($userId); |
|
182 | - // Do not insert empty entry |
|
183 | - if (!empty($userData)) { |
|
184 | - $usersDetails[$userId] = $userData; |
|
185 | - } else { |
|
186 | - // Logged user does not have permissions to see this user |
|
187 | - // only showing its id |
|
188 | - $usersDetails[$userId] = ['id' => $userId]; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - return new DataResponse([ |
|
193 | - 'users' => $usersDetails |
|
194 | - ]); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @throws OCSException |
|
199 | - */ |
|
200 | - private function createNewUserId(): string { |
|
201 | - $attempts = 0; |
|
202 | - do { |
|
203 | - $uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE); |
|
204 | - if (!$this->userManager->userExists($uidCandidate)) { |
|
205 | - return $uidCandidate; |
|
206 | - } |
|
207 | - $attempts++; |
|
208 | - } while ($attempts < 10); |
|
209 | - throw new OCSException('Could not create non-existing user id', 111); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @PasswordConfirmationRequired |
|
214 | - * @NoAdminRequired |
|
215 | - * |
|
216 | - * @param string $userid |
|
217 | - * @param string $password |
|
218 | - * @param string $displayName |
|
219 | - * @param string $email |
|
220 | - * @param array $groups |
|
221 | - * @param array $subadmin |
|
222 | - * @param string $quota |
|
223 | - * @param string $language |
|
224 | - * @return DataResponse |
|
225 | - * @throws OCSException |
|
226 | - */ |
|
227 | - public function addUser(string $userid, |
|
228 | - string $password = '', |
|
229 | - string $displayName = '', |
|
230 | - string $email = '', |
|
231 | - array $groups = [], |
|
232 | - array $subadmin = [], |
|
233 | - string $quota = '', |
|
234 | - string $language = ''): DataResponse { |
|
235 | - $user = $this->userSession->getUser(); |
|
236 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
237 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
238 | - |
|
239 | - if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { |
|
240 | - $userid = $this->createNewUserId(); |
|
241 | - } |
|
242 | - |
|
243 | - if ($this->userManager->userExists($userid)) { |
|
244 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
245 | - throw new OCSException('User already exists', 102); |
|
246 | - } |
|
247 | - |
|
248 | - if ($groups !== []) { |
|
249 | - foreach ($groups as $group) { |
|
250 | - if (!$this->groupManager->groupExists($group)) { |
|
251 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
252 | - } |
|
253 | - if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) { |
|
254 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
255 | - } |
|
256 | - } |
|
257 | - } else { |
|
258 | - if (!$isAdmin) { |
|
259 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - $subadminGroups = []; |
|
264 | - if ($subadmin !== []) { |
|
265 | - foreach ($subadmin as $groupid) { |
|
266 | - $group = $this->groupManager->get($groupid); |
|
267 | - // Check if group exists |
|
268 | - if ($group === null) { |
|
269 | - throw new OCSException('Subadmin group does not exist', 102); |
|
270 | - } |
|
271 | - // Check if trying to make subadmin of admin group |
|
272 | - if ($group->getGID() === 'admin') { |
|
273 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
274 | - } |
|
275 | - // Check if has permission to promote subadmins |
|
276 | - if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) { |
|
277 | - throw new OCSForbiddenException('No permissions to promote subadmins'); |
|
278 | - } |
|
279 | - $subadminGroups[] = $group; |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - $generatePasswordResetToken = false; |
|
284 | - if ($password === '') { |
|
285 | - if ($email === '') { |
|
286 | - throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
287 | - } |
|
288 | - |
|
289 | - $password = $this->secureRandom->generate(10); |
|
290 | - // Make sure we pass the password_policy |
|
291 | - $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
292 | - $generatePasswordResetToken = true; |
|
293 | - } |
|
294 | - |
|
295 | - if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') { |
|
296 | - throw new OCSException('Required email address was not provided', 110); |
|
297 | - } |
|
298 | - |
|
299 | - try { |
|
300 | - $newUser = $this->userManager->createUser($userid, $password); |
|
301 | - $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
302 | - |
|
303 | - foreach ($groups as $group) { |
|
304 | - $this->groupManager->get($group)->addUser($newUser); |
|
305 | - $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
306 | - } |
|
307 | - foreach ($subadminGroups as $group) { |
|
308 | - $subAdminManager->createSubAdmin($newUser, $group); |
|
309 | - } |
|
310 | - |
|
311 | - if ($displayName !== '') { |
|
312 | - $this->editUser($userid, 'display', $displayName); |
|
313 | - } |
|
314 | - |
|
315 | - if ($quota !== '') { |
|
316 | - $this->editUser($userid, 'quota', $quota); |
|
317 | - } |
|
318 | - |
|
319 | - if ($language !== '') { |
|
320 | - $this->editUser($userid, 'language', $language); |
|
321 | - } |
|
322 | - |
|
323 | - // Send new user mail only if a mail is set |
|
324 | - if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { |
|
325 | - $newUser->setEMailAddress($email); |
|
326 | - try { |
|
327 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
328 | - $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
329 | - } catch (\Exception $e) { |
|
330 | - // Mail could be failing hard or just be plain not configured |
|
331 | - // Logging error as it is the hardest of the two |
|
332 | - $this->logger->logException($e, [ |
|
333 | - 'message' => "Unable to send the invitation mail to $email", |
|
334 | - 'level' => ILogger::ERROR, |
|
335 | - 'app' => 'ocs_api', |
|
336 | - ]); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - return new DataResponse(['id' => $userid]); |
|
341 | - } catch (HintException $e) { |
|
342 | - $this->logger->logException($e, [ |
|
343 | - 'message' => 'Failed addUser attempt with hint exception.', |
|
344 | - 'level' => ILogger::WARN, |
|
345 | - 'app' => 'ocs_api', |
|
346 | - ]); |
|
347 | - throw new OCSException($e->getHint(), 107); |
|
348 | - } catch (OCSException $e) { |
|
349 | - $this->logger->logException($e, [ |
|
350 | - 'message' => 'Failed addUser attempt with ocs exeption.', |
|
351 | - 'level' => ILogger::ERROR, |
|
352 | - 'app' => 'ocs_api', |
|
353 | - ]); |
|
354 | - throw $e; |
|
355 | - } catch (\Exception $e) { |
|
356 | - $this->logger->logException($e, [ |
|
357 | - 'message' => 'Failed addUser attempt with exception.', |
|
358 | - 'level' => ILogger::ERROR, |
|
359 | - 'app' => 'ocs_api', |
|
360 | - ]); |
|
361 | - throw new OCSException('Bad request', 101); |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * @NoAdminRequired |
|
367 | - * @NoSubAdminRequired |
|
368 | - * |
|
369 | - * gets user info |
|
370 | - * |
|
371 | - * @param string $userId |
|
372 | - * @return DataResponse |
|
373 | - * @throws OCSException |
|
374 | - */ |
|
375 | - public function getUser(string $userId): DataResponse { |
|
376 | - $data = $this->getUserData($userId); |
|
377 | - // getUserData returns empty array if not enough permissions |
|
378 | - if (empty($data)) { |
|
379 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
380 | - } |
|
381 | - return new DataResponse($data); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * @NoAdminRequired |
|
386 | - * @NoSubAdminRequired |
|
387 | - * |
|
388 | - * gets user info from the currently logged in user |
|
389 | - * |
|
390 | - * @return DataResponse |
|
391 | - * @throws OCSException |
|
392 | - */ |
|
393 | - public function getCurrentUser(): DataResponse { |
|
394 | - $user = $this->userSession->getUser(); |
|
395 | - if ($user) { |
|
396 | - $data = $this->getUserData($user->getUID()); |
|
397 | - // rename "displayname" to "display-name" only for this call to keep |
|
398 | - // the API stable. |
|
399 | - $data['display-name'] = $data['displayname']; |
|
400 | - unset($data['displayname']); |
|
401 | - return new DataResponse($data); |
|
402 | - } |
|
403 | - |
|
404 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * @NoAdminRequired |
|
409 | - * @NoSubAdminRequired |
|
410 | - */ |
|
411 | - public function getEditableFields(): DataResponse { |
|
412 | - $permittedFields = []; |
|
413 | - |
|
414 | - // Editing self (display, email) |
|
415 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
416 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
417 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
418 | - } |
|
419 | - |
|
420 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
421 | - $shareProvider = $this->federatedShareProviderFactory->get(); |
|
422 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
423 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
424 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
425 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
426 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - return new DataResponse($permittedFields); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @NoAdminRequired |
|
435 | - * @NoSubAdminRequired |
|
436 | - * @PasswordConfirmationRequired |
|
437 | - * |
|
438 | - * edit users |
|
439 | - * |
|
440 | - * @param string $userId |
|
441 | - * @param string $key |
|
442 | - * @param string $value |
|
443 | - * @return DataResponse |
|
444 | - * @throws OCSException |
|
445 | - */ |
|
446 | - public function editUser(string $userId, string $key, string $value): DataResponse { |
|
447 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
448 | - |
|
449 | - $targetUser = $this->userManager->get($userId); |
|
450 | - if ($targetUser === null) { |
|
451 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
452 | - } |
|
453 | - |
|
454 | - $permittedFields = []; |
|
455 | - if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
456 | - // Editing self (display, email) |
|
457 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
458 | - $permittedFields[] = 'display'; |
|
459 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
460 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
461 | - } |
|
462 | - |
|
463 | - $permittedFields[] = 'password'; |
|
464 | - if ($this->config->getSystemValue('force_language', false) === false || |
|
465 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
466 | - $permittedFields[] = 'language'; |
|
467 | - } |
|
468 | - |
|
469 | - if ($this->config->getSystemValue('force_locale', false) === false || |
|
470 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
471 | - $permittedFields[] = 'locale'; |
|
472 | - } |
|
473 | - |
|
474 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
475 | - $shareProvider = $this->federatedShareProviderFactory->get(); |
|
476 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
477 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
478 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
479 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
480 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
481 | - } |
|
482 | - } |
|
483 | - |
|
484 | - // If admin they can edit their own quota |
|
485 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
486 | - $permittedFields[] = 'quota'; |
|
487 | - } |
|
488 | - } else { |
|
489 | - // Check if admin / subadmin |
|
490 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
491 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
492 | - || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
493 | - // They have permissions over the user |
|
494 | - $permittedFields[] = 'display'; |
|
495 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
496 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
497 | - $permittedFields[] = 'password'; |
|
498 | - $permittedFields[] = 'language'; |
|
499 | - $permittedFields[] = 'locale'; |
|
500 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
501 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
502 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
503 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
504 | - $permittedFields[] = 'quota'; |
|
505 | - } else { |
|
506 | - // No rights |
|
507 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
508 | - } |
|
509 | - } |
|
510 | - // Check if permitted to edit this field |
|
511 | - if (!in_array($key, $permittedFields)) { |
|
512 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
513 | - } |
|
514 | - // Process the edit |
|
515 | - switch ($key) { |
|
516 | - case 'display': |
|
517 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
518 | - $targetUser->setDisplayName($value); |
|
519 | - break; |
|
520 | - case 'quota': |
|
521 | - $quota = $value; |
|
522 | - if ($quota !== 'none' && $quota !== 'default') { |
|
523 | - if (is_numeric($quota)) { |
|
524 | - $quota = (float) $quota; |
|
525 | - } else { |
|
526 | - $quota = \OCP\Util::computerFileSize($quota); |
|
527 | - } |
|
528 | - if ($quota === false) { |
|
529 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
530 | - } |
|
531 | - if ($quota === -1) { |
|
532 | - $quota = 'none'; |
|
533 | - } else { |
|
534 | - $quota = \OCP\Util::humanFileSize($quota); |
|
535 | - } |
|
536 | - } |
|
537 | - $targetUser->setQuota($quota); |
|
538 | - break; |
|
539 | - case 'password': |
|
540 | - try { |
|
541 | - if (!$targetUser->canChangePassword()) { |
|
542 | - throw new OCSException('Setting the password is not supported by the users backend', 103); |
|
543 | - } |
|
544 | - $targetUser->setPassword($value); |
|
545 | - } catch (HintException $e) { // password policy error |
|
546 | - throw new OCSException($e->getMessage(), 103); |
|
547 | - } |
|
548 | - break; |
|
549 | - case 'language': |
|
550 | - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
551 | - if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
552 | - throw new OCSException('Invalid language', 102); |
|
553 | - } |
|
554 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
555 | - break; |
|
556 | - case 'locale': |
|
557 | - if (!$this->l10nFactory->localeExists($value)) { |
|
558 | - throw new OCSException('Invalid locale', 102); |
|
559 | - } |
|
560 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
561 | - break; |
|
562 | - case AccountManager::PROPERTY_EMAIL: |
|
563 | - if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
564 | - $targetUser->setEMailAddress($value); |
|
565 | - } else { |
|
566 | - throw new OCSException('', 102); |
|
567 | - } |
|
568 | - break; |
|
569 | - case AccountManager::PROPERTY_PHONE: |
|
570 | - case AccountManager::PROPERTY_ADDRESS: |
|
571 | - case AccountManager::PROPERTY_WEBSITE: |
|
572 | - case AccountManager::PROPERTY_TWITTER: |
|
573 | - $userAccount = $this->accountManager->getUser($targetUser); |
|
574 | - if ($userAccount[$key]['value'] !== $value) { |
|
575 | - $userAccount[$key]['value'] = $value; |
|
576 | - $this->accountManager->updateUser($targetUser, $userAccount); |
|
577 | - } |
|
578 | - break; |
|
579 | - default: |
|
580 | - throw new OCSException('', 103); |
|
581 | - } |
|
582 | - return new DataResponse(); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * @PasswordConfirmationRequired |
|
587 | - * @NoAdminRequired |
|
588 | - * |
|
589 | - * @param string $userId |
|
590 | - * |
|
591 | - * @return DataResponse |
|
592 | - * |
|
593 | - * @throws OCSException |
|
594 | - */ |
|
595 | - public function wipeUserDevices(string $userId): DataResponse { |
|
596 | - /** @var IUser $currentLoggedInUser */ |
|
597 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
598 | - |
|
599 | - $targetUser = $this->userManager->get($userId); |
|
600 | - |
|
601 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
602 | - throw new OCSException('', 101); |
|
603 | - } |
|
604 | - |
|
605 | - // If not permitted |
|
606 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
607 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
608 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
609 | - } |
|
610 | - |
|
611 | - $this->remoteWipe->markAllTokensForWipe($targetUser); |
|
612 | - |
|
613 | - return new DataResponse(); |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * @PasswordConfirmationRequired |
|
618 | - * @NoAdminRequired |
|
619 | - * |
|
620 | - * @param string $userId |
|
621 | - * @return DataResponse |
|
622 | - * @throws OCSException |
|
623 | - */ |
|
624 | - public function deleteUser(string $userId): DataResponse { |
|
625 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
626 | - |
|
627 | - $targetUser = $this->userManager->get($userId); |
|
628 | - |
|
629 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
630 | - throw new OCSException('', 101); |
|
631 | - } |
|
632 | - |
|
633 | - // If not permitted |
|
634 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
635 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
636 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
637 | - } |
|
638 | - |
|
639 | - // Go ahead with the delete |
|
640 | - if ($targetUser->delete()) { |
|
641 | - return new DataResponse(); |
|
642 | - } else { |
|
643 | - throw new OCSException('', 101); |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * @PasswordConfirmationRequired |
|
649 | - * @NoAdminRequired |
|
650 | - * |
|
651 | - * @param string $userId |
|
652 | - * @return DataResponse |
|
653 | - * @throws OCSException |
|
654 | - * @throws OCSForbiddenException |
|
655 | - */ |
|
656 | - public function disableUser(string $userId): DataResponse { |
|
657 | - return $this->setEnabled($userId, false); |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * @PasswordConfirmationRequired |
|
662 | - * @NoAdminRequired |
|
663 | - * |
|
664 | - * @param string $userId |
|
665 | - * @return DataResponse |
|
666 | - * @throws OCSException |
|
667 | - * @throws OCSForbiddenException |
|
668 | - */ |
|
669 | - public function enableUser(string $userId): DataResponse { |
|
670 | - return $this->setEnabled($userId, true); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * @param string $userId |
|
675 | - * @param bool $value |
|
676 | - * @return DataResponse |
|
677 | - * @throws OCSException |
|
678 | - */ |
|
679 | - private function setEnabled(string $userId, bool $value): DataResponse { |
|
680 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
681 | - |
|
682 | - $targetUser = $this->userManager->get($userId); |
|
683 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
684 | - throw new OCSException('', 101); |
|
685 | - } |
|
686 | - |
|
687 | - // If not permitted |
|
688 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
689 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
690 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
691 | - } |
|
692 | - |
|
693 | - // enable/disable the user now |
|
694 | - $targetUser->setEnabled($value); |
|
695 | - return new DataResponse(); |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * @NoAdminRequired |
|
700 | - * @NoSubAdminRequired |
|
701 | - * |
|
702 | - * @param string $userId |
|
703 | - * @return DataResponse |
|
704 | - * @throws OCSException |
|
705 | - */ |
|
706 | - public function getUsersGroups(string $userId): DataResponse { |
|
707 | - $loggedInUser = $this->userSession->getUser(); |
|
708 | - |
|
709 | - $targetUser = $this->userManager->get($userId); |
|
710 | - if ($targetUser === null) { |
|
711 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
712 | - } |
|
713 | - |
|
714 | - if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
715 | - // Self lookup or admin lookup |
|
716 | - return new DataResponse([ |
|
717 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
718 | - ]); |
|
719 | - } else { |
|
720 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
721 | - |
|
722 | - // Looking up someone else |
|
723 | - if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
724 | - // Return the group that the method caller is subadmin of for the user in question |
|
725 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
726 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
727 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
728 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
729 | - } |
|
730 | - $groups = array_intersect( |
|
731 | - $getSubAdminsGroups, |
|
732 | - $this->groupManager->getUserGroupIds($targetUser) |
|
733 | - ); |
|
734 | - return new DataResponse(['groups' => $groups]); |
|
735 | - } else { |
|
736 | - // Not permitted |
|
737 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
738 | - } |
|
739 | - } |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * @PasswordConfirmationRequired |
|
744 | - * @NoAdminRequired |
|
745 | - * |
|
746 | - * @param string $userId |
|
747 | - * @param string $groupid |
|
748 | - * @return DataResponse |
|
749 | - * @throws OCSException |
|
750 | - */ |
|
751 | - public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
752 | - if ($groupid === '') { |
|
753 | - throw new OCSException('', 101); |
|
754 | - } |
|
755 | - |
|
756 | - $group = $this->groupManager->get($groupid); |
|
757 | - $targetUser = $this->userManager->get($userId); |
|
758 | - if ($group === null) { |
|
759 | - throw new OCSException('', 102); |
|
760 | - } |
|
761 | - if ($targetUser === null) { |
|
762 | - throw new OCSException('', 103); |
|
763 | - } |
|
764 | - |
|
765 | - // If they're not an admin, check they are a subadmin of the group in question |
|
766 | - $loggedInUser = $this->userSession->getUser(); |
|
767 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
768 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
769 | - throw new OCSException('', 104); |
|
770 | - } |
|
771 | - |
|
772 | - // Add user to group |
|
773 | - $group->addUser($targetUser); |
|
774 | - return new DataResponse(); |
|
775 | - } |
|
776 | - |
|
777 | - /** |
|
778 | - * @PasswordConfirmationRequired |
|
779 | - * @NoAdminRequired |
|
780 | - * |
|
781 | - * @param string $userId |
|
782 | - * @param string $groupid |
|
783 | - * @return DataResponse |
|
784 | - * @throws OCSException |
|
785 | - */ |
|
786 | - public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
787 | - $loggedInUser = $this->userSession->getUser(); |
|
788 | - |
|
789 | - if ($groupid === null || trim($groupid) === '') { |
|
790 | - throw new OCSException('', 101); |
|
791 | - } |
|
792 | - |
|
793 | - $group = $this->groupManager->get($groupid); |
|
794 | - if ($group === null) { |
|
795 | - throw new OCSException('', 102); |
|
796 | - } |
|
797 | - |
|
798 | - $targetUser = $this->userManager->get($userId); |
|
799 | - if ($targetUser === null) { |
|
800 | - throw new OCSException('', 103); |
|
801 | - } |
|
802 | - |
|
803 | - // If they're not an admin, check they are a subadmin of the group in question |
|
804 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
805 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
806 | - throw new OCSException('', 104); |
|
807 | - } |
|
808 | - |
|
809 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
810 | - if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
811 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
812 | - if ($group->getGID() === 'admin') { |
|
813 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
814 | - } |
|
815 | - } else { |
|
816 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
817 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
818 | - } |
|
819 | - } elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
820 | - /** @var IGroup[] $subAdminGroups */ |
|
821 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
822 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
823 | - return $subAdminGroup->getGID(); |
|
824 | - }, $subAdminGroups); |
|
825 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
826 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
827 | - |
|
828 | - if (count($userSubAdminGroups) <= 1) { |
|
829 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
830 | - throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105); |
|
831 | - } |
|
832 | - } |
|
833 | - |
|
834 | - // Remove user from group |
|
835 | - $group->removeUser($targetUser); |
|
836 | - return new DataResponse(); |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Creates a subadmin |
|
841 | - * |
|
842 | - * @PasswordConfirmationRequired |
|
843 | - * |
|
844 | - * @param string $userId |
|
845 | - * @param string $groupid |
|
846 | - * @return DataResponse |
|
847 | - * @throws OCSException |
|
848 | - */ |
|
849 | - public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
850 | - $group = $this->groupManager->get($groupid); |
|
851 | - $user = $this->userManager->get($userId); |
|
852 | - |
|
853 | - // Check if the user exists |
|
854 | - if ($user === null) { |
|
855 | - throw new OCSException('User does not exist', 101); |
|
856 | - } |
|
857 | - // Check if group exists |
|
858 | - if ($group === null) { |
|
859 | - throw new OCSException('Group does not exist', 102); |
|
860 | - } |
|
861 | - // Check if trying to make subadmin of admin group |
|
862 | - if ($group->getGID() === 'admin') { |
|
863 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
864 | - } |
|
865 | - |
|
866 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
867 | - |
|
868 | - // We cannot be subadmin twice |
|
869 | - if ($subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
870 | - return new DataResponse(); |
|
871 | - } |
|
872 | - // Go |
|
873 | - $subAdminManager->createSubAdmin($user, $group); |
|
874 | - return new DataResponse(); |
|
875 | - } |
|
876 | - |
|
877 | - /** |
|
878 | - * Removes a subadmin from a group |
|
879 | - * |
|
880 | - * @PasswordConfirmationRequired |
|
881 | - * |
|
882 | - * @param string $userId |
|
883 | - * @param string $groupid |
|
884 | - * @return DataResponse |
|
885 | - * @throws OCSException |
|
886 | - */ |
|
887 | - public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
888 | - $group = $this->groupManager->get($groupid); |
|
889 | - $user = $this->userManager->get($userId); |
|
890 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
891 | - |
|
892 | - // Check if the user exists |
|
893 | - if ($user === null) { |
|
894 | - throw new OCSException('User does not exist', 101); |
|
895 | - } |
|
896 | - // Check if the group exists |
|
897 | - if ($group === null) { |
|
898 | - throw new OCSException('Group does not exist', 101); |
|
899 | - } |
|
900 | - // Check if they are a subadmin of this said group |
|
901 | - if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
902 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
903 | - } |
|
904 | - |
|
905 | - // Go |
|
906 | - $subAdminManager->deleteSubAdmin($user, $group); |
|
907 | - return new DataResponse(); |
|
908 | - } |
|
909 | - |
|
910 | - /** |
|
911 | - * Get the groups a user is a subadmin of |
|
912 | - * |
|
913 | - * @param string $userId |
|
914 | - * @return DataResponse |
|
915 | - * @throws OCSException |
|
916 | - */ |
|
917 | - public function getUserSubAdminGroups(string $userId): DataResponse { |
|
918 | - $groups = $this->getUserSubAdminGroupsData($userId); |
|
919 | - return new DataResponse($groups); |
|
920 | - } |
|
921 | - |
|
922 | - /** |
|
923 | - * @NoAdminRequired |
|
924 | - * @PasswordConfirmationRequired |
|
925 | - * |
|
926 | - * resend welcome message |
|
927 | - * |
|
928 | - * @param string $userId |
|
929 | - * @return DataResponse |
|
930 | - * @throws OCSException |
|
931 | - */ |
|
932 | - public function resendWelcomeMessage(string $userId): DataResponse { |
|
933 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
934 | - |
|
935 | - $targetUser = $this->userManager->get($userId); |
|
936 | - if ($targetUser === null) { |
|
937 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
938 | - } |
|
939 | - |
|
940 | - // Check if admin / subadmin |
|
941 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
942 | - if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
943 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
944 | - // No rights |
|
945 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
946 | - } |
|
947 | - |
|
948 | - $email = $targetUser->getEMailAddress(); |
|
949 | - if ($email === '' || $email === null) { |
|
950 | - throw new OCSException('Email address not available', 101); |
|
951 | - } |
|
952 | - |
|
953 | - try { |
|
954 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
955 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
956 | - } catch (\Exception $e) { |
|
957 | - $this->logger->logException($e, [ |
|
958 | - 'message' => "Can't send new user mail to $email", |
|
959 | - 'level' => ILogger::ERROR, |
|
960 | - 'app' => 'settings', |
|
961 | - ]); |
|
962 | - throw new OCSException('Sending email failed', 102); |
|
963 | - } |
|
964 | - |
|
965 | - return new DataResponse(); |
|
966 | - } |
|
65 | + /** @var IAppManager */ |
|
66 | + private $appManager; |
|
67 | + /** @var ILogger */ |
|
68 | + private $logger; |
|
69 | + /** @var IFactory */ |
|
70 | + protected $l10nFactory; |
|
71 | + /** @var NewUserMailHelper */ |
|
72 | + private $newUserMailHelper; |
|
73 | + /** @var FederatedShareProviderFactory */ |
|
74 | + private $federatedShareProviderFactory; |
|
75 | + /** @var ISecureRandom */ |
|
76 | + private $secureRandom; |
|
77 | + /** @var RemoteWipe */ |
|
78 | + private $remoteWipe; |
|
79 | + |
|
80 | + public function __construct(string $appName, |
|
81 | + IRequest $request, |
|
82 | + IUserManager $userManager, |
|
83 | + IConfig $config, |
|
84 | + IAppManager $appManager, |
|
85 | + IGroupManager $groupManager, |
|
86 | + IUserSession $userSession, |
|
87 | + AccountManager $accountManager, |
|
88 | + ILogger $logger, |
|
89 | + IFactory $l10nFactory, |
|
90 | + NewUserMailHelper $newUserMailHelper, |
|
91 | + FederatedShareProviderFactory $federatedShareProviderFactory, |
|
92 | + ISecureRandom $secureRandom, |
|
93 | + RemoteWipe $remoteWipe) { |
|
94 | + parent::__construct($appName, |
|
95 | + $request, |
|
96 | + $userManager, |
|
97 | + $config, |
|
98 | + $groupManager, |
|
99 | + $userSession, |
|
100 | + $accountManager, |
|
101 | + $l10nFactory); |
|
102 | + |
|
103 | + $this->appManager = $appManager; |
|
104 | + $this->logger = $logger; |
|
105 | + $this->l10nFactory = $l10nFactory; |
|
106 | + $this->newUserMailHelper = $newUserMailHelper; |
|
107 | + $this->federatedShareProviderFactory = $federatedShareProviderFactory; |
|
108 | + $this->secureRandom = $secureRandom; |
|
109 | + $this->remoteWipe = $remoteWipe; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @NoAdminRequired |
|
114 | + * |
|
115 | + * returns a list of users |
|
116 | + * |
|
117 | + * @param string $search |
|
118 | + * @param int $limit |
|
119 | + * @param int $offset |
|
120 | + * @return DataResponse |
|
121 | + */ |
|
122 | + public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
123 | + $user = $this->userSession->getUser(); |
|
124 | + $users = []; |
|
125 | + |
|
126 | + // Admin? Or SubAdmin? |
|
127 | + $uid = $user->getUID(); |
|
128 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
129 | + if ($this->groupManager->isAdmin($uid)) { |
|
130 | + $users = $this->userManager->search($search, $limit, $offset); |
|
131 | + } elseif ($subAdminManager->isSubAdmin($user)) { |
|
132 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
133 | + foreach ($subAdminOfGroups as $key => $group) { |
|
134 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
135 | + } |
|
136 | + |
|
137 | + $users = []; |
|
138 | + foreach ($subAdminOfGroups as $group) { |
|
139 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $users = array_keys($users); |
|
144 | + |
|
145 | + return new DataResponse([ |
|
146 | + 'users' => $users |
|
147 | + ]); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @NoAdminRequired |
|
152 | + * |
|
153 | + * returns a list of users and their data |
|
154 | + */ |
|
155 | + public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
156 | + $currentUser = $this->userSession->getUser(); |
|
157 | + $users = []; |
|
158 | + |
|
159 | + // Admin? Or SubAdmin? |
|
160 | + $uid = $currentUser->getUID(); |
|
161 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
162 | + if ($this->groupManager->isAdmin($uid)) { |
|
163 | + $users = $this->userManager->search($search, $limit, $offset); |
|
164 | + $users = array_keys($users); |
|
165 | + } elseif ($subAdminManager->isSubAdmin($currentUser)) { |
|
166 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser); |
|
167 | + foreach ($subAdminOfGroups as $key => $group) { |
|
168 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
169 | + } |
|
170 | + |
|
171 | + $users = []; |
|
172 | + foreach ($subAdminOfGroups as $group) { |
|
173 | + $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
174 | + } |
|
175 | + $users = array_merge(...$users); |
|
176 | + } |
|
177 | + |
|
178 | + $usersDetails = []; |
|
179 | + foreach ($users as $userId) { |
|
180 | + $userId = (string) $userId; |
|
181 | + $userData = $this->getUserData($userId); |
|
182 | + // Do not insert empty entry |
|
183 | + if (!empty($userData)) { |
|
184 | + $usersDetails[$userId] = $userData; |
|
185 | + } else { |
|
186 | + // Logged user does not have permissions to see this user |
|
187 | + // only showing its id |
|
188 | + $usersDetails[$userId] = ['id' => $userId]; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + return new DataResponse([ |
|
193 | + 'users' => $usersDetails |
|
194 | + ]); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @throws OCSException |
|
199 | + */ |
|
200 | + private function createNewUserId(): string { |
|
201 | + $attempts = 0; |
|
202 | + do { |
|
203 | + $uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE); |
|
204 | + if (!$this->userManager->userExists($uidCandidate)) { |
|
205 | + return $uidCandidate; |
|
206 | + } |
|
207 | + $attempts++; |
|
208 | + } while ($attempts < 10); |
|
209 | + throw new OCSException('Could not create non-existing user id', 111); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @PasswordConfirmationRequired |
|
214 | + * @NoAdminRequired |
|
215 | + * |
|
216 | + * @param string $userid |
|
217 | + * @param string $password |
|
218 | + * @param string $displayName |
|
219 | + * @param string $email |
|
220 | + * @param array $groups |
|
221 | + * @param array $subadmin |
|
222 | + * @param string $quota |
|
223 | + * @param string $language |
|
224 | + * @return DataResponse |
|
225 | + * @throws OCSException |
|
226 | + */ |
|
227 | + public function addUser(string $userid, |
|
228 | + string $password = '', |
|
229 | + string $displayName = '', |
|
230 | + string $email = '', |
|
231 | + array $groups = [], |
|
232 | + array $subadmin = [], |
|
233 | + string $quota = '', |
|
234 | + string $language = ''): DataResponse { |
|
235 | + $user = $this->userSession->getUser(); |
|
236 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
237 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
238 | + |
|
239 | + if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { |
|
240 | + $userid = $this->createNewUserId(); |
|
241 | + } |
|
242 | + |
|
243 | + if ($this->userManager->userExists($userid)) { |
|
244 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
245 | + throw new OCSException('User already exists', 102); |
|
246 | + } |
|
247 | + |
|
248 | + if ($groups !== []) { |
|
249 | + foreach ($groups as $group) { |
|
250 | + if (!$this->groupManager->groupExists($group)) { |
|
251 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
252 | + } |
|
253 | + if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) { |
|
254 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
255 | + } |
|
256 | + } |
|
257 | + } else { |
|
258 | + if (!$isAdmin) { |
|
259 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + $subadminGroups = []; |
|
264 | + if ($subadmin !== []) { |
|
265 | + foreach ($subadmin as $groupid) { |
|
266 | + $group = $this->groupManager->get($groupid); |
|
267 | + // Check if group exists |
|
268 | + if ($group === null) { |
|
269 | + throw new OCSException('Subadmin group does not exist', 102); |
|
270 | + } |
|
271 | + // Check if trying to make subadmin of admin group |
|
272 | + if ($group->getGID() === 'admin') { |
|
273 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
274 | + } |
|
275 | + // Check if has permission to promote subadmins |
|
276 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) { |
|
277 | + throw new OCSForbiddenException('No permissions to promote subadmins'); |
|
278 | + } |
|
279 | + $subadminGroups[] = $group; |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + $generatePasswordResetToken = false; |
|
284 | + if ($password === '') { |
|
285 | + if ($email === '') { |
|
286 | + throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
287 | + } |
|
288 | + |
|
289 | + $password = $this->secureRandom->generate(10); |
|
290 | + // Make sure we pass the password_policy |
|
291 | + $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
292 | + $generatePasswordResetToken = true; |
|
293 | + } |
|
294 | + |
|
295 | + if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') { |
|
296 | + throw new OCSException('Required email address was not provided', 110); |
|
297 | + } |
|
298 | + |
|
299 | + try { |
|
300 | + $newUser = $this->userManager->createUser($userid, $password); |
|
301 | + $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
302 | + |
|
303 | + foreach ($groups as $group) { |
|
304 | + $this->groupManager->get($group)->addUser($newUser); |
|
305 | + $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
306 | + } |
|
307 | + foreach ($subadminGroups as $group) { |
|
308 | + $subAdminManager->createSubAdmin($newUser, $group); |
|
309 | + } |
|
310 | + |
|
311 | + if ($displayName !== '') { |
|
312 | + $this->editUser($userid, 'display', $displayName); |
|
313 | + } |
|
314 | + |
|
315 | + if ($quota !== '') { |
|
316 | + $this->editUser($userid, 'quota', $quota); |
|
317 | + } |
|
318 | + |
|
319 | + if ($language !== '') { |
|
320 | + $this->editUser($userid, 'language', $language); |
|
321 | + } |
|
322 | + |
|
323 | + // Send new user mail only if a mail is set |
|
324 | + if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { |
|
325 | + $newUser->setEMailAddress($email); |
|
326 | + try { |
|
327 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
328 | + $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
329 | + } catch (\Exception $e) { |
|
330 | + // Mail could be failing hard or just be plain not configured |
|
331 | + // Logging error as it is the hardest of the two |
|
332 | + $this->logger->logException($e, [ |
|
333 | + 'message' => "Unable to send the invitation mail to $email", |
|
334 | + 'level' => ILogger::ERROR, |
|
335 | + 'app' => 'ocs_api', |
|
336 | + ]); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + return new DataResponse(['id' => $userid]); |
|
341 | + } catch (HintException $e) { |
|
342 | + $this->logger->logException($e, [ |
|
343 | + 'message' => 'Failed addUser attempt with hint exception.', |
|
344 | + 'level' => ILogger::WARN, |
|
345 | + 'app' => 'ocs_api', |
|
346 | + ]); |
|
347 | + throw new OCSException($e->getHint(), 107); |
|
348 | + } catch (OCSException $e) { |
|
349 | + $this->logger->logException($e, [ |
|
350 | + 'message' => 'Failed addUser attempt with ocs exeption.', |
|
351 | + 'level' => ILogger::ERROR, |
|
352 | + 'app' => 'ocs_api', |
|
353 | + ]); |
|
354 | + throw $e; |
|
355 | + } catch (\Exception $e) { |
|
356 | + $this->logger->logException($e, [ |
|
357 | + 'message' => 'Failed addUser attempt with exception.', |
|
358 | + 'level' => ILogger::ERROR, |
|
359 | + 'app' => 'ocs_api', |
|
360 | + ]); |
|
361 | + throw new OCSException('Bad request', 101); |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * @NoAdminRequired |
|
367 | + * @NoSubAdminRequired |
|
368 | + * |
|
369 | + * gets user info |
|
370 | + * |
|
371 | + * @param string $userId |
|
372 | + * @return DataResponse |
|
373 | + * @throws OCSException |
|
374 | + */ |
|
375 | + public function getUser(string $userId): DataResponse { |
|
376 | + $data = $this->getUserData($userId); |
|
377 | + // getUserData returns empty array if not enough permissions |
|
378 | + if (empty($data)) { |
|
379 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
380 | + } |
|
381 | + return new DataResponse($data); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * @NoAdminRequired |
|
386 | + * @NoSubAdminRequired |
|
387 | + * |
|
388 | + * gets user info from the currently logged in user |
|
389 | + * |
|
390 | + * @return DataResponse |
|
391 | + * @throws OCSException |
|
392 | + */ |
|
393 | + public function getCurrentUser(): DataResponse { |
|
394 | + $user = $this->userSession->getUser(); |
|
395 | + if ($user) { |
|
396 | + $data = $this->getUserData($user->getUID()); |
|
397 | + // rename "displayname" to "display-name" only for this call to keep |
|
398 | + // the API stable. |
|
399 | + $data['display-name'] = $data['displayname']; |
|
400 | + unset($data['displayname']); |
|
401 | + return new DataResponse($data); |
|
402 | + } |
|
403 | + |
|
404 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * @NoAdminRequired |
|
409 | + * @NoSubAdminRequired |
|
410 | + */ |
|
411 | + public function getEditableFields(): DataResponse { |
|
412 | + $permittedFields = []; |
|
413 | + |
|
414 | + // Editing self (display, email) |
|
415 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
416 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
417 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
418 | + } |
|
419 | + |
|
420 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
421 | + $shareProvider = $this->federatedShareProviderFactory->get(); |
|
422 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
423 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
424 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
425 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
426 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + return new DataResponse($permittedFields); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @NoAdminRequired |
|
435 | + * @NoSubAdminRequired |
|
436 | + * @PasswordConfirmationRequired |
|
437 | + * |
|
438 | + * edit users |
|
439 | + * |
|
440 | + * @param string $userId |
|
441 | + * @param string $key |
|
442 | + * @param string $value |
|
443 | + * @return DataResponse |
|
444 | + * @throws OCSException |
|
445 | + */ |
|
446 | + public function editUser(string $userId, string $key, string $value): DataResponse { |
|
447 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
448 | + |
|
449 | + $targetUser = $this->userManager->get($userId); |
|
450 | + if ($targetUser === null) { |
|
451 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
452 | + } |
|
453 | + |
|
454 | + $permittedFields = []; |
|
455 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
456 | + // Editing self (display, email) |
|
457 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
458 | + $permittedFields[] = 'display'; |
|
459 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
460 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
461 | + } |
|
462 | + |
|
463 | + $permittedFields[] = 'password'; |
|
464 | + if ($this->config->getSystemValue('force_language', false) === false || |
|
465 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
466 | + $permittedFields[] = 'language'; |
|
467 | + } |
|
468 | + |
|
469 | + if ($this->config->getSystemValue('force_locale', false) === false || |
|
470 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
471 | + $permittedFields[] = 'locale'; |
|
472 | + } |
|
473 | + |
|
474 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
475 | + $shareProvider = $this->federatedShareProviderFactory->get(); |
|
476 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
477 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
478 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
479 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
480 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
481 | + } |
|
482 | + } |
|
483 | + |
|
484 | + // If admin they can edit their own quota |
|
485 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
486 | + $permittedFields[] = 'quota'; |
|
487 | + } |
|
488 | + } else { |
|
489 | + // Check if admin / subadmin |
|
490 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
491 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
492 | + || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
493 | + // They have permissions over the user |
|
494 | + $permittedFields[] = 'display'; |
|
495 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
496 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
497 | + $permittedFields[] = 'password'; |
|
498 | + $permittedFields[] = 'language'; |
|
499 | + $permittedFields[] = 'locale'; |
|
500 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
501 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
502 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
503 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
504 | + $permittedFields[] = 'quota'; |
|
505 | + } else { |
|
506 | + // No rights |
|
507 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
508 | + } |
|
509 | + } |
|
510 | + // Check if permitted to edit this field |
|
511 | + if (!in_array($key, $permittedFields)) { |
|
512 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
513 | + } |
|
514 | + // Process the edit |
|
515 | + switch ($key) { |
|
516 | + case 'display': |
|
517 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
518 | + $targetUser->setDisplayName($value); |
|
519 | + break; |
|
520 | + case 'quota': |
|
521 | + $quota = $value; |
|
522 | + if ($quota !== 'none' && $quota !== 'default') { |
|
523 | + if (is_numeric($quota)) { |
|
524 | + $quota = (float) $quota; |
|
525 | + } else { |
|
526 | + $quota = \OCP\Util::computerFileSize($quota); |
|
527 | + } |
|
528 | + if ($quota === false) { |
|
529 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
530 | + } |
|
531 | + if ($quota === -1) { |
|
532 | + $quota = 'none'; |
|
533 | + } else { |
|
534 | + $quota = \OCP\Util::humanFileSize($quota); |
|
535 | + } |
|
536 | + } |
|
537 | + $targetUser->setQuota($quota); |
|
538 | + break; |
|
539 | + case 'password': |
|
540 | + try { |
|
541 | + if (!$targetUser->canChangePassword()) { |
|
542 | + throw new OCSException('Setting the password is not supported by the users backend', 103); |
|
543 | + } |
|
544 | + $targetUser->setPassword($value); |
|
545 | + } catch (HintException $e) { // password policy error |
|
546 | + throw new OCSException($e->getMessage(), 103); |
|
547 | + } |
|
548 | + break; |
|
549 | + case 'language': |
|
550 | + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
551 | + if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
552 | + throw new OCSException('Invalid language', 102); |
|
553 | + } |
|
554 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
555 | + break; |
|
556 | + case 'locale': |
|
557 | + if (!$this->l10nFactory->localeExists($value)) { |
|
558 | + throw new OCSException('Invalid locale', 102); |
|
559 | + } |
|
560 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
561 | + break; |
|
562 | + case AccountManager::PROPERTY_EMAIL: |
|
563 | + if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
564 | + $targetUser->setEMailAddress($value); |
|
565 | + } else { |
|
566 | + throw new OCSException('', 102); |
|
567 | + } |
|
568 | + break; |
|
569 | + case AccountManager::PROPERTY_PHONE: |
|
570 | + case AccountManager::PROPERTY_ADDRESS: |
|
571 | + case AccountManager::PROPERTY_WEBSITE: |
|
572 | + case AccountManager::PROPERTY_TWITTER: |
|
573 | + $userAccount = $this->accountManager->getUser($targetUser); |
|
574 | + if ($userAccount[$key]['value'] !== $value) { |
|
575 | + $userAccount[$key]['value'] = $value; |
|
576 | + $this->accountManager->updateUser($targetUser, $userAccount); |
|
577 | + } |
|
578 | + break; |
|
579 | + default: |
|
580 | + throw new OCSException('', 103); |
|
581 | + } |
|
582 | + return new DataResponse(); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * @PasswordConfirmationRequired |
|
587 | + * @NoAdminRequired |
|
588 | + * |
|
589 | + * @param string $userId |
|
590 | + * |
|
591 | + * @return DataResponse |
|
592 | + * |
|
593 | + * @throws OCSException |
|
594 | + */ |
|
595 | + public function wipeUserDevices(string $userId): DataResponse { |
|
596 | + /** @var IUser $currentLoggedInUser */ |
|
597 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
598 | + |
|
599 | + $targetUser = $this->userManager->get($userId); |
|
600 | + |
|
601 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
602 | + throw new OCSException('', 101); |
|
603 | + } |
|
604 | + |
|
605 | + // If not permitted |
|
606 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
607 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
608 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
609 | + } |
|
610 | + |
|
611 | + $this->remoteWipe->markAllTokensForWipe($targetUser); |
|
612 | + |
|
613 | + return new DataResponse(); |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * @PasswordConfirmationRequired |
|
618 | + * @NoAdminRequired |
|
619 | + * |
|
620 | + * @param string $userId |
|
621 | + * @return DataResponse |
|
622 | + * @throws OCSException |
|
623 | + */ |
|
624 | + public function deleteUser(string $userId): DataResponse { |
|
625 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
626 | + |
|
627 | + $targetUser = $this->userManager->get($userId); |
|
628 | + |
|
629 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
630 | + throw new OCSException('', 101); |
|
631 | + } |
|
632 | + |
|
633 | + // If not permitted |
|
634 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
635 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
636 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
637 | + } |
|
638 | + |
|
639 | + // Go ahead with the delete |
|
640 | + if ($targetUser->delete()) { |
|
641 | + return new DataResponse(); |
|
642 | + } else { |
|
643 | + throw new OCSException('', 101); |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * @PasswordConfirmationRequired |
|
649 | + * @NoAdminRequired |
|
650 | + * |
|
651 | + * @param string $userId |
|
652 | + * @return DataResponse |
|
653 | + * @throws OCSException |
|
654 | + * @throws OCSForbiddenException |
|
655 | + */ |
|
656 | + public function disableUser(string $userId): DataResponse { |
|
657 | + return $this->setEnabled($userId, false); |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * @PasswordConfirmationRequired |
|
662 | + * @NoAdminRequired |
|
663 | + * |
|
664 | + * @param string $userId |
|
665 | + * @return DataResponse |
|
666 | + * @throws OCSException |
|
667 | + * @throws OCSForbiddenException |
|
668 | + */ |
|
669 | + public function enableUser(string $userId): DataResponse { |
|
670 | + return $this->setEnabled($userId, true); |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * @param string $userId |
|
675 | + * @param bool $value |
|
676 | + * @return DataResponse |
|
677 | + * @throws OCSException |
|
678 | + */ |
|
679 | + private function setEnabled(string $userId, bool $value): DataResponse { |
|
680 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
681 | + |
|
682 | + $targetUser = $this->userManager->get($userId); |
|
683 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
684 | + throw new OCSException('', 101); |
|
685 | + } |
|
686 | + |
|
687 | + // If not permitted |
|
688 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
689 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
690 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
691 | + } |
|
692 | + |
|
693 | + // enable/disable the user now |
|
694 | + $targetUser->setEnabled($value); |
|
695 | + return new DataResponse(); |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * @NoAdminRequired |
|
700 | + * @NoSubAdminRequired |
|
701 | + * |
|
702 | + * @param string $userId |
|
703 | + * @return DataResponse |
|
704 | + * @throws OCSException |
|
705 | + */ |
|
706 | + public function getUsersGroups(string $userId): DataResponse { |
|
707 | + $loggedInUser = $this->userSession->getUser(); |
|
708 | + |
|
709 | + $targetUser = $this->userManager->get($userId); |
|
710 | + if ($targetUser === null) { |
|
711 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
712 | + } |
|
713 | + |
|
714 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
715 | + // Self lookup or admin lookup |
|
716 | + return new DataResponse([ |
|
717 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
718 | + ]); |
|
719 | + } else { |
|
720 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
721 | + |
|
722 | + // Looking up someone else |
|
723 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
724 | + // Return the group that the method caller is subadmin of for the user in question |
|
725 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
726 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
727 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
728 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
729 | + } |
|
730 | + $groups = array_intersect( |
|
731 | + $getSubAdminsGroups, |
|
732 | + $this->groupManager->getUserGroupIds($targetUser) |
|
733 | + ); |
|
734 | + return new DataResponse(['groups' => $groups]); |
|
735 | + } else { |
|
736 | + // Not permitted |
|
737 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
738 | + } |
|
739 | + } |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * @PasswordConfirmationRequired |
|
744 | + * @NoAdminRequired |
|
745 | + * |
|
746 | + * @param string $userId |
|
747 | + * @param string $groupid |
|
748 | + * @return DataResponse |
|
749 | + * @throws OCSException |
|
750 | + */ |
|
751 | + public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
752 | + if ($groupid === '') { |
|
753 | + throw new OCSException('', 101); |
|
754 | + } |
|
755 | + |
|
756 | + $group = $this->groupManager->get($groupid); |
|
757 | + $targetUser = $this->userManager->get($userId); |
|
758 | + if ($group === null) { |
|
759 | + throw new OCSException('', 102); |
|
760 | + } |
|
761 | + if ($targetUser === null) { |
|
762 | + throw new OCSException('', 103); |
|
763 | + } |
|
764 | + |
|
765 | + // If they're not an admin, check they are a subadmin of the group in question |
|
766 | + $loggedInUser = $this->userSession->getUser(); |
|
767 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
768 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
769 | + throw new OCSException('', 104); |
|
770 | + } |
|
771 | + |
|
772 | + // Add user to group |
|
773 | + $group->addUser($targetUser); |
|
774 | + return new DataResponse(); |
|
775 | + } |
|
776 | + |
|
777 | + /** |
|
778 | + * @PasswordConfirmationRequired |
|
779 | + * @NoAdminRequired |
|
780 | + * |
|
781 | + * @param string $userId |
|
782 | + * @param string $groupid |
|
783 | + * @return DataResponse |
|
784 | + * @throws OCSException |
|
785 | + */ |
|
786 | + public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
787 | + $loggedInUser = $this->userSession->getUser(); |
|
788 | + |
|
789 | + if ($groupid === null || trim($groupid) === '') { |
|
790 | + throw new OCSException('', 101); |
|
791 | + } |
|
792 | + |
|
793 | + $group = $this->groupManager->get($groupid); |
|
794 | + if ($group === null) { |
|
795 | + throw new OCSException('', 102); |
|
796 | + } |
|
797 | + |
|
798 | + $targetUser = $this->userManager->get($userId); |
|
799 | + if ($targetUser === null) { |
|
800 | + throw new OCSException('', 103); |
|
801 | + } |
|
802 | + |
|
803 | + // If they're not an admin, check they are a subadmin of the group in question |
|
804 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
805 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
806 | + throw new OCSException('', 104); |
|
807 | + } |
|
808 | + |
|
809 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
810 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
811 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
812 | + if ($group->getGID() === 'admin') { |
|
813 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
814 | + } |
|
815 | + } else { |
|
816 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
817 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
818 | + } |
|
819 | + } elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
820 | + /** @var IGroup[] $subAdminGroups */ |
|
821 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
822 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
823 | + return $subAdminGroup->getGID(); |
|
824 | + }, $subAdminGroups); |
|
825 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
826 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
827 | + |
|
828 | + if (count($userSubAdminGroups) <= 1) { |
|
829 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
830 | + throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105); |
|
831 | + } |
|
832 | + } |
|
833 | + |
|
834 | + // Remove user from group |
|
835 | + $group->removeUser($targetUser); |
|
836 | + return new DataResponse(); |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Creates a subadmin |
|
841 | + * |
|
842 | + * @PasswordConfirmationRequired |
|
843 | + * |
|
844 | + * @param string $userId |
|
845 | + * @param string $groupid |
|
846 | + * @return DataResponse |
|
847 | + * @throws OCSException |
|
848 | + */ |
|
849 | + public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
850 | + $group = $this->groupManager->get($groupid); |
|
851 | + $user = $this->userManager->get($userId); |
|
852 | + |
|
853 | + // Check if the user exists |
|
854 | + if ($user === null) { |
|
855 | + throw new OCSException('User does not exist', 101); |
|
856 | + } |
|
857 | + // Check if group exists |
|
858 | + if ($group === null) { |
|
859 | + throw new OCSException('Group does not exist', 102); |
|
860 | + } |
|
861 | + // Check if trying to make subadmin of admin group |
|
862 | + if ($group->getGID() === 'admin') { |
|
863 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
864 | + } |
|
865 | + |
|
866 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
867 | + |
|
868 | + // We cannot be subadmin twice |
|
869 | + if ($subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
870 | + return new DataResponse(); |
|
871 | + } |
|
872 | + // Go |
|
873 | + $subAdminManager->createSubAdmin($user, $group); |
|
874 | + return new DataResponse(); |
|
875 | + } |
|
876 | + |
|
877 | + /** |
|
878 | + * Removes a subadmin from a group |
|
879 | + * |
|
880 | + * @PasswordConfirmationRequired |
|
881 | + * |
|
882 | + * @param string $userId |
|
883 | + * @param string $groupid |
|
884 | + * @return DataResponse |
|
885 | + * @throws OCSException |
|
886 | + */ |
|
887 | + public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
888 | + $group = $this->groupManager->get($groupid); |
|
889 | + $user = $this->userManager->get($userId); |
|
890 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
891 | + |
|
892 | + // Check if the user exists |
|
893 | + if ($user === null) { |
|
894 | + throw new OCSException('User does not exist', 101); |
|
895 | + } |
|
896 | + // Check if the group exists |
|
897 | + if ($group === null) { |
|
898 | + throw new OCSException('Group does not exist', 101); |
|
899 | + } |
|
900 | + // Check if they are a subadmin of this said group |
|
901 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
902 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
903 | + } |
|
904 | + |
|
905 | + // Go |
|
906 | + $subAdminManager->deleteSubAdmin($user, $group); |
|
907 | + return new DataResponse(); |
|
908 | + } |
|
909 | + |
|
910 | + /** |
|
911 | + * Get the groups a user is a subadmin of |
|
912 | + * |
|
913 | + * @param string $userId |
|
914 | + * @return DataResponse |
|
915 | + * @throws OCSException |
|
916 | + */ |
|
917 | + public function getUserSubAdminGroups(string $userId): DataResponse { |
|
918 | + $groups = $this->getUserSubAdminGroupsData($userId); |
|
919 | + return new DataResponse($groups); |
|
920 | + } |
|
921 | + |
|
922 | + /** |
|
923 | + * @NoAdminRequired |
|
924 | + * @PasswordConfirmationRequired |
|
925 | + * |
|
926 | + * resend welcome message |
|
927 | + * |
|
928 | + * @param string $userId |
|
929 | + * @return DataResponse |
|
930 | + * @throws OCSException |
|
931 | + */ |
|
932 | + public function resendWelcomeMessage(string $userId): DataResponse { |
|
933 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
934 | + |
|
935 | + $targetUser = $this->userManager->get($userId); |
|
936 | + if ($targetUser === null) { |
|
937 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
938 | + } |
|
939 | + |
|
940 | + // Check if admin / subadmin |
|
941 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
942 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
943 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
944 | + // No rights |
|
945 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
946 | + } |
|
947 | + |
|
948 | + $email = $targetUser->getEMailAddress(); |
|
949 | + if ($email === '' || $email === null) { |
|
950 | + throw new OCSException('Email address not available', 101); |
|
951 | + } |
|
952 | + |
|
953 | + try { |
|
954 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
955 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
956 | + } catch (\Exception $e) { |
|
957 | + $this->logger->logException($e, [ |
|
958 | + 'message' => "Can't send new user mail to $email", |
|
959 | + 'level' => ILogger::ERROR, |
|
960 | + 'app' => 'settings', |
|
961 | + ]); |
|
962 | + throw new OCSException('Sending email failed', 102); |
|
963 | + } |
|
964 | + |
|
965 | + return new DataResponse(); |
|
966 | + } |
|
967 | 967 | } |
@@ -30,14 +30,14 @@ |
||
30 | 30 | |
31 | 31 | class FederatedShareProviderFactory { |
32 | 32 | |
33 | - /** @var IServerContainer */ |
|
34 | - private $serverContainer; |
|
33 | + /** @var IServerContainer */ |
|
34 | + private $serverContainer; |
|
35 | 35 | |
36 | - public function __construct(IServerContainer $serverContainer) { |
|
37 | - $this->serverContainer = $serverContainer; |
|
38 | - } |
|
36 | + public function __construct(IServerContainer $serverContainer) { |
|
37 | + $this->serverContainer = $serverContainer; |
|
38 | + } |
|
39 | 39 | |
40 | - public function get(): FederatedShareProvider { |
|
41 | - return $this->serverContainer->query(FederatedShareProvider::class); |
|
42 | - } |
|
40 | + public function get(): FederatedShareProvider { |
|
41 | + return $this->serverContainer->query(FederatedShareProvider::class); |
|
42 | + } |
|
43 | 43 | } |
@@ -6,35 +6,35 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitProvisioning_API |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\Provisioning_API\\' => 21, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\Provisioning_API\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
25 | - 'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__ . '/..' . '/../lib/Controller/AUserData.php', |
|
26 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php', |
|
27 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php', |
|
28 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php', |
|
29 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php', |
|
30 | - 'OCA\\Provisioning_API\\FederatedShareProviderFactory' => __DIR__ . '/..' . '/../lib/FederatedShareProviderFactory.php', |
|
31 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
32 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
25 | + 'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__.'/..'.'/../lib/Controller/AUserData.php', |
|
26 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__.'/..'.'/../lib/Controller/AppConfigController.php', |
|
27 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__.'/..'.'/../lib/Controller/AppsController.php', |
|
28 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__.'/..'.'/../lib/Controller/GroupsController.php', |
|
29 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__.'/..'.'/../lib/Controller/UsersController.php', |
|
30 | + 'OCA\\Provisioning_API\\FederatedShareProviderFactory' => __DIR__.'/..'.'/../lib/FederatedShareProviderFactory.php', |
|
31 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__.'/..'.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
32 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__.'/..'.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | public static function getInitializer(ClassLoader $loader) |
36 | 36 | { |
37 | - return \Closure::bind(function () use ($loader) { |
|
37 | + return \Closure::bind(function() use ($loader) { |
|
38 | 38 | $loader->prefixLengthsPsr4 = ComposerStaticInitProvisioning_API::$prefixLengthsPsr4; |
39 | 39 | $loader->prefixDirsPsr4 = ComposerStaticInitProvisioning_API::$prefixDirsPsr4; |
40 | 40 | $loader->classMap = ComposerStaticInitProvisioning_API::$classMap; |
@@ -6,13 +6,13 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
10 | - 'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir . '/../lib/Controller/AUserData.php', |
|
11 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php', |
|
12 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php', |
|
13 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php', |
|
14 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php', |
|
15 | - 'OCA\\Provisioning_API\\FederatedShareProviderFactory' => $baseDir . '/../lib/FederatedShareProviderFactory.php', |
|
16 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
17 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
9 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
10 | + 'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir.'/../lib/Controller/AUserData.php', |
|
11 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir.'/../lib/Controller/AppConfigController.php', |
|
12 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir.'/../lib/Controller/AppsController.php', |
|
13 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir.'/../lib/Controller/GroupsController.php', |
|
14 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir.'/../lib/Controller/UsersController.php', |
|
15 | + 'OCA\\Provisioning_API\\FederatedShareProviderFactory' => $baseDir.'/../lib/FederatedShareProviderFactory.php', |
|
16 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
17 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
18 | 18 | ); |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | |
41 | 41 | // Backends |
42 | 42 | $authBackend = new OCA\DAV\Connector\PublicAuth( |
43 | - \OC::$server->getRequest(), |
|
44 | - \OC::$server->getShareManager(), |
|
45 | - \OC::$server->getSession() |
|
43 | + \OC::$server->getRequest(), |
|
44 | + \OC::$server->getShareManager(), |
|
45 | + \OC::$server->getSession() |
|
46 | 46 | ); |
47 | 47 | $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); |
48 | 48 | |
49 | 49 | $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( |
50 | - \OC::$server->getConfig(), |
|
51 | - \OC::$server->getLogger(), |
|
52 | - \OC::$server->getDatabaseConnection(), |
|
53 | - \OC::$server->getUserSession(), |
|
54 | - \OC::$server->getMountManager(), |
|
55 | - \OC::$server->getTagManager(), |
|
56 | - \OC::$server->getRequest(), |
|
57 | - \OC::$server->getPreviewManager(), |
|
58 | - \OC::$server->getEventDispatcher(), |
|
59 | - \OC::$server->getL10N('dav') |
|
50 | + \OC::$server->getConfig(), |
|
51 | + \OC::$server->getLogger(), |
|
52 | + \OC::$server->getDatabaseConnection(), |
|
53 | + \OC::$server->getUserSession(), |
|
54 | + \OC::$server->getMountManager(), |
|
55 | + \OC::$server->getTagManager(), |
|
56 | + \OC::$server->getRequest(), |
|
57 | + \OC::$server->getPreviewManager(), |
|
58 | + \OC::$server->getEventDispatcher(), |
|
59 | + \OC::$server->getL10N('dav') |
|
60 | 60 | ); |
61 | 61 | |
62 | 62 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
@@ -65,45 +65,45 @@ discard block |
||
65 | 65 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
66 | 66 | |
67 | 67 | $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
68 | - $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
69 | - /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ |
|
70 | - $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); |
|
71 | - if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
72 | - // this is what is thrown when trying to access a non-existing share |
|
73 | - throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
74 | - } |
|
75 | - |
|
76 | - $share = $authBackend->getShare(); |
|
77 | - $owner = $share->getShareOwner(); |
|
78 | - $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
79 | - $fileId = $share->getNodeId(); |
|
80 | - |
|
81 | - // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
82 | - $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
83 | - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
84 | - return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); |
|
85 | - }); |
|
86 | - \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { |
|
87 | - return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); |
|
88 | - }); |
|
89 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
90 | - |
|
91 | - OC_Util::tearDownFS(); |
|
92 | - OC_Util::setupFS($owner); |
|
93 | - $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
94 | - $path = $ownerView->getPath($fileId); |
|
95 | - $fileInfo = $ownerView->getFileInfo($path); |
|
96 | - $linkCheckPlugin->setFileInfo($fileInfo); |
|
97 | - |
|
98 | - // If not readble (files_drop) enable the filesdrop plugin |
|
99 | - if (!$isReadable) { |
|
100 | - $filesDropPlugin->enable(); |
|
101 | - } |
|
102 | - |
|
103 | - $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
104 | - $filesDropPlugin->setView($view); |
|
105 | - |
|
106 | - return $view; |
|
68 | + $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
69 | + /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ |
|
70 | + $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); |
|
71 | + if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
72 | + // this is what is thrown when trying to access a non-existing share |
|
73 | + throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
74 | + } |
|
75 | + |
|
76 | + $share = $authBackend->getShare(); |
|
77 | + $owner = $share->getShareOwner(); |
|
78 | + $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
79 | + $fileId = $share->getNodeId(); |
|
80 | + |
|
81 | + // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
82 | + $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
83 | + \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
84 | + return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); |
|
85 | + }); |
|
86 | + \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { |
|
87 | + return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); |
|
88 | + }); |
|
89 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
90 | + |
|
91 | + OC_Util::tearDownFS(); |
|
92 | + OC_Util::setupFS($owner); |
|
93 | + $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
94 | + $path = $ownerView->getPath($fileId); |
|
95 | + $fileInfo = $ownerView->getFileInfo($path); |
|
96 | + $linkCheckPlugin->setFileInfo($fileInfo); |
|
97 | + |
|
98 | + // If not readble (files_drop) enable the filesdrop plugin |
|
99 | + if (!$isReadable) { |
|
100 | + $filesDropPlugin->enable(); |
|
101 | + } |
|
102 | + |
|
103 | + $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
104 | + $filesDropPlugin->setView($view); |
|
105 | + |
|
106 | + return $view; |
|
107 | 107 | }); |
108 | 108 | |
109 | 109 | $server->addPlugin($linkCheckPlugin); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); |
65 | 65 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
66 | 66 | |
67 | -$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
|
67 | +$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function(\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
|
68 | 68 | $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
69 | 69 | /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ |
70 | 70 | $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | |
81 | 81 | // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
82 | 82 | $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
83 | - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
83 | + \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function($mountPoint, $storage) use ($share) { |
|
84 | 84 | return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); |
85 | 85 | }); |
86 | - \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { |
|
86 | + \OC\Files\Filesystem::addStorageWrapper('shareOwner', function($mountPoint, $storage) use ($share) { |
|
87 | 87 | return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); |
88 | 88 | }); |
89 | 89 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
90 | 90 | |
91 | 91 | OC_Util::tearDownFS(); |
92 | 92 | OC_Util::setupFS($owner); |
93 | - $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
93 | + $ownerView = new \OC\Files\View('/'.$owner.'/files'); |
|
94 | 94 | $path = $ownerView->getPath($fileId); |
95 | 95 | $fileInfo = $ownerView->getFileInfo($path); |
96 | 96 | $linkCheckPlugin->setFileInfo($fileInfo); |
@@ -31,20 +31,20 @@ |
||
31 | 31 | use OCP\EventDispatcher\IEventListener; |
32 | 32 | |
33 | 33 | class LoadAdditionalScriptsListener implements IEventListener { |
34 | - /** @var FederatedShareProvider */ |
|
35 | - protected $federatedShareProvider; |
|
34 | + /** @var FederatedShareProvider */ |
|
35 | + protected $federatedShareProvider; |
|
36 | 36 | |
37 | - public function __construct(FederatedShareProvider $federatedShareProvider) { |
|
38 | - $this->federatedShareProvider = $federatedShareProvider; |
|
39 | - } |
|
37 | + public function __construct(FederatedShareProvider $federatedShareProvider) { |
|
38 | + $this->federatedShareProvider = $federatedShareProvider; |
|
39 | + } |
|
40 | 40 | |
41 | - public function handle(Event $event): void { |
|
42 | - if (!$event instanceof LoadAdditionalScriptsEvent) { |
|
43 | - return; |
|
44 | - } |
|
41 | + public function handle(Event $event): void { |
|
42 | + if (!$event instanceof LoadAdditionalScriptsEvent) { |
|
43 | + return; |
|
44 | + } |
|
45 | 45 | |
46 | - if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
47 | - \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
48 | - } |
|
49 | - } |
|
46 | + if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
47 | + \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |
@@ -38,25 +38,25 @@ |
||
38 | 38 | use OCP\AppFramework\Bootstrap\IRegistrationContext; |
39 | 39 | |
40 | 40 | class Application extends App implements IBootstrap { |
41 | - public function __construct() { |
|
42 | - parent::__construct('federatedfilesharing'); |
|
43 | - } |
|
41 | + public function __construct() { |
|
42 | + parent::__construct('federatedfilesharing'); |
|
43 | + } |
|
44 | 44 | |
45 | - public function register(IRegistrationContext $context): void { |
|
46 | - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); |
|
47 | - } |
|
45 | + public function register(IRegistrationContext $context): void { |
|
46 | + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); |
|
47 | + } |
|
48 | 48 | |
49 | - public function boot(IBootContext $context): void { |
|
50 | - $server = $context->getServerContainer(); |
|
49 | + public function boot(IBootContext $context): void { |
|
50 | + $server = $context->getServerContainer(); |
|
51 | 51 | |
52 | - $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
53 | - $cloudFederationManager->addCloudFederationProvider('file', |
|
54 | - 'Federated Files Sharing', |
|
55 | - function () use ($server) { |
|
56 | - return $server->query(CloudFederationProviderFiles::class); |
|
57 | - }); |
|
52 | + $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
53 | + $cloudFederationManager->addCloudFederationProvider('file', |
|
54 | + 'Federated Files Sharing', |
|
55 | + function () use ($server) { |
|
56 | + return $server->query(CloudFederationProviderFiles::class); |
|
57 | + }); |
|
58 | 58 | |
59 | - $manager = $server->getNotificationManager(); |
|
60 | - $manager->registerNotifierService(Notifier::class); |
|
61 | - } |
|
59 | + $manager = $server->getNotificationManager(); |
|
60 | + $manager->registerNotifierService(Notifier::class); |
|
61 | + } |
|
62 | 62 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $cloudFederationManager = $server->getCloudFederationProviderManager(); |
53 | 53 | $cloudFederationManager->addCloudFederationProvider('file', |
54 | 54 | 'Federated Files Sharing', |
55 | - function () use ($server) { |
|
55 | + function() use ($server) { |
|
56 | 56 | return $server->query(CloudFederationProviderFiles::class); |
57 | 57 | }); |
58 | 58 |
@@ -6,41 +6,41 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitFederatedFileSharing |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\FederatedFileSharing\\' => 25, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\FederatedFileSharing\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\FederatedFileSharing\\AddressHandler' => __DIR__ . '/..' . '/../lib/AddressHandler.php', |
|
25 | - 'OCA\\FederatedFileSharing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
26 | - 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RetryJob.php', |
|
27 | - 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php', |
|
28 | - 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php', |
|
29 | - 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php', |
|
30 | - 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', |
|
31 | - 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191755.php', |
|
32 | - 'OCA\\FederatedFileSharing\\Notifications' => __DIR__ . '/..' . '/../lib/Notifications.php', |
|
33 | - 'OCA\\FederatedFileSharing\\Notifier' => __DIR__ . '/..' . '/../lib/Notifier.php', |
|
34 | - 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => __DIR__ . '/..' . '/../lib/OCM/CloudFederationProviderFiles.php', |
|
35 | - 'OCA\\FederatedFileSharing\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
36 | - 'OCA\\FederatedFileSharing\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php', |
|
37 | - 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => __DIR__ . '/..' . '/../lib/Settings/PersonalSection.php', |
|
38 | - 'OCA\\FederatedFileSharing\\TokenHandler' => __DIR__ . '/..' . '/../lib/TokenHandler.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\FederatedFileSharing\\AddressHandler' => __DIR__.'/..'.'/../lib/AddressHandler.php', |
|
25 | + 'OCA\\FederatedFileSharing\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
26 | + 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__.'/..'.'/../lib/BackgroundJob/RetryJob.php', |
|
27 | + 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__.'/..'.'/../lib/Controller/MountPublicLinkController.php', |
|
28 | + 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__.'/..'.'/../lib/Controller/RequestHandlerController.php', |
|
29 | + 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__.'/..'.'/../lib/FederatedShareProvider.php', |
|
30 | + 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__.'/..'.'/../lib/Listeners/LoadAdditionalScriptsListener.php', |
|
31 | + 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__.'/..'.'/../lib/Migration/Version1010Date20200630191755.php', |
|
32 | + 'OCA\\FederatedFileSharing\\Notifications' => __DIR__.'/..'.'/../lib/Notifications.php', |
|
33 | + 'OCA\\FederatedFileSharing\\Notifier' => __DIR__.'/..'.'/../lib/Notifier.php', |
|
34 | + 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => __DIR__.'/..'.'/../lib/OCM/CloudFederationProviderFiles.php', |
|
35 | + 'OCA\\FederatedFileSharing\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
36 | + 'OCA\\FederatedFileSharing\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php', |
|
37 | + 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => __DIR__.'/..'.'/../lib/Settings/PersonalSection.php', |
|
38 | + 'OCA\\FederatedFileSharing\\TokenHandler' => __DIR__.'/..'.'/../lib/TokenHandler.php', |
|
39 | 39 | ); |
40 | 40 | |
41 | 41 | public static function getInitializer(ClassLoader $loader) |
42 | 42 | { |
43 | - return \Closure::bind(function () use ($loader) { |
|
43 | + return \Closure::bind(function() use ($loader) { |
|
44 | 44 | $loader->prefixLengthsPsr4 = ComposerStaticInitFederatedFileSharing::$prefixLengthsPsr4; |
45 | 45 | $loader->prefixDirsPsr4 = ComposerStaticInitFederatedFileSharing::$prefixDirsPsr4; |
46 | 46 | $loader->classMap = ComposerStaticInitFederatedFileSharing::$classMap; |