Files
discourse/spec/serializers/admin_detailed_user_serializer_spec.rb
Krzysztof Kotlarek 290b435a72 FIX: Admin can edit the name even if enable_names is disabled (#33170)
There is a bug that when `SiteSetting.enable_names` is disabled, the
admin can click the pencil next to the user and successfully update the
name. However, the change is not saved as the action is blocked by the
guardian.

Meta:
https://meta.discourse.org/t/disabling-enable-names-makes-admin-act-strange/291912
2025-06-16 09:24:17 +08:00

18 lines
579 B
Ruby

# frozen_string_literal: true
RSpec.describe AdminDetailedUserSerializer do
fab!(:user) { Fabricate(:user, trust_level: 0) }
fab!(:admin)
fab!(:moderator)
it "serializes name for admin even if enable_names setting is false" do
serializer = AdminDetailedUserSerializer.new(user, scope: Guardian.new(admin), root: false)
json = serializer.as_json
expect(json[:name]).to eq(user.name)
serializer = AdminDetailedUserSerializer.new(user, scope: Guardian.new(moderator), root: false)
json = serializer.as_json
expect(json[:name]).to be_nil
end
end