feat: invert access restriction

pull/67/head
sualko 2020-08-28 11:36:15 +02:00
parent d6abf23792
commit 0afe8818e5
5 changed files with 24 additions and 12 deletions

View File

@ -123,7 +123,6 @@ class JoinController extends Controller {
'room' => $room->name,
'url' => $joinUrl,
], 'guest');
;
}
private function getRoom(): ?Room {

View File

@ -48,9 +48,7 @@ class RestrictionService {
}
$rRoomTypes = \json_decode($r->getRoomTypes());
if (count($rRoomTypes) > 0) {
$roomTypes = \array_merge($roomTypes, $rRoomTypes);
}
$roomTypes = array_intersect($roomTypes, $rRoomTypes);
if ($restriction->getMaxParticipants() > -1 && ($r->getMaxParticipants() === -1 || $restriction->getMaxParticipants() < $r->getMaxParticipants())) {
$restriction->setMaxParticipants($r->getMaxParticipants());
@ -63,7 +61,7 @@ class RestrictionService {
$restriction->setId(0);
$restriction->setGroupId('__cumulative');
$restriction->setRoomTypes(\json_encode(\array_values(\array_unique($roomTypes))));
$restriction->setRoomTypes(\json_encode(\array_values($roomTypes)));
return $restriction;
}

View File

@ -6,9 +6,10 @@ type Props = {
field: string;
options: {[key: string]: string};
placeholder?: string;
invert?: boolean;
}
const EditableSelection: React.FC<Props> = ({ setValue, field, values: currentValues, options, placeholder }) => {
const EditableSelection: React.FC<Props> = ({ setValue, field, values: currentValues, options, placeholder, invert = false }) => {
const [active, setActive] = useState<boolean>(false);
currentValues = currentValues || [];
@ -29,15 +30,23 @@ const EditableSelection: React.FC<Props> = ({ setValue, field, values: currentVa
}
}
const selection = !invert ? currentValues : (currentValues.length ? Object.keys(options).filter(option => currentValues?.indexOf(option) < 0) : []);
return (<>
<a className="action-rename" onClick={onClick}>{currentValues?.join(', ') || placeholder}</a>
<a className="action-rename" onClick={onClick}>{selection.join(', ') || placeholder}</a>
{active && <ul className="bbb-selection">
{Object.keys(options).map(key => {
const label = options[key];
return (
<li key={key}>
<input type="checkbox" id={key} className="checkbox" checked={currentValues.indexOf(key) > -1} value="1" onChange={(ev) => addOption(key, ev.target.checked)} />
<input
type="checkbox"
id={key}
className="checkbox"
checked={(currentValues.indexOf(key) > -1) !== invert}
value="1"
onChange={(ev) => addOption(key, ev.target.checked !== invert)} />
<label htmlFor={key}>{label}</label>
</li>
);

View File

@ -64,7 +64,7 @@ const App: React.FC<Props> = () => {
{t('bbb', 'Max. rooms')}
</th>
<th>
{t('bbb', 'Forbidden room types')}
{t('bbb', 'Access options')}
</th>
<th>
{t('bbb', 'Max. participants')}

View File

@ -48,7 +48,13 @@ const RestrictionRoom: React.FC<Props> = (props) => {
</td>
<td>
<EditableSelection field="roomTypes" values={restriction.roomTypes} options={AccessOptions} setValue={updateRestriction} placeholder={t('bbb', 'No restriction')} />
<EditableSelection
field="roomTypes"
values={restriction.roomTypes}
options={AccessOptions}
setValue={updateRestriction}
invert={true}
placeholder={t('bbb', 'All')} />
</td>
<td className="max-participants bbb-shrink">