From 0afe8818e51bcafe4f8e2ad50f5c924667b6287b Mon Sep 17 00:00:00 2001 From: sualko Date: Fri, 28 Aug 2020 11:36:15 +0200 Subject: [PATCH] feat: invert access restriction --- lib/Controller/JoinController.php | 5 ++--- lib/Service/RestrictionService.php | 6 ++---- ts/Common/EditableSelection.tsx | 15 ++++++++++++--- ts/Restrictions/App.tsx | 2 +- ts/Restrictions/RestrictionRow.tsx | 8 +++++++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/Controller/JoinController.php b/lib/Controller/JoinController.php index a311cbc..b734f58 100644 --- a/lib/Controller/JoinController.php +++ b/lib/Controller/JoinController.php @@ -120,10 +120,9 @@ class JoinController extends Controller { \OCP\Util::addHeader('meta', ['http-equiv' => 'refresh', 'content' => '3;url='.$joinUrl]); return new TemplateResponse($this->appName, 'forward', [ - 'room' => $room->name, - 'url' => $joinUrl, + 'room' => $room->name, + 'url' => $joinUrl, ], 'guest'); - ; } private function getRoom(): ?Room { diff --git a/lib/Service/RestrictionService.php b/lib/Service/RestrictionService.php index 8e7a13c..7670c42 100644 --- a/lib/Service/RestrictionService.php +++ b/lib/Service/RestrictionService.php @@ -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; } diff --git a/ts/Common/EditableSelection.tsx b/ts/Common/EditableSelection.tsx index 534b356..4ea029f 100644 --- a/ts/Common/EditableSelection.tsx +++ b/ts/Common/EditableSelection.tsx @@ -6,9 +6,10 @@ type Props = { field: string; options: {[key: string]: string}; placeholder?: string; + invert?: boolean; } -const EditableSelection: React.FC = ({ setValue, field, values: currentValues, options, placeholder }) => { +const EditableSelection: React.FC = ({ setValue, field, values: currentValues, options, placeholder, invert = false }) => { const [active, setActive] = useState(false); currentValues = currentValues || []; @@ -29,15 +30,23 @@ const EditableSelection: React.FC = ({ setValue, field, values: currentVa } } + const selection = !invert ? currentValues : (currentValues.length ? Object.keys(options).filter(option => currentValues?.indexOf(option) < 0) : []); + return (<> - {currentValues?.join(', ') || placeholder} + {selection.join(', ') || placeholder} {active &&
    {Object.keys(options).map(key => { const label = options[key]; return (
  • - -1} value="1" onChange={(ev) => addOption(key, ev.target.checked)} /> + -1) !== invert} + value="1" + onChange={(ev) => addOption(key, ev.target.checked !== invert)} />
  • ); diff --git a/ts/Restrictions/App.tsx b/ts/Restrictions/App.tsx index 1f670d8..477a933 100644 --- a/ts/Restrictions/App.tsx +++ b/ts/Restrictions/App.tsx @@ -64,7 +64,7 @@ const App: React.FC = () => { {t('bbb', 'Max. rooms')} - {t('bbb', 'Forbidden room types')} + {t('bbb', 'Access options')} {t('bbb', 'Max. participants')} diff --git a/ts/Restrictions/RestrictionRow.tsx b/ts/Restrictions/RestrictionRow.tsx index 98c300d..f622b52 100644 --- a/ts/Restrictions/RestrictionRow.tsx +++ b/ts/Restrictions/RestrictionRow.tsx @@ -48,7 +48,13 @@ const RestrictionRoom: React.FC = (props) => { - +