@@ -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 ) {
0 commit comments