diff --git a/app/javascript/dashboard/i18n/locale/en/auditLogs.json b/app/javascript/dashboard/i18n/locale/en/auditLogs.json index b1653e027..22b0f1bf1 100644 --- a/app/javascript/dashboard/i18n/locale/en/auditLogs.json +++ b/app/javascript/dashboard/i18n/locale/en/auditLogs.json @@ -38,6 +38,11 @@ "USER_ACTION": { "SIGN_IN": "%{agentName} signed in", "SIGN_OUT": "%{agentName} signed out" - } + }, + "TEAM": { + "ADD": "%{agentName} created a new team (#%{id})", + "EDIT": "%{agentName} updated a team (#%{id})", + "DELETE": "%{agentName} deleted a team (#%{id})" + } } } diff --git a/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue index d7d94f2e8..97e5830e0 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue @@ -127,6 +127,9 @@ export default { 'inbox:destroy': `AUDIT_LOGS.INBOX.DELETE`, 'user:sign_in': `AUDIT_LOGS.USER_ACTION.SIGN_IN`, 'user:sign_out': `AUDIT_LOGS.USER_ACTION.SIGN_OUT`, + 'team:create': `AUDIT_LOGS.TEAM.ADD`, + 'team:update': `AUDIT_LOGS.TEAM.EDIT`, + 'team:destroy': `AUDIT_LOGS.TEAM.DELETE`, }; return this.$t(translationKeys[logActionKey] || '', translationPayload); diff --git a/app/models/team.rb b/app/models/team.rb index 57bd30451..c5935c285 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -54,3 +54,5 @@ class Team < ApplicationRecord } end end + +Team.include_mod_with('Audit::Team') diff --git a/enterprise/app/models/enterprise/audit/team.rb b/enterprise/app/models/enterprise/audit/team.rb new file mode 100644 index 000000000..9e4102280 --- /dev/null +++ b/enterprise/app/models/enterprise/audit/team.rb @@ -0,0 +1,7 @@ +module Enterprise::Audit::Team + extend ActiveSupport::Concern + + included do + audited associated_with: :account + end +end diff --git a/spec/enterprise/models/team_spec.rb b/spec/enterprise/models/team_spec.rb new file mode 100644 index 000000000..af8bcdc1b --- /dev/null +++ b/spec/enterprise/models/team_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Team do + let(:account) { create(:account) } + let!(:team) { create(:team, account: account) } + + describe 'audit log' do + context 'when team is created' do + it 'has associated audit log created' do + expect(Audited::Audit.where(auditable_type: 'Team', action: 'create').count).to eq 1 + end + end + + context 'when team is updated' do + it 'has associated audit log created' do + team.update(description: 'awesome team') + expect(Audited::Audit.where(auditable_type: 'Team', action: 'update').count).to eq 1 + end + end + + context 'when team is deleted' do + it 'has associated audit log created' do + team.destroy! + expect(Audited::Audit.where(auditable_type: 'Team', action: 'destroy').count).to eq 1 + end + end + end +end