Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Log user approvals. (#7121)

Bianca Nenciu191e31dccf5a
diff --git a/app/models/user.rb b/app/models/user.rb
index d47cc92c37e..09ae5c6c2e3 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -421,6 +421,8 @@ class User < ActiveRecord::Base
DiscourseEvent.trigger(:user_approved, self)
end
+ StaffActionLogger.new(approved_by).log_user_approve(self)
+
result
end
diff --git a/app/models/user_history.rb b/app/models/user_history.rb
index c8ec8754396..75a7bd1b1f4 100644
--- a/app/models/user_history.rb
+++ b/app/models/user_history.rb
@@ -84,7 +84,8 @@ class UserHistory < ActiveRecord::Base
merge_user: 65,
entity_export: 66,
change_password: 67,
- topic_timestamps_changed: 68
+ topic_timestamps_changed: 68,
+ approve_user: 69
)
end
@@ -147,7 +148,8 @@ class UserHistory < ActiveRecord::Base
:merge_user,
:entity_export,
:change_name,
- :topic_timestamps_changed
+ :topic_timestamps_changed,
+ :approve_user
]
end
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index a270dee3536..5ae62667387 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -503,6 +503,13 @@ class StaffActionLogger
))
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(
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 5e23831ce51..c77a2e821f1 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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."
diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb
index 33d8e7b19e7..48324b84936 100644
--- a/spec/requests/admin/users_controller_spec.rb
+++ b/spec/requests/admin/users_controller_spec.rb
@@ -71,6 +71,7 @@ RSpec.describe Admin::UsersController do
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