Commit 4b188141 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '217948-check-create_issue-permissions-when-creating-alert-issue' into 'master'

Check create_issue permissions on create Alert Issue

Closes #217948

See merge request gitlab-org/gitlab!32415
parents 1d35e510 3657efe8
......@@ -30,7 +30,7 @@ module AlertManagement
def allowed?
Feature.enabled?(:alert_management_create_alert_issue, project) &&
user.can?(:update_alert_management_alert, project)
user.can?(:create_issue, project)
end
def create_issue(alert, user, alert_payload)
......
......@@ -25,7 +25,7 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
before do
allow(user).to receive(:can?).and_call_original
allow(user).to receive(:can?)
.with(:update_alert_management_alert, project)
.with(:create_issue, project)
.and_return(can_create)
end
......@@ -62,6 +62,11 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
project.add_developer(user)
end
it 'checks permissions' do
execute
expect(user).to have_received(:can?).with(:create_issue, project)
end
context 'when the alert is prometheus alert' do
let(:alert) { prometheus_alert }
......@@ -133,6 +138,11 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
context 'when a user is not allowed to create an issue' do
let(:can_create) { false }
it 'checks permissions' do
execute
expect(user).to have_received(:can?).with(:create_issue, project)
end
it 'responds with error' do
expect(execute).to be_error
expect(execute.message).to eq(_('You have no permissions'))
......
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