From 4cde66c11f78330f0d6a168891923ada5eb88ba9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 31 Jul 2024 09:37:02 +0100 Subject: [PATCH] Chore: Add created and updated activities on announcements (#4679) 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. --- app/controllers/admin_v2/announcements_controller.rb | 10 ++++++++++ app/models/announcement.rb | 2 ++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/admin_v2/announcements_controller.rb b/app/controllers/admin_v2/announcements_controller.rb index a1050d31d4..4070819ced 100644 --- a/app/controllers/admin_v2/announcements_controller.rb +++ b/app/controllers/admin_v2/announcements_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/models/announcement.rb b/app/models/announcement.rb index 1a96abb430..9d6c9a5c0d 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -1,4 +1,6 @@ class Announcement < ApplicationRecord + include PublicActivity::Common + belongs_to :user, optional: true belongs_to :admin_user, optional: true