Skip to content

Commit

Permalink
Fix for superadmins when changing pages (#5470)
Browse files Browse the repository at this point in the history
* Fix for superadmins when changing pages

* eslint
  • Loading branch information
farhatahmad authored Oct 18, 2023
1 parent 9331123 commit 03598be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def append_info_to_payload(payload)
def invalid_session?(user)
return true if user&.session_token != session[:session_token]
return true if user&.session_expiry && DateTime.now > user&.session_expiry
return true if !user.super_admin? && user.provider != current_provider

false
end
Expand Down
9 changes: 7 additions & 2 deletions app/javascript/routes/AuthenticatedOnly.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function AuthenticatedOnly() {
const { t } = useTranslation();
const currentUser = useAuth();
const location = useLocation();
const match = useMatch('/rooms/:friendlyId');
const roomsMatch = useMatch('/rooms/:friendlyId');
const superAdminMatch = useMatch('/admin/*');
const deleteSession = useDeleteSession({ showToast: false });

// User is either pending or banned
Expand All @@ -44,10 +45,14 @@ export default function AuthenticatedOnly() {
}

// Custom logic to redirect from Rooms page to join page if the user isn't signed in
if (!currentUser.signed_in && match) {
if (!currentUser.signed_in && roomsMatch) {
return <Navigate to={`${location.pathname}/join`} />;
}

if (currentUser.signed_in && currentUser.isSuperAdmin && !superAdminMatch) {
return <Navigate to="/admin/users" />;
}

if (!currentUser.signed_in) {
toast.error(t('toast.error.signin_required'));
return <Navigate to="/" />;
Expand Down
23 changes: 23 additions & 0 deletions config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with Greenlight; if not, see <http://www.gnu.org/licenses/>.

# frozen_string_literal: true

if ENV['LOADBALANCER_ENDPOINT'].present?
Rails.application.config.session_store :cookie_store, key: '_greenlight-3_0_session', domain: ENV.fetch('SESSION_DOMAIN_NAME', nil)
else
Rails.application.config.session_store :cookie_store, key: '_greenlight-3_0_session'
end

0 comments on commit 03598be

Please sign in to comment.