Skip to content

Commit

Permalink
Merge pull request littleredbutton#296 from arawa/fix/290/max_number_…
Browse files Browse the repository at this point in the history
…of_rooms_count_only_owned_rooms

fix: littleredbutton#290 max number of rooms shloud take only owned rooms in account
  • Loading branch information
ThibautPlg authored Oct 23, 2024
2 parents 31bc8ae + 79518b9 commit 3c45a93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ public function getRestriction(string $uid): Restriction {
}

public function isAllowedToCreateRoom(string $uid): bool {
$numberOfCreatedRooms = count($this->roomService->findAll($uid, [], []));
$restriction = $this->getRestriction($uid);
if ($restriction->getMaxRooms() < 0) {
return true;
}
$numberOfCreatedRooms = count($this->roomService->findByUserId($uid));

return $restriction->getMaxRooms() < 0 || $restriction->getMaxRooms() > $numberOfCreatedRooms;
return $restriction->getMaxRooms() > $numberOfCreatedRooms;
}

public function isUser(Room $room, ?string $uid): bool {
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function testIsUserNotAllowed() {

$this->roomService
->expects($this->once())
->method('findAll')
->method('findByUserId')
->with('foobar')
->willReturn([
$this->createRoom(1, 'foo'),
$this->createRoom(2, 'bar'),
Expand Down
5 changes: 3 additions & 2 deletions ts/Manager/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ const App: React.FC<Props> = () => {
}

const maxRooms = restriction?.maxRooms || 0;
const quota = maxRooms < 0 ? t('bbb', 'unlimited') : rooms.filter(room => room.userId === OC.currentUser).length + ' / ' + maxRooms;
const ownRoomsLength = rooms.filter(room => room.userId === OC.currentUser).length;
const quota = maxRooms < 0 ? t('bbb', 'unlimited') : ownRoomsLength + ' / ' + maxRooms;

return (
<div id="bbb-react-root"
Expand Down Expand Up @@ -188,7 +189,7 @@ const App: React.FC<Props> = () => {
{!isLoaded && <span className="icon icon-loading-small icon-visible"></span>}
</td>
<td>
{(maxRooms > rows.length || maxRooms < 0) ?
{(maxRooms > ownRoomsLength || maxRooms < 0) ?
<NewRoomForm addRoom={addRoom} /> :
<p className="text-muted">{maxRooms === 0 ?
t('bbb', 'You are not permitted to create a room.') :
Expand Down

0 comments on commit 3c45a93

Please sign in to comment.