Commit adcddf44 authored by harsimarsandhu's avatar harsimarsandhu

Creates audit event on approval rule creation

Record an audit event when user creates
a new MR approval rule. This event should
be visible under Project > Audit Events
and Admin Area > Audit Log

Changelog: changed
EE: true
parent b6446f61
......@@ -15,6 +15,7 @@ class ApprovalProjectRule < ApplicationRecord
has_and_belongs_to_many :protected_branches
has_many :approval_merge_request_rule_sources
has_many :approval_merge_request_rules, through: :approval_merge_request_rule_sources
after_create_commit :audit_creation
enum rule_type: {
regular: 0,
......@@ -67,6 +68,10 @@ class ApprovalProjectRule < ApplicationRecord
push_audit_event("Added #{model.class.name} #{model.name} to approval group on #{self.name} rule")
end
def audit_creation
push_audit_event("Added approval rule with number of required approvals of #{approvals_required}")
end
def audit_remove(model)
push_audit_event("Removed #{model.class.name} #{model.name} from approval group on #{self.name} rule")
end
......
......@@ -300,6 +300,13 @@ RSpec.describe ApprovalProjectRule do
it_behaves_like 'auditable'
end
describe "#audit_creation after approval rule is created" do
let(:action!) { create(:approval_project_rule, approvals_required: 1) }
let(:message) {'Added approval rule with number of required approvals of 1'}
it_behaves_like 'auditable'
end
describe '#vulnerability_states_for_branch' do
let(:project) { create(:project, :repository) }
let(:branch_name) { project.default_branch }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment