Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@
},
"allowed_domains": "Allowed Email Domains",
"allowed_domains_signup_description": "Allow specific email domains to sign up. Format must be: @test.com,domain.com",
"enter_allowed_domains_rule" : "Enter the allowed domains"
"enter_allowed_domains_rule" : "Enter the allowed domains",
"allow_name_update": "Allow Users To Update Their Name",
"allow_name_update_description": "Allow users to change their name after account creation. When disabled, only admins can update user names."
}
},
"room_configuration": {
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def permitted_params

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

allow_name_update = SettingGetter.new(setting_name: 'AllowNameUpdate', provider: current_provider).call

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

%i[name password avatar language role_id invite_token]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Registration() {
const { t } = useTranslation();
const { data: env } = useEnv();
const { data: siteSettings } = useSiteSettings(
['RoleMapping', 'DefaultRole', 'ResyncOnLogin', 'SignInOnRoomJoin', 'RegistrationMethod', 'AllowedDomains'],
['RoleMapping', 'DefaultRole', 'ResyncOnLogin', 'SignInOnRoomJoin', 'RegistrationMethod', 'AllowedDomains', 'AllowNameUpdate'],
);
const { data: roles } = useRoles();
const updateRegistrationMethod = useUpdateSiteSetting('RegistrationMethod');
Expand Down Expand Up @@ -95,6 +95,17 @@ export default function Registration() {
value={siteSettings?.SignInOnRoomJoin}
/>

<SettingsRow
name="AllowNameUpdate"
title={t('admin.site_settings.registration.allow_name_update')}
description={(
<p className="text-muted">
{t('admin.site_settings.registration.allow_name_update_description')}
</p>
)}
value={siteSettings?.AllowNameUpdate}
/>

<Row className="mb-3">
<strong> { t('admin.site_settings.registration.role_mapping_by_email') } </strong>
<p className="text-muted"> { t('admin.site_settings.registration.role_mapping_by_email_description') } </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import useLocales from '../../../../hooks/queries/locales/useLocales';
import useUpdateUserForm from '../../../../hooks/forms/users/user/useUpdateUserForm';
import PermissionChecker from '../../../../helpers/PermissionChecker';
import useCreateResetPwd from '../../../../hooks/mutations/users/useCreateResetPwd';
import useSiteSetting from '../../../../hooks/queries/site_settings/useSiteSetting';

export default function UpdateUserForm({ user }) {
const { t } = useTranslation();
Expand All @@ -42,6 +43,9 @@ export default function UpdateUserForm({ user }) {

const { data: roles } = useRoles({ enabled: canUpdateRole });
const { data: locales } = useLocales();
const { data: allowNameUpdate } = useSiteSetting('AllowNameUpdate');
const nameReadOnly = (!allowNameUpdate && !PermissionChecker.hasManageUsers(currentUser))
|| (user.external_account && !PermissionChecker.hasManageUsers(currentUser));
const updateUserAPI = useUpdateUser(user?.id);
const resetPasswordAPI = useCreateResetPwd({ shouldNavigate: false });

Expand Down Expand Up @@ -72,7 +76,7 @@ export default function UpdateUserForm({ user }) {

return (
<Form methods={methods} onSubmit={updateUserAPI.mutate}>
<FormControl field={fields.name} type="text" readOnly={user.external_account && !PermissionChecker.hasManageUsers(currentUser)} />
<FormControl field={fields.name} type="text" readOnly={nameReadOnly} />
<FormControl field={fields.email} type="email" readOnly />
<FormSelect field={fields.language} variant="dropdown">
{
Expand Down
23 changes: 23 additions & 0 deletions db/data/20260402000001_add_allow_name_update_to_site_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class AddAllowNameUpdateToSiteSettings < ActiveRecord::Migration[7.0]
def up
setting = Setting.find_or_create_by(name: 'AllowNameUpdate')

SiteSetting.create!(setting:, value: 'true', provider: 'greenlight') unless SiteSetting.exists?(setting:, provider: 'greenlight')

Tenant.find_each do |tenant|
SiteSetting.create!(setting:, value: 'true', provider: tenant.name) unless SiteSetting.exists?(setting:, provider: tenant.name)
end
end

def down
Tenant.find_each do |tenant|
SiteSetting.find_by(setting: Setting.find_by(name: 'AllowNameUpdate'), provider: tenant.name)&.destroy
end

SiteSetting.find_by(setting: Setting.find_by(name: 'AllowNameUpdate'), provider: 'greenlight')&.destroy

Setting.find_by(name: 'AllowNameUpdate')&.destroy
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataMigrate::Data.define(version: 20250501185954)
DataMigrate::Data.define(version: 2026_04_02_000001)
3 changes: 3 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@
describe '#update' do
before do
sign_in_user(user)
allow(SettingGetter).to receive(:new).and_call_original
allow(SettingGetter).to receive(:new).with(setting_name: 'AllowNameUpdate', provider: 'greenlight').and_return(fake_setting_getter)
allow(fake_setting_getter).to receive(:call).and_return(true)
end

it 'updates the users attributes' do
Expand Down
Loading