Skip to content
Snippets Groups Projects
Unverified Commit 43371343 authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

Added missing features from external login (#4741)

* Added missing features from external login

* quick fix
parent 984a25c5
No related branches found
No related tags found
No related merge requests found
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
"administration": { "administration": {
"administration": "Administration", "administration": "Administration",
"terms": "Terms & Conditions", "terms": "Terms & Conditions",
"privacy": "Privacy", "privacy": "Privacy Policy",
"privacy_policy": "Privacy Policy", "privacy_policy": "Privacy Policy",
"change_term_links": "Change the terms links that appears at the bottom of the page", "change_term_links": "Change the terms links that appears at the bottom of the page",
"change_privacy_link": "Change the privacy link that appears at the bottom of the page", "change_privacy_link": "Change the privacy link that appears at the bottom of the page",
...@@ -395,6 +395,7 @@ ...@@ -395,6 +395,7 @@
"role_assigned": "This role can't be deleted as it is assigned to at least one user." "role_assigned": "This role can't be deleted as it is assigned to at least one user."
}, },
"users": { "users": {
"signup_error": "There was an error signing you in. Please contact your administrator.",
"invalid_invite": "Your invitation token is either invalid or incorrect. Please contact your administrator to receive a new one", "invalid_invite": "Your invitation token is either invalid or incorrect. Please contact your administrator to receive a new one",
"email_exists": "An account under this email already exists. Please try again with another email", "email_exists": "An account under this email already exists. Please try again with another email",
"old_password": "The current password you have entered is incorrect", "old_password": "The current password you have entered is incorrect",
......
...@@ -133,13 +133,6 @@ module Api ...@@ -133,13 +133,6 @@ module Api
@update_user_params ||= params.require(:user).permit(:name, :password, :avatar, :language, :role_id, :invite_token) @update_user_params ||= params.require(:user).permit(:name, :password, :avatar, :language, :role_id, :invite_token)
end end
def create_default_room(user)
return unless user.rooms.count <= 0
return unless PermissionsChecker.new(permission_names: 'CreateRoom', user_id: user.id, current_user: user, current_provider:).call
Room.create(name: "#{user.name}'s Room", user_id: user.id)
end
def change_password_params def change_password_params
params.require(:user).permit(:old_password, :new_password) params.require(:user).permit(:old_password, :new_password)
end end
......
...@@ -41,6 +41,14 @@ class ApplicationController < ActionController::Base ...@@ -41,6 +41,14 @@ class ApplicationController < ActionController::Base
@default_role = Role.find_by(name: default_role_setting, provider: current_provider) || Role.find_by(name: 'User', provider: current_provider) @default_role = Role.find_by(name: default_role_setting, provider: current_provider) || Role.find_by(name: 'User', provider: current_provider)
end end
# Creates the default room for the user if they don't already have one
def create_default_room(user)
return unless user.rooms.count <= 0
return unless PermissionsChecker.new(permission_names: 'CreateRoom', user_id: user.id, current_user: user, current_provider:).call
Room.create(name: "#{user.name}'s Room", user_id: user.id)
end
private private
# Checks if the user's session_token matches the session and that it is not expired # Checks if the user's session_token matches the session and that it is not expired
......
...@@ -13,6 +13,7 @@ class ExternalController < ApplicationController ...@@ -13,6 +13,7 @@ class ExternalController < ApplicationController
name: credentials['info']['name'], name: credentials['info']['name'],
email: credentials['info']['email'], email: credentials['info']['email'],
language: extract_language_code(credentials['info']['locale']), language: extract_language_code(credentials['info']['locale']),
external_id: credentials['uid'],
verified: true verified: true
} }
...@@ -27,7 +28,11 @@ class ExternalController < ApplicationController ...@@ -27,7 +28,11 @@ class ExternalController < ApplicationController
end end
# Create the user if they dont exist # Create the user if they dont exist
user = User.create({ external_id: credentials['uid'], provider:, role: default_role }.merge(user_info)) if new_user if new_user
user = UserCreator.new(user_params: user_info, provider: current_provider, role: default_role).call
user.save!
create_default_room(user)
end
if SettingGetter.new(setting_name: 'ResyncOnLogin', provider:).call if SettingGetter.new(setting_name: 'ResyncOnLogin', provider:).call
user.assign_attributes(user_info.except(:language)) # Don't reset the user's language user.assign_attributes(user_info.except(:language)) # Don't reset the user's language
...@@ -49,6 +54,9 @@ class ExternalController < ApplicationController ...@@ -49,6 +54,9 @@ class ExternalController < ApplicationController
return redirect_to redirect_location if redirect_location&.match?('\A\/rooms\/\w{3}-\w{3}-\w{3}-\w{3}\/join\z') return redirect_to redirect_location if redirect_location&.match?('\A\/rooms\/\w{3}-\w{3}-\w{3}-\w{3}\/join\z')
redirect_to '/rooms' redirect_to '/rooms'
rescue StandardError => e
Rails.logger.error("Error during authentication: #{e}")
redirect_to '/?error=SignupError'
end end
# POST /recording_ready # POST /recording_ready
......
...@@ -15,7 +15,7 @@ export default function HomePage() { ...@@ -15,7 +15,7 @@ export default function HomePage() {
const { t } = useTranslation(); const { t } = useTranslation();
const currentUser = useAuth(); const currentUser = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const [searchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const error = searchParams.get('error'); const error = searchParams.get('error');
// Redirects the user to the proper page based on signed in status and CreateRoom permission // Redirects the user to the proper page based on signed in status and CreateRoom permission
...@@ -33,9 +33,17 @@ export default function HomePage() { ...@@ -33,9 +33,17 @@ export default function HomePage() {
// hack to deal with the fact that useEffect and toast dont work together very well // hack to deal with the fact that useEffect and toast dont work together very well
useMemo(() => { useMemo(() => {
if (error === 'InviteInvalid') { switch (error) {
case 'InviteInvald':
toast.error(t('toast.error.users.invalid_invite')); toast.error(t('toast.error.users.invalid_invite'));
break;
case 'SignupError':
toast.error(t('toast.error.users.signup_error'));
break;
default:
} }
// Remove the error
setSearchParams(searchParams.delete('error'));
}, [error]); }, [error]);
return ( return (
......
...@@ -239,6 +239,25 @@ RSpec.describe ExternalController, type: :controller do ...@@ -239,6 +239,25 @@ RSpec.describe ExternalController, type: :controller do
end end
end end
end end
context 'Role mapping' do
let!(:role1) { create(:role, name: 'role1') }
before do
role_map = instance_double(SettingGetter)
allow(SettingGetter).to receive(:new).with(setting_name: 'RoleMapping', provider: 'greenlight').and_return(role_map)
allow(role_map).to receive(:call).and_return(
"role1=#{OmniAuth.config.mock_auth[:openid_connect][:info][:email].split('@')[1]}"
)
end
it 'Creates a User and assign a role if a rule matches their email' do
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).by(1)
expect(User.find_by(email: OmniAuth.config.mock_auth[:openid_connect][:info][:email]).role).to eq(role1)
end
end
end end
describe '#recording_ready' do describe '#recording_ready' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment