Skip to content

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

FIX: Create group staff action logging hole (#43153)

Martin Brennane22f9900d688
diff --git a/app/models/user_history.rb b/app/models/user_history.rb
index f3eea77b9a1..27a8c23e7fc 100644
--- a/app/models/user_history.rb
+++ b/app/models/user_history.rb
@@ -174,6 +174,7 @@ class UserHistory < ActiveRecord::Base
admin_onboarding_completed: 129,
admin_onboarding_dismissed: 130,
removed_avatar: 131,
+ create_group: 132,
)
end
@@ -309,6 +310,7 @@ class UserHistory < ActiveRecord::Base
admin_onboarding_completed
admin_onboarding_dismissed
removed_avatar
+ create_group
]
end
diff --git a/app/services/group_action_logger.rb b/app/services/group_action_logger.rb
index 2278fac13ea..9023a9e302e 100644
--- a/app/services/group_action_logger.rb
+++ b/app/services/group_action_logger.rb
@@ -63,6 +63,8 @@ class GroupActionLogger
log_make_user_group_owner(group_user.user) if group_user.owner?
log_add_user_to_group(group_user.user)
end
+
+ StaffActionLogger.new(@acting_user).log_group_creation(@group)
end
private
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index b8beff62a2b..6d08932877d 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -1169,6 +1169,18 @@ class StaffActionLogger
)
end
+ def log_group_creation(group)
+ raise Discourse::InvalidParameters.new(:group) if group.nil?
+
+ details = ["name: #{group.name}", "full_name: #{group.full_name}", "id: #{group.id}"]
+
+ UserHistory.create!(
+ acting_user_id: @admin.id,
+ action: UserHistory.actions[:create_group],
+ details: details.join(", "),
+ )
+ end
+
def log_permanently_delete_post_revisions(post)
raise Discourse::InvalidParameters.new(:post) if post.nil?
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 4f2d9df2ff8..ea5e5934b0e 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -9340,6 +9340,7 @@ en:
admin_onboarding_step_completed: "complete admin onboarding step"
admin_onboarding_completed: "complete admin onboarding"
admin_onboarding_dismissed: "dismiss admin onboarding"
+ create_group: "create 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/services/groups/create_spec.rb b/spec/services/groups/create_spec.rb
index b3db3473bd7..82e03c82029 100644
--- a/spec/services/groups/create_spec.rb
+++ b/spec/services/groups/create_spec.rb
@@ -126,6 +126,7 @@ RSpec.describe Groups::Create do
{
name: "builders",
title: "Builders",
+ full_name: "Builders",
usernames: [member_1.username, member_2.username].join(","),
owner_usernames: [admin.username].join(","),
}
@@ -173,6 +174,20 @@ RSpec.describe Groups::Create do
expect { result }.to change { GroupHistory.count }.by(4)
end
+ it "logs group creation in staff action log" do
+ result
+ expect(
+ UserHistory.where(action: UserHistory.actions[:create_group]).find_by(
+ acting_user_id: admin.id,
+ ),
+ ).to have_attributes(
+ acting_user_id: admin.id,
+ details: ["name: #{group.name}", "full_name: #{group.full_name}", "id: #{group.id}"].join(
+ ", ",
+ ),
+ )
+ end
+
context "when guardian can associate groups" do
fab!(:associated_group_1, :associated_group)
fab!(:associated_group_2, :associated_group)