Commit 23346d01 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sy-publish-issue-service' into 'master'

Add StatusPage::MarkForPublicationService

See merge request gitlab-org/gitlab!31395
parents 9400ff4f ac938e5a
......@@ -370,6 +370,7 @@ module EE
rule { compliance_framework_available & can?(:admin_project) }.enable :admin_compliance_framework
rule { status_page_available & can?(:owner_access) }.enable :mark_issue_for_publication
rule { status_page_available & can?(:developer_access) }.enable :publish_status_page
end
......
# frozen_string_literal: true
module StatusPage
# Marks an issue as published.
class MarkForPublicationService
def initialize(project, user, issue)
@project = project
@user = user
@issue = issue
end
def execute
return unless status_page_enabled?
return unless can_publish?
return unless publishable_issue?
track_incident
add_system_note
end
private
attr_reader :user, :project, :issue
def can_publish?
user&.can?(:mark_issue_for_publication, project)
end
def status_page_enabled?
project.status_page_setting&.enabled?
end
def publishable_issue?
!issue.confidential? &&
!issue.status_page_published_incident
end
def add_system_note
::SystemNoteService.publish_issue_to_status_page(issue, project, user)
end
def track_incident
PublishedIncident.track(issue)
end
end
end
......@@ -10,4 +10,9 @@ module StatusPage
def self.trigger_publish(project, user, triggered_by)
TriggerPublishService.new(project, user, triggered_by).execute
end
# Method to mark an issue as published and trigger update
def self.mark_for_publication(project, user, issue)
MarkForPublicationService.new(project, user, issue).execute
end
end
......@@ -3,11 +3,11 @@
require 'spec_helper'
describe StatusPage do
describe '.trigger_publish' do
let(:project) { instance_double(Project) }
let(:user) { instance_double(User) }
let(:triggered_by) { instance_double(Issue) }
let(:project) { instance_double(Project) }
let(:user) { instance_double(User) }
let(:triggered_by) { instance_double(Issue) }
describe '.trigger_publish' do
subject { described_class.trigger_publish(project, user, triggered_by) }
it 'delegates to TriggerPublishService' do
......@@ -19,4 +19,17 @@ describe StatusPage do
subject
end
end
describe '.mark_for_publication' do
subject { described_class.mark_for_publication(project, user, triggered_by) }
it 'delegates to PublishIssueService' do
expect_next_instance_of(StatusPage::MarkForPublicationService,
project, user, triggered_by) do |service|
expect(service).to receive(:execute)
end
subject
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe StatusPage::MarkForPublicationService do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project, refind: true) { create(:project, group: group) }
let_it_be(:issue, refind: true) { create(:issue, project: project) }
let(:service) { described_class.new(project, user, issue) }
before do
stub_licensed_features(status_page: true)
group.add_owner(user)
end
describe '#execute' do
subject { service.execute }
shared_examples 'does not track the incident' do
specify { expect { subject }.not_to change { ::StatusPage::PublishedIncident.count } }
specify { expect { subject }.not_to change { issue.notes.count } }
end
context 'when license is not available' do
before do
stub_licensed_features(status_page: false)
end
it_behaves_like 'does not track the incident'
end
context 'when status page does not exist' do
it_behaves_like 'does not track the incident'
end
context 'when status page is disabled' do
let_it_be(:status_page_setting) { create(:status_page_setting, project: project) }
it_behaves_like 'does not track the incident'
end
context 'when status page is enabled' do
let_it_be(:status_page_setting) { create(:status_page_setting, :enabled, project: project) }
context 'when issue is publishable' do
specify { expect { subject }.to change { ::StatusPage::PublishedIncident.count }.by(1) }
specify { expect { subject }.to change { issue.notes.count }.by(1) }
end
context 'when issue is confidential' do
let_it_be(:issue) { create(:issue, :confidential, project: project) }
it_behaves_like 'does not track the incident'
end
context 'when issue is already published' do
let_it_be(:incident) { create(:status_page_published_incident, issue: issue) }
it_behaves_like 'does not track the incident'
end
context 'when user does not have permissions' do
let(:service) { described_class.new(project, create(:user), issue) }
it_behaves_like 'does not track the incident'
end
end
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