fix: #290 max number of rooms shloud take only owned rooms in account

Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
pull/296/head
Sebastien Marinier 2024-10-22 17:11:41 +02:00
parent 7233d21a85
commit 79518b9bac
3 changed files with 10 additions and 5 deletions

View File

@ -55,10 +55,13 @@ class Permission {
} }
public function isAllowedToCreateRoom(string $uid): bool { public function isAllowedToCreateRoom(string $uid): bool {
$numberOfCreatedRooms = count($this->roomService->findAll($uid, [], []));
$restriction = $this->getRestriction($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 { public function isUser(Room $room, ?string $uid): bool {

View File

@ -83,7 +83,8 @@ class PermissionTest extends TestCase {
$this->roomService $this->roomService
->expects($this->once()) ->expects($this->once())
->method('findAll') ->method('findByUserId')
->with('foobar')
->willReturn([ ->willReturn([
$this->createRoom(1, 'foo'), $this->createRoom(1, 'foo'),
$this->createRoom(2, 'bar'), $this->createRoom(2, 'bar'),

View File

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