@@ -72,260 +72,260 @@ |
||
72 | 72 | |
73 | 73 | class Server { |
74 | 74 | |
75 | - /** @var IRequest */ |
|
76 | - private $request; |
|
77 | - |
|
78 | - /** @var string */ |
|
79 | - private $baseUri; |
|
80 | - |
|
81 | - /** @var Connector\Sabre\Server */ |
|
82 | - public $server; |
|
83 | - |
|
84 | - public function __construct(IRequest $request, $baseUri) { |
|
85 | - $this->request = $request; |
|
86 | - $this->baseUri = $baseUri; |
|
87 | - $logger = \OC::$server->getLogger(); |
|
88 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
89 | - |
|
90 | - $root = new RootCollection(); |
|
91 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
92 | - |
|
93 | - // Add maintenance plugin |
|
94 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
95 | - |
|
96 | - // Backends |
|
97 | - $authBackend = new Auth( |
|
98 | - \OC::$server->getSession(), |
|
99 | - \OC::$server->getUserSession(), |
|
100 | - \OC::$server->getRequest(), |
|
101 | - \OC::$server->getTwoFactorAuthManager(), |
|
102 | - \OC::$server->getBruteForceThrottler() |
|
103 | - ); |
|
104 | - |
|
105 | - // Set URL explicitly due to reverse-proxy situations |
|
106 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
107 | - $this->server->setBaseUri($this->baseUri); |
|
108 | - |
|
109 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
110 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
111 | - $authPlugin = new Plugin(); |
|
112 | - $authPlugin->addBackend(new PublicAuth()); |
|
113 | - $this->server->addPlugin($authPlugin); |
|
114 | - |
|
115 | - // allow setup of additional auth backends |
|
116 | - $event = new SabrePluginEvent($this->server); |
|
117 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
118 | - |
|
119 | - $bearerAuthBackend = new BearerAuth( |
|
120 | - \OC::$server->getUserSession(), |
|
121 | - \OC::$server->getSession(), |
|
122 | - \OC::$server->getRequest() |
|
123 | - ); |
|
124 | - $authPlugin->addBackend($bearerAuthBackend); |
|
125 | - // because we are throwing exceptions this plugin has to be the last one |
|
126 | - $authPlugin->addBackend($authBackend); |
|
127 | - |
|
128 | - // debugging |
|
129 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
131 | - } else { |
|
132 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
133 | - } |
|
134 | - |
|
135 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
136 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
137 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
138 | - |
|
139 | - // acl |
|
140 | - $acl = new DavAclPlugin(); |
|
141 | - $acl->principalCollectionSet = [ |
|
142 | - 'principals/users', |
|
143 | - 'principals/groups', |
|
144 | - 'principals/calendar-resources', |
|
145 | - 'principals/calendar-rooms', |
|
146 | - ]; |
|
147 | - $acl->defaultUsernamePath = 'principals/users'; |
|
148 | - $this->server->addPlugin($acl); |
|
149 | - |
|
150 | - // calendar plugins |
|
151 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
152 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
153 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
154 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
155 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
156 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
157 | - } |
|
158 | - |
|
159 | - $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
160 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
161 | - |
|
162 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
163 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
164 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
165 | - \OC::$server->getConfig(), |
|
166 | - \OC::$server->getURLGenerator() |
|
167 | - )); |
|
168 | - } |
|
169 | - |
|
170 | - // addressbook plugins |
|
171 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
172 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
173 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
174 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
175 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
176 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
177 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
178 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
179 | - \OC::$server->getLogger()) |
|
180 | - )); |
|
181 | - } |
|
182 | - |
|
183 | - // system tags plugins |
|
184 | - $this->server->addPlugin(new SystemTagPlugin( |
|
185 | - \OC::$server->getSystemTagManager(), |
|
186 | - \OC::$server->getGroupManager(), |
|
187 | - \OC::$server->getUserSession() |
|
188 | - )); |
|
189 | - |
|
190 | - // comments plugin |
|
191 | - $this->server->addPlugin(new CommentsPlugin( |
|
192 | - \OC::$server->getCommentsManager(), |
|
193 | - \OC::$server->getUserSession() |
|
194 | - )); |
|
195 | - |
|
196 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
197 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
198 | - |
|
199 | - // allow setup of additional plugins |
|
200 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
201 | - |
|
202 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
203 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
204 | - if($request->isUserAgent([ |
|
205 | - '/WebDAVFS/', |
|
206 | - '/OneNote/', |
|
207 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | - ])) { |
|
209 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
210 | - } |
|
211 | - |
|
212 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
213 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
214 | - } |
|
215 | - |
|
216 | - $lazySearchBackend = new LazySearchBackend(); |
|
217 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
218 | - |
|
219 | - // wait with registering these until auth is handled and the filesystem is setup |
|
220 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
221 | - // custom properties plugin must be the last one |
|
222 | - $userSession = \OC::$server->getUserSession(); |
|
223 | - $user = $userSession->getUser(); |
|
224 | - if ($user !== null) { |
|
225 | - $view = \OC\Files\Filesystem::getView(); |
|
226 | - $this->server->addPlugin( |
|
227 | - new FilesPlugin( |
|
228 | - $this->server->tree, |
|
229 | - \OC::$server->getConfig(), |
|
230 | - $this->request, |
|
231 | - \OC::$server->getPreviewManager(), |
|
232 | - false, |
|
233 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - $this->server->addPlugin( |
|
238 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
239 | - new CustomPropertiesBackend( |
|
240 | - $this->server->tree, |
|
241 | - \OC::$server->getDatabaseConnection(), |
|
242 | - \OC::$server->getUserSession()->getUser() |
|
243 | - ) |
|
244 | - ) |
|
245 | - ); |
|
246 | - if ($view !== null) { |
|
247 | - $this->server->addPlugin( |
|
248 | - new QuotaPlugin($view, false)); |
|
249 | - } |
|
250 | - $this->server->addPlugin( |
|
251 | - new TagsPlugin( |
|
252 | - $this->server->tree, \OC::$server->getTagManager() |
|
253 | - ) |
|
254 | - ); |
|
255 | - // TODO: switch to LazyUserFolder |
|
256 | - $userFolder = \OC::$server->getUserFolder(); |
|
257 | - $this->server->addPlugin(new SharesPlugin( |
|
258 | - $this->server->tree, |
|
259 | - $userSession, |
|
260 | - $userFolder, |
|
261 | - \OC::$server->getShareManager() |
|
262 | - )); |
|
263 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
264 | - \OC::$server->getCommentsManager(), |
|
265 | - $userSession |
|
266 | - )); |
|
267 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
268 | - if ($view !== null) { |
|
269 | - $this->server->addPlugin(new FilesReportPlugin( |
|
270 | - $this->server->tree, |
|
271 | - $view, |
|
272 | - \OC::$server->getSystemTagManager(), |
|
273 | - \OC::$server->getSystemTagObjectMapper(), |
|
274 | - \OC::$server->getTagManager(), |
|
275 | - $userSession, |
|
276 | - \OC::$server->getGroupManager(), |
|
277 | - $userFolder, |
|
278 | - \OC::$server->getAppManager() |
|
279 | - )); |
|
280 | - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
281 | - $this->server->tree, |
|
282 | - $user, |
|
283 | - \OC::$server->getRootFolder(), |
|
284 | - \OC::$server->getShareManager(), |
|
285 | - $view |
|
286 | - )); |
|
287 | - } |
|
288 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
289 | - \OC::$server->getConfig(), |
|
290 | - \OC::$server->query(BirthdayService::class) |
|
291 | - )); |
|
292 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
293 | - \OC::$server->getUserSession(), |
|
294 | - \OC::$server->getURLGenerator(), |
|
295 | - \OC::$server->getThemingDefaults(), |
|
296 | - \OC::$server->getRequest(), |
|
297 | - \OC::$server->getL10N('dav'), |
|
298 | - function () { |
|
299 | - return UUIDUtil::getUUID(); |
|
300 | - } |
|
301 | - )); |
|
302 | - } |
|
303 | - |
|
304 | - // register plugins from apps |
|
305 | - $pluginManager = new PluginManager( |
|
306 | - \OC::$server, |
|
307 | - \OC::$server->getAppManager() |
|
308 | - ); |
|
309 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
310 | - $this->server->addPlugin($appPlugin); |
|
311 | - } |
|
312 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
313 | - $root->addChild($appCollection); |
|
314 | - } |
|
315 | - }); |
|
316 | - } |
|
317 | - |
|
318 | - public function exec() { |
|
319 | - $this->server->exec(); |
|
320 | - } |
|
321 | - |
|
322 | - private function requestIsForSubtree(array $subTrees): bool { |
|
323 | - foreach ($subTrees as $subTree) { |
|
324 | - $subTree = trim($subTree, ' /'); |
|
325 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
326 | - return true; |
|
327 | - } |
|
328 | - } |
|
329 | - return false; |
|
330 | - } |
|
75 | + /** @var IRequest */ |
|
76 | + private $request; |
|
77 | + |
|
78 | + /** @var string */ |
|
79 | + private $baseUri; |
|
80 | + |
|
81 | + /** @var Connector\Sabre\Server */ |
|
82 | + public $server; |
|
83 | + |
|
84 | + public function __construct(IRequest $request, $baseUri) { |
|
85 | + $this->request = $request; |
|
86 | + $this->baseUri = $baseUri; |
|
87 | + $logger = \OC::$server->getLogger(); |
|
88 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
89 | + |
|
90 | + $root = new RootCollection(); |
|
91 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
92 | + |
|
93 | + // Add maintenance plugin |
|
94 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
95 | + |
|
96 | + // Backends |
|
97 | + $authBackend = new Auth( |
|
98 | + \OC::$server->getSession(), |
|
99 | + \OC::$server->getUserSession(), |
|
100 | + \OC::$server->getRequest(), |
|
101 | + \OC::$server->getTwoFactorAuthManager(), |
|
102 | + \OC::$server->getBruteForceThrottler() |
|
103 | + ); |
|
104 | + |
|
105 | + // Set URL explicitly due to reverse-proxy situations |
|
106 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
107 | + $this->server->setBaseUri($this->baseUri); |
|
108 | + |
|
109 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
110 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
111 | + $authPlugin = new Plugin(); |
|
112 | + $authPlugin->addBackend(new PublicAuth()); |
|
113 | + $this->server->addPlugin($authPlugin); |
|
114 | + |
|
115 | + // allow setup of additional auth backends |
|
116 | + $event = new SabrePluginEvent($this->server); |
|
117 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
118 | + |
|
119 | + $bearerAuthBackend = new BearerAuth( |
|
120 | + \OC::$server->getUserSession(), |
|
121 | + \OC::$server->getSession(), |
|
122 | + \OC::$server->getRequest() |
|
123 | + ); |
|
124 | + $authPlugin->addBackend($bearerAuthBackend); |
|
125 | + // because we are throwing exceptions this plugin has to be the last one |
|
126 | + $authPlugin->addBackend($authBackend); |
|
127 | + |
|
128 | + // debugging |
|
129 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
131 | + } else { |
|
132 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
133 | + } |
|
134 | + |
|
135 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
136 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
137 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
138 | + |
|
139 | + // acl |
|
140 | + $acl = new DavAclPlugin(); |
|
141 | + $acl->principalCollectionSet = [ |
|
142 | + 'principals/users', |
|
143 | + 'principals/groups', |
|
144 | + 'principals/calendar-resources', |
|
145 | + 'principals/calendar-rooms', |
|
146 | + ]; |
|
147 | + $acl->defaultUsernamePath = 'principals/users'; |
|
148 | + $this->server->addPlugin($acl); |
|
149 | + |
|
150 | + // calendar plugins |
|
151 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
152 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
153 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
154 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
155 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
156 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
157 | + } |
|
158 | + |
|
159 | + $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); |
|
160 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
161 | + |
|
162 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
163 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
164 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
165 | + \OC::$server->getConfig(), |
|
166 | + \OC::$server->getURLGenerator() |
|
167 | + )); |
|
168 | + } |
|
169 | + |
|
170 | + // addressbook plugins |
|
171 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
172 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
173 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
174 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
175 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
176 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
177 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
178 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
179 | + \OC::$server->getLogger()) |
|
180 | + )); |
|
181 | + } |
|
182 | + |
|
183 | + // system tags plugins |
|
184 | + $this->server->addPlugin(new SystemTagPlugin( |
|
185 | + \OC::$server->getSystemTagManager(), |
|
186 | + \OC::$server->getGroupManager(), |
|
187 | + \OC::$server->getUserSession() |
|
188 | + )); |
|
189 | + |
|
190 | + // comments plugin |
|
191 | + $this->server->addPlugin(new CommentsPlugin( |
|
192 | + \OC::$server->getCommentsManager(), |
|
193 | + \OC::$server->getUserSession() |
|
194 | + )); |
|
195 | + |
|
196 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
197 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
198 | + |
|
199 | + // allow setup of additional plugins |
|
200 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
201 | + |
|
202 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
203 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
204 | + if($request->isUserAgent([ |
|
205 | + '/WebDAVFS/', |
|
206 | + '/OneNote/', |
|
207 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | + ])) { |
|
209 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
210 | + } |
|
211 | + |
|
212 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
213 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
214 | + } |
|
215 | + |
|
216 | + $lazySearchBackend = new LazySearchBackend(); |
|
217 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
218 | + |
|
219 | + // wait with registering these until auth is handled and the filesystem is setup |
|
220 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
221 | + // custom properties plugin must be the last one |
|
222 | + $userSession = \OC::$server->getUserSession(); |
|
223 | + $user = $userSession->getUser(); |
|
224 | + if ($user !== null) { |
|
225 | + $view = \OC\Files\Filesystem::getView(); |
|
226 | + $this->server->addPlugin( |
|
227 | + new FilesPlugin( |
|
228 | + $this->server->tree, |
|
229 | + \OC::$server->getConfig(), |
|
230 | + $this->request, |
|
231 | + \OC::$server->getPreviewManager(), |
|
232 | + false, |
|
233 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + $this->server->addPlugin( |
|
238 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
239 | + new CustomPropertiesBackend( |
|
240 | + $this->server->tree, |
|
241 | + \OC::$server->getDatabaseConnection(), |
|
242 | + \OC::$server->getUserSession()->getUser() |
|
243 | + ) |
|
244 | + ) |
|
245 | + ); |
|
246 | + if ($view !== null) { |
|
247 | + $this->server->addPlugin( |
|
248 | + new QuotaPlugin($view, false)); |
|
249 | + } |
|
250 | + $this->server->addPlugin( |
|
251 | + new TagsPlugin( |
|
252 | + $this->server->tree, \OC::$server->getTagManager() |
|
253 | + ) |
|
254 | + ); |
|
255 | + // TODO: switch to LazyUserFolder |
|
256 | + $userFolder = \OC::$server->getUserFolder(); |
|
257 | + $this->server->addPlugin(new SharesPlugin( |
|
258 | + $this->server->tree, |
|
259 | + $userSession, |
|
260 | + $userFolder, |
|
261 | + \OC::$server->getShareManager() |
|
262 | + )); |
|
263 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
264 | + \OC::$server->getCommentsManager(), |
|
265 | + $userSession |
|
266 | + )); |
|
267 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
268 | + if ($view !== null) { |
|
269 | + $this->server->addPlugin(new FilesReportPlugin( |
|
270 | + $this->server->tree, |
|
271 | + $view, |
|
272 | + \OC::$server->getSystemTagManager(), |
|
273 | + \OC::$server->getSystemTagObjectMapper(), |
|
274 | + \OC::$server->getTagManager(), |
|
275 | + $userSession, |
|
276 | + \OC::$server->getGroupManager(), |
|
277 | + $userFolder, |
|
278 | + \OC::$server->getAppManager() |
|
279 | + )); |
|
280 | + $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
281 | + $this->server->tree, |
|
282 | + $user, |
|
283 | + \OC::$server->getRootFolder(), |
|
284 | + \OC::$server->getShareManager(), |
|
285 | + $view |
|
286 | + )); |
|
287 | + } |
|
288 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
289 | + \OC::$server->getConfig(), |
|
290 | + \OC::$server->query(BirthdayService::class) |
|
291 | + )); |
|
292 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
293 | + \OC::$server->getUserSession(), |
|
294 | + \OC::$server->getURLGenerator(), |
|
295 | + \OC::$server->getThemingDefaults(), |
|
296 | + \OC::$server->getRequest(), |
|
297 | + \OC::$server->getL10N('dav'), |
|
298 | + function () { |
|
299 | + return UUIDUtil::getUUID(); |
|
300 | + } |
|
301 | + )); |
|
302 | + } |
|
303 | + |
|
304 | + // register plugins from apps |
|
305 | + $pluginManager = new PluginManager( |
|
306 | + \OC::$server, |
|
307 | + \OC::$server->getAppManager() |
|
308 | + ); |
|
309 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
310 | + $this->server->addPlugin($appPlugin); |
|
311 | + } |
|
312 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
313 | + $root->addChild($appCollection); |
|
314 | + } |
|
315 | + }); |
|
316 | + } |
|
317 | + |
|
318 | + public function exec() { |
|
319 | + $this->server->exec(); |
|
320 | + } |
|
321 | + |
|
322 | + private function requestIsForSubtree(array $subTrees): bool { |
|
323 | + foreach ($subTrees as $subTree) { |
|
324 | + $subTree = trim($subTree, ' /'); |
|
325 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
326 | + return true; |
|
327 | + } |
|
328 | + } |
|
329 | + return false; |
|
330 | + } |
|
331 | 331 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $authPlugin->addBackend($authBackend); |
127 | 127 | |
128 | 128 | // debugging |
129 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
129 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
130 | 130 | $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
131 | 131 | } else { |
132 | 132 | $this->server->addPlugin(new DummyGetResponsePlugin()); |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | |
202 | 202 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
203 | 203 | // we do not provide locking we emulate it using a fake locking plugin. |
204 | - if($request->isUserAgent([ |
|
204 | + if ($request->isUserAgent([ |
|
205 | 205 | '/WebDAVFS/', |
206 | 206 | '/OneNote/', |
207 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
207 | + '/^Microsoft-WebDAV/', // Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
208 | 208 | ])) { |
209 | 209 | $this->server->addPlugin(new FakeLockerPlugin()); |
210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
218 | 218 | |
219 | 219 | // wait with registering these until auth is handled and the filesystem is setup |
220 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
220 | + $this->server->on('beforeMethod:*', function() use ($root, $lazySearchBackend) { |
|
221 | 221 | // custom properties plugin must be the last one |
222 | 222 | $userSession = \OC::$server->getUserSession(); |
223 | 223 | $user = $userSession->getUser(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | \OC::$server->getThemingDefaults(), |
296 | 296 | \OC::$server->getRequest(), |
297 | 297 | \OC::$server->getL10N('dav'), |
298 | - function () { |
|
298 | + function() { |
|
299 | 299 | return UUIDUtil::getUUID(); |
300 | 300 | } |
301 | 301 | )); |
@@ -38,86 +38,86 @@ |
||
38 | 38 | |
39 | 39 | class SyncBirthdayCalendar extends Command { |
40 | 40 | |
41 | - /** @var BirthdayService */ |
|
42 | - private $birthdayService; |
|
43 | - |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - |
|
47 | - /** @var IUserManager */ |
|
48 | - private $userManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param IUserManager $userManager |
|
52 | - * @param IConfig $config |
|
53 | - * @param BirthdayService $birthdayService |
|
54 | - */ |
|
55 | - function __construct(IUserManager $userManager, IConfig $config, |
|
56 | - BirthdayService $birthdayService) { |
|
57 | - parent::__construct(); |
|
58 | - $this->birthdayService = $birthdayService; |
|
59 | - $this->config = $config; |
|
60 | - $this->userManager = $userManager; |
|
61 | - } |
|
62 | - |
|
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('dav:sync-birthday-calendar') |
|
66 | - ->setDescription('Synchronizes the birthday calendar') |
|
67 | - ->addArgument('user', |
|
68 | - InputArgument::OPTIONAL, |
|
69 | - 'User for whom the birthday calendar will be synchronized'); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param InputInterface $input |
|
74 | - * @param OutputInterface $output |
|
75 | - */ |
|
76 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
77 | - $this->verifyEnabled(); |
|
78 | - |
|
79 | - $user = $input->getArgument('user'); |
|
80 | - if (!is_null($user)) { |
|
81 | - if (!$this->userManager->userExists($user)) { |
|
82 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
83 | - } |
|
84 | - |
|
85 | - // re-enable the birthday calendar in case it's called directly with a user name |
|
86 | - $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
87 | - if ($isEnabled !== 'yes') { |
|
88 | - $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
89 | - $output->writeln("Re-enabling birthday calendar for $user"); |
|
90 | - } |
|
91 | - |
|
92 | - $output->writeln("Start birthday calendar sync for $user"); |
|
93 | - $this->birthdayService->syncUser($user); |
|
94 | - return; |
|
95 | - } |
|
96 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
97 | - $p = new ProgressBar($output); |
|
98 | - $p->start(); |
|
99 | - $this->userManager->callForSeenUsers(function ($user) use ($p) { |
|
100 | - $p->advance(); |
|
101 | - |
|
102 | - $userId = $user->getUID(); |
|
103 | - $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
104 | - if ($isEnabled !== 'yes') { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - /** @var IUser $user */ |
|
109 | - $this->birthdayService->syncUser($user->getUID()); |
|
110 | - }); |
|
111 | - |
|
112 | - $p->finish(); |
|
113 | - $output->writeln(''); |
|
114 | - } |
|
115 | - |
|
116 | - protected function verifyEnabled() { |
|
117 | - $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
118 | - |
|
119 | - if ($isEnabled !== 'yes') { |
|
120 | - throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
121 | - } |
|
122 | - } |
|
41 | + /** @var BirthdayService */ |
|
42 | + private $birthdayService; |
|
43 | + |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + |
|
47 | + /** @var IUserManager */ |
|
48 | + private $userManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param IUserManager $userManager |
|
52 | + * @param IConfig $config |
|
53 | + * @param BirthdayService $birthdayService |
|
54 | + */ |
|
55 | + function __construct(IUserManager $userManager, IConfig $config, |
|
56 | + BirthdayService $birthdayService) { |
|
57 | + parent::__construct(); |
|
58 | + $this->birthdayService = $birthdayService; |
|
59 | + $this->config = $config; |
|
60 | + $this->userManager = $userManager; |
|
61 | + } |
|
62 | + |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('dav:sync-birthday-calendar') |
|
66 | + ->setDescription('Synchronizes the birthday calendar') |
|
67 | + ->addArgument('user', |
|
68 | + InputArgument::OPTIONAL, |
|
69 | + 'User for whom the birthday calendar will be synchronized'); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param InputInterface $input |
|
74 | + * @param OutputInterface $output |
|
75 | + */ |
|
76 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
77 | + $this->verifyEnabled(); |
|
78 | + |
|
79 | + $user = $input->getArgument('user'); |
|
80 | + if (!is_null($user)) { |
|
81 | + if (!$this->userManager->userExists($user)) { |
|
82 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
83 | + } |
|
84 | + |
|
85 | + // re-enable the birthday calendar in case it's called directly with a user name |
|
86 | + $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
87 | + if ($isEnabled !== 'yes') { |
|
88 | + $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
89 | + $output->writeln("Re-enabling birthday calendar for $user"); |
|
90 | + } |
|
91 | + |
|
92 | + $output->writeln("Start birthday calendar sync for $user"); |
|
93 | + $this->birthdayService->syncUser($user); |
|
94 | + return; |
|
95 | + } |
|
96 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
97 | + $p = new ProgressBar($output); |
|
98 | + $p->start(); |
|
99 | + $this->userManager->callForSeenUsers(function ($user) use ($p) { |
|
100 | + $p->advance(); |
|
101 | + |
|
102 | + $userId = $user->getUID(); |
|
103 | + $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
104 | + if ($isEnabled !== 'yes') { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + /** @var IUser $user */ |
|
109 | + $this->birthdayService->syncUser($user->getUID()); |
|
110 | + }); |
|
111 | + |
|
112 | + $p->finish(); |
|
113 | + $output->writeln(''); |
|
114 | + } |
|
115 | + |
|
116 | + protected function verifyEnabled() { |
|
117 | + $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
118 | + |
|
119 | + if ($isEnabled !== 'yes') { |
|
120 | + throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -96,7 +96,7 @@ |
||
96 | 96 | $output->writeln("Start birthday calendar sync for all users ..."); |
97 | 97 | $p = new ProgressBar($output); |
98 | 98 | $p->start(); |
99 | - $this->userManager->callForSeenUsers(function ($user) use ($p) { |
|
99 | + $this->userManager->callForSeenUsers(function($user) use ($p) { |
|
100 | 100 | $p->advance(); |
101 | 101 | |
102 | 102 | $userId = $user->getUID(); |
@@ -35,191 +35,191 @@ |
||
35 | 35 | */ |
36 | 36 | trait PrincipalProxyTrait { |
37 | 37 | |
38 | - /** |
|
39 | - * Returns the list of members for a group-principal |
|
40 | - * |
|
41 | - * @param string $principal |
|
42 | - * @return string[] |
|
43 | - * @throws Exception |
|
44 | - */ |
|
45 | - public function getGroupMemberSet($principal) { |
|
46 | - $members = []; |
|
47 | - |
|
48 | - if ($this->isProxyPrincipal($principal)) { |
|
49 | - $realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal); |
|
50 | - $principalArray = $this->getPrincipalByPath($realPrincipal); |
|
51 | - if (!$principalArray) { |
|
52 | - throw new Exception('Principal not found'); |
|
53 | - } |
|
54 | - |
|
55 | - $proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']); |
|
56 | - foreach ($proxies as $proxy) { |
|
57 | - if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
58 | - $members[] = $proxy->getProxyId(); |
|
59 | - } |
|
60 | - |
|
61 | - if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
62 | - $members[] = $proxy->getProxyId(); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $members; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the list of groups a principal is a member of |
|
72 | - * |
|
73 | - * @param string $principal |
|
74 | - * @param bool $needGroups |
|
75 | - * @return array |
|
76 | - * @throws Exception |
|
77 | - */ |
|
78 | - public function getGroupMembership($principal, $needGroups = false) { |
|
79 | - list($prefix, $name) = \Sabre\Uri\split($principal); |
|
80 | - |
|
81 | - if ($prefix !== $this->principalPrefix) { |
|
82 | - return []; |
|
83 | - } |
|
84 | - |
|
85 | - $principalArray = $this->getPrincipalByPath($principal); |
|
86 | - if (!$principalArray) { |
|
87 | - throw new Exception('Principal not found'); |
|
88 | - } |
|
89 | - |
|
90 | - $groups = []; |
|
91 | - $proxies = $this->proxyMapper->getProxiesFor($principal); |
|
92 | - foreach ($proxies as $proxy) { |
|
93 | - if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
94 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
95 | - } |
|
96 | - |
|
97 | - if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
98 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $groups; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Updates the list of group members for a group principal. |
|
107 | - * |
|
108 | - * The principals should be passed as a list of uri's. |
|
109 | - * |
|
110 | - * @param string $principal |
|
111 | - * @param string[] $members |
|
112 | - * @throws Exception |
|
113 | - */ |
|
114 | - public function setGroupMemberSet($principal, array $members) { |
|
115 | - list($principalUri, $target) = \Sabre\Uri\split($principal); |
|
116 | - |
|
117 | - if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') { |
|
118 | - throw new Exception('Setting members of the group is not supported yet'); |
|
119 | - } |
|
120 | - |
|
121 | - $masterPrincipalArray = $this->getPrincipalByPath($principalUri); |
|
122 | - if (!$masterPrincipalArray) { |
|
123 | - throw new Exception('Principal not found'); |
|
124 | - } |
|
125 | - |
|
126 | - $permission = ProxyMapper::PERMISSION_READ; |
|
127 | - if ($target === 'calendar-proxy-write') { |
|
128 | - $permission |= ProxyMapper::PERMISSION_WRITE; |
|
129 | - } |
|
130 | - |
|
131 | - list($prefix, $owner) = \Sabre\Uri\split($principalUri); |
|
132 | - $proxies = $this->proxyMapper->getProxiesOf($principalUri); |
|
133 | - |
|
134 | - foreach ($members as $member) { |
|
135 | - list($prefix, $name) = \Sabre\Uri\split($member); |
|
136 | - |
|
137 | - if ($prefix !== $this->principalPrefix) { |
|
138 | - throw new Exception('Invalid member group prefix: ' . $prefix); |
|
139 | - } |
|
140 | - |
|
141 | - $principalArray = $this->getPrincipalByPath($member); |
|
142 | - if (!$principalArray) { |
|
143 | - throw new Exception('Principal not found'); |
|
144 | - } |
|
145 | - |
|
146 | - $found = false; |
|
147 | - foreach ($proxies as $proxy) { |
|
148 | - if ($proxy->getProxyId() === $member) { |
|
149 | - $found = true; |
|
150 | - $proxy->setPermissions($proxy->getPermissions() | $permission); |
|
151 | - $this->proxyMapper->update($proxy); |
|
152 | - |
|
153 | - $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
154 | - return $p->getId() !== $proxy->getId(); |
|
155 | - }); |
|
156 | - break; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - if ($found === false) { |
|
161 | - $proxy = new Proxy(); |
|
162 | - $proxy->setOwnerId($principalUri); |
|
163 | - $proxy->setProxyId($member); |
|
164 | - $proxy->setPermissions($permission); |
|
165 | - $this->proxyMapper->insert($proxy); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - // Delete all remaining proxies |
|
170 | - foreach ($proxies as $proxy) { |
|
171 | - // Write and Read Proxies have individual requests, |
|
172 | - // so only delete proxies of this permission |
|
173 | - if ($proxy->getPermissions() === $permission) { |
|
174 | - $this->proxyMapper->delete($proxy); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @param string $principalUri |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - private function isProxyPrincipal(string $principalUri):bool { |
|
184 | - list($realPrincipalUri, $proxy) = \Sabre\Uri\split($principalUri); |
|
185 | - list($prefix, $userId) = \Sabre\Uri\split($realPrincipalUri); |
|
186 | - |
|
187 | - if (!isset($prefix) || !isset($userId)) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - if ($prefix !== $this->principalPrefix) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - |
|
194 | - return $proxy === 'calendar-proxy-read' |
|
195 | - || $proxy === 'calendar-proxy-write'; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $principalUri |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function isReadProxyPrincipal(string $principalUri):bool { |
|
204 | - list(, $proxy) = \Sabre\Uri\split($principalUri); |
|
205 | - return $proxy === 'calendar-proxy-read'; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string $principalUri |
|
210 | - * @return bool |
|
211 | - */ |
|
212 | - private function isWriteProxyPrincipal(string $principalUri):bool { |
|
213 | - list(, $proxy) = \Sabre\Uri\split($principalUri); |
|
214 | - return $proxy === 'calendar-proxy-write'; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @param string $principalUri |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function getPrincipalUriFromProxyPrincipal(string $principalUri):string { |
|
222 | - list($realPrincipalUri, ) = \Sabre\Uri\split($principalUri); |
|
223 | - return $realPrincipalUri; |
|
224 | - } |
|
38 | + /** |
|
39 | + * Returns the list of members for a group-principal |
|
40 | + * |
|
41 | + * @param string $principal |
|
42 | + * @return string[] |
|
43 | + * @throws Exception |
|
44 | + */ |
|
45 | + public function getGroupMemberSet($principal) { |
|
46 | + $members = []; |
|
47 | + |
|
48 | + if ($this->isProxyPrincipal($principal)) { |
|
49 | + $realPrincipal = $this->getPrincipalUriFromProxyPrincipal($principal); |
|
50 | + $principalArray = $this->getPrincipalByPath($realPrincipal); |
|
51 | + if (!$principalArray) { |
|
52 | + throw new Exception('Principal not found'); |
|
53 | + } |
|
54 | + |
|
55 | + $proxies = $this->proxyMapper->getProxiesOf($principalArray['uri']); |
|
56 | + foreach ($proxies as $proxy) { |
|
57 | + if ($this->isReadProxyPrincipal($principal) && $proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
58 | + $members[] = $proxy->getProxyId(); |
|
59 | + } |
|
60 | + |
|
61 | + if ($this->isWriteProxyPrincipal($principal) && $proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
62 | + $members[] = $proxy->getProxyId(); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $members; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the list of groups a principal is a member of |
|
72 | + * |
|
73 | + * @param string $principal |
|
74 | + * @param bool $needGroups |
|
75 | + * @return array |
|
76 | + * @throws Exception |
|
77 | + */ |
|
78 | + public function getGroupMembership($principal, $needGroups = false) { |
|
79 | + list($prefix, $name) = \Sabre\Uri\split($principal); |
|
80 | + |
|
81 | + if ($prefix !== $this->principalPrefix) { |
|
82 | + return []; |
|
83 | + } |
|
84 | + |
|
85 | + $principalArray = $this->getPrincipalByPath($principal); |
|
86 | + if (!$principalArray) { |
|
87 | + throw new Exception('Principal not found'); |
|
88 | + } |
|
89 | + |
|
90 | + $groups = []; |
|
91 | + $proxies = $this->proxyMapper->getProxiesFor($principal); |
|
92 | + foreach ($proxies as $proxy) { |
|
93 | + if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
|
94 | + $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
95 | + } |
|
96 | + |
|
97 | + if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
|
98 | + $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $groups; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Updates the list of group members for a group principal. |
|
107 | + * |
|
108 | + * The principals should be passed as a list of uri's. |
|
109 | + * |
|
110 | + * @param string $principal |
|
111 | + * @param string[] $members |
|
112 | + * @throws Exception |
|
113 | + */ |
|
114 | + public function setGroupMemberSet($principal, array $members) { |
|
115 | + list($principalUri, $target) = \Sabre\Uri\split($principal); |
|
116 | + |
|
117 | + if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') { |
|
118 | + throw new Exception('Setting members of the group is not supported yet'); |
|
119 | + } |
|
120 | + |
|
121 | + $masterPrincipalArray = $this->getPrincipalByPath($principalUri); |
|
122 | + if (!$masterPrincipalArray) { |
|
123 | + throw new Exception('Principal not found'); |
|
124 | + } |
|
125 | + |
|
126 | + $permission = ProxyMapper::PERMISSION_READ; |
|
127 | + if ($target === 'calendar-proxy-write') { |
|
128 | + $permission |= ProxyMapper::PERMISSION_WRITE; |
|
129 | + } |
|
130 | + |
|
131 | + list($prefix, $owner) = \Sabre\Uri\split($principalUri); |
|
132 | + $proxies = $this->proxyMapper->getProxiesOf($principalUri); |
|
133 | + |
|
134 | + foreach ($members as $member) { |
|
135 | + list($prefix, $name) = \Sabre\Uri\split($member); |
|
136 | + |
|
137 | + if ($prefix !== $this->principalPrefix) { |
|
138 | + throw new Exception('Invalid member group prefix: ' . $prefix); |
|
139 | + } |
|
140 | + |
|
141 | + $principalArray = $this->getPrincipalByPath($member); |
|
142 | + if (!$principalArray) { |
|
143 | + throw new Exception('Principal not found'); |
|
144 | + } |
|
145 | + |
|
146 | + $found = false; |
|
147 | + foreach ($proxies as $proxy) { |
|
148 | + if ($proxy->getProxyId() === $member) { |
|
149 | + $found = true; |
|
150 | + $proxy->setPermissions($proxy->getPermissions() | $permission); |
|
151 | + $this->proxyMapper->update($proxy); |
|
152 | + |
|
153 | + $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
154 | + return $p->getId() !== $proxy->getId(); |
|
155 | + }); |
|
156 | + break; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + if ($found === false) { |
|
161 | + $proxy = new Proxy(); |
|
162 | + $proxy->setOwnerId($principalUri); |
|
163 | + $proxy->setProxyId($member); |
|
164 | + $proxy->setPermissions($permission); |
|
165 | + $this->proxyMapper->insert($proxy); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + // Delete all remaining proxies |
|
170 | + foreach ($proxies as $proxy) { |
|
171 | + // Write and Read Proxies have individual requests, |
|
172 | + // so only delete proxies of this permission |
|
173 | + if ($proxy->getPermissions() === $permission) { |
|
174 | + $this->proxyMapper->delete($proxy); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @param string $principalUri |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + private function isProxyPrincipal(string $principalUri):bool { |
|
184 | + list($realPrincipalUri, $proxy) = \Sabre\Uri\split($principalUri); |
|
185 | + list($prefix, $userId) = \Sabre\Uri\split($realPrincipalUri); |
|
186 | + |
|
187 | + if (!isset($prefix) || !isset($userId)) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + if ($prefix !== $this->principalPrefix) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + |
|
194 | + return $proxy === 'calendar-proxy-read' |
|
195 | + || $proxy === 'calendar-proxy-write'; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $principalUri |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function isReadProxyPrincipal(string $principalUri):bool { |
|
204 | + list(, $proxy) = \Sabre\Uri\split($principalUri); |
|
205 | + return $proxy === 'calendar-proxy-read'; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string $principalUri |
|
210 | + * @return bool |
|
211 | + */ |
|
212 | + private function isWriteProxyPrincipal(string $principalUri):bool { |
|
213 | + list(, $proxy) = \Sabre\Uri\split($principalUri); |
|
214 | + return $proxy === 'calendar-proxy-write'; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @param string $principalUri |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function getPrincipalUriFromProxyPrincipal(string $principalUri):string { |
|
222 | + list($realPrincipalUri, ) = \Sabre\Uri\split($principalUri); |
|
223 | + return $realPrincipalUri; |
|
224 | + } |
|
225 | 225 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | $proxies = $this->proxyMapper->getProxiesFor($principal); |
92 | 92 | foreach ($proxies as $proxy) { |
93 | 93 | if ($proxy->getPermissions() === ProxyMapper::PERMISSION_READ) { |
94 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-read'; |
|
94 | + $groups[] = $proxy->getOwnerId().'/calendar-proxy-read'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | if ($proxy->getPermissions() === (ProxyMapper::PERMISSION_READ | ProxyMapper::PERMISSION_WRITE)) { |
98 | - $groups[] = $proxy->getOwnerId() . '/calendar-proxy-write'; |
|
98 | + $groups[] = $proxy->getOwnerId().'/calendar-proxy-write'; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | list($prefix, $name) = \Sabre\Uri\split($member); |
136 | 136 | |
137 | 137 | if ($prefix !== $this->principalPrefix) { |
138 | - throw new Exception('Invalid member group prefix: ' . $prefix); |
|
138 | + throw new Exception('Invalid member group prefix: '.$prefix); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $principalArray = $this->getPrincipalByPath($member); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $proxy->setPermissions($proxy->getPermissions() | $permission); |
151 | 151 | $this->proxyMapper->update($proxy); |
152 | 152 | |
153 | - $proxies = array_filter($proxies, function (Proxy $p) use ($proxy) { |
|
153 | + $proxies = array_filter($proxies, function(Proxy $p) use ($proxy) { |
|
154 | 154 | return $p->getId() !== $proxy->getId(); |
155 | 155 | }); |
156 | 156 | break; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @return string |
220 | 220 | */ |
221 | 221 | private function getPrincipalUriFromProxyPrincipal(string $principalUri):string { |
222 | - list($realPrincipalUri, ) = \Sabre\Uri\split($principalUri); |
|
222 | + list($realPrincipalUri,) = \Sabre\Uri\split($principalUri); |
|
223 | 223 | return $realPrincipalUri; |
224 | 224 | } |
225 | 225 | } |
@@ -36,164 +36,164 @@ discard block |
||
36 | 36 | |
37 | 37 | class AppleProvisioningPlugin extends ServerPlugin { |
38 | 38 | |
39 | - /** |
|
40 | - * @var Server |
|
41 | - */ |
|
42 | - protected $server; |
|
39 | + /** |
|
40 | + * @var Server |
|
41 | + */ |
|
42 | + protected $server; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var IURLGenerator |
|
46 | - */ |
|
47 | - protected $urlGenerator; |
|
44 | + /** |
|
45 | + * @var IURLGenerator |
|
46 | + */ |
|
47 | + protected $urlGenerator; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var IUserSession |
|
51 | - */ |
|
52 | - protected $userSession; |
|
49 | + /** |
|
50 | + * @var IUserSession |
|
51 | + */ |
|
52 | + protected $userSession; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @var \OC_Defaults |
|
56 | - */ |
|
57 | - protected $themingDefaults; |
|
54 | + /** |
|
55 | + * @var \OC_Defaults |
|
56 | + */ |
|
57 | + protected $themingDefaults; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @var IRequest |
|
61 | - */ |
|
62 | - protected $request; |
|
59 | + /** |
|
60 | + * @var IRequest |
|
61 | + */ |
|
62 | + protected $request; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @var IL10N |
|
66 | - */ |
|
67 | - protected $l10n; |
|
64 | + /** |
|
65 | + * @var IL10N |
|
66 | + */ |
|
67 | + protected $l10n; |
|
68 | 68 | |
69 | - /** |
|
70 | - * @var \closure |
|
71 | - */ |
|
72 | - protected $uuidClosure; |
|
69 | + /** |
|
70 | + * @var \closure |
|
71 | + */ |
|
72 | + protected $uuidClosure; |
|
73 | 73 | |
74 | - /** |
|
75 | - * AppleProvisioningPlugin constructor. |
|
76 | - * |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param IURLGenerator $urlGenerator |
|
79 | - * @param \OC_Defaults $themingDefaults |
|
80 | - * @param IRequest $request |
|
81 | - * @param IL10N $l10n |
|
82 | - * @param \closure $uuidClosure |
|
83 | - */ |
|
84 | - public function __construct(IUserSession $userSession, IURLGenerator $urlGenerator, |
|
85 | - \OC_Defaults $themingDefaults, IRequest $request, |
|
86 | - IL10N $l10n, \closure $uuidClosure) { |
|
87 | - $this->userSession = $userSession; |
|
88 | - $this->urlGenerator = $urlGenerator; |
|
89 | - $this->themingDefaults = $themingDefaults; |
|
90 | - $this->request = $request; |
|
91 | - $this->l10n = $l10n; |
|
92 | - $this->uuidClosure = $uuidClosure; |
|
93 | - } |
|
74 | + /** |
|
75 | + * AppleProvisioningPlugin constructor. |
|
76 | + * |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param IURLGenerator $urlGenerator |
|
79 | + * @param \OC_Defaults $themingDefaults |
|
80 | + * @param IRequest $request |
|
81 | + * @param IL10N $l10n |
|
82 | + * @param \closure $uuidClosure |
|
83 | + */ |
|
84 | + public function __construct(IUserSession $userSession, IURLGenerator $urlGenerator, |
|
85 | + \OC_Defaults $themingDefaults, IRequest $request, |
|
86 | + IL10N $l10n, \closure $uuidClosure) { |
|
87 | + $this->userSession = $userSession; |
|
88 | + $this->urlGenerator = $urlGenerator; |
|
89 | + $this->themingDefaults = $themingDefaults; |
|
90 | + $this->request = $request; |
|
91 | + $this->l10n = $l10n; |
|
92 | + $this->uuidClosure = $uuidClosure; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param Server $server |
|
97 | - */ |
|
98 | - public function initialize(Server $server) { |
|
99 | - $this->server = $server; |
|
100 | - $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
101 | - } |
|
95 | + /** |
|
96 | + * @param Server $server |
|
97 | + */ |
|
98 | + public function initialize(Server $server) { |
|
99 | + $this->server = $server; |
|
100 | + $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param RequestInterface $request |
|
105 | - * @param ResponseInterface $response |
|
106 | - * @return boolean |
|
107 | - */ |
|
108 | - public function httpGet(RequestInterface $request, ResponseInterface $response):bool { |
|
109 | - if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) { |
|
110 | - return true; |
|
111 | - } |
|
103 | + /** |
|
104 | + * @param RequestInterface $request |
|
105 | + * @param ResponseInterface $response |
|
106 | + * @return boolean |
|
107 | + */ |
|
108 | + public function httpGet(RequestInterface $request, ResponseInterface $response):bool { |
|
109 | + if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) { |
|
110 | + return true; |
|
111 | + } |
|
112 | 112 | |
113 | - $user = $this->userSession->getUser(); |
|
114 | - if (!$user) { |
|
115 | - return true; |
|
116 | - } |
|
113 | + $user = $this->userSession->getUser(); |
|
114 | + if (!$user) { |
|
115 | + return true; |
|
116 | + } |
|
117 | 117 | |
118 | - $serverProtocol = $this->request->getServerProtocol(); |
|
119 | - $useSSL = ($serverProtocol === 'https'); |
|
118 | + $serverProtocol = $this->request->getServerProtocol(); |
|
119 | + $useSSL = ($serverProtocol === 'https'); |
|
120 | 120 | |
121 | - if (!$useSSL) { |
|
122 | - $response->setStatus(200); |
|
123 | - $response->setHeader('Content-Type', 'text/plain; charset=utf-8'); |
|
124 | - $response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()])); |
|
121 | + if (!$useSSL) { |
|
122 | + $response->setStatus(200); |
|
123 | + $response->setHeader('Content-Type', 'text/plain; charset=utf-8'); |
|
124 | + $response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()])); |
|
125 | 125 | |
126 | - return false; |
|
127 | - } |
|
126 | + return false; |
|
127 | + } |
|
128 | 128 | |
129 | - $absoluteURL = $this->urlGenerator->getBaseUrl(); |
|
130 | - $parsedUrl = parse_url($absoluteURL); |
|
131 | - if (isset($parsedUrl['port'])) { |
|
132 | - $serverPort = (int) $parsedUrl['port']; |
|
133 | - } else { |
|
134 | - $serverPort = 443; |
|
135 | - } |
|
136 | - $server_url = $parsedUrl['host']; |
|
129 | + $absoluteURL = $this->urlGenerator->getBaseUrl(); |
|
130 | + $parsedUrl = parse_url($absoluteURL); |
|
131 | + if (isset($parsedUrl['port'])) { |
|
132 | + $serverPort = (int) $parsedUrl['port']; |
|
133 | + } else { |
|
134 | + $serverPort = 443; |
|
135 | + } |
|
136 | + $server_url = $parsedUrl['host']; |
|
137 | 137 | |
138 | - $description = $this->themingDefaults->getName(); |
|
139 | - $userId = $user->getUID(); |
|
138 | + $description = $this->themingDefaults->getName(); |
|
139 | + $userId = $user->getUID(); |
|
140 | 140 | |
141 | - $reverseDomain = implode('.', array_reverse(explode('.', $parsedUrl['host']))); |
|
141 | + $reverseDomain = implode('.', array_reverse(explode('.', $parsedUrl['host']))); |
|
142 | 142 | |
143 | - $caldavUUID = call_user_func($this->uuidClosure); |
|
144 | - $carddavUUID = call_user_func($this->uuidClosure); |
|
145 | - $profileUUID = call_user_func($this->uuidClosure); |
|
143 | + $caldavUUID = call_user_func($this->uuidClosure); |
|
144 | + $carddavUUID = call_user_func($this->uuidClosure); |
|
145 | + $profileUUID = call_user_func($this->uuidClosure); |
|
146 | 146 | |
147 | - $caldavIdentifier = $reverseDomain . '.' . $caldavUUID; |
|
148 | - $carddavIdentifier = $reverseDomain . '.' . $carddavUUID; |
|
149 | - $profileIdentifier = $reverseDomain . '.' . $profileUUID; |
|
147 | + $caldavIdentifier = $reverseDomain . '.' . $caldavUUID; |
|
148 | + $carddavIdentifier = $reverseDomain . '.' . $carddavUUID; |
|
149 | + $profileIdentifier = $reverseDomain . '.' . $profileUUID; |
|
150 | 150 | |
151 | - $caldavDescription = $this->l10n->t('Configures a CalDAV account'); |
|
152 | - $caldavDisplayname = $description . ' CalDAV'; |
|
153 | - $carddavDescription = $this->l10n->t('Configures a CardDAV account'); |
|
154 | - $carddavDisplayname = $description . ' CardDAV'; |
|
151 | + $caldavDescription = $this->l10n->t('Configures a CalDAV account'); |
|
152 | + $caldavDisplayname = $description . ' CalDAV'; |
|
153 | + $carddavDescription = $this->l10n->t('Configures a CardDAV account'); |
|
154 | + $carddavDisplayname = $description . ' CardDAV'; |
|
155 | 155 | |
156 | - $filename = $userId . '-' . AppleProvisioningNode::FILENAME; |
|
156 | + $filename = $userId . '-' . AppleProvisioningNode::FILENAME; |
|
157 | 157 | |
158 | - $xmlSkeleton = $this->getTemplate(); |
|
159 | - $body = vsprintf($xmlSkeleton, array_map(function ($v) { |
|
160 | - return \htmlspecialchars($v, ENT_XML1, 'UTF-8'); |
|
161 | - }, [ |
|
162 | - $description, |
|
163 | - $server_url, |
|
164 | - $userId, |
|
165 | - $serverPort, |
|
166 | - $caldavDescription, |
|
167 | - $caldavDisplayname, |
|
168 | - $caldavIdentifier, |
|
169 | - $caldavUUID, |
|
170 | - $description, |
|
171 | - $server_url, |
|
172 | - $userId, |
|
173 | - $serverPort, |
|
174 | - $carddavDescription, |
|
175 | - $carddavDisplayname, |
|
176 | - $carddavIdentifier, |
|
177 | - $carddavUUID, |
|
178 | - $description, |
|
179 | - $profileIdentifier, |
|
180 | - $profileUUID |
|
181 | - ] |
|
182 | - )); |
|
158 | + $xmlSkeleton = $this->getTemplate(); |
|
159 | + $body = vsprintf($xmlSkeleton, array_map(function ($v) { |
|
160 | + return \htmlspecialchars($v, ENT_XML1, 'UTF-8'); |
|
161 | + }, [ |
|
162 | + $description, |
|
163 | + $server_url, |
|
164 | + $userId, |
|
165 | + $serverPort, |
|
166 | + $caldavDescription, |
|
167 | + $caldavDisplayname, |
|
168 | + $caldavIdentifier, |
|
169 | + $caldavUUID, |
|
170 | + $description, |
|
171 | + $server_url, |
|
172 | + $userId, |
|
173 | + $serverPort, |
|
174 | + $carddavDescription, |
|
175 | + $carddavDisplayname, |
|
176 | + $carddavIdentifier, |
|
177 | + $carddavUUID, |
|
178 | + $description, |
|
179 | + $profileIdentifier, |
|
180 | + $profileUUID |
|
181 | + ] |
|
182 | + )); |
|
183 | 183 | |
184 | - $response->setStatus(200); |
|
185 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); |
|
186 | - $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
187 | - $response->setBody($body); |
|
184 | + $response->setStatus(200); |
|
185 | + $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); |
|
186 | + $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
187 | + $response->setBody($body); |
|
188 | 188 | |
189 | - return false; |
|
190 | - } |
|
189 | + return false; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - private function getTemplate():string { |
|
196 | - return <<<EOF |
|
192 | + /** |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + private function getTemplate():string { |
|
196 | + return <<<EOF |
|
197 | 197 | <?xml version="1.0" encoding="UTF-8"?> |
198 | 198 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
199 | 199 | <plist version="1.0"> |
@@ -265,5 +265,5 @@ discard block |
||
265 | 265 | </plist> |
266 | 266 | |
267 | 267 | EOF; |
268 | - } |
|
268 | + } |
|
269 | 269 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return boolean |
107 | 107 | */ |
108 | 108 | public function httpGet(RequestInterface $request, ResponseInterface $response):bool { |
109 | - if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) { |
|
109 | + if ($request->getPath() !== 'provisioning/'.AppleProvisioningNode::FILENAME) { |
|
110 | 110 | return true; |
111 | 111 | } |
112 | 112 | |
@@ -144,19 +144,19 @@ discard block |
||
144 | 144 | $carddavUUID = call_user_func($this->uuidClosure); |
145 | 145 | $profileUUID = call_user_func($this->uuidClosure); |
146 | 146 | |
147 | - $caldavIdentifier = $reverseDomain . '.' . $caldavUUID; |
|
148 | - $carddavIdentifier = $reverseDomain . '.' . $carddavUUID; |
|
149 | - $profileIdentifier = $reverseDomain . '.' . $profileUUID; |
|
147 | + $caldavIdentifier = $reverseDomain.'.'.$caldavUUID; |
|
148 | + $carddavIdentifier = $reverseDomain.'.'.$carddavUUID; |
|
149 | + $profileIdentifier = $reverseDomain.'.'.$profileUUID; |
|
150 | 150 | |
151 | 151 | $caldavDescription = $this->l10n->t('Configures a CalDAV account'); |
152 | - $caldavDisplayname = $description . ' CalDAV'; |
|
152 | + $caldavDisplayname = $description.' CalDAV'; |
|
153 | 153 | $carddavDescription = $this->l10n->t('Configures a CardDAV account'); |
154 | - $carddavDisplayname = $description . ' CardDAV'; |
|
154 | + $carddavDisplayname = $description.' CardDAV'; |
|
155 | 155 | |
156 | - $filename = $userId . '-' . AppleProvisioningNode::FILENAME; |
|
156 | + $filename = $userId.'-'.AppleProvisioningNode::FILENAME; |
|
157 | 157 | |
158 | 158 | $xmlSkeleton = $this->getTemplate(); |
159 | - $body = vsprintf($xmlSkeleton, array_map(function ($v) { |
|
159 | + $body = vsprintf($xmlSkeleton, array_map(function($v) { |
|
160 | 160 | return \htmlspecialchars($v, ENT_XML1, 'UTF-8'); |
161 | 161 | }, [ |
162 | 162 | $description, |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | )); |
183 | 183 | |
184 | 184 | $response->setStatus(200); |
185 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); |
|
185 | + $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); |
|
186 | 186 | $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
187 | 187 | $response->setBody($body); |
188 | 188 |
@@ -48,272 +48,272 @@ |
||
48 | 48 | |
49 | 49 | class GroupsController extends AUserData { |
50 | 50 | |
51 | - /** @var ILogger */ |
|
52 | - private $logger; |
|
51 | + /** @var ILogger */ |
|
52 | + private $logger; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $appName |
|
56 | - * @param IRequest $request |
|
57 | - * @param IUserManager $userManager |
|
58 | - * @param IConfig $config |
|
59 | - * @param IGroupManager $groupManager |
|
60 | - * @param IUserSession $userSession |
|
61 | - * @param AccountManager $accountManager |
|
62 | - * @param ILogger $logger |
|
63 | - * @param UsersController $userController |
|
64 | - */ |
|
65 | - public function __construct(string $appName, |
|
66 | - IRequest $request, |
|
67 | - IUserManager $userManager, |
|
68 | - IConfig $config, |
|
69 | - IGroupManager $groupManager, |
|
70 | - IUserSession $userSession, |
|
71 | - AccountManager $accountManager, |
|
72 | - ILogger $logger) { |
|
73 | - parent::__construct($appName, |
|
74 | - $request, |
|
75 | - $userManager, |
|
76 | - $config, |
|
77 | - $groupManager, |
|
78 | - $userSession, |
|
79 | - $accountManager); |
|
54 | + /** |
|
55 | + * @param string $appName |
|
56 | + * @param IRequest $request |
|
57 | + * @param IUserManager $userManager |
|
58 | + * @param IConfig $config |
|
59 | + * @param IGroupManager $groupManager |
|
60 | + * @param IUserSession $userSession |
|
61 | + * @param AccountManager $accountManager |
|
62 | + * @param ILogger $logger |
|
63 | + * @param UsersController $userController |
|
64 | + */ |
|
65 | + public function __construct(string $appName, |
|
66 | + IRequest $request, |
|
67 | + IUserManager $userManager, |
|
68 | + IConfig $config, |
|
69 | + IGroupManager $groupManager, |
|
70 | + IUserSession $userSession, |
|
71 | + AccountManager $accountManager, |
|
72 | + ILogger $logger) { |
|
73 | + parent::__construct($appName, |
|
74 | + $request, |
|
75 | + $userManager, |
|
76 | + $config, |
|
77 | + $groupManager, |
|
78 | + $userSession, |
|
79 | + $accountManager); |
|
80 | 80 | |
81 | - $this->logger = $logger; |
|
82 | - } |
|
81 | + $this->logger = $logger; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * returns a list of groups |
|
86 | - * |
|
87 | - * @NoAdminRequired |
|
88 | - * |
|
89 | - * @param string $search |
|
90 | - * @param int $limit |
|
91 | - * @param int $offset |
|
92 | - * @return DataResponse |
|
93 | - */ |
|
94 | - public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
95 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
96 | - $groups = array_map(function ($group) { |
|
97 | - /** @var IGroup $group */ |
|
98 | - return $group->getGID(); |
|
99 | - }, $groups); |
|
84 | + /** |
|
85 | + * returns a list of groups |
|
86 | + * |
|
87 | + * @NoAdminRequired |
|
88 | + * |
|
89 | + * @param string $search |
|
90 | + * @param int $limit |
|
91 | + * @param int $offset |
|
92 | + * @return DataResponse |
|
93 | + */ |
|
94 | + public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
95 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
96 | + $groups = array_map(function ($group) { |
|
97 | + /** @var IGroup $group */ |
|
98 | + return $group->getGID(); |
|
99 | + }, $groups); |
|
100 | 100 | |
101 | - return new DataResponse(['groups' => $groups]); |
|
102 | - } |
|
101 | + return new DataResponse(['groups' => $groups]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * returns a list of groups details with ids and displaynames |
|
106 | - * |
|
107 | - * @NoAdminRequired |
|
108 | - * |
|
109 | - * @param string $search |
|
110 | - * @param int $limit |
|
111 | - * @param int $offset |
|
112 | - * @return DataResponse |
|
113 | - */ |
|
114 | - public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
115 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
116 | - $groups = array_map(function ($group) { |
|
117 | - /** @var IGroup $group */ |
|
118 | - return [ |
|
119 | - 'id' => $group->getGID(), |
|
120 | - 'displayname' => $group->getDisplayName(), |
|
121 | - 'usercount' => $group->count(), |
|
122 | - 'disabled' => $group->countDisabled(), |
|
123 | - 'canAdd' => $group->canAddUser(), |
|
124 | - 'canRemove' => $group->canRemoveUser(), |
|
125 | - ]; |
|
126 | - }, $groups); |
|
104 | + /** |
|
105 | + * returns a list of groups details with ids and displaynames |
|
106 | + * |
|
107 | + * @NoAdminRequired |
|
108 | + * |
|
109 | + * @param string $search |
|
110 | + * @param int $limit |
|
111 | + * @param int $offset |
|
112 | + * @return DataResponse |
|
113 | + */ |
|
114 | + public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
115 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
116 | + $groups = array_map(function ($group) { |
|
117 | + /** @var IGroup $group */ |
|
118 | + return [ |
|
119 | + 'id' => $group->getGID(), |
|
120 | + 'displayname' => $group->getDisplayName(), |
|
121 | + 'usercount' => $group->count(), |
|
122 | + 'disabled' => $group->countDisabled(), |
|
123 | + 'canAdd' => $group->canAddUser(), |
|
124 | + 'canRemove' => $group->canRemoveUser(), |
|
125 | + ]; |
|
126 | + }, $groups); |
|
127 | 127 | |
128 | - return new DataResponse(['groups' => $groups]); |
|
129 | - } |
|
128 | + return new DataResponse(['groups' => $groups]); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @NoAdminRequired |
|
133 | - * |
|
134 | - * @param string $groupId |
|
135 | - * @return DataResponse |
|
136 | - * @throws OCSException |
|
137 | - * |
|
138 | - * @deprecated 14 Use getGroupUsers |
|
139 | - */ |
|
140 | - public function getGroup(string $groupId): DataResponse { |
|
141 | - return $this->getGroupUsers($groupId); |
|
142 | - } |
|
131 | + /** |
|
132 | + * @NoAdminRequired |
|
133 | + * |
|
134 | + * @param string $groupId |
|
135 | + * @return DataResponse |
|
136 | + * @throws OCSException |
|
137 | + * |
|
138 | + * @deprecated 14 Use getGroupUsers |
|
139 | + */ |
|
140 | + public function getGroup(string $groupId): DataResponse { |
|
141 | + return $this->getGroupUsers($groupId); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * returns an array of users in the specified group |
|
146 | - * |
|
147 | - * @NoAdminRequired |
|
148 | - * |
|
149 | - * @param string $groupId |
|
150 | - * @return DataResponse |
|
151 | - * @throws OCSException |
|
152 | - */ |
|
153 | - public function getGroupUsers(string $groupId): DataResponse { |
|
154 | - $user = $this->userSession->getUser(); |
|
155 | - $isSubadminOfGroup = false; |
|
144 | + /** |
|
145 | + * returns an array of users in the specified group |
|
146 | + * |
|
147 | + * @NoAdminRequired |
|
148 | + * |
|
149 | + * @param string $groupId |
|
150 | + * @return DataResponse |
|
151 | + * @throws OCSException |
|
152 | + */ |
|
153 | + public function getGroupUsers(string $groupId): DataResponse { |
|
154 | + $user = $this->userSession->getUser(); |
|
155 | + $isSubadminOfGroup = false; |
|
156 | 156 | |
157 | - // Check the group exists |
|
158 | - $group = $this->groupManager->get($groupId); |
|
159 | - if ($group !== null) { |
|
160 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
161 | - } else { |
|
162 | - throw new OCSNotFoundException('The requested group could not be found'); |
|
163 | - } |
|
157 | + // Check the group exists |
|
158 | + $group = $this->groupManager->get($groupId); |
|
159 | + if ($group !== null) { |
|
160 | + $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
161 | + } else { |
|
162 | + throw new OCSNotFoundException('The requested group could not be found'); |
|
163 | + } |
|
164 | 164 | |
165 | - // Check subadmin has access to this group |
|
166 | - if($this->groupManager->isAdmin($user->getUID()) |
|
167 | - || $isSubadminOfGroup) { |
|
168 | - $users = $this->groupManager->get($groupId)->getUsers(); |
|
169 | - $users = array_map(function ($user) { |
|
170 | - /** @var IUser $user */ |
|
171 | - return $user->getUID(); |
|
172 | - }, $users); |
|
173 | - $users = array_values($users); |
|
174 | - return new DataResponse(['users' => $users]); |
|
175 | - } |
|
165 | + // Check subadmin has access to this group |
|
166 | + if($this->groupManager->isAdmin($user->getUID()) |
|
167 | + || $isSubadminOfGroup) { |
|
168 | + $users = $this->groupManager->get($groupId)->getUsers(); |
|
169 | + $users = array_map(function ($user) { |
|
170 | + /** @var IUser $user */ |
|
171 | + return $user->getUID(); |
|
172 | + }, $users); |
|
173 | + $users = array_values($users); |
|
174 | + return new DataResponse(['users' => $users]); |
|
175 | + } |
|
176 | 176 | |
177 | - throw new OCSForbiddenException(); |
|
178 | - } |
|
177 | + throw new OCSForbiddenException(); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * returns an array of users details in the specified group |
|
182 | - * |
|
183 | - * @NoAdminRequired |
|
184 | - * |
|
185 | - * @param string $groupId |
|
186 | - * @param string $search |
|
187 | - * @param int $limit |
|
188 | - * @param int $offset |
|
189 | - * @return DataResponse |
|
190 | - * @throws OCSException |
|
191 | - */ |
|
192 | - public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
193 | - $currentUser = $this->userSession->getUser(); |
|
180 | + /** |
|
181 | + * returns an array of users details in the specified group |
|
182 | + * |
|
183 | + * @NoAdminRequired |
|
184 | + * |
|
185 | + * @param string $groupId |
|
186 | + * @param string $search |
|
187 | + * @param int $limit |
|
188 | + * @param int $offset |
|
189 | + * @return DataResponse |
|
190 | + * @throws OCSException |
|
191 | + */ |
|
192 | + public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
193 | + $currentUser = $this->userSession->getUser(); |
|
194 | 194 | |
195 | - // Check the group exists |
|
196 | - $group = $this->groupManager->get($groupId); |
|
197 | - if ($group !== null) { |
|
198 | - $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); |
|
199 | - } else { |
|
200 | - throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
201 | - } |
|
195 | + // Check the group exists |
|
196 | + $group = $this->groupManager->get($groupId); |
|
197 | + if ($group !== null) { |
|
198 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($currentUser, $group); |
|
199 | + } else { |
|
200 | + throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
201 | + } |
|
202 | 202 | |
203 | - // Check subadmin has access to this group |
|
204 | - if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
205 | - $users = $group->searchUsers($search, $limit, $offset); |
|
203 | + // Check subadmin has access to this group |
|
204 | + if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
205 | + $users = $group->searchUsers($search, $limit, $offset); |
|
206 | 206 | |
207 | - // Extract required number |
|
208 | - $usersDetails = []; |
|
209 | - foreach ($users as $user) { |
|
210 | - try { |
|
211 | - /** @var IUser $user */ |
|
212 | - $userId = (string)$user->getUID(); |
|
213 | - $userData = $this->getUserData($userId); |
|
214 | - // Do not insert empty entry |
|
215 | - if (!empty($userData)) { |
|
216 | - $usersDetails[$userId] = $userData; |
|
217 | - } else { |
|
218 | - // Logged user does not have permissions to see this user |
|
219 | - // only showing its id |
|
220 | - $usersDetails[$userId] = ['id' => $userId]; |
|
221 | - } |
|
222 | - } catch(OCSNotFoundException $e) { |
|
223 | - // continue if a users ceased to exist. |
|
224 | - } |
|
225 | - } |
|
226 | - return new DataResponse(['users' => $usersDetails]); |
|
227 | - } |
|
207 | + // Extract required number |
|
208 | + $usersDetails = []; |
|
209 | + foreach ($users as $user) { |
|
210 | + try { |
|
211 | + /** @var IUser $user */ |
|
212 | + $userId = (string)$user->getUID(); |
|
213 | + $userData = $this->getUserData($userId); |
|
214 | + // Do not insert empty entry |
|
215 | + if (!empty($userData)) { |
|
216 | + $usersDetails[$userId] = $userData; |
|
217 | + } else { |
|
218 | + // Logged user does not have permissions to see this user |
|
219 | + // only showing its id |
|
220 | + $usersDetails[$userId] = ['id' => $userId]; |
|
221 | + } |
|
222 | + } catch(OCSNotFoundException $e) { |
|
223 | + // continue if a users ceased to exist. |
|
224 | + } |
|
225 | + } |
|
226 | + return new DataResponse(['users' => $usersDetails]); |
|
227 | + } |
|
228 | 228 | |
229 | - throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
230 | - } |
|
229 | + throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * creates a new group |
|
234 | - * |
|
235 | - * @PasswordConfirmationRequired |
|
236 | - * |
|
237 | - * @param string $groupid |
|
238 | - * @return DataResponse |
|
239 | - * @throws OCSException |
|
240 | - */ |
|
241 | - public function addGroup(string $groupid): DataResponse { |
|
242 | - // Validate name |
|
243 | - if(empty($groupid)) { |
|
244 | - $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
245 | - throw new OCSException('Invalid group name', 101); |
|
246 | - } |
|
247 | - // Check if it exists |
|
248 | - if($this->groupManager->groupExists($groupid)){ |
|
249 | - throw new OCSException('group exists', 102); |
|
250 | - } |
|
251 | - $this->groupManager->createGroup($groupid); |
|
252 | - return new DataResponse(); |
|
253 | - } |
|
232 | + /** |
|
233 | + * creates a new group |
|
234 | + * |
|
235 | + * @PasswordConfirmationRequired |
|
236 | + * |
|
237 | + * @param string $groupid |
|
238 | + * @return DataResponse |
|
239 | + * @throws OCSException |
|
240 | + */ |
|
241 | + public function addGroup(string $groupid): DataResponse { |
|
242 | + // Validate name |
|
243 | + if(empty($groupid)) { |
|
244 | + $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
245 | + throw new OCSException('Invalid group name', 101); |
|
246 | + } |
|
247 | + // Check if it exists |
|
248 | + if($this->groupManager->groupExists($groupid)){ |
|
249 | + throw new OCSException('group exists', 102); |
|
250 | + } |
|
251 | + $this->groupManager->createGroup($groupid); |
|
252 | + return new DataResponse(); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @PasswordConfirmationRequired |
|
257 | - * |
|
258 | - * @param string $groupId |
|
259 | - * @param string $key |
|
260 | - * @param string $value |
|
261 | - * @return DataResponse |
|
262 | - * @throws OCSException |
|
263 | - */ |
|
264 | - public function updateGroup(string $groupId, string $key, string $value): DataResponse { |
|
265 | - if ($key === 'displayname') { |
|
266 | - $group = $this->groupManager->get($groupId); |
|
267 | - if ($group->setDisplayName($value)) { |
|
268 | - return new DataResponse(); |
|
269 | - } |
|
255 | + /** |
|
256 | + * @PasswordConfirmationRequired |
|
257 | + * |
|
258 | + * @param string $groupId |
|
259 | + * @param string $key |
|
260 | + * @param string $value |
|
261 | + * @return DataResponse |
|
262 | + * @throws OCSException |
|
263 | + */ |
|
264 | + public function updateGroup(string $groupId, string $key, string $value): DataResponse { |
|
265 | + if ($key === 'displayname') { |
|
266 | + $group = $this->groupManager->get($groupId); |
|
267 | + if ($group->setDisplayName($value)) { |
|
268 | + return new DataResponse(); |
|
269 | + } |
|
270 | 270 | |
271 | - throw new OCSException('Not supported by backend', 101); |
|
272 | - } else { |
|
273 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
274 | - } |
|
275 | - } |
|
271 | + throw new OCSException('Not supported by backend', 101); |
|
272 | + } else { |
|
273 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @PasswordConfirmationRequired |
|
279 | - * |
|
280 | - * @param string $groupId |
|
281 | - * @return DataResponse |
|
282 | - * @throws OCSException |
|
283 | - */ |
|
284 | - public function deleteGroup(string $groupId): DataResponse { |
|
285 | - // Check it exists |
|
286 | - if(!$this->groupManager->groupExists($groupId)){ |
|
287 | - throw new OCSException('', 101); |
|
288 | - } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
289 | - // Cannot delete admin group |
|
290 | - throw new OCSException('', 102); |
|
291 | - } |
|
277 | + /** |
|
278 | + * @PasswordConfirmationRequired |
|
279 | + * |
|
280 | + * @param string $groupId |
|
281 | + * @return DataResponse |
|
282 | + * @throws OCSException |
|
283 | + */ |
|
284 | + public function deleteGroup(string $groupId): DataResponse { |
|
285 | + // Check it exists |
|
286 | + if(!$this->groupManager->groupExists($groupId)){ |
|
287 | + throw new OCSException('', 101); |
|
288 | + } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
289 | + // Cannot delete admin group |
|
290 | + throw new OCSException('', 102); |
|
291 | + } |
|
292 | 292 | |
293 | - return new DataResponse(); |
|
294 | - } |
|
293 | + return new DataResponse(); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * @param string $groupId |
|
298 | - * @return DataResponse |
|
299 | - * @throws OCSException |
|
300 | - */ |
|
301 | - public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
302 | - // Check group exists |
|
303 | - $targetGroup = $this->groupManager->get($groupId); |
|
304 | - if($targetGroup === null) { |
|
305 | - throw new OCSException('Group does not exist', 101); |
|
306 | - } |
|
296 | + /** |
|
297 | + * @param string $groupId |
|
298 | + * @return DataResponse |
|
299 | + * @throws OCSException |
|
300 | + */ |
|
301 | + public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
302 | + // Check group exists |
|
303 | + $targetGroup = $this->groupManager->get($groupId); |
|
304 | + if($targetGroup === null) { |
|
305 | + throw new OCSException('Group does not exist', 101); |
|
306 | + } |
|
307 | 307 | |
308 | - /** @var IUser[] $subadmins */ |
|
309 | - $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
310 | - // New class returns IUser[] so convert back |
|
311 | - $uids = []; |
|
312 | - foreach ($subadmins as $user) { |
|
313 | - $uids[] = $user->getUID(); |
|
314 | - } |
|
308 | + /** @var IUser[] $subadmins */ |
|
309 | + $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
310 | + // New class returns IUser[] so convert back |
|
311 | + $uids = []; |
|
312 | + foreach ($subadmins as $user) { |
|
313 | + $uids[] = $user->getUID(); |
|
314 | + } |
|
315 | 315 | |
316 | - return new DataResponse($uids); |
|
317 | - } |
|
316 | + return new DataResponse($uids); |
|
317 | + } |
|
318 | 318 | |
319 | 319 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
95 | 95 | $groups = $this->groupManager->search($search, $limit, $offset); |
96 | - $groups = array_map(function ($group) { |
|
96 | + $groups = array_map(function($group) { |
|
97 | 97 | /** @var IGroup $group */ |
98 | 98 | return $group->getGID(); |
99 | 99 | }, $groups); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
115 | 115 | $groups = $this->groupManager->search($search, $limit, $offset); |
116 | - $groups = array_map(function ($group) { |
|
116 | + $groups = array_map(function($group) { |
|
117 | 117 | /** @var IGroup $group */ |
118 | 118 | return [ |
119 | 119 | 'id' => $group->getGID(), |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | // Check the group exists |
158 | 158 | $group = $this->groupManager->get($groupId); |
159 | 159 | if ($group !== null) { |
160 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
160 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
161 | 161 | } else { |
162 | 162 | throw new OCSNotFoundException('The requested group could not be found'); |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Check subadmin has access to this group |
166 | - if($this->groupManager->isAdmin($user->getUID()) |
|
166 | + if ($this->groupManager->isAdmin($user->getUID()) |
|
167 | 167 | || $isSubadminOfGroup) { |
168 | 168 | $users = $this->groupManager->get($groupId)->getUsers(); |
169 | - $users = array_map(function ($user) { |
|
169 | + $users = array_map(function($user) { |
|
170 | 170 | /** @var IUser $user */ |
171 | 171 | return $user->getUID(); |
172 | 172 | }, $users); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | // Check subadmin has access to this group |
204 | - if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
204 | + if ($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { |
|
205 | 205 | $users = $group->searchUsers($search, $limit, $offset); |
206 | 206 | |
207 | 207 | // Extract required number |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | foreach ($users as $user) { |
210 | 210 | try { |
211 | 211 | /** @var IUser $user */ |
212 | - $userId = (string)$user->getUID(); |
|
212 | + $userId = (string) $user->getUID(); |
|
213 | 213 | $userData = $this->getUserData($userId); |
214 | 214 | // Do not insert empty entry |
215 | 215 | if (!empty($userData)) { |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | // only showing its id |
220 | 220 | $usersDetails[$userId] = ['id' => $userId]; |
221 | 221 | } |
222 | - } catch(OCSNotFoundException $e) { |
|
222 | + } catch (OCSNotFoundException $e) { |
|
223 | 223 | // continue if a users ceased to exist. |
224 | 224 | } |
225 | 225 | } |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function addGroup(string $groupid): DataResponse { |
242 | 242 | // Validate name |
243 | - if(empty($groupid)) { |
|
243 | + if (empty($groupid)) { |
|
244 | 244 | $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
245 | 245 | throw new OCSException('Invalid group name', 101); |
246 | 246 | } |
247 | 247 | // Check if it exists |
248 | - if($this->groupManager->groupExists($groupid)){ |
|
248 | + if ($this->groupManager->groupExists($groupid)) { |
|
249 | 249 | throw new OCSException('group exists', 102); |
250 | 250 | } |
251 | 251 | $this->groupManager->createGroup($groupid); |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function deleteGroup(string $groupId): DataResponse { |
285 | 285 | // Check it exists |
286 | - if(!$this->groupManager->groupExists($groupId)){ |
|
286 | + if (!$this->groupManager->groupExists($groupId)) { |
|
287 | 287 | throw new OCSException('', 101); |
288 | - } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
288 | + } else if ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) { |
|
289 | 289 | // Cannot delete admin group |
290 | 290 | throw new OCSException('', 102); |
291 | 291 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | public function getSubAdminsOfGroup(string $groupId): DataResponse { |
302 | 302 | // Check group exists |
303 | 303 | $targetGroup = $this->groupManager->get($groupId); |
304 | - if($targetGroup === null) { |
|
304 | + if ($targetGroup === null) { |
|
305 | 305 | throw new OCSException('Group does not exist', 101); |
306 | 306 | } |
307 | 307 |
@@ -43,55 +43,55 @@ |
||
43 | 43 | |
44 | 44 | class Application extends App { |
45 | 45 | |
46 | - const APP_ID = 'comments'; |
|
46 | + const APP_ID = 'comments'; |
|
47 | 47 | |
48 | - public function __construct(array $urlParams = []) { |
|
49 | - parent::__construct(self::APP_ID, $urlParams); |
|
50 | - $container = $this->getContainer(); |
|
48 | + public function __construct(array $urlParams = []) { |
|
49 | + parent::__construct(self::APP_ID, $urlParams); |
|
50 | + $container = $this->getContainer(); |
|
51 | 51 | |
52 | - $container->registerAlias('NotificationsController', Notifications::class); |
|
52 | + $container->registerAlias('NotificationsController', Notifications::class); |
|
53 | 53 | |
54 | - $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
55 | - Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
54 | + $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
55 | + Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
56 | 56 | |
57 | - $this->register(); |
|
58 | - } |
|
57 | + $this->register(); |
|
58 | + } |
|
59 | 59 | |
60 | - private function register() { |
|
61 | - $server = $this->getContainer()->getServer(); |
|
60 | + private function register() { |
|
61 | + $server = $this->getContainer()->getServer(); |
|
62 | 62 | |
63 | - /** @var IEventDispatcher $newDispatcher */ |
|
64 | - $dispatcher = $server->query(IEventDispatcher::class); |
|
63 | + /** @var IEventDispatcher $newDispatcher */ |
|
64 | + $dispatcher = $server->query(IEventDispatcher::class); |
|
65 | 65 | |
66 | - $this->registerEventsScripts($dispatcher); |
|
67 | - $this->registerDavEntity($dispatcher); |
|
68 | - $this->registerNotifier(); |
|
69 | - $this->registerCommentsEventHandler(); |
|
66 | + $this->registerEventsScripts($dispatcher); |
|
67 | + $this->registerDavEntity($dispatcher); |
|
68 | + $this->registerNotifier(); |
|
69 | + $this->registerCommentsEventHandler(); |
|
70 | 70 | |
71 | - $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
72 | - } |
|
71 | + $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
72 | + } |
|
73 | 73 | |
74 | - protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
75 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); |
|
76 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class); |
|
77 | - } |
|
74 | + protected function registerEventsScripts(IEventDispatcher $dispatcher) { |
|
75 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); |
|
76 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class); |
|
77 | + } |
|
78 | 78 | |
79 | - protected function registerDavEntity(IEventDispatcher $dispatcher) { |
|
80 | - $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { |
|
81 | - $event->addEntityCollection('files', function ($name) { |
|
82 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
83 | - return !empty($nodes); |
|
84 | - }); |
|
85 | - }); |
|
86 | - } |
|
79 | + protected function registerDavEntity(IEventDispatcher $dispatcher) { |
|
80 | + $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { |
|
81 | + $event->addEntityCollection('files', function ($name) { |
|
82 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
83 | + return !empty($nodes); |
|
84 | + }); |
|
85 | + }); |
|
86 | + } |
|
87 | 87 | |
88 | - protected function registerNotifier() { |
|
89 | - $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
90 | - } |
|
88 | + protected function registerNotifier() { |
|
89 | + $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
90 | + } |
|
91 | 91 | |
92 | - protected function registerCommentsEventHandler() { |
|
93 | - $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
94 | - return $this->getContainer()->query(EventHandler::class); |
|
95 | - }); |
|
96 | - } |
|
92 | + protected function registerCommentsEventHandler() { |
|
93 | + $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
94 | + return $this->getContainer()->query(EventHandler::class); |
|
95 | + }); |
|
96 | + } |
|
97 | 97 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | protected function registerDavEntity(IEventDispatcher $dispatcher) { |
80 | - $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { |
|
81 | - $event->addEntityCollection('files', function ($name) { |
|
82 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
80 | + $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { |
|
81 | + $event->addEntityCollection('files', function($name) { |
|
82 | + $nodes = \OC::$server->getUserFolder()->getById((int) $name); |
|
83 | 83 | return !empty($nodes); |
84 | 84 | }); |
85 | 85 | }); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | protected function registerCommentsEventHandler() { |
93 | - $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
93 | + $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function() { |
|
94 | 94 | return $this->getContainer()->query(EventHandler::class); |
95 | 95 | }); |
96 | 96 | } |
@@ -28,87 +28,87 @@ |
||
28 | 28 | |
29 | 29 | class CommentersSorter implements ISorter { |
30 | 30 | |
31 | - /** @var ICommentsManager */ |
|
32 | - private $commentsManager; |
|
33 | - |
|
34 | - public function __construct(ICommentsManager $commentsManager) { |
|
35 | - $this->commentsManager = $commentsManager; |
|
36 | - } |
|
37 | - |
|
38 | - public function getId() { |
|
39 | - return 'commenters'; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Sorts people who commented on the given item atop (descelating) of the |
|
44 | - * others |
|
45 | - * |
|
46 | - * @param array $sortArray |
|
47 | - * @param array $context |
|
48 | - */ |
|
49 | - public function sort(array &$sortArray, array $context) { |
|
50 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
51 | - if(count($commenters) === 0) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - foreach ($sortArray as $type => &$byType) { |
|
56 | - if(!isset($commenters[$type])) { |
|
57 | - continue; |
|
58 | - } |
|
59 | - |
|
60 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
61 | - // the current index to the value and compare it on a draw |
|
62 | - $i = 0; |
|
63 | - $workArray = array_map(function ($element) use (&$i) { |
|
64 | - return [$i++, $element]; |
|
65 | - }, $byType); |
|
66 | - |
|
67 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
68 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
69 | - if($r === 0) { |
|
70 | - $r = $a[0] - $b[0]; |
|
71 | - } |
|
72 | - return $r; |
|
73 | - }); |
|
74 | - |
|
75 | - // and remove the index values again |
|
76 | - $byType = array_column($workArray, 1); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param $type |
|
82 | - * @param $id |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function retrieveCommentsInformation($type, $id) { |
|
86 | - $comments = $this->commentsManager->getForObject($type, $id); |
|
87 | - if(count($comments) === 0) { |
|
88 | - return []; |
|
89 | - } |
|
90 | - |
|
91 | - $actors = []; |
|
92 | - foreach ($comments as $comment) { |
|
93 | - if(!isset($actors[$comment->getActorType()])) { |
|
94 | - $actors[$comment->getActorType()] = []; |
|
95 | - } |
|
96 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
97 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
98 | - } else { |
|
99 | - $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
100 | - } |
|
101 | - } |
|
102 | - return $actors; |
|
103 | - } |
|
104 | - |
|
105 | - protected function compare(array $a, array $b, array $commenters) { |
|
106 | - $a = $a['value']['shareWith']; |
|
107 | - $b = $b['value']['shareWith']; |
|
108 | - |
|
109 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
110 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
111 | - |
|
112 | - return $valueB - $valueA; |
|
113 | - } |
|
31 | + /** @var ICommentsManager */ |
|
32 | + private $commentsManager; |
|
33 | + |
|
34 | + public function __construct(ICommentsManager $commentsManager) { |
|
35 | + $this->commentsManager = $commentsManager; |
|
36 | + } |
|
37 | + |
|
38 | + public function getId() { |
|
39 | + return 'commenters'; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Sorts people who commented on the given item atop (descelating) of the |
|
44 | + * others |
|
45 | + * |
|
46 | + * @param array $sortArray |
|
47 | + * @param array $context |
|
48 | + */ |
|
49 | + public function sort(array &$sortArray, array $context) { |
|
50 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
51 | + if(count($commenters) === 0) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + foreach ($sortArray as $type => &$byType) { |
|
56 | + if(!isset($commenters[$type])) { |
|
57 | + continue; |
|
58 | + } |
|
59 | + |
|
60 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
61 | + // the current index to the value and compare it on a draw |
|
62 | + $i = 0; |
|
63 | + $workArray = array_map(function ($element) use (&$i) { |
|
64 | + return [$i++, $element]; |
|
65 | + }, $byType); |
|
66 | + |
|
67 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
68 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
69 | + if($r === 0) { |
|
70 | + $r = $a[0] - $b[0]; |
|
71 | + } |
|
72 | + return $r; |
|
73 | + }); |
|
74 | + |
|
75 | + // and remove the index values again |
|
76 | + $byType = array_column($workArray, 1); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param $type |
|
82 | + * @param $id |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function retrieveCommentsInformation($type, $id) { |
|
86 | + $comments = $this->commentsManager->getForObject($type, $id); |
|
87 | + if(count($comments) === 0) { |
|
88 | + return []; |
|
89 | + } |
|
90 | + |
|
91 | + $actors = []; |
|
92 | + foreach ($comments as $comment) { |
|
93 | + if(!isset($actors[$comment->getActorType()])) { |
|
94 | + $actors[$comment->getActorType()] = []; |
|
95 | + } |
|
96 | + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
97 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
98 | + } else { |
|
99 | + $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
100 | + } |
|
101 | + } |
|
102 | + return $actors; |
|
103 | + } |
|
104 | + |
|
105 | + protected function compare(array $a, array $b, array $commenters) { |
|
106 | + $a = $a['value']['shareWith']; |
|
107 | + $b = $b['value']['shareWith']; |
|
108 | + |
|
109 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
110 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
111 | + |
|
112 | + return $valueB - $valueA; |
|
113 | + } |
|
114 | 114 | } |
@@ -48,25 +48,25 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function sort(array &$sortArray, array $context) { |
50 | 50 | $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
51 | - if(count($commenters) === 0) { |
|
51 | + if (count($commenters) === 0) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | foreach ($sortArray as $type => &$byType) { |
56 | - if(!isset($commenters[$type])) { |
|
56 | + if (!isset($commenters[$type])) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | 59 | |
60 | 60 | // at least on PHP 5.6 usort turned out to be not stable. So we add |
61 | 61 | // the current index to the value and compare it on a draw |
62 | 62 | $i = 0; |
63 | - $workArray = array_map(function ($element) use (&$i) { |
|
63 | + $workArray = array_map(function($element) use (&$i) { |
|
64 | 64 | return [$i++, $element]; |
65 | 65 | }, $byType); |
66 | 66 | |
67 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
67 | + usort($workArray, function($a, $b) use ($commenters, $type) { |
|
68 | 68 | $r = $this->compare($a[1], $b[1], $commenters[$type]); |
69 | - if($r === 0) { |
|
69 | + if ($r === 0) { |
|
70 | 70 | $r = $a[0] - $b[0]; |
71 | 71 | } |
72 | 72 | return $r; |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function retrieveCommentsInformation($type, $id) { |
86 | 86 | $comments = $this->commentsManager->getForObject($type, $id); |
87 | - if(count($comments) === 0) { |
|
87 | + if (count($comments) === 0) { |
|
88 | 88 | return []; |
89 | 89 | } |
90 | 90 | |
91 | 91 | $actors = []; |
92 | 92 | foreach ($comments as $comment) { |
93 | - if(!isset($actors[$comment->getActorType()])) { |
|
93 | + if (!isset($actors[$comment->getActorType()])) { |
|
94 | 94 | $actors[$comment->getActorType()] = []; |
95 | 95 | } |
96 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
96 | + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
97 | 97 | $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
98 | 98 | } else { |
99 | 99 | $actors[$comment->getActorType()][$comment->getActorId()]++; |
@@ -47,247 +47,247 @@ |
||
47 | 47 | |
48 | 48 | class PersonalInfo implements ISettings { |
49 | 49 | |
50 | - /** @var IConfig */ |
|
51 | - private $config; |
|
52 | - /** @var IUserManager */ |
|
53 | - private $userManager; |
|
54 | - /** @var AccountManager */ |
|
55 | - private $accountManager; |
|
56 | - /** @var IGroupManager */ |
|
57 | - private $groupManager; |
|
58 | - /** @var IAppManager */ |
|
59 | - private $appManager; |
|
60 | - /** @var IFactory */ |
|
61 | - private $l10nFactory; |
|
62 | - /** @var IL10N */ |
|
63 | - private $l; |
|
64 | - |
|
65 | - /** |
|
66 | - * @param IConfig $config |
|
67 | - * @param IUserManager $userManager |
|
68 | - * @param IGroupManager $groupManager |
|
69 | - * @param AccountManager $accountManager |
|
70 | - * @param IFactory $l10nFactory |
|
71 | - * @param IL10N $l |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - IConfig $config, |
|
75 | - IUserManager $userManager, |
|
76 | - IGroupManager $groupManager, |
|
77 | - AccountManager $accountManager, |
|
78 | - IAppManager $appManager, |
|
79 | - IFactory $l10nFactory, |
|
80 | - IL10N $l |
|
81 | - ) { |
|
82 | - $this->config = $config; |
|
83 | - $this->userManager = $userManager; |
|
84 | - $this->accountManager = $accountManager; |
|
85 | - $this->groupManager = $groupManager; |
|
86 | - $this->appManager = $appManager; |
|
87 | - $this->l10nFactory = $l10nFactory; |
|
88 | - $this->l = $l; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
93 | - * @since 9.1 |
|
94 | - */ |
|
95 | - public function getForm() { |
|
96 | - $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
97 | - $lookupServerUploadEnabled = false; |
|
98 | - if($federatedFileSharingEnabled) { |
|
99 | - $federatedFileSharing = \OC::$server->query(Application::class); |
|
100 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
101 | - $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
102 | - } |
|
103 | - |
|
104 | - $uid = \OC_User::getUser(); |
|
105 | - $user = $this->userManager->get($uid); |
|
106 | - $userData = $this->accountManager->getUser($user); |
|
107 | - |
|
108 | - $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
109 | - if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
110 | - $totalSpace = $this->l->t('Unlimited'); |
|
111 | - } else { |
|
112 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
113 | - } |
|
114 | - |
|
115 | - $languageParameters = $this->getLanguages($user); |
|
116 | - $localeParameters = $this->getLocales($user); |
|
117 | - $messageParameters = $this->getMessageParameters($userData); |
|
118 | - |
|
119 | - $parameters = [ |
|
120 | - 'total_space' => $totalSpace, |
|
121 | - 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
122 | - 'usage_relative' => round($storageInfo['relative']), |
|
123 | - 'quota' => $storageInfo['quota'], |
|
124 | - 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
125 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
126 | - 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
127 | - 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
128 | - 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
129 | - 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
130 | - 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
131 | - 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
132 | - 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
133 | - 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
134 | - 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
135 | - 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
136 | - 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
137 | - 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
138 | - 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
139 | - 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
140 | - 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
141 | - 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
142 | - 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
143 | - 'groups' => $this->getGroups($user), |
|
144 | - ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | - |
|
146 | - |
|
147 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string the section ID, e.g. 'sharing' |
|
152 | - * @since 9.1 |
|
153 | - */ |
|
154 | - public function getSection() { |
|
155 | - return 'personal-info'; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int whether the form should be rather on the top or bottom of |
|
160 | - * the admin section. The forms are arranged in ascending order of the |
|
161 | - * priority values. It is required to return a value between 0 and 100. |
|
162 | - * |
|
163 | - * E.g.: 70 |
|
164 | - * @since 9.1 |
|
165 | - */ |
|
166 | - public function getPriority() { |
|
167 | - return 10; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * returns a sorted list of the user's group GIDs |
|
172 | - * |
|
173 | - * @param IUser $user |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - private function getGroups(IUser $user) { |
|
177 | - $groups = array_map( |
|
178 | - function (IGroup $group) { |
|
179 | - return $group->getDisplayName(); |
|
180 | - }, |
|
181 | - $this->groupManager->getUserGroups($user) |
|
182 | - ); |
|
183 | - sort($groups); |
|
184 | - |
|
185 | - return $groups; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * returns the user language, common language and other languages in an |
|
190 | - * associative array |
|
191 | - * |
|
192 | - * @param IUser $user |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - private function getLanguages(IUser $user) { |
|
196 | - $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | - if($forceLanguage !== false) { |
|
198 | - return []; |
|
199 | - } |
|
200 | - |
|
201 | - $uid = $user->getUID(); |
|
202 | - |
|
203 | - $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | - $languages = $this->l10nFactory->getLanguages(); |
|
205 | - |
|
206 | - // associate the user language with the proper array |
|
207 | - $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
208 | - $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
209 | - // search in the other languages |
|
210 | - if ($userLangIndex === false) { |
|
211 | - $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
212 | - $userLang = $languages['languages'][$userLangIndex]; |
|
213 | - } |
|
214 | - // if user language is not available but set somehow: show the actual code as name |
|
215 | - if (!is_array($userLang)) { |
|
216 | - $userLang = [ |
|
217 | - 'code' => $userConfLang, |
|
218 | - 'name' => $userConfLang, |
|
219 | - ]; |
|
220 | - } |
|
221 | - |
|
222 | - return array_merge( |
|
223 | - ['activelanguage' => $userLang], |
|
224 | - $languages |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - private function getLocales(IUser $user) { |
|
229 | - $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
230 | - if($forceLanguage !== false) { |
|
231 | - return []; |
|
232 | - } |
|
233 | - |
|
234 | - $uid = $user->getUID(); |
|
235 | - |
|
236 | - $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
237 | - |
|
238 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
239 | - |
|
240 | - $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
241 | - |
|
242 | - $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
243 | - return $userLocaleString === $value['code']; |
|
244 | - }); |
|
245 | - |
|
246 | - if (!empty($userLocale)) |
|
247 | - { |
|
248 | - $userLocale = reset($userLocale); |
|
249 | - } |
|
250 | - |
|
251 | - $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
252 | - return 0 === strpos($localeCode['code'], $userLang); |
|
253 | - }); |
|
254 | - |
|
255 | - if (!$userLocale) { |
|
256 | - $userLocale = [ |
|
257 | - 'code' => 'en', |
|
258 | - 'name' => 'English' |
|
259 | - ]; |
|
260 | - } |
|
261 | - |
|
262 | - return [ |
|
263 | - 'activelocaleLang' => $userLocaleString, |
|
264 | - 'activelocale' => $userLocale, |
|
265 | - 'locales' => $localeCodes, |
|
266 | - 'localesForLanguage' => $localesForLanguage, |
|
267 | - ]; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @param array $userData |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - private function getMessageParameters(array $userData) { |
|
275 | - $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
276 | - $messageParameters = []; |
|
277 | - foreach ($needVerifyMessage as $property) { |
|
278 | - switch ($userData[$property]['verified']) { |
|
279 | - case AccountManager::VERIFIED: |
|
280 | - $message = $this->l->t('Verifying'); |
|
281 | - break; |
|
282 | - case AccountManager::VERIFICATION_IN_PROGRESS: |
|
283 | - $message = $this->l->t('Verifying …'); |
|
284 | - break; |
|
285 | - default: |
|
286 | - $message = $this->l->t('Verify'); |
|
287 | - } |
|
288 | - $messageParameters[$property . 'Message'] = $message; |
|
289 | - } |
|
290 | - return $messageParameters; |
|
291 | - } |
|
50 | + /** @var IConfig */ |
|
51 | + private $config; |
|
52 | + /** @var IUserManager */ |
|
53 | + private $userManager; |
|
54 | + /** @var AccountManager */ |
|
55 | + private $accountManager; |
|
56 | + /** @var IGroupManager */ |
|
57 | + private $groupManager; |
|
58 | + /** @var IAppManager */ |
|
59 | + private $appManager; |
|
60 | + /** @var IFactory */ |
|
61 | + private $l10nFactory; |
|
62 | + /** @var IL10N */ |
|
63 | + private $l; |
|
64 | + |
|
65 | + /** |
|
66 | + * @param IConfig $config |
|
67 | + * @param IUserManager $userManager |
|
68 | + * @param IGroupManager $groupManager |
|
69 | + * @param AccountManager $accountManager |
|
70 | + * @param IFactory $l10nFactory |
|
71 | + * @param IL10N $l |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + IConfig $config, |
|
75 | + IUserManager $userManager, |
|
76 | + IGroupManager $groupManager, |
|
77 | + AccountManager $accountManager, |
|
78 | + IAppManager $appManager, |
|
79 | + IFactory $l10nFactory, |
|
80 | + IL10N $l |
|
81 | + ) { |
|
82 | + $this->config = $config; |
|
83 | + $this->userManager = $userManager; |
|
84 | + $this->accountManager = $accountManager; |
|
85 | + $this->groupManager = $groupManager; |
|
86 | + $this->appManager = $appManager; |
|
87 | + $this->l10nFactory = $l10nFactory; |
|
88 | + $this->l = $l; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
93 | + * @since 9.1 |
|
94 | + */ |
|
95 | + public function getForm() { |
|
96 | + $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
97 | + $lookupServerUploadEnabled = false; |
|
98 | + if($federatedFileSharingEnabled) { |
|
99 | + $federatedFileSharing = \OC::$server->query(Application::class); |
|
100 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
101 | + $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
102 | + } |
|
103 | + |
|
104 | + $uid = \OC_User::getUser(); |
|
105 | + $user = $this->userManager->get($uid); |
|
106 | + $userData = $this->accountManager->getUser($user); |
|
107 | + |
|
108 | + $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
109 | + if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
110 | + $totalSpace = $this->l->t('Unlimited'); |
|
111 | + } else { |
|
112 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
113 | + } |
|
114 | + |
|
115 | + $languageParameters = $this->getLanguages($user); |
|
116 | + $localeParameters = $this->getLocales($user); |
|
117 | + $messageParameters = $this->getMessageParameters($userData); |
|
118 | + |
|
119 | + $parameters = [ |
|
120 | + 'total_space' => $totalSpace, |
|
121 | + 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
122 | + 'usage_relative' => round($storageInfo['relative']), |
|
123 | + 'quota' => $storageInfo['quota'], |
|
124 | + 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
125 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
126 | + 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
127 | + 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
128 | + 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
129 | + 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
130 | + 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
131 | + 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
132 | + 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
133 | + 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
134 | + 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
135 | + 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
136 | + 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
137 | + 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
138 | + 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
139 | + 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
140 | + 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
141 | + 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
142 | + 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
143 | + 'groups' => $this->getGroups($user), |
|
144 | + ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | + |
|
146 | + |
|
147 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string the section ID, e.g. 'sharing' |
|
152 | + * @since 9.1 |
|
153 | + */ |
|
154 | + public function getSection() { |
|
155 | + return 'personal-info'; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int whether the form should be rather on the top or bottom of |
|
160 | + * the admin section. The forms are arranged in ascending order of the |
|
161 | + * priority values. It is required to return a value between 0 and 100. |
|
162 | + * |
|
163 | + * E.g.: 70 |
|
164 | + * @since 9.1 |
|
165 | + */ |
|
166 | + public function getPriority() { |
|
167 | + return 10; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * returns a sorted list of the user's group GIDs |
|
172 | + * |
|
173 | + * @param IUser $user |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + private function getGroups(IUser $user) { |
|
177 | + $groups = array_map( |
|
178 | + function (IGroup $group) { |
|
179 | + return $group->getDisplayName(); |
|
180 | + }, |
|
181 | + $this->groupManager->getUserGroups($user) |
|
182 | + ); |
|
183 | + sort($groups); |
|
184 | + |
|
185 | + return $groups; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * returns the user language, common language and other languages in an |
|
190 | + * associative array |
|
191 | + * |
|
192 | + * @param IUser $user |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + private function getLanguages(IUser $user) { |
|
196 | + $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | + if($forceLanguage !== false) { |
|
198 | + return []; |
|
199 | + } |
|
200 | + |
|
201 | + $uid = $user->getUID(); |
|
202 | + |
|
203 | + $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | + $languages = $this->l10nFactory->getLanguages(); |
|
205 | + |
|
206 | + // associate the user language with the proper array |
|
207 | + $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
208 | + $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
209 | + // search in the other languages |
|
210 | + if ($userLangIndex === false) { |
|
211 | + $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
212 | + $userLang = $languages['languages'][$userLangIndex]; |
|
213 | + } |
|
214 | + // if user language is not available but set somehow: show the actual code as name |
|
215 | + if (!is_array($userLang)) { |
|
216 | + $userLang = [ |
|
217 | + 'code' => $userConfLang, |
|
218 | + 'name' => $userConfLang, |
|
219 | + ]; |
|
220 | + } |
|
221 | + |
|
222 | + return array_merge( |
|
223 | + ['activelanguage' => $userLang], |
|
224 | + $languages |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + private function getLocales(IUser $user) { |
|
229 | + $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
230 | + if($forceLanguage !== false) { |
|
231 | + return []; |
|
232 | + } |
|
233 | + |
|
234 | + $uid = $user->getUID(); |
|
235 | + |
|
236 | + $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
237 | + |
|
238 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
239 | + |
|
240 | + $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
241 | + |
|
242 | + $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
243 | + return $userLocaleString === $value['code']; |
|
244 | + }); |
|
245 | + |
|
246 | + if (!empty($userLocale)) |
|
247 | + { |
|
248 | + $userLocale = reset($userLocale); |
|
249 | + } |
|
250 | + |
|
251 | + $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
252 | + return 0 === strpos($localeCode['code'], $userLang); |
|
253 | + }); |
|
254 | + |
|
255 | + if (!$userLocale) { |
|
256 | + $userLocale = [ |
|
257 | + 'code' => 'en', |
|
258 | + 'name' => 'English' |
|
259 | + ]; |
|
260 | + } |
|
261 | + |
|
262 | + return [ |
|
263 | + 'activelocaleLang' => $userLocaleString, |
|
264 | + 'activelocale' => $userLocale, |
|
265 | + 'locales' => $localeCodes, |
|
266 | + 'localesForLanguage' => $localesForLanguage, |
|
267 | + ]; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @param array $userData |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + private function getMessageParameters(array $userData) { |
|
275 | + $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
276 | + $messageParameters = []; |
|
277 | + foreach ($needVerifyMessage as $property) { |
|
278 | + switch ($userData[$property]['verified']) { |
|
279 | + case AccountManager::VERIFIED: |
|
280 | + $message = $this->l->t('Verifying'); |
|
281 | + break; |
|
282 | + case AccountManager::VERIFICATION_IN_PROGRESS: |
|
283 | + $message = $this->l->t('Verifying …'); |
|
284 | + break; |
|
285 | + default: |
|
286 | + $message = $this->l->t('Verify'); |
|
287 | + } |
|
288 | + $messageParameters[$property . 'Message'] = $message; |
|
289 | + } |
|
290 | + return $messageParameters; |
|
291 | + } |
|
292 | 292 | |
293 | 293 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function getForm() { |
96 | 96 | $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
97 | 97 | $lookupServerUploadEnabled = false; |
98 | - if($federatedFileSharingEnabled) { |
|
98 | + if ($federatedFileSharingEnabled) { |
|
99 | 99 | $federatedFileSharing = \OC::$server->query(Application::class); |
100 | 100 | $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
101 | 101 | $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | private function getGroups(IUser $user) { |
177 | 177 | $groups = array_map( |
178 | - function (IGroup $group) { |
|
178 | + function(IGroup $group) { |
|
179 | 179 | return $group->getDisplayName(); |
180 | 180 | }, |
181 | 181 | $this->groupManager->getUserGroups($user) |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | private function getLanguages(IUser $user) { |
196 | 196 | $forceLanguage = $this->config->getSystemValue('force_language', false); |
197 | - if($forceLanguage !== false) { |
|
197 | + if ($forceLanguage !== false) { |
|
198 | 198 | return []; |
199 | 199 | } |
200 | 200 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | |
228 | 228 | private function getLocales(IUser $user) { |
229 | 229 | $forceLanguage = $this->config->getSystemValue('force_locale', false); |
230 | - if($forceLanguage !== false) { |
|
230 | + if ($forceLanguage !== false) { |
|
231 | 231 | return []; |
232 | 232 | } |
233 | 233 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | $localeCodes = $this->l10nFactory->findAvailableLocales(); |
241 | 241 | |
242 | - $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
242 | + $userLocale = array_filter($localeCodes, function($value) use ($userLocaleString) { |
|
243 | 243 | return $userLocaleString === $value['code']; |
244 | 244 | }); |
245 | 245 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $userLocale = reset($userLocale); |
249 | 249 | } |
250 | 250 | |
251 | - $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
251 | + $localesForLanguage = array_filter($localeCodes, function($localeCode) use ($userLang) { |
|
252 | 252 | return 0 === strpos($localeCode['code'], $userLang); |
253 | 253 | }); |
254 | 254 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | default: |
286 | 286 | $message = $this->l->t('Verify'); |
287 | 287 | } |
288 | - $messageParameters[$property . 'Message'] = $message; |
|
288 | + $messageParameters[$property.'Message'] = $message; |
|
289 | 289 | } |
290 | 290 | return $messageParameters; |
291 | 291 | } |
@@ -55,165 +55,165 @@ |
||
55 | 55 | |
56 | 56 | class Application extends App { |
57 | 57 | |
58 | - const APP_ID = 'settings'; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array $urlParams |
|
62 | - */ |
|
63 | - public function __construct(array $urlParams=[]) { |
|
64 | - parent::__construct(self::APP_ID, $urlParams); |
|
65 | - |
|
66 | - $container = $this->getContainer(); |
|
67 | - |
|
68 | - // Register Middleware |
|
69 | - $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
70 | - $container->registerMiddleWare('SubadminMiddleware'); |
|
71 | - |
|
72 | - /** |
|
73 | - * Core class wrappers |
|
74 | - */ |
|
75 | - /** FIXME: Remove once OC_User is non-static and mockable */ |
|
76 | - $container->registerService('isAdmin', function () { |
|
77 | - return \OC_User::isAdminUser(\OC_User::getUser()); |
|
78 | - }); |
|
79 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
80 | - $container->registerService('isSubAdmin', function (IContainer $c) { |
|
81 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
82 | - $isSubAdmin = false; |
|
83 | - if($userObject !== null) { |
|
84 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
85 | - } |
|
86 | - return $isSubAdmin; |
|
87 | - }); |
|
88 | - $container->registerService('userCertificateManager', function (IContainer $c) { |
|
89 | - return $c->query('ServerContainer')->getCertificateManager(); |
|
90 | - }, false); |
|
91 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
92 | - return $c->query('ServerContainer')->getCertificateManager(null); |
|
93 | - }, false); |
|
94 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
95 | - return $c->query('ServerContainer')->query(IProvider::class); |
|
96 | - }); |
|
97 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
98 | - return $c->query('ServerContainer')->getSettingsManager(); |
|
99 | - }); |
|
100 | - |
|
101 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
102 | - /** @var Server $server */ |
|
103 | - $server = $c->query('ServerContainer'); |
|
104 | - /** @var Defaults $defaults */ |
|
105 | - $defaults = $server->query(Defaults::class); |
|
106 | - |
|
107 | - return new NewUserMailHelper( |
|
108 | - $defaults, |
|
109 | - $server->getURLGenerator(), |
|
110 | - $server->getL10NFactory(), |
|
111 | - $server->getMailer(), |
|
112 | - $server->getSecureRandom(), |
|
113 | - new TimeFactory(), |
|
114 | - $server->getConfig(), |
|
115 | - $server->getCrypto(), |
|
116 | - Util::getDefaultEmailAddress('no-reply') |
|
117 | - ); |
|
118 | - }); |
|
119 | - |
|
120 | - /** @var EventDispatcherInterface $eventDispatcher */ |
|
121 | - $eventDispatcher = $container->getServer()->getEventDispatcher(); |
|
122 | - $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
123 | - if (($token = $event->getSubject()) instanceof IToken) { |
|
124 | - /** @var IActivityManager $activityManager */ |
|
125 | - $activityManager = $container->query(IActivityManager::class); |
|
126 | - /** @var ILogger $logger */ |
|
127 | - $logger = $container->query(ILogger::class); |
|
128 | - |
|
129 | - $activity = $activityManager->generateEvent(); |
|
130 | - $activity->setApp('settings') |
|
131 | - ->setType('security') |
|
132 | - ->setAffectedUser($token->getUID()) |
|
133 | - ->setAuthor($token->getUID()) |
|
134 | - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
135 | - ->setObject('app_token', $token->getId()); |
|
136 | - |
|
137 | - try { |
|
138 | - $activityManager->publish($activity); |
|
139 | - } catch (BadMethodCallException $e) { |
|
140 | - $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
141 | - } |
|
142 | - } |
|
143 | - }); |
|
144 | - } |
|
145 | - |
|
146 | - public function register() { |
|
147 | - Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
148 | - Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
149 | - |
|
150 | - $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
|
151 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | - $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
153 | - |
|
154 | - Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
155 | - } |
|
156 | - |
|
157 | - public function addUserToGroup(IGroup $group, IUser $user): void { |
|
158 | - /** @var Hooks $hooks */ |
|
159 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
160 | - $hooks->addUserToGroup($group, $user); |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
165 | - /** @var Hooks $hooks */ |
|
166 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
167 | - $hooks->removeUserFromGroup($group, $user); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param array $parameters |
|
173 | - * @throws \InvalidArgumentException |
|
174 | - * @throws \BadMethodCallException |
|
175 | - * @throws \Exception |
|
176 | - * @throws \OCP\AppFramework\QueryException |
|
177 | - */ |
|
178 | - public function onChangePassword(array $parameters) { |
|
179 | - /** @var Hooks $hooks */ |
|
180 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
181 | - $hooks->onChangePassword($parameters['uid']); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @param array $parameters |
|
186 | - * @throws \InvalidArgumentException |
|
187 | - * @throws \BadMethodCallException |
|
188 | - * @throws \Exception |
|
189 | - * @throws \OCP\AppFramework\QueryException |
|
190 | - */ |
|
191 | - public function onChangeInfo(array $parameters) { |
|
192 | - if ($parameters['feature'] !== 'eMailAddress') { |
|
193 | - return; |
|
194 | - } |
|
195 | - |
|
196 | - /** @var Hooks $hooks */ |
|
197 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
198 | - $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param array $settings |
|
203 | - */ |
|
204 | - public function extendJsConfig(array $settings) { |
|
205 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
206 | - |
|
207 | - $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
208 | - if (!empty($publicWebFinger)) { |
|
209 | - $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
210 | - } |
|
211 | - |
|
212 | - $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
213 | - if (!empty($publicNodeInfo)) { |
|
214 | - $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
215 | - } |
|
216 | - |
|
217 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
218 | - } |
|
58 | + const APP_ID = 'settings'; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array $urlParams |
|
62 | + */ |
|
63 | + public function __construct(array $urlParams=[]) { |
|
64 | + parent::__construct(self::APP_ID, $urlParams); |
|
65 | + |
|
66 | + $container = $this->getContainer(); |
|
67 | + |
|
68 | + // Register Middleware |
|
69 | + $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
70 | + $container->registerMiddleWare('SubadminMiddleware'); |
|
71 | + |
|
72 | + /** |
|
73 | + * Core class wrappers |
|
74 | + */ |
|
75 | + /** FIXME: Remove once OC_User is non-static and mockable */ |
|
76 | + $container->registerService('isAdmin', function () { |
|
77 | + return \OC_User::isAdminUser(\OC_User::getUser()); |
|
78 | + }); |
|
79 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
80 | + $container->registerService('isSubAdmin', function (IContainer $c) { |
|
81 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
82 | + $isSubAdmin = false; |
|
83 | + if($userObject !== null) { |
|
84 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
85 | + } |
|
86 | + return $isSubAdmin; |
|
87 | + }); |
|
88 | + $container->registerService('userCertificateManager', function (IContainer $c) { |
|
89 | + return $c->query('ServerContainer')->getCertificateManager(); |
|
90 | + }, false); |
|
91 | + $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
92 | + return $c->query('ServerContainer')->getCertificateManager(null); |
|
93 | + }, false); |
|
94 | + $container->registerService(IProvider::class, function (IContainer $c) { |
|
95 | + return $c->query('ServerContainer')->query(IProvider::class); |
|
96 | + }); |
|
97 | + $container->registerService(IManager::class, function (IContainer $c) { |
|
98 | + return $c->query('ServerContainer')->getSettingsManager(); |
|
99 | + }); |
|
100 | + |
|
101 | + $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
102 | + /** @var Server $server */ |
|
103 | + $server = $c->query('ServerContainer'); |
|
104 | + /** @var Defaults $defaults */ |
|
105 | + $defaults = $server->query(Defaults::class); |
|
106 | + |
|
107 | + return new NewUserMailHelper( |
|
108 | + $defaults, |
|
109 | + $server->getURLGenerator(), |
|
110 | + $server->getL10NFactory(), |
|
111 | + $server->getMailer(), |
|
112 | + $server->getSecureRandom(), |
|
113 | + new TimeFactory(), |
|
114 | + $server->getConfig(), |
|
115 | + $server->getCrypto(), |
|
116 | + Util::getDefaultEmailAddress('no-reply') |
|
117 | + ); |
|
118 | + }); |
|
119 | + |
|
120 | + /** @var EventDispatcherInterface $eventDispatcher */ |
|
121 | + $eventDispatcher = $container->getServer()->getEventDispatcher(); |
|
122 | + $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
123 | + if (($token = $event->getSubject()) instanceof IToken) { |
|
124 | + /** @var IActivityManager $activityManager */ |
|
125 | + $activityManager = $container->query(IActivityManager::class); |
|
126 | + /** @var ILogger $logger */ |
|
127 | + $logger = $container->query(ILogger::class); |
|
128 | + |
|
129 | + $activity = $activityManager->generateEvent(); |
|
130 | + $activity->setApp('settings') |
|
131 | + ->setType('security') |
|
132 | + ->setAffectedUser($token->getUID()) |
|
133 | + ->setAuthor($token->getUID()) |
|
134 | + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
135 | + ->setObject('app_token', $token->getId()); |
|
136 | + |
|
137 | + try { |
|
138 | + $activityManager->publish($activity); |
|
139 | + } catch (BadMethodCallException $e) { |
|
140 | + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
141 | + } |
|
142 | + } |
|
143 | + }); |
|
144 | + } |
|
145 | + |
|
146 | + public function register() { |
|
147 | + Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
148 | + Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
149 | + |
|
150 | + $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
|
151 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | + $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
153 | + |
|
154 | + Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
155 | + } |
|
156 | + |
|
157 | + public function addUserToGroup(IGroup $group, IUser $user): void { |
|
158 | + /** @var Hooks $hooks */ |
|
159 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
160 | + $hooks->addUserToGroup($group, $user); |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
165 | + /** @var Hooks $hooks */ |
|
166 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
167 | + $hooks->removeUserFromGroup($group, $user); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param array $parameters |
|
173 | + * @throws \InvalidArgumentException |
|
174 | + * @throws \BadMethodCallException |
|
175 | + * @throws \Exception |
|
176 | + * @throws \OCP\AppFramework\QueryException |
|
177 | + */ |
|
178 | + public function onChangePassword(array $parameters) { |
|
179 | + /** @var Hooks $hooks */ |
|
180 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
181 | + $hooks->onChangePassword($parameters['uid']); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @param array $parameters |
|
186 | + * @throws \InvalidArgumentException |
|
187 | + * @throws \BadMethodCallException |
|
188 | + * @throws \Exception |
|
189 | + * @throws \OCP\AppFramework\QueryException |
|
190 | + */ |
|
191 | + public function onChangeInfo(array $parameters) { |
|
192 | + if ($parameters['feature'] !== 'eMailAddress') { |
|
193 | + return; |
|
194 | + } |
|
195 | + |
|
196 | + /** @var Hooks $hooks */ |
|
197 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
198 | + $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param array $settings |
|
203 | + */ |
|
204 | + public function extendJsConfig(array $settings) { |
|
205 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
206 | + |
|
207 | + $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
208 | + if (!empty($publicWebFinger)) { |
|
209 | + $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
210 | + } |
|
211 | + |
|
212 | + $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
213 | + if (!empty($publicNodeInfo)) { |
|
214 | + $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
215 | + } |
|
216 | + |
|
217 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
218 | + } |
|
219 | 219 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @param array $urlParams |
62 | 62 | */ |
63 | - public function __construct(array $urlParams=[]) { |
|
63 | + public function __construct(array $urlParams = []) { |
|
64 | 64 | parent::__construct(self::APP_ID, $urlParams); |
65 | 65 | |
66 | 66 | $container = $this->getContainer(); |
@@ -73,32 +73,32 @@ discard block |
||
73 | 73 | * Core class wrappers |
74 | 74 | */ |
75 | 75 | /** FIXME: Remove once OC_User is non-static and mockable */ |
76 | - $container->registerService('isAdmin', function () { |
|
76 | + $container->registerService('isAdmin', function() { |
|
77 | 77 | return \OC_User::isAdminUser(\OC_User::getUser()); |
78 | 78 | }); |
79 | 79 | /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
80 | - $container->registerService('isSubAdmin', function (IContainer $c) { |
|
80 | + $container->registerService('isSubAdmin', function(IContainer $c) { |
|
81 | 81 | $userObject = \OC::$server->getUserSession()->getUser(); |
82 | 82 | $isSubAdmin = false; |
83 | - if($userObject !== null) { |
|
83 | + if ($userObject !== null) { |
|
84 | 84 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
85 | 85 | } |
86 | 86 | return $isSubAdmin; |
87 | 87 | }); |
88 | - $container->registerService('userCertificateManager', function (IContainer $c) { |
|
88 | + $container->registerService('userCertificateManager', function(IContainer $c) { |
|
89 | 89 | return $c->query('ServerContainer')->getCertificateManager(); |
90 | 90 | }, false); |
91 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
91 | + $container->registerService('systemCertificateManager', function(IContainer $c) { |
|
92 | 92 | return $c->query('ServerContainer')->getCertificateManager(null); |
93 | 93 | }, false); |
94 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
94 | + $container->registerService(IProvider::class, function(IContainer $c) { |
|
95 | 95 | return $c->query('ServerContainer')->query(IProvider::class); |
96 | 96 | }); |
97 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
97 | + $container->registerService(IManager::class, function(IContainer $c) { |
|
98 | 98 | return $c->query('ServerContainer')->getSettingsManager(); |
99 | 99 | }); |
100 | 100 | |
101 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
101 | + $container->registerService(NewUserMailHelper::class, function(IContainer $c) { |
|
102 | 102 | /** @var Server $server */ |
103 | 103 | $server = $c->query('ServerContainer'); |
104 | 104 | /** @var Defaults $defaults */ |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | /** @var EventDispatcherInterface $eventDispatcher */ |
121 | 121 | $eventDispatcher = $container->getServer()->getEventDispatcher(); |
122 | - $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
122 | + $eventDispatcher->addListener('app_password_created', function(GenericEvent $event) use ($container) { |
|
123 | 123 | if (($token = $event->getSubject()) instanceof IToken) { |
124 | 124 | /** @var IActivityManager $activityManager */ |
125 | 125 | $activityManager = $container->query(IActivityManager::class); |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
149 | 149 | |
150 | 150 | $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
151 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | - $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
151 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
152 | + $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
153 | 153 | |
154 | 154 | Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
155 | 155 | } |