Commit 7b369727 authored by Felipe Artur's avatar Felipe Artur

Update blocking issues count on reopening

Refresh blocking issues count cache when reopening issue
parent 7dc38e15
......@@ -5,6 +5,8 @@ module Issues
def execute(issue)
return issue unless can?(current_user, :reopen_issue, issue)
before_reopen(issue)
if issue.reopen
event_service.reopen_issue(issue, current_user)
create_note(issue, 'reopened')
......@@ -21,8 +23,14 @@ module Issues
private
def before_reopen(issue)
# Overriden in EE
end
def create_note(issue, state = issue.state)
SystemNoteService.change_status(issue, issue.project, current_user, state, nil)
end
end
end
Issues::ReopenService.prepend_if_ee('EE::Issues::ReopenService')
# frozen_string_literal: true
module EE
module Issues
module ReopenService
extend ::Gitlab::Utils::Override
override :before_reopen
def before_reopen(issue)
# Assign blocking_issues_count to issue object instead of performing an update,
# this way we can keep issue#previous_changes attributes consistent.
# Some services may use them to perform callbacks like StatusPage::TriggerPublishService
issue.blocking_issues_count = ::IssueLink.blocking_issues_count_for(issue)
super
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issues::ReopenService do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue, :closed, project: project) }
let_it_be(:blocked_issue) { create(:issue, project: project) }
subject { described_class.new(project, user).execute(issue) }
before do
create(:issue_link, source: issue, target: blocked_issue, link_type: ::IssueLink::TYPE_BLOCKS)
issue.update!(blocking_issues_count: 0)
end
describe '#execute' do
context 'when user is not authorized to reopen issue' do
before do
project.add_guest(user)
end
it 'does not update blocking issues count' do
expect { subject }.not_to change { issue.blocking_issues_count }.from(0)
end
end
context 'when user is authorized to reopen issue' do
before do
project.add_maintainer(user)
end
it 'updates blocking issues count' do
expect { subject }.to change { issue.blocking_issues_count }.from(0).to(1)
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