Commit d67d43d1 authored by Jarka Kadlecova's avatar Jarka Kadlecova

Split status and confidentiality action

parent b57ed57f
class SystemNoteMetadata < ActiveRecord::Base class SystemNoteMetadata < ActiveRecord::Base
ICON_TYPES = %w[ ICON_TYPES = %w[
commit merge confidentiality status label assignee cross_reference commit merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved title time_tracking branch milestone discussion task moved opened closed merged
].freeze ].freeze
validates :note, presence: true validates :note, presence: true
......
...@@ -183,7 +183,9 @@ module SystemNoteService ...@@ -183,7 +183,9 @@ module SystemNoteService
body = status.dup body = status.dup
body << " via #{source.gfm_reference(project)}" if source body << " via #{source.gfm_reference(project)}" if source
create_note(NoteSummary.new(noteable, project, author, body, action: 'status')) action = status == 'reopened' ? 'opened' : status
create_note(NoteSummary.new(noteable, project, author, body, action: action))
end end
# Called when 'merge when pipeline succeeds' is executed # Called when 'merge when pipeline succeeds' is executed
...@@ -273,9 +275,15 @@ module SystemNoteService ...@@ -273,9 +275,15 @@ module SystemNoteService
# #
# Returns the created Note object # Returns the created Note object
def change_issue_confidentiality(issue, project, author) def change_issue_confidentiality(issue, project, author)
body = issue.confidential ? 'made the issue confidential' : 'made the issue visible to everyone' if issue.confidential
body = 'made the issue confidential'
action = 'confidential'
else
body = 'made the issue visible to everyone'
action = 'visible'
end
create_note(NoteSummary.new(issue, project, author, body, action: 'confidentiality')) create_note(NoteSummary.new(issue, project, author, body, action: action))
end end
# Called when a branch in Noteable is changed # Called when a branch in Noteable is changed
......
...@@ -221,26 +221,23 @@ describe SystemNoteService, services: true do ...@@ -221,26 +221,23 @@ describe SystemNoteService, services: true do
describe '.change_status' do describe '.change_status' do
subject { described_class.change_status(noteable, project, author, status, source) } subject { described_class.change_status(noteable, project, author, status, source) }
let(:status) { 'new_status' } context 'with status reopened' do
let(:source) { nil } let(:status) { 'reopened' }
let(:source) { nil }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'status' } let(:action) { 'opened' }
end
end end
context 'with a source' do context 'with a source' do
let(:status) { 'opened' }
let(:source) { double('commit', gfm_reference: 'commit 123456') } let(:source) { double('commit', gfm_reference: 'commit 123456') }
it 'sets the note text' do it 'sets the note text' do
expect(subject.note).to eq "#{status} via commit 123456" expect(subject.note).to eq "#{status} via commit 123456"
end end
end end
context 'without a source' do
it 'sets the note text' do
expect(subject.note).to eq status
end
end
end end
describe '.merge_when_pipeline_succeeds' do describe '.merge_when_pipeline_succeeds' do
...@@ -298,9 +295,23 @@ describe SystemNoteService, services: true do ...@@ -298,9 +295,23 @@ describe SystemNoteService, services: true do
describe '.change_issue_confidentiality' do describe '.change_issue_confidentiality' do
subject { described_class.change_issue_confidentiality(noteable, project, author) } subject { described_class.change_issue_confidentiality(noteable, project, author) }
context 'when noteable responds to `confidential`' do context 'issue has been made confidential' do
before do
noteable.update_attribute(:confidential, true)
end
it_behaves_like 'a system note' do
let(:action) { 'confidential' }
end
it 'sets the note text' do
expect(subject.note).to eq 'made the issue confidential'
end
end
context 'issue has been made visible' do
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'confidentiality' } let(:action) { 'visible' }
end end
it 'sets the note text' do it 'sets the note text' do
......
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