Skip to content

Commit

Permalink
Merge pull request littleredbutton#295 from arawa/fix/289/admin_inter…
Browse files Browse the repository at this point in the history
…face_displays_gid

fix: littleredbutton#289 admin interface displays groups gid instead of displayname
  • Loading branch information
ThibautPlg authored Oct 23, 2024
2 parents 3c45a93 + ab80d61 commit dede2b2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
7 changes: 7 additions & 0 deletions lib/Db/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
* @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;
Expand All @@ -32,10 +34,15 @@ public function __construct() {
$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,
Expand Down
20 changes: 12 additions & 8 deletions lib/Db/RestrictionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function __construct(IDBConnection $db) {
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);
Expand All @@ -33,8 +34,9 @@ public function find(int $id): Restriction {
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);
Expand All @@ -46,8 +48,9 @@ public function findByGroupId(string $groupId): Restriction {
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<Restriction> */
Expand All @@ -60,8 +63,9 @@ public function findByGroupIds(array $groupIds): array {
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<Restriction> */
return $this->findEntities($qb);
Expand Down
11 changes: 10 additions & 1 deletion lib/Service/RestrictionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IGroupManager;

class RestrictionService {
/** @var RestrictionMapper */
private $mapper;

public function __construct(RestrictionMapper $mapper) {
/** @var IGroupManager */
private $groupManager;

public function __construct(RestrictionMapper $mapper, IGroupManager $groupManager) {
$this->mapper = $mapper;
$this->groupManager = $groupManager;
}

public function findAll(): array {
Expand Down Expand Up @@ -78,6 +83,10 @@ public function create(string $groupId): Restriction {
$restriction = new Restriction();

$restriction->setGroupId($groupId);
$group = $this->groupManager->get($groupId);
if ($group) {
$restriction->setGroupName($group->getDisplayName());
}

return $this->mapper->insert($restriction);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Service/RestrictionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
use OCA\BigBlueButton\Db\RestrictionMapper;
use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Service\RestrictionService;
use OCP\IGroupManager;
use PHPUnit\Framework\TestCase;

class RestrictionServiceTest extends TestCase {
protected $mapper;
protected $groupManager;
protected $service;

public function setUp(): void {
$this->mapper = $this->createMock(RestrictionMapper::class);
$this->groupManager = $this->createMock(IGroupManager::class);

$this->service = new RestrictionService($this->mapper);
$this->service = new RestrictionService($this->mapper, $this->groupManager);
}

public function testFindByGroupIds() {
Expand Down
1 change: 1 addition & 0 deletions ts/Common/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum Access {
export interface Restriction {
id: number;
groupId: string;
groupName: string;
maxRooms: number;
roomTypes: string[];
maxParticipants: number;
Expand Down
8 changes: 4 additions & 4 deletions ts/Restrictions/RestrictionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const RestrictionRoom: React.FC<Props> = (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);
Expand All @@ -42,7 +42,7 @@ const RestrictionRoom: React.FC<Props> = (props) => {

return (
<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">
{edit('maxRooms', 'number')}
</td>
Expand Down

0 comments on commit dede2b2

Please sign in to comment.