diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index f3071d79..b83f8974 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -27,8 +27,7 @@ public function __construct( } /** - * @param string $code - * @return JSONResponse + * Sets the readable location code for the app. */ public function setReadableLocation(string $code): JSONResponse { $this->config->setAppValue($this->appName, 'readableLocation', $code); @@ -36,47 +35,43 @@ public function setReadableLocation(string $code): JSONResponse { } /** - * @param string $name - * @return JSONResponse + * Adds an external privacy admin by display name. */ - public function addAdditionalAdmin(string $name): JSONResponse { - $query = $this->dbConnection->getQueryBuilder(); - $query->insert('privacy_admins') - ->setValue('displayname', $query->createNamedParameter($name)) + public function addAdditionalAdmin(string $displayName): JSONResponse { + $qb = $this->dbConnection->getQueryBuilder(); + $qb->insert('privacy_admins') + ->setValue('displayname', $qb->createNamedParameter($displayName)) ->executeStatement(); - $id = $query->getLastInsertId(); + $id = $qb->getLastInsertId(); return new JSONResponse([ 'id' => $id, - 'displayname' => $name, + 'displayname' => $displayName, 'internal' => false, ], Http::STATUS_CREATED); } /** - * @param int $id - * @return JSONResponse + * Removes an external privacy admin by ID. */ public function deleteAdditionalAdmin(int $id): JSONResponse { - $query = $this->dbConnection->getQueryBuilder(); - $query->delete('privacy_admins') - ->where($query->expr()->eq('id', $query->createNamedParameter($id))) + $qb = $this->dbConnection->getQueryBuilder(); + $qb->delete('privacy_admins') + ->where($query->expr()->eq('id', $qb->createNamedParameter($id))) ->executeStatement(); return new JSONResponse([], Http::STATUS_OK); } /** - * @param string $enabled - * @return JSONResponse + * Enables or disables full disk encryption indicator (only) for privacy disclosure purposes. */ public function setFullDiskEncryption(string $enabled): JSONResponse { $allowedValues = ['0', '1']; if (!\in_array($enabled, $allowedValues, true)) { return new JSONResponse([], HTTP::STATUS_NOT_ACCEPTABLE); } - $this->config->setAppValue('privacy', 'fullDiskEncryptionEnabled', $enabled); return new JSONResponse([], HTTP::STATUS_OK); } diff --git a/lib/Controller/PersonalController.php b/lib/Controller/PersonalController.php index e34d98fd..d7d6948d 100644 --- a/lib/Controller/PersonalController.php +++ b/lib/Controller/PersonalController.php @@ -33,40 +33,44 @@ public function __construct( * @NoAdminRequired */ public function getAdmins(): JSONResponse { - $adminGroup = $this->groupManager->get('admin'); + $admins = []; - // Admin Group should always exist, just catch for safety's sake - if (!$adminGroup) { - return new JSONResponse([]); - } - - $adminUsers = $adminGroup->getUsers(); - $uids = []; - foreach ($adminUsers as $adminUser) { - if (!$adminUser->isEnabled()) { - continue; + // Internal admin group members + $group = $this->groupManager->get('admin'); + if ($group !== null) { + foreach ($group->getUsers() as $user) { + if ($user->isEnabled()) { + $admins[] = [ + 'id' => $user->getUID(), + 'displayname' => $user->getDisplayName(), + 'internal' => true, + ]; + } } - - $uids[] = [ - 'id' => $adminUser->getUID(), - 'displayname' => $adminUser->getDisplayName(), - 'internal' => true, - ]; } - $query = $this->dbConnection->getQueryBuilder(); - $query->select(['id', 'displayname']) - ->from('privacy_admins'); - $stmt = $query->executeQuery(); - - foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { - $uids[] = [ + // External privacy admins from DB + foreach ($this->getDbPrivacyAdmins() as $row) { + $admins[] = [ 'id' => (int)$row['id'], 'displayname' => (string)$row['displayname'], 'internal' => false, ]; } - return new JSONResponse($uids, Http::STATUS_OK); + return new JSONResponse($admins, Http::STATUS_OK); + } + + /** + * Fetches additional admins from the privacy_admins table. + * + * @return array + */ + private function getDbPrivacyAdmins(): array { + $qb = $this->dbConnection->getQueryBuilder(); + $qb->select(['id', 'displayname']) + ->from('privacy_admins') + ->orderBy('id', 'ASC'); + return $qb->executeQuery()->fetchAll(\PDO::FETCH_ASSOC) ?: []; } }