Merge pull request #855 from iLinaza/fix/set-displayname-on-groupbackend

feat(groups): add setting display name to group backend
This commit is contained in:
Arthur Schiwon 2024-12-02 11:53:23 +01:00 коммит произвёл GitHub
Родитель 4368a73d93 fe0186b7d5
Коммит 8ddf3d35ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -15,10 +15,11 @@ use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\Group\Backend\IRemoveFromGroupBackend;
use OCP\Group\Backend\ISetDisplayNameBackend;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBackend, ICreateGroupBackend, IDeleteGroupBackend, IGetDisplayNameBackend, IRemoveFromGroupBackend, INamedBackend {
class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBackend, ICreateGroupBackend, IDeleteGroupBackend, IGetDisplayNameBackend, IRemoveFromGroupBackend, ISetDisplayNameBackend, INamedBackend {
/** @var array */
private $groupCache = [];
@ -78,6 +79,9 @@ class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBa
$query->where($query->expr()->iLike('gid', $query->createNamedParameter(
'%' . $this->dbc->escapeLikeParameter($search) . '%'
)));
$query->orWhere($query->expr()->iLike('displayname', $query->createNamedParameter(
'%' . $this->dbc->escapeLikeParameter($search) . '%'
)));
}
if ((int)$limit > 0) {
@ -292,4 +296,27 @@ class GroupBackend extends ABackend implements IAddToGroupBackend, ICountUsersBa
return $this->groupCache[$gid] ?? $gid;
}
public function setDisplayName(string $gid, string $displayName): bool {
if (!$this->groupExists($gid)) {
return false;
}
$displayName = trim($displayName);
if ($displayName === '') {
$displayName = $gid;
}
$query = $this->dbc->getQueryBuilder();
$isUpdated = $query->update(self::TABLE_GROUPS)
->set('displayname', $query->createNamedParameter($displayName))
->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
->executeStatement() > 0;
if ($isUpdated) {
$this->groupCache[$gid] = $displayName;
}
return $isUpdated;
}
}