Skip to content

Commit

Permalink
Chore: Add created and updated activities on announcements (#4679)
Browse files Browse the repository at this point in the history
Because:
- Announcements are seen by everyone and need to be auditable

This commit:
- Creates activities when an announcement is created and updated.
- We aren't exposing these activities in the UI yet, but may do in the
future.
  • Loading branch information
KevinMulhern authored Jul 31, 2024
1 parent aaa78d7 commit 4cde66c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/admin_v2/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create
@announcement = Announcement.new(announcement_params.merge(admin_user: current_admin_user))

if @announcement.save
create_activity(@announcement, 'created')
redirect_to admin_v2_announcement_path(@announcement)
else
render :new, status: :unprocessable_entity
Expand All @@ -32,6 +33,7 @@ def update
@announcement = Announcement.find(params[:id])

if @announcement.update(announcement_params)
create_activity(@announcement, 'updated')
redirect_to admin_v2_announcement_path(@announcement), notice: 'Announcement updated.'
else
render :edit, status: :unprocessable_entity
Expand All @@ -51,5 +53,13 @@ def destroy
def announcement_params
params.require(:announcement).permit(:message, :expires_at, :learn_more_url)
end

def create_activity(announcement, key)
announcement.create_activity(
key: "announcement.#{key}",
owner: current_admin_user,
parameters: { params: announcement_params.to_h }
)
end
end
end
2 changes: 2 additions & 0 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Announcement < ApplicationRecord
include PublicActivity::Common

belongs_to :user, optional: true
belongs_to :admin_user, optional: true

Expand Down

0 comments on commit 4cde66c

Please sign in to comment.