mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 14:55:48 +08:00
FIX: hide emails on admin user list for moderators (#6781)
This commit is contained in:
parent
2fcbbead45
commit
0ce5f05b2a
|
@ -2,8 +2,9 @@ import debounce from "discourse/lib/debounce";
|
||||||
import { i18n } from "discourse/lib/computed";
|
import { i18n } from "discourse/lib/computed";
|
||||||
import AdminUser from "admin/models/admin-user";
|
import AdminUser from "admin/models/admin-user";
|
||||||
import { observes } from "ember-addons/ember-computed-decorators";
|
import { observes } from "ember-addons/ember-computed-decorators";
|
||||||
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend(CanCheckEmails, {
|
||||||
query: null,
|
query: null,
|
||||||
queryParams: ["order", "ascending"],
|
queryParams: ["order", "ascending"],
|
||||||
order: null,
|
order: null,
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
<div class="admin-title">
|
<div class="admin-title">
|
||||||
<h2>{{title}}</h2>
|
<h2>{{title}}</h2>
|
||||||
{{#unless showEmails}}
|
{{#if canCheckEmails}}
|
||||||
<button {{action "showEmails"}} class="show-emails btn btn-default">{{i18n 'admin.users.show_emails'}}</button>
|
<button {{action "showEmails"}} class="show-emails btn btn-default">{{i18n 'admin.users.show_emails'}}</button>
|
||||||
{{/unless}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div class='username controls'>
|
<div class='username controls'>
|
||||||
{{text-field value=listFilter placeholder=searchHint}}
|
{{text-field value=listFilter placeholder=searchHint}}
|
||||||
|
|
|
@ -38,8 +38,8 @@ class AdminUserListSerializer < BasicUserSerializer
|
||||||
|
|
||||||
def include_email?
|
def include_email?
|
||||||
# staff members can always see their email
|
# staff members can always see their email
|
||||||
(scope.is_staff? && object.id == scope.user.id) || scope.can_see_emails? ||
|
(scope.is_staff? && (object.id == scope.user.id || object.staged?)) ||
|
||||||
(scope.is_staff? && object.staged?)
|
(scope.is_admin? && scope.can_see_emails?)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :include_secondary_emails?, :include_email?
|
alias_method :include_secondary_emails?, :include_email?
|
||||||
|
|
|
@ -5,8 +5,10 @@ describe AdminUserListSerializer do
|
||||||
|
|
||||||
context "emails" do
|
context "emails" do
|
||||||
let(:admin) { Fabricate(:user_single_email, admin: true, email: "admin@email.com") }
|
let(:admin) { Fabricate(:user_single_email, admin: true, email: "admin@email.com") }
|
||||||
|
let(:moderator) { Fabricate(:user_single_email, moderator: true, email: "moderator@email.com") }
|
||||||
let(:user) { Fabricate(:user_single_email, email: "user@email.com") }
|
let(:user) { Fabricate(:user_single_email, email: "user@email.com") }
|
||||||
let(:guardian) { Guardian.new(admin) }
|
let(:guardian) { Guardian.new(admin) }
|
||||||
|
let(:mod_guardian) { Guardian.new(moderator) }
|
||||||
|
|
||||||
let(:json) do
|
let(:json) do
|
||||||
AdminUserListSerializer.new(user,
|
AdminUserListSerializer.new(user,
|
||||||
|
@ -15,6 +17,13 @@ describe AdminUserListSerializer do
|
||||||
).as_json
|
).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:mod_json) do
|
||||||
|
AdminUserListSerializer.new(user,
|
||||||
|
scope: mod_guardian,
|
||||||
|
root: false
|
||||||
|
).as_json
|
||||||
|
end
|
||||||
|
|
||||||
def fabricate_secondary_emails_for(u)
|
def fabricate_secondary_emails_for(u)
|
||||||
["first", "second"].each do |name|
|
["first", "second"].each do |name|
|
||||||
Fabricate(:secondary_email, user: u, email: "#{name}@email.com")
|
Fabricate(:secondary_email, user: u, email: "#{name}@email.com")
|
||||||
|
@ -57,6 +66,18 @@ describe AdminUserListSerializer do
|
||||||
include_examples "not shown"
|
include_examples "not shown"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when moderator makes a request with show_emails param set to true" do
|
||||||
|
before do
|
||||||
|
mod_guardian.can_see_emails = true
|
||||||
|
fabricate_secondary_emails_for(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't contain emails" do
|
||||||
|
expect(mod_json[:email]).to eq(nil)
|
||||||
|
expect(mod_json[:secondary_emails]).to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with a normal user after clicking 'show emails'" do
|
context "with a normal user after clicking 'show emails'" do
|
||||||
before do
|
before do
|
||||||
guardian.can_see_emails = true
|
guardian.can_see_emails = true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user