diff --git a/lib/Db/Restriction.php b/lib/Db/Restriction.php index 33db7ce..b014204 100644 --- a/lib/Db/Restriction.php +++ b/lib/Db/Restriction.php @@ -16,11 +16,13 @@ use OCP\AppFramework\Db\Entity; * @method void setMaxRooms(int $number) * @method void setMaxParticipants(int $number) * @method void setAllowRecording(bool $allow) + * @method void setGroupName(string $groupName) */ class Restriction extends Entity implements JsonSerializable { public const ALL_ID = ''; protected $groupId; + protected $groupName; protected $maxRooms = -1; protected $roomTypes = '[]'; protected $maxParticipants = -1; @@ -32,10 +34,15 @@ class Restriction extends Entity implements JsonSerializable { $this->addType('allowRecording', 'boolean'); } + public function setGroupName(string $groupName) { + $this->groupName = $groupName; + } + public function jsonSerialize(): array { return [ 'id' => $this->id, 'groupId' => $this->groupId, + 'groupName' => $this->groupName, 'maxRooms' => (int) $this->maxRooms, 'roomTypes' => \json_decode($this->roomTypes), 'maxParticipants' => (int) $this->maxParticipants, diff --git a/lib/Db/RestrictionMapper.php b/lib/Db/RestrictionMapper.php index 41772a4..0bf49fe 100644 --- a/lib/Db/RestrictionMapper.php +++ b/lib/Db/RestrictionMapper.php @@ -19,8 +19,9 @@ class RestrictionMapper extends QBMapper { public function find(int $id): Restriction { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName) + $qb->select('r.*', 'g.displayname as groupName') + ->from($this->tableName, 'r') + ->leftJoin('r', 'groups', 'g', $qb->expr()->eq('r.group_id', 'g.gid')) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); return $this->findEntity($qb); @@ -33,8 +34,9 @@ class RestrictionMapper extends QBMapper { public function findByGroupId(string $groupId): Restriction { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName) + $qb->select('r.*', 'g.displayname as groupName') + ->from($this->tableName, 'r') + ->leftJoin('r', 'groups', 'g', $qb->expr()->eq('r.group_id', 'g.gid')) ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($groupId))); return $this->findEntity($qb); @@ -46,8 +48,9 @@ class RestrictionMapper extends QBMapper { public function findByGroupIds(array $groupIds): array { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName) + $qb->select('r.*', 'g.displayname as groupName') + ->from($this->tableName, 'r') + ->leftJoin('r', 'groups', 'g', $qb->expr()->eq('r.group_id', 'g.gid')) ->where($qb->expr()->in('group_id', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))); /** @var array */ @@ -60,8 +63,9 @@ class RestrictionMapper extends QBMapper { public function findAll(): array { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName); + $qb->select('r.*', 'g.displayname as groupName') + ->from($this->tableName, 'r') + ->leftJoin('r', 'groups', 'g', $qb->expr()->eq('r.group_id', 'g.gid')); /** @var array */ return $this->findEntities($qb); diff --git a/lib/Service/RestrictionService.php b/lib/Service/RestrictionService.php index 1bbcff7..3ce331a 100644 --- a/lib/Service/RestrictionService.php +++ b/lib/Service/RestrictionService.php @@ -9,13 +9,10 @@ use OCA\BigBlueButton\Db\RestrictionMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; +use OCP\IGroupManager; class RestrictionService { - /** @var RestrictionMapper */ - private $mapper; - - public function __construct(RestrictionMapper $mapper) { - $this->mapper = $mapper; + public function __construct(private RestrictionMapper $mapper, private IGroupManager $groupManager) { } public function findAll(): array { @@ -78,6 +75,10 @@ class RestrictionService { $restriction = new Restriction(); $restriction->setGroupId($groupId); + $group = $this->groupManager->get($groupId); + if ($group) { + $restriction->setGroupName($group->getDisplayName()); + } return $this->mapper->insert($restriction); } diff --git a/ts/Common/Api.ts b/ts/Common/Api.ts index e31c5b5..da5bbb4 100644 --- a/ts/Common/Api.ts +++ b/ts/Common/Api.ts @@ -20,6 +20,7 @@ export enum Access { export interface Restriction { id: number; groupId: string; + groupName: string; maxRooms: number; roomTypes: string[]; maxParticipants: number; diff --git a/ts/Restrictions/RestrictionRow.tsx b/ts/Restrictions/RestrictionRow.tsx index 39642a9..525dacd 100644 --- a/ts/Restrictions/RestrictionRow.tsx +++ b/ts/Restrictions/RestrictionRow.tsx @@ -23,10 +23,10 @@ const RestrictionRoom: React.FC = (props) => { function deleteRow(ev: MouseEvent) { ev.preventDefault(); - + const groupName = restriction.groupName || restriction.groupId; OC.dialogs.confirm( - t('bbb', 'Are you sure you want to delete the restrictions for group "{name}"? This operation cannot be undone.', { name: restriction.groupId }), - t('bbb', 'Delete restrictions for "{name}"?', { name: restriction.groupId }), + t('bbb', 'Are you sure you want to delete the restrictions for group "{name}"? This operation cannot be undone.', { name: groupName }), + t('bbb', 'Delete restrictions for "{name}"?', { name: groupName}), confirmed => { if (confirmed) { props.deleteRestriction(restriction.id); @@ -42,7 +42,7 @@ const RestrictionRoom: React.FC = (props) => { return ( - {restriction.groupId || t('bbb', 'All users')} + {restriction.groupName || restriction.groupId || t('bbb', 'All users')} {edit('maxRooms', 'number')}