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

@ -120,10 +120,9 @@ class JoinController extends Controller {
\OCP\Util::addHeader('meta', ['http-equiv' => 'refresh', 'content' => '3;url='.$joinUrl]); \OCP\Util::addHeader('meta', ['http-equiv' => 'refresh', 'content' => '3;url='.$joinUrl]);
return new TemplateResponse($this->appName, 'forward', [ return new TemplateResponse($this->appName, 'forward', [
'room' => $room->name, 'room' => $room->name,
'url' => $joinUrl, 'url' => $joinUrl,
], 'guest'); ], 'guest');
;
} }
private function getRoom(): ?Room { private function getRoom(): ?Room {

View File

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

View File

@ -6,9 +6,10 @@ type Props = {
field: string; field: string;
options: {[key: string]: string}; options: {[key: string]: string};
placeholder?: 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); const [active, setActive] = useState<boolean>(false);
currentValues = currentValues || []; 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 (<> 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"> {active && <ul className="bbb-selection">
{Object.keys(options).map(key => { {Object.keys(options).map(key => {
const label = options[key]; const label = options[key];
return ( return (
<li key={key}> <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> <label htmlFor={key}>{label}</label>
</li> </li>
); );

View File

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

View File

@ -48,7 +48,13 @@ const RestrictionRoom: React.FC<Props> = (props) => {
</td> </td>
<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>
<td className="max-participants bbb-shrink"> <td className="max-participants bbb-shrink">