Skip to content

Commit

Permalink
feat(groups): enable group support display names
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Dec 20, 2023
1 parent ab39d2e commit a5bbde3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/GroupBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
use OCP\Group\Backend\ICountUsersBackend;
use OCP\Group\Backend\ICreateGroupBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\Group\Backend\IRemoveFromGroupBackend;
use OCP\IDBConnection;

class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBackend, ICreateGroupBackend, IDeleteGroupBackend, IRemoveFromGroupBackend, INamedBackend {
class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBackend, ICreateGroupBackend, IDeleteGroupBackend, IGetDisplayNameBackend, IRemoveFromGroupBackend, INamedBackend {
/** @var IDBConnection */
private $dbc;

Expand Down Expand Up @@ -79,7 +80,6 @@ public function getUserGroups($uid): array {
$groups = [];
while ($row = $cursor->fetch()) {
$groups[] = $row['gid'];
$this->groupCache[$row['gid']] = $row['gid'];
}
$cursor->closeCursor();

Expand All @@ -91,7 +91,7 @@ public function getUserGroups($uid): array {
*/
public function getGroups($search = '', $limit = null, $offset = null): array {
$query = $this->dbc->getQueryBuilder();
$query->select('gid')
$query->select('gid', 'displayname')
->from(self::TABLE_GROUPS)
->orderBy('gid', 'ASC');

Expand All @@ -112,6 +112,7 @@ public function getGroups($search = '', $limit = null, $offset = null): array {
$groups = [];
while ($row = $result->fetch()) {
$groups[] = $row['gid'];
$this->groupCache[$row['gid']] = $row['displayname'];
}
$result->closeCursor();

Expand All @@ -128,15 +129,16 @@ public function groupExists($gid): bool {
}

$qb = $this->dbc->getQueryBuilder();
$cursor = $qb->select('gid')
$cursor = $qb->select('gid', 'displayname')
->from(self::TABLE_GROUPS)
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
->setMaxResults(1)
->executeQuery();
$result = $cursor->fetch();
$cursor->closeCursor();

if ($result !== false) {
$this->groupCache[$gid] = $gid;
$this->groupCache[$gid] = $result['displayname'];
return true;
}
return false;
Expand Down Expand Up @@ -212,7 +214,7 @@ public function createGroup(string $gid, string $samlGid = null): bool {
}

// Add to cache
$this->groupCache[$gid] = $gid;
$this->groupCache[$gid] = $samlGid;

return $result === 1;
}
Expand Down Expand Up @@ -297,4 +299,12 @@ public function deleteGroup(string $gid): bool {
public function getBackendName(): string {
return 'user_saml';
}

public function getDisplayName(string $gid): string {
if (!isset($this->groupCache[$gid])) {
$this->getGroups($gid);
}

return $this->groupCache[$gid] ?? $gid;
}
}

0 comments on commit a5bbde3

Please sign in to comment.