mirror of
https://github.com/discourse/discourse.git
synced 2025-04-28 20:14:35 +08:00
serialize can_be_deleted field only when needed
This commit is contained in:
parent
728fcab49d
commit
0369f9a4a5
@ -32,7 +32,7 @@ class Admin::UsersController < Admin::StaffController
|
|||||||
def index
|
def index
|
||||||
users = ::AdminUserIndexQuery.new(params).find_users
|
users = ::AdminUserIndexQuery.new(params).find_users
|
||||||
|
|
||||||
opts = {}
|
opts = { include_can_be_deleted: true }
|
||||||
if params[:show_emails] == "true"
|
if params[:show_emails] == "true"
|
||||||
StaffActionLogger.new(current_user).log_show_emails(users, context: request.path)
|
StaffActionLogger.new(current_user).log_show_emails(users, context: request.path)
|
||||||
opts[:emails_desired] = true
|
opts[:emails_desired] = true
|
||||||
|
@ -116,4 +116,8 @@ class AdminUserListSerializer < BasicUserSerializer
|
|||||||
def can_be_deleted
|
def can_be_deleted
|
||||||
scope.can_delete_user?(object)
|
scope.can_delete_user?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_can_be_deleted?
|
||||||
|
@options[:include_can_be_deleted]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,4 +89,24 @@ RSpec.describe AdminUserListSerializer do
|
|||||||
expect(json[:secondary_emails]).to contain_exactly("first@email.com", "second@email.com")
|
expect(json[:secondary_emails]).to contain_exactly("first@email.com", "second@email.com")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#can_be_deleted" do
|
||||||
|
it "is not included if the include_can_be_deleted option is not present" do
|
||||||
|
json = AdminUserListSerializer.new(user, scope: guardian, root: false).as_json
|
||||||
|
|
||||||
|
expect(json.key?(:can_be_deleted)).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is included if the include_can_be_deleted option is true" do
|
||||||
|
json =
|
||||||
|
AdminUserListSerializer.new(
|
||||||
|
user,
|
||||||
|
scope: guardian,
|
||||||
|
root: false,
|
||||||
|
include_can_be_deleted: true,
|
||||||
|
).as_json
|
||||||
|
|
||||||
|
expect(json[:can_be_deleted]).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user