зеркало из https://github.com/nextcloud/user_saml.git
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:
Коммит
8ddf3d35ee
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче