Commit b5d674da authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '207473-graphl-update-note-conf' into 'master'

Add confidential attr to graphQL for notes update

See merge request gitlab-org/gitlab!37920
parents 888daeb5 de219055
...@@ -40,7 +40,7 @@ module Mutations ...@@ -40,7 +40,7 @@ module Mutations
end end
def note_params(_note, args) def note_params(_note, args)
{ note: args[:body] }.compact { note: args[:body], confidential: args[:confidential] }.compact
end end
end end
end end
......
...@@ -8,9 +8,14 @@ module Mutations ...@@ -8,9 +8,14 @@ module Mutations
argument :body, argument :body,
GraphQL::STRING_TYPE, GraphQL::STRING_TYPE,
required: true, required: false,
description: copy_field_description(Types::Notes::NoteType, :body) description: copy_field_description(Types::Notes::NoteType, :body)
argument :confidential,
GraphQL::BOOLEAN_TYPE,
required: false,
description: 'The confidentiality flag of a note. Default is false.'
private private
def pre_update_checks!(note, _args) def pre_update_checks!(note, _args)
......
---
title: Add confidential attribute to graphQL for notes update
merge_request: 37920
author:
type: added
...@@ -14322,13 +14322,18 @@ input UpdateNoteInput { ...@@ -14322,13 +14322,18 @@ input UpdateNoteInput {
""" """
Content of the note Content of the note
""" """
body: String! body: String
""" """
A unique identifier for the client performing the mutation. A unique identifier for the client performing the mutation.
""" """
clientMutationId: String clientMutationId: String
"""
The confidentiality flag of a note. Default is false.
"""
confidential: Boolean
""" """
The global id of the note to update The global id of the note to update
""" """
......
...@@ -42358,13 +42358,19 @@ ...@@ -42358,13 +42358,19 @@
"name": "body", "name": "body",
"description": "Content of the note", "description": "Content of the note",
"type": { "type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "String", "name": "String",
"ofType": null "ofType": null
} },
"defaultValue": null
},
{
"name": "confidential",
"description": "The confidentiality flag of a note. Default is false.",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}, },
"defaultValue": null "defaultValue": null
}, },
...@@ -8,11 +8,9 @@ RSpec.describe 'Updating a Note' do ...@@ -8,11 +8,9 @@ RSpec.describe 'Updating a Note' do
let!(:note) { create(:note, note: original_body) } let!(:note) { create(:note, note: original_body) }
let(:original_body) { 'Initial body text' } let(:original_body) { 'Initial body text' }
let(:updated_body) { 'Updated body text' } let(:updated_body) { 'Updated body text' }
let(:params) { { body: updated_body, confidential: true } }
let(:mutation) do let(:mutation) do
variables = { variables = params.merge(id: GitlabSchema.id_from_object(note).to_s)
id: GitlabSchema.id_from_object(note).to_s,
body: updated_body
}
graphql_mutation(:update_note, variables) graphql_mutation(:update_note, variables)
end end
...@@ -31,6 +29,7 @@ RSpec.describe 'Updating a Note' do ...@@ -31,6 +29,7 @@ RSpec.describe 'Updating a Note' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(note.reload.note).to eq(original_body) expect(note.reload.note).to eq(original_body)
expect(note.confidential).to be_falsey
end end
end end
...@@ -43,12 +42,40 @@ RSpec.describe 'Updating a Note' do ...@@ -43,12 +42,40 @@ RSpec.describe 'Updating a Note' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(note.reload.note).to eq(updated_body) expect(note.reload.note).to eq(updated_body)
expect(note.confidential).to be_truthy
end end
it 'returns the updated Note' do it 'returns the updated Note' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['note']['body']).to eq(updated_body) expect(mutation_response['note']['body']).to eq(updated_body)
expect(mutation_response['note']['confidential']).to be_truthy
end
context 'when only confidential param is present' do
let(:params) { { confidential: true } }
it 'updates only the note confidentiality' do
post_graphql_mutation(mutation, current_user: current_user)
expect(note.reload.note).to eq(original_body)
expect(note.confidential).to be_truthy
end
end
context 'when only body param is present' do
let(:params) { { body: updated_body } }
before do
note.update_column(:confidential, true)
end
it 'updates only the note body' do
post_graphql_mutation(mutation, current_user: current_user)
expect(note.reload.note).to eq(updated_body)
expect(note.confidential).to be_truthy
end
end end
context 'when there are ActiveRecord validation errors' do context 'when there are ActiveRecord validation errors' do
...@@ -60,12 +87,14 @@ RSpec.describe 'Updating a Note' do ...@@ -60,12 +87,14 @@ RSpec.describe 'Updating a Note' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(note.reload.note).to eq(original_body) expect(note.reload.note).to eq(original_body)
expect(note.confidential).to be_falsey
end end
it 'returns the Note with its original body' do it 'returns the original Note' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['note']['body']).to eq(original_body) expect(mutation_response['note']['body']).to eq(original_body)
expect(mutation_response['note']['confidential']).to be_falsey
end end
end end
......
...@@ -36,6 +36,16 @@ RSpec.describe Notes::UpdateService do ...@@ -36,6 +36,16 @@ RSpec.describe Notes::UpdateService do
end end
end end
context 'with system note' do
before do
note.update_column(:system, true)
end
it 'does not update the note' do
expect { update_note(note: 'new text') }.not_to change { note.reload.note }
end
end
context 'suggestions' do context 'suggestions' do
it 'refreshes note suggestions' do it 'refreshes note suggestions' do
markdown = <<-MARKDOWN.strip_heredoc markdown = <<-MARKDOWN.strip_heredoc
......
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