X Tutup
Skip to content

Commit fe9ab19

Browse files
committed
Fix personal setting for apps which are not whitelisted
When apps are not whitelisted for guest user they should not be visible in the personal settings. Signed-off-by: Sujith H <sharidasan@owncloud.com>
1 parent f29f6ec commit fe9ab19

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

lib/private/App/AppManager.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,20 @@ public function getInstalledApps() {
160160
*/
161161
public function getEnabledAppsForUser(IUser $user = null) {
162162
$apps = $this->getInstalledAppsValues();
163-
$appsForUser = \array_filter($apps, function ($enabled) use ($user) {
164-
return $this->checkAppForUser($enabled, $user);
165-
});
163+
$whiteListedAppsForGuest = [];
164+
if ($user === null && $this->userSession !== null) {
165+
$user = $this->userSession->getUser();
166+
}
167+
$userAppAttributes = $user->getExtendedAttributes();
168+
/**
169+
* Check if the user is guest user, if so get the apps which it is allowed for.
170+
*/
171+
if (\array_key_exists('guests', $userAppAttributes)) {
172+
$whiteListedAppsForGuest = $userAppAttributes['guests']['whiteListedApps'];
173+
}
174+
$appsForUser = \array_filter($apps, function ($enabled, $appName) use ($user, $whiteListedAppsForGuest) {
175+
return $this->checkAppForUser($enabled, $user, $appName, $whiteListedAppsForGuest);
176+
}, ARRAY_FILTER_USE_BOTH);
166177
return \array_keys($appsForUser);
167178
}
168179

@@ -182,7 +193,15 @@ public function isEnabledForUser($appId, $user = null) {
182193
}
183194
$installedApps = $this->getInstalledAppsValues();
184195
if (isset($installedApps[$appId])) {
185-
return $this->checkAppForUser($installedApps[$appId], $user);
196+
$whiteListedApps = [];
197+
/**
198+
* Check if the user is guest user, if so get the apps which it is allowed for.
199+
*/
200+
$userAppAttributes = $user->getExtendedAttributes();
201+
if (\array_key_exists('guests', $userAppAttributes)) {
202+
$whiteListedApps = $userAppAttributes['guests']['whiteListedApps'];
203+
}
204+
return $this->checkAppForUser($installedApps[$appId], $user, $appId, $whiteListedApps);
186205
} else {
187206
return false;
188207
}
@@ -191,9 +210,14 @@ public function isEnabledForUser($appId, $user = null) {
191210
/**
192211
* @param string $enabled
193212
* @param IUser $user
213+
* @param string|null $appName
214+
* @param array $whiteListedAppsForGuest
194215
* @return bool
195216
*/
196-
private function checkAppForUser($enabled, $user) {
217+
private function checkAppForUser($enabled, $user, $appName = null, $whiteListedAppsForGuest = []) {
218+
if (\count($whiteListedAppsForGuest) > 0 && !\in_array($appName, $whiteListedAppsForGuest)) {
219+
return false;
220+
}
197221
if ($enabled === 'yes') {
198222
return true;
199223
} elseif ($user === null) {

lib/private/User/User.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,21 @@ public function setSearchTerms(array $terms) {
555555
public function getAccountId() {
556556
return $this->account->getId();
557557
}
558+
559+
/**
560+
* get the attributes of user for apps
561+
*
562+
* @return array
563+
* @since 10.3.1
564+
*/
565+
public function getExtendedAttributes() {
566+
if ($this->eventDispatcher === null) {
567+
$this->eventDispatcher = \OC::$server->getEventDispatcher();
568+
}
569+
570+
$event = new GenericEvent('appAttributesForUser', []);
571+
$this->eventDispatcher->dispatch('getAppAttributesForUser', $event);
572+
573+
return $event->getArguments();
574+
}
558575
}

lib/public/IUser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,13 @@ public function setSearchTerms(array $terms);
238238
* @since 10.0.1
239239
*/
240240
public function getSearchTerms();
241+
242+
/**
243+
* Get attributes of user for apps
244+
* The attributes are of the form key => value map
245+
*
246+
* @return array
247+
* @since 10.3.1
248+
*/
249+
public function getExtendedAttributes();
241250
}

0 commit comments

Comments
 (0)
X Tutup