Compare commits

...

8 Commits

Author SHA1 Message Date
Thibaut e5bfcc8ec8
Merge pull request #294 from arawa/fix/style_lint_and_typescript
fix: style lint warnings and typescript compiler need upgrade
2024-10-23 10:49:14 +02:00
Thibaut dede2b2857
Merge pull request #295 from arawa/fix/289/admin_interface_displays_gid
fix: #289 admin interface displays groups gid instead of displayname
2024-10-23 10:43:30 +02:00
Thibaut 3c45a93ece
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
2024-10-23 10:41:35 +02:00
Sebastien Marinier 79518b9bac fix: #290 max number of rooms shloud take only owned rooms in account
Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
2024-10-22 17:11:41 +02:00
Sebastien Marinier ab80d613e7 fix: unit test with groupManager
Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
2024-10-22 16:21:15 +02:00
Sebastien Marinier da0cc79b9e fix: unit test with groupManager
Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
2024-10-22 15:46:50 +02:00
Sebastien Marinier 71fe272888 fix: #289 admin interface displays groups gid instead of displayname
Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
2024-10-22 15:30:10 +02:00
Sebastien Marinier 323e9df9f4 fix: style lint warnings and typescript compiler need upgrade
Signed-off-by: Sebastien Marinier <sebastien.marinier@arawa.fr>
2024-10-22 15:04:46 +02:00
11 changed files with 81 additions and 55 deletions

View File

@ -16,11 +16,13 @@ use OCP\AppFramework\Db\Entity;
* @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;
@ -32,10 +34,15 @@ class Restriction extends Entity implements JsonSerializable {
$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,

View File

@ -19,8 +19,9 @@ class RestrictionMapper extends QBMapper {
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);
@ -33,8 +34,9 @@ class RestrictionMapper extends QBMapper {
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);
@ -46,8 +48,9 @@ class RestrictionMapper extends QBMapper {
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> */
@ -60,8 +63,9 @@ class RestrictionMapper extends QBMapper {
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);

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

@ -9,13 +9,18 @@ use OCA\BigBlueButton\Db\RestrictionMapper;
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 {
@ -78,6 +83,10 @@ class RestrictionService {
$restriction = new Restriction();
$restriction->setGroupId($groupId);
$group = $this->groupManager->get($groupId);
if ($group) {
$restriction->setGroupName($group->getDisplayName());
}
return $this->mapper->insert($restriction);
}

View File

@ -109,7 +109,7 @@
"stylelint-config-recommended-scss": "^5.0.2",
"stylelint-scss": "^4.2.0",
"ts-loader": "^9.2.8",
"typescript": "^4.0.2",
"typescript": "^4.9.3",
"url-loader": "^4.0.0",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",

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

@ -8,16 +8,19 @@ use OCA\BigBlueButton\Db\Restriction;
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() {

View File

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

View File

@ -37,6 +37,36 @@
opacity: 0.6;
}
.bbb-qrcode-container {
display: block;
height: 34px;
width: 34px;
margin: 3px;
position: relative;
cursor: zoom-in;
canvas {
max-width: 100%;
max-height: 100%;
position: absolute;
top: 0;
right: 0;
}
input[type="checkbox"] {
display: none;
&:checked + canvas {
max-width: none;
max-height: none;
box-shadow: 0 0 10px;
box-shadow: 0 0 5px var(--color-box-shadow);
cursor: zoom-out;
border: 5px solid #fff;
}
}
}
#bbb-root, #bbb-app {
width: 100%;
background-color: var(--color-main-background);
@ -95,10 +125,6 @@ pre {
}
}
#bbb-react-root table tbody tr td {
border-bottom: 1px solid var(--color-border-dark);
}
#bbb-react-root,
#bbb-restrictions {
#bbb-warning,
@ -194,6 +220,7 @@ pre {
padding: 0 6px;
position: relative;
display: table-cell;
border-bottom: 1px solid var(--color-border-dark);
& > form {
margin: -10px;
@ -298,39 +325,9 @@ pre {
}
.bbb-simple-menu {
min-width: auto;
min-width: auto;
}
.bbb-input-container {
display: flex;
}
.bbb-qrcode-container {
display: block;
height: 34px;
width: 34px;
margin: 3px;
position: relative;
cursor: zoom-in;
canvas {
max-width: 100%;
max-height: 100%;
position: absolute;
top: 0;
right: 0;
}
input[type="checkbox"] {
display: none;
&:checked + canvas {
max-width: none;
max-height: none;
box-shadow: 0 0 10px;
box-shadow: 0 0 5px var(--color-box-shadow);
cursor: zoom-out;
border: 5px solid #fff;
}
}
}

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

View File

@ -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);
@ -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>