FIX: Mods weren't able to see emails in admin user list

This commit is contained in:
Gerhard Schlager 2019-01-18 15:26:44 +01:00
parent f774f08d5f
commit 457e6c7b37
3 changed files with 12 additions and 3 deletions

View File

@ -34,7 +34,7 @@ class Admin::UsersController < Admin::AdminController
opts = {}
if params[:show_emails] == "true"
StaffActionLogger.new(current_user).log_show_emails(users)
StaffActionLogger.new(current_user).log_show_emails(users, context: request.path)
opts[:emails_desired] = true
end

View File

@ -39,7 +39,7 @@ class AdminUserListSerializer < BasicUserSerializer
def include_email?
# staff members can always see their email
(scope.is_staff? && (object.id == scope.user.id || object.staged?)) ||
(scope.is_admin? && @options[:emails_desired])
(@options[:emails_desired] && scope.can_check_emails?(object))
end
alias_method :include_secondary_emails?, :include_email?

View File

@ -41,13 +41,22 @@ describe AdminUserListSerializer do
expect(json[:secondary_emails]).to eq(nil)
end
it "doesn't return emails for a moderator request" do
it "doesn't return emails for a moderator request when show_email_on_profile is disabled" do
SiteSetting.show_email_on_profile = false
fabricate_secondary_emails_for(user)
json = serialize(user, moderator, emails_desired: true)
expect(json[:email]).to eq(nil)
expect(json[:secondary_emails]).to eq(nil)
end
it "returns emails for a moderator request when show_email_on_profile is enabled" do
SiteSetting.show_email_on_profile = true
fabricate_secondary_emails_for(user)
json = serialize(user, moderator, emails_desired: true)
expect(json[:email]).to eq("user@email.com")
expect(json[:secondary_emails]).to contain_exactly("first@email.com", "second@email.com")
end
it "returns emails for admins when emails_desired is true" do
fabricate_secondary_emails_for(user)
json = serialize(user, admin, emails_desired: true)