Skip to content

Commit

Permalink
Merge branch 'master' into SIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianAppDev authored Jan 13, 2025
2 parents e97338f + 5e1dbb4 commit 7a907c4
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Metrics/ClassLength:
# A calculated magnitude based on number of assignments,
# branches, and conditions.
Metrics/AbcSize:
Max: 90
Max: 95

Metrics/ParameterLists:
CountKeywordArgs: false
Expand All @@ -82,10 +82,10 @@ RSpec/AnyInstance:
Enabled: false

Metrics/CyclomaticComplexity:
Max: 20
Max: 25

Metrics/PerceivedComplexity:
Max: 20
Max: 25

Rails/Exit:
Exclude:
Expand Down
20 changes: 12 additions & 8 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def show
render_data data: user, status: :ok
end

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize
# POST /api/v1/users.json
# Creates and saves a new user record in the database with the provided parameters
def create
Expand All @@ -62,7 +62,7 @@ def create
create_user_params[:language] = current_user&.language || I18n.default_locale if create_user_params[:language].blank?

# renders an error if the user is signing up with an invalid domain based off site settings
return render_error errors: Rails.configuration.custom_error_msgs[:unauthorized], status: :forbidden unless valid_domain?
return render_error errors: Rails.configuration.custom_error_msgs[:banned_user], status: :forbidden unless valid_domain?

user = UserCreator.new(user_params: create_user_params.except(:invite_token), provider: current_provider, role: default_role).call

Expand Down Expand Up @@ -97,7 +97,7 @@ def create
render_error errors: Rails.configuration.custom_error_msgs[:record_invalid], status: :bad_request
end
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize

# PATCH /api/v1/users/:id.json
# Updates the values of a user
Expand Down Expand Up @@ -169,11 +169,7 @@ def create_user_params
end

def update_user_params
@update_user_params ||= if external_auth?
params.require(:user).permit(:password, :avatar, :language, :role_id, :invite_token)
else
params.require(:user).permit(:name, :password, :avatar, :language, :role_id, :invite_token)
end
@update_user_params ||= params.require(:user).permit(permitted_params)
end

def change_password_params
Expand All @@ -198,6 +194,14 @@ def valid_domain?
end
false
end

def permitted_params
is_admin = PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call

return %i[password avatar language role_id invite_token] if external_auth? && !is_admin

%i[name password avatar language role_id invite_token]
end
end
end
end
7 changes: 5 additions & 2 deletions app/controllers/external_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def create_user
return redirect_to root_path(error: Rails.configuration.custom_error_msgs[:invite_token_invalid])
end

return render_error status: :forbidden unless valid_domain?(user_info[:email])
# Redirect to root if the user doesn't exist and has an invalid domain
return redirect_to root_path(error: Rails.configuration.custom_error_msgs[:banned_user]) if new_user && !valid_domain?(user_info[:email])

# Create the user if they dont exist
# Create the user if they don't exist
if new_user
user = UserCreator.new(user_params: user_info, provider: current_provider, role: default_role).call
user.save!
Expand Down Expand Up @@ -113,6 +114,8 @@ def recording_ready
RecordingCreator.new(recording:, first_creation: true).call

render json: {}, status: :ok
rescue JWT::DecodeError
render json: {}, status: :unauthorized
end

# GET /meeting_ended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default function Registration() {
<input
className="form-control"
placeholder={t('admin.site_settings.registration.enter_allowed_domains_rule')}
defaultValue={siteSettings?.AllowedDomains}
/>
<Button
variant="brand"
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/components/home/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export default function HomePage() {
case 'SignupError':
toast.error(t('toast.error.users.signup_error'));
break;
case 'BannedUser':
toast.error(t('toast.error.users.banned'));
break;
default:
}
if (error) { setSearchParams(searchParams.delete('error')); }
Expand Down
6 changes: 4 additions & 2 deletions app/javascript/components/rooms/room/join/JoinCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import useRoomJoinForm from '../../../../hooks/forms/rooms/useRoomJoinForm';
import ButtonLink from '../../../shared_components/utilities/ButtonLink';
import Title from '../../../shared_components/utilities/Title';
import useRoomConfigValue from '../../../../hooks/queries/rooms/useRoomConfigValue';
import usePublicRecordings from '../../../../hooks/queries/recordings/usePublicRecordings';

export default function JoinCard() {
const { t } = useTranslation();
Expand All @@ -53,6 +54,7 @@ export default function JoinCard() {

const publicRoom = usePublicRoom(friendlyId);
const roomStatusAPI = useRoomStatus(friendlyId, joinInterval);
const { data: recordings } = usePublicRecordings({ friendlyId });

const { data: env } = useEnv();
const { data: recordValue } = useRoomConfigValue('record');
Expand All @@ -69,7 +71,7 @@ export default function JoinCard() {

useEffect(() => { // set cookie to return to if needed
const date = new Date();
date.setTime(date.getTime() + (60 * 1000)); // expire the cookie in 1min
date.setTime(date.getTime() + (60 * 10000)); // expire the cookie in 10min
document.cookie = `location=${path};path=/;expires=${date.toGMTString()}`;

return () => { // delete redirect location when unmounting
Expand Down Expand Up @@ -222,7 +224,7 @@ export default function JoinCard() {
<h1 className="mt-2">
{publicRoom?.data.name}
</h1>
{ (recordValue !== 'false') && (
{ (recordValue !== 'false') && recordings?.data?.length > 0 && (
<ButtonLink
variant="brand-outline"
className="mt-3 mb-0 cursor-pointer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function UpdateUserForm({ user }) {

return (
<Form methods={methods} onSubmit={updateUserAPI.mutate}>
<FormControl field={fields.name} type="text" readOnly={currentUser.external_account} />
<FormControl field={fields.name} type="text" readOnly={user.external_account && !PermissionChecker.hasManageUsers(currentUser)} />
<FormControl field={fields.email} type="email" readOnly />
<FormSelect field={fields.language} variant="dropdown">
{
Expand Down Expand Up @@ -102,6 +102,7 @@ UpdateUserForm.propTypes = {
name: PropTypes.string.isRequired,
email: PropTypes.string.isRequired,
provider: PropTypes.string.isRequired,
external_account: PropTypes.bool.isRequired,
role: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/hooks/mutations/users/useCreateUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default function useCreateUser() {
toast.error(t('toast.error.users.invalid_invite'));
} else if (err.response.data.errors === 'EmailAlreadyExists') {
toast.error(t('toast.error.users.email_exists'));
} else if (err.response.data.errors === 'BannedUser') {
toast.error(t('toast.error.users.banned'));
} else {
toast.error(t('toast.error.problem_completing_action'));
}
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/current_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
# frozen_string_literal: true

class CurrentUserSerializer < UserSerializer
attributes :signed_in, :permissions, :status, :external_account, :super_admin
attributes :signed_in, :permissions, :status, :super_admin

def signed_in
true
end

def external_account
object.external_id?
end

def permissions
RolePermission.joins(:permission)
.where(role_id: object.role_id)
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
class UserSerializer < ApplicationSerializer
include Avatarable

attributes :id, :name, :email, :provider, :language, :avatar, :verified, :created_at
attributes :id, :name, :email, :provider, :language, :avatar, :verified, :created_at, :external_account

belongs_to :role

def language
object.language.tr('_', '-')
end

def external_account
object.external_id?
end

def avatar
user_avatar(object)
end
Expand Down
1 change: 1 addition & 0 deletions bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fi

rails assets:precompile
rails db:create
rails db:migrate
rails db:migrate:with_data

exec rails s -b 0.0.0.0 -p $PORT
9 changes: 9 additions & 0 deletions spec/controllers/external_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@

expect { get :create_user, params: { provider: 'openid_connect' } }.not_to change(User, :count)
end

it 'does not affect existing users with different domains' do
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]

create(:user, external_id: OmniAuth.config.mock_auth[:openid_connect][:uid])

get :create_user, params: { provider: 'openid_connect' }
expect(response).not_to redirect_to(root_path(error: Rails.configuration.custom_error_msgs[:banned_user]))
end
end

context 'restricted domain set to multiple domain' do
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,21 @@

expect(user.role_id).to eq(updated_params[:role_id])
end

it 'allows a user with ManageUser permissions to edit an external users name' do
sign_in_user(user_with_manage_users_permission)

external_user = create(:user, external_id: 'external-id')
updated_params = {
name: 'New External Name'
}

patch :update, params: { id: external_user.id, user: updated_params }

external_user.reload

expect(external_user.name).to eq(updated_params[:name])
end
end

describe '#destroy' do
Expand Down

0 comments on commit 7a907c4

Please sign in to comment.