Merge pull request #296 from arawa/fix/290/max_number_of_rooms_count_only_owned_rooms

fix: #290 max number of rooms shloud take only owned rooms in account
pull/298/head
Thibaut 2024-10-23 10:41:35 +02:00 committed by GitHub
commit 3c45a93ece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -55,10 +55,13 @@ class Permission {
}
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 {

View File

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

View File

@ -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"
@ -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.') :