Skip to content

Commit

Permalink
fix for when user does not have can create room permissions rooms pag…
Browse files Browse the repository at this point in the history
…e loads and doesnt error out (#5602)

Co-authored-by: Ahmad Farhat <[email protected]>
  • Loading branch information
SilentFlameCR and farhatahmad authored Dec 13, 2023
1 parent 98485dd commit 4554909
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
3 changes: 0 additions & 3 deletions app/controllers/api/v1/recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class RecordingsController < ApiController
before_action only: %i[update update_visibility recording_url] do
ensure_authorized(%w[ManageRecordings SharedRoom PublicRecordings], record_id: params[:id])
end
before_action only: %i[index recordings_count] do
ensure_authorized('CreateRoom')
end

# GET /api/v1/recordings.json
# Returns all of the current_user's recordings
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RoomsController < ApiController

before_action :find_room, only: %i[show update destroy recordings recordings_processing purge_presentation public_show public_recordings]

before_action only: %i[create index] do
before_action only: %i[create] do
ensure_authorized('CreateRoom')
end
before_action only: %i[create] do
Expand Down
13 changes: 8 additions & 5 deletions app/javascript/components/rooms/EmptyRoomsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import UserBoardIcon from './UserBoardIcon';
export default function EmptyRoomsList() {
const { t } = useTranslation();
const currentUser = useAuth();
const canCreate = currentUser?.permissions.CreateRoom;
const mutationWrapper = (args) => useCreateRoom({ userId: currentUser.id, ...args });

return (
Expand All @@ -39,11 +40,13 @@ export default function EmptyRoomsList() {
<Card.Text>
{ t('room.rooms_list_empty_create_room') }
</Card.Text>
<Modal
modalButton={<Button variant="brand" className="ms-auto me-xxl-1">{ t('room.add_new_room') }</Button>}
title={t('room.create_new_room')}
body={<CreateRoomForm mutation={mutationWrapper} userId={currentUser.id} />}
/>
{ (canCreate === 'true') && (
<Modal
modalButton={<Button variant="brand" className="ms-auto me-xxl-1">{ t('room.add_new_room') }</Button>}
title={t('room.create_new_room')}
body={<CreateRoomForm mutation={mutationWrapper} userId={currentUser.id} />}
/>
)}
</Card.Body>
</Card>
</div>
Expand Down
25 changes: 14 additions & 11 deletions app/javascript/components/rooms/RoomsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function RoomsList() {
const [searchInput, setSearchInput] = useState('');
const { isLoading, data: rooms } = useRooms(searchInput);
const currentUser = useAuth();
const canCreate = currentUser?.permissions.CreateRoom;
const mutationWrapper = (args) => useCreateRoom({ userId: currentUser.id, ...args });

if (!isLoading && rooms?.length === 0 && !searchInput) {
Expand All @@ -47,17 +48,19 @@ export default function RoomsList() {
<div>
<SearchBar searchInput={searchInput} id="rooms-search" setSearchInput={setSearchInput} />
</div>
<Modal
modalButton={(
<Button
variant="brand"
className="ms-auto me-xxl-1"
>{t('room.add_new_room')}
</Button>
)}
title={t('room.create_new_room')}
body={<CreateRoomForm mutation={mutationWrapper} userId={currentUser.id} />}
/>
{ (canCreate === 'true') && (
<Modal
modalButton={(
<Button
variant="brand"
className="ms-auto me-xxl-1"
>{t('room.add_new_room')}
</Button>
)}
title={t('room.create_new_room')}
body={<CreateRoomForm mutation={mutationWrapper} userId={currentUser.id} />}
/>
)}
</Stack>
<Row className="g-4 mt-4">
{
Expand Down

0 comments on commit 4554909

Please sign in to comment.