Commit 15eacc87 authored by charlie ablett's avatar charlie ablett

Merge branch '217616-fix-note-confidential' into 'master'

Fix confidential note attribute getter

See merge request gitlab-org/gitlab!32571
parents 0a98de1f c6329158
......@@ -351,8 +351,10 @@ class Note < ApplicationRecord
self.special_role = Note::SpecialRole::FIRST_TIME_CONTRIBUTOR
end
def confidential?
confidential || noteable.try(:confidential?)
def confidential?(include_noteable: false)
return true if confidential
include_noteable && noteable.try(:confidential?)
end
def editable?
......
......@@ -36,7 +36,7 @@ module Notes
return unless @note.project
note_data = hook_data
hooks_scope = @note.confidential? ? :confidential_note_hooks : :note_hooks
hooks_scope = @note.confidential?(include_noteable: true) ? :confidential_note_hooks : :note_hooks
@note.project.execute_hooks(note_data, hooks_scope)
@note.project.execute_services(note_data, hooks_scope)
......
---
title: Don't display confidential note icon on confidential issue public notes
merge_request: 32571
author:
type: fixed
......@@ -55,7 +55,7 @@ module Gitlab
end
def build_base_data(project, user, note)
event_type = note.confidential? ? 'confidential_note' : 'note'
event_type = note.confidential?(include_noteable: true) ? 'confidential_note' : 'note'
base_data = {
object_kind: "note",
......
......@@ -305,11 +305,22 @@ describe Note do
describe '#confidential?' do
context 'when note is not confidential' do
it 'is true when a noteable is confidential' do
issue = create(:issue, :confidential)
note = build(:note, noteable: issue, project: issue.project)
context 'when include_noteable is set to true' do
it 'is true when a noteable is confidential ' do
issue = create(:issue, :confidential)
note = build(:note, noteable: issue, project: issue.project)
expect(note.confidential?).to be_truthy
expect(note.confidential?(include_noteable: true)).to be_truthy
end
end
context 'when include_noteable is not set to true' do
it 'is false when a noteable is confidential ' do
issue = create(:issue, :confidential)
note = build(:note, noteable: issue, project: issue.project)
expect(note.confidential?).to be_falsey
end
end
it 'is false when a noteable is not confidential' do
......@@ -319,7 +330,7 @@ describe Note do
expect(note.confidential?).to be_falsy
end
it "is falsey when noteable can't be confidential" do
it "is false when noteable can't be confidential" do
commit_note = build(:note_on_commit)
expect(commit_note.confidential?).to be_falsy
......
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