FEATURE: Log when a group is deleted. (#11706)

FEATURE: Log when a group is deleted. (#11706)

We include the group “name” and “granted_trust_level” attributes.

diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 8fdf6c4..e3bae01 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -80,6 +80,10 @@ class Admin::GroupsController < Admin::AdminController
     if group.automatic
       can_not_modify_automatic
     else
+      details = { name: group.name }
+      details[:grant_trust_level] = group.grant_trust_level if group.grant_trust_level
+
+      StaffActionLogger.new(current_user).log_custom('delete_group', details)
       group.destroy!
       render json: success_json
     end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 098c53d..92cda30 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4437,6 +4437,7 @@ en:
             topic_unarchived: "topic unarchived"
             post_staff_note_create: "add staff note"
             post_staff_note_destroy: "destroy staff note"
+            delete_group: "delete group"
         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/groups_controller_spec.rb b/spec/requests/admin/groups_controller_spec.rb
index 721a449..2181cb3 100644
--- a/spec/requests/admin/groups_controller_spec.rb
+++ b/spec/requests/admin/groups_controller_spec.rb
@@ -235,6 +235,27 @@ RSpec.describe Admin::GroupsController do
       expect(response.status).to eq(404)
     end
 
+    it 'logs when a group is destroyed' do
+      delete "/admin/groups/#{group.id}.json"
+
+      history = UserHistory.where(acting_user: admin).last
+
+      expect(history).to be_present
+      expect(history.details).to include("name: #{group.name}")
+    end
+
+    it 'logs the grant_trust_level attribute' do
+      trust_level = TrustLevel[4]
+      group.update!(grant_trust_level: trust_level)
+      delete "/admin/groups/#{group.id}.json"
+
+      history = UserHistory.where(acting_user: admin).last
+
+      expect(history).to be_present
+      expect(history.details).to include("grant_trust_level: #{trust_level}")
+      expect(history.details).to include("name: #{group.name}")
+    end
+
     describe 'when group is automatic' do
       it "returns the right response" do
         group.update!(automatic: true)

GitHub sha: 1ad378f5

1 Like

This commit appears in #11706 which was approved by CvX. It was merged by romanrizzi.