mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 02:25:42 +08:00
FEATURE: log admin/moderator grant/revoke action
This commit is contained in:
parent
0916007d01
commit
74f22f95da
app
config/locales
@ -87,6 +87,7 @@ class Admin::UsersController < Admin::AdminController
|
|||||||
def revoke_admin
|
def revoke_admin
|
||||||
guardian.ensure_can_revoke_admin!(@user)
|
guardian.ensure_can_revoke_admin!(@user)
|
||||||
@user.revoke_admin!
|
@user.revoke_admin!
|
||||||
|
StaffActionLogger.new(current_user).log_revoke_admin(@user)
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,18 +104,21 @@ class Admin::UsersController < Admin::AdminController
|
|||||||
def grant_admin
|
def grant_admin
|
||||||
guardian.ensure_can_grant_admin!(@user)
|
guardian.ensure_can_grant_admin!(@user)
|
||||||
@user.grant_admin!
|
@user.grant_admin!
|
||||||
|
StaffActionLogger.new(current_user).log_grant_admin(@user)
|
||||||
render_serialized(@user, AdminUserSerializer)
|
render_serialized(@user, AdminUserSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def revoke_moderation
|
def revoke_moderation
|
||||||
guardian.ensure_can_revoke_moderation!(@user)
|
guardian.ensure_can_revoke_moderation!(@user)
|
||||||
@user.revoke_moderation!
|
@user.revoke_moderation!
|
||||||
|
StaffActionLogger.new(current_user).log_revoke_moderation(@user)
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def grant_moderation
|
def grant_moderation
|
||||||
guardian.ensure_can_grant_moderation!(@user)
|
guardian.ensure_can_grant_moderation!(@user)
|
||||||
@user.grant_moderation!
|
@user.grant_moderation!
|
||||||
|
StaffActionLogger.new(current_user).log_grant_moderation(@user)
|
||||||
render_serialized(@user, AdminUserSerializer)
|
render_serialized(@user, AdminUserSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,7 +46,11 @@ class UserHistory < ActiveRecord::Base
|
|||||||
create_category: 28,
|
create_category: 28,
|
||||||
change_site_text: 29,
|
change_site_text: 29,
|
||||||
block_user: 30,
|
block_user: 30,
|
||||||
unblock_user: 31)
|
unblock_user: 31,
|
||||||
|
grant_admin: 32,
|
||||||
|
revoke_admin: 33,
|
||||||
|
grant_moderation: 34,
|
||||||
|
revoke_moderation: 35)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Staff actions is a subset of all actions, used to audit actions taken by staff users.
|
# Staff actions is a subset of all actions, used to audit actions taken by staff users.
|
||||||
@ -74,7 +78,11 @@ class UserHistory < ActiveRecord::Base
|
|||||||
:delete_category,
|
:delete_category,
|
||||||
:create_category,
|
:create_category,
|
||||||
:block_user,
|
:block_user,
|
||||||
:unblock_user]
|
:unblock_user,
|
||||||
|
:grant_admin,
|
||||||
|
:revoke_admin,
|
||||||
|
:grant_moderation,
|
||||||
|
:revoke_moderation]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.staff_action_ids
|
def self.staff_action_ids
|
||||||
|
@ -294,6 +294,38 @@ class StaffActionLogger
|
|||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_grant_admin(user, opts={})
|
||||||
|
raise Discourse::InvalidParameters.new(:user) unless user
|
||||||
|
UserHistory.create( params(opts).merge({
|
||||||
|
action: UserHistory.actions[:grant_admin],
|
||||||
|
target_user_id: user.id
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_revoke_admin(user, opts={})
|
||||||
|
raise Discourse::InvalidParameters.new(:user) unless user
|
||||||
|
UserHistory.create( params(opts).merge({
|
||||||
|
action: UserHistory.actions[:revoke_admin],
|
||||||
|
target_user_id: user.id
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_grant_moderation(user, opts={})
|
||||||
|
raise Discourse::InvalidParameters.new(:user) unless user
|
||||||
|
UserHistory.create( params(opts).merge({
|
||||||
|
action: UserHistory.actions[:grant_moderation],
|
||||||
|
target_user_id: user.id
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_revoke_moderation(user, opts={})
|
||||||
|
raise Discourse::InvalidParameters.new(:user) unless user
|
||||||
|
UserHistory.create( params(opts).merge({
|
||||||
|
action: UserHistory.actions[:revoke_moderation],
|
||||||
|
target_user_id: user.id
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def params(opts=nil)
|
def params(opts=nil)
|
||||||
|
@ -2329,6 +2329,10 @@ en:
|
|||||||
create_category: "create category"
|
create_category: "create category"
|
||||||
block_user: "block user"
|
block_user: "block user"
|
||||||
unblock_user: "unblock user"
|
unblock_user: "unblock user"
|
||||||
|
grant_admin: "grant admin"
|
||||||
|
revoke_admin: "revoke admin"
|
||||||
|
grant_moderation: "grant moderation"
|
||||||
|
revoke_moderation: "revoke moderation"
|
||||||
screened_emails:
|
screened_emails:
|
||||||
title: "Screened Emails"
|
title: "Screened Emails"
|
||||||
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."
|
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user