Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,51 @@ 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);
return new JSONResponse([], Http::STATUS_OK);
}

/**
* @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);
}
Expand Down
54 changes: 29 additions & 25 deletions lib/Controller/PersonalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array{id: int, displayname: string}>
*/
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) ?: [];
}
}
Loading