Commit 03bdabb5 authored by Peter Leitzen's avatar Peter Leitzen Committed by Sean McGivern

Enable alert bot to use quick actions

Stop preventing `internal` users from using quick actions and just
prevent the support bot from using them.
parent abfac0dd
......@@ -44,7 +44,6 @@ class GlobalPolicy < BasePolicy
prevent :access_api
prevent :access_git
prevent :receive_notifications
prevent :use_quick_actions
end
rule { required_terms_not_accepted }.policy do
......
......@@ -11,6 +11,9 @@ module EE
with_scope :user
condition(:support_bot, score: 0) { @user&.support_bot? }
with_scope :user
condition(:alert_bot, score: 0) { @user&.alert_bot? }
with_scope :global
condition(:license_block) { License.block_changes? }
end
......
......@@ -14,6 +14,8 @@ module EE
enable :read_licenses
enable :destroy_licenses
end
rule { support_bot }.prevent :use_quick_actions
end
end
end
......@@ -9,5 +9,9 @@ module EE
def support_bot?
false
end
def alert_bot?
false
end
end
end
......@@ -80,6 +80,8 @@ module EE
prevent :read_project
end
rule { alert_bot }.enable :reporter_access
rule { license_block }.policy do
prevent :create_issue
prevent :create_merge_request_in
......
---
title: Enable alert bot to use quick actions
merge_request: 12127
author:
type: fixed
......@@ -503,4 +503,10 @@ describe ProjectPolicy do
projects: [clusterable])
end
end
context 'alert bot' do
let(:current_user) { User.alert_bot }
it { is_expected.to be_allowed(:reporter_access) }
end
end
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe IncidentManagement::CreateIssueService do
set(:project) { create(:project, :repository, create_templates: :issue) }
let(:project) { create(:project, :repository) }
let(:service) { described_class.new(project, nil, alert_payload) }
let(:alert_title) { 'TITLE' }
let(:alert_payload) do
......@@ -17,7 +17,8 @@ describe IncidentManagement::CreateIssueService do
subject { service.execute }
context 'when create_issue enabled' do
let(:user) { create(:user) }
let(:issue) { subject[:issue] }
let(:summary_separator) { "---\n\n" }
before do
setting.update!(create_issue: true)
......@@ -27,26 +28,68 @@ describe IncidentManagement::CreateIssueService do
it 'creates an issue with alert summary only' do
expect(subject).to include(status: :success)
issue = subject[:issue]
expect(issue.author).to eq(User.alert_bot)
expect(issue.title).to eq(alert_title)
expect(issue.description).to include('Summary')
expect(issue.description).to include(alert_title)
expect(issue.description).not_to include("---\n\n")
expect(issue.description).not_to include(summary_separator)
end
end
context 'with issue_template_content' do
before do
create_issue_template('bug', issue_template_content)
setting.update!(issue_template_key: 'bug')
end
it 'creates an issue appending issue template' do
expect(subject).to include(status: :success)
context 'plain content' do
let(:issue_template_content) { 'some content' }
it 'creates an issue appending issue template' do
expect(subject).to include(status: :success)
expect(issue.description).to include('Summary')
expect(issue.description).to include(alert_title)
expect(issue.description).to include(summary_separator)
expect(issue.description).to include(issue_template_content)
end
end
context 'quick actions' do
let(:user) { create(:user) }
let(:plain_text) { 'some content' }
let(:issue_template_content) do
<<~CONTENT
#{plain_text}
/due tomorrow
/assign @#{user.username}
CONTENT
end
before do
project.add_maintainer(user)
end
it 'creates an issue interpreting quick actions' do
expect(subject).to include(status: :success)
expect(issue.description).to include(plain_text)
expect(issue.due_date).to be_present
expect(issue.assignees).to eq([user])
end
end
private
issue = subject[:issue]
expect(issue.description).to include("---\n\n")
expect(issue.description).to include(setting.issue_template_content)
def create_issue_template(name, content)
project.repository.create_file(
project.creator,
".gitlab/issue_templates/#{name}.md",
content,
message: 'message',
branch_name: 'master'
)
end
end
......
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