Skip to content

Commit

Permalink
FEATURE: Log user approvals. (#7121)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbianca authored and SamSaffron committed Mar 12, 2019
1 parent da94184 commit 191e31d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -421,6 +421,8 @@ def approve(approved_by, send_mail = true)
DiscourseEvent.trigger(:user_approved, self)
end

StaffActionLogger.new(approved_by).log_user_approve(self)

result
end

Expand Down
6 changes: 4 additions & 2 deletions app/models/user_history.rb
Expand Up @@ -84,7 +84,8 @@ def self.actions
merge_user: 65,
entity_export: 66,
change_password: 67,
topic_timestamps_changed: 68
topic_timestamps_changed: 68,
approve_user: 69
)
end

Expand Down Expand Up @@ -147,7 +148,8 @@ def self.staff_actions
:merge_user,
:entity_export,
:change_name,
:topic_timestamps_changed
:topic_timestamps_changed,
:approve_user
]
end

Expand Down
7 changes: 7 additions & 0 deletions app/services/staff_action_logger.rb
Expand Up @@ -503,6 +503,13 @@ def log_revoke_email(user, reason, opts = {})
))
end

def log_user_approve(user, opts = {})
UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:approve_user],
target_user_id: user.id
))
end

def log_user_deactivate(user, reason, opts = {})
raise Discourse::InvalidParameters.new(:user) unless user
UserHistory.create!(params(opts).merge(
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -3689,6 +3689,7 @@ en:
entity_export: "export entity"
change_name: "change name"
topic_timestamps_changed: "topic timestamps changed"
approve_user: "approved user"
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."
Expand Down
1 change: 1 addition & 0 deletions spec/requests/admin/users_controller_spec.rb
Expand Up @@ -71,6 +71,7 @@
expect(response.status).to eq(200)
evil_trout.reload
expect(evil_trout.approved).to eq(true)
expect(UserHistory.where(action: UserHistory.actions[:approve_user], target_user_id: evil_trout.id).count).to eq(1)
end
end

Expand Down

0 comments on commit 191e31d

Please sign in to comment.