fix: #289 admin interface displays groups gid instead of displayname

Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
pull/295/head
Sebastien Marinier 2024-10-22 15:30:10 +02:00
parent 7233d21a85
commit 71fe272888
5 changed files with 30 additions and 17 deletions

View File

@ -16,11 +16,13 @@ use OCP\AppFramework\Db\Entity;
* @method void setMaxRooms(int $number) * @method void setMaxRooms(int $number)
* @method void setMaxParticipants(int $number) * @method void setMaxParticipants(int $number)
* @method void setAllowRecording(bool $allow) * @method void setAllowRecording(bool $allow)
* @method void setGroupName(string $groupName)
*/ */
class Restriction extends Entity implements JsonSerializable { class Restriction extends Entity implements JsonSerializable {
public const ALL_ID = ''; public const ALL_ID = '';
protected $groupId; protected $groupId;
protected $groupName;
protected $maxRooms = -1; protected $maxRooms = -1;
protected $roomTypes = '[]'; protected $roomTypes = '[]';
protected $maxParticipants = -1; protected $maxParticipants = -1;
@ -32,10 +34,15 @@ class Restriction extends Entity implements JsonSerializable {
$this->addType('allowRecording', 'boolean'); $this->addType('allowRecording', 'boolean');
} }
public function setGroupName(string $groupName) {
$this->groupName = $groupName;
}
public function jsonSerialize(): array { public function jsonSerialize(): array {
return [ return [
'id' => $this->id, 'id' => $this->id,
'groupId' => $this->groupId, 'groupId' => $this->groupId,
'groupName' => $this->groupName,
'maxRooms' => (int) $this->maxRooms, 'maxRooms' => (int) $this->maxRooms,
'roomTypes' => \json_decode($this->roomTypes), 'roomTypes' => \json_decode($this->roomTypes),
'maxParticipants' => (int) $this->maxParticipants, 'maxParticipants' => (int) $this->maxParticipants,

View File

@ -19,8 +19,9 @@ class RestrictionMapper extends QBMapper {
public function find(int $id): Restriction { public function find(int $id): Restriction {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*', 'g.displayname as groupName')
->from($this->tableName) ->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))); ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
return $this->findEntity($qb); return $this->findEntity($qb);
@ -33,8 +34,9 @@ class RestrictionMapper extends QBMapper {
public function findByGroupId(string $groupId): Restriction { public function findByGroupId(string $groupId): Restriction {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*', 'g.displayname as groupName')
->from($this->tableName) ->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))); ->where($qb->expr()->eq('group_id', $qb->createNamedParameter($groupId)));
return $this->findEntity($qb); return $this->findEntity($qb);
@ -46,8 +48,9 @@ class RestrictionMapper extends QBMapper {
public function findByGroupIds(array $groupIds): array { public function findByGroupIds(array $groupIds): array {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*', 'g.displayname as groupName')
->from($this->tableName) ->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))); ->where($qb->expr()->in('group_id', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)));
/** @var array<Restriction> */ /** @var array<Restriction> */
@ -60,8 +63,9 @@ class RestrictionMapper extends QBMapper {
public function findAll(): array { public function findAll(): array {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*', 'g.displayname as groupName')
->from($this->tableName); ->from($this->tableName, 'r')
->leftJoin('r', 'groups', 'g', $qb->expr()->eq('r.group_id', 'g.gid'));
/** @var array<Restriction> */ /** @var array<Restriction> */
return $this->findEntities($qb); return $this->findEntities($qb);

View File

@ -9,13 +9,10 @@ use OCA\BigBlueButton\Db\RestrictionMapper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IGroupManager;
class RestrictionService { class RestrictionService {
/** @var RestrictionMapper */ public function __construct(private RestrictionMapper $mapper, private IGroupManager $groupManager) {
private $mapper;
public function __construct(RestrictionMapper $mapper) {
$this->mapper = $mapper;
} }
public function findAll(): array { public function findAll(): array {
@ -78,6 +75,10 @@ class RestrictionService {
$restriction = new Restriction(); $restriction = new Restriction();
$restriction->setGroupId($groupId); $restriction->setGroupId($groupId);
$group = $this->groupManager->get($groupId);
if ($group) {
$restriction->setGroupName($group->getDisplayName());
}
return $this->mapper->insert($restriction); return $this->mapper->insert($restriction);
} }

View File

@ -20,6 +20,7 @@ export enum Access {
export interface Restriction { export interface Restriction {
id: number; id: number;
groupId: string; groupId: string;
groupName: string;
maxRooms: number; maxRooms: number;
roomTypes: string[]; roomTypes: string[];
maxParticipants: number; maxParticipants: number;

View File

@ -23,10 +23,10 @@ const RestrictionRoom: React.FC<Props> = (props) => {
function deleteRow(ev: MouseEvent) { function deleteRow(ev: MouseEvent) {
ev.preventDefault(); ev.preventDefault();
const groupName = restriction.groupName || restriction.groupId;
OC.dialogs.confirm( 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', '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: restriction.groupId }), t('bbb', 'Delete restrictions for "{name}"?', { name: groupName}),
confirmed => { confirmed => {
if (confirmed) { if (confirmed) {
props.deleteRestriction(restriction.id); props.deleteRestriction(restriction.id);
@ -42,7 +42,7 @@ const RestrictionRoom: React.FC<Props> = (props) => {
return ( return (
<tr> <tr>
<td className="name">{restriction.groupId || t('bbb', 'All users')}</td> <td className="name">{restriction.groupName || restriction.groupId || t('bbb', 'All users')}</td>
<td className="max-rooms bbb-shrink"> <td className="max-rooms bbb-shrink">
{edit('maxRooms', 'number')} {edit('maxRooms', 'number')}
</td> </td>