Commit befd570d authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '207334-design-view-relax-permissions-for-updateimagediffnote-mutation' into 'master'

Change the mutation and permissions for image note reposition

See merge request gitlab-org/gitlab!47161
parents cb5152e1 3d6713f6
...@@ -112,9 +112,9 @@ export default { ...@@ -112,9 +112,9 @@ export default {
}, },
canMoveNote(note) { canMoveNote(note) {
const { userPermissions } = note; const { userPermissions } = note;
const { adminNote } = userPermissions || {}; const { repositionNote } = userPermissions || {};
return Boolean(adminNote); return Boolean(repositionNote);
}, },
isPositionInOverlay(position) { isPositionInOverlay(position) {
const { top, left } = this.getNoteRelativePosition(position); const { top, left } = this.getNoteRelativePosition(position);
......
fragment DesignNotePermissions on NotePermissions { fragment DesignNotePermissions on NotePermissions {
adminNote adminNote
repositionNote
} }
#import "../fragments/design_note.fragment.graphql" #import "../fragments/design_note.fragment.graphql"
mutation updateImageDiffNote($input: UpdateImageDiffNoteInput!) { mutation repositionImageDiffNote($input: RepositionImageDiffNoteInput!) {
updateImageDiffNote(input: $input) { repositionImageDiffNote(input: $input) {
errors errors
note { note {
...DesignNote ...DesignNote
......
...@@ -13,19 +13,19 @@ import DesignReplyForm from '../../components/design_notes/design_reply_form.vue ...@@ -13,19 +13,19 @@ import DesignReplyForm from '../../components/design_notes/design_reply_form.vue
import DesignSidebar from '../../components/design_sidebar.vue'; import DesignSidebar from '../../components/design_sidebar.vue';
import getDesignQuery from '../../graphql/queries/get_design.query.graphql'; import getDesignQuery from '../../graphql/queries/get_design.query.graphql';
import createImageDiffNoteMutation from '../../graphql/mutations/create_image_diff_note.mutation.graphql'; import createImageDiffNoteMutation from '../../graphql/mutations/create_image_diff_note.mutation.graphql';
import updateImageDiffNoteMutation from '../../graphql/mutations/update_image_diff_note.mutation.graphql'; import repositionImageDiffNoteMutation from '../../graphql/mutations/reposition_image_diff_note.mutation.graphql';
import updateActiveDiscussionMutation from '../../graphql/mutations/update_active_discussion.mutation.graphql'; import updateActiveDiscussionMutation from '../../graphql/mutations/update_active_discussion.mutation.graphql';
import { import {
extractDiscussions, extractDiscussions,
extractDesign, extractDesign,
updateImageDiffNoteOptimisticResponse, repositionImageDiffNoteOptimisticResponse,
toDiffNoteGid, toDiffNoteGid,
extractDesignNoteId, extractDesignNoteId,
getPageLayoutElement, getPageLayoutElement,
} from '../../utils/design_management_utils'; } from '../../utils/design_management_utils';
import { import {
updateStoreAfterAddImageDiffNote, updateStoreAfterAddImageDiffNote,
updateStoreAfterUpdateImageDiffNote, updateStoreAfterRepositionImageDiffNote,
} from '../../utils/cache_update'; } from '../../utils/cache_update';
import { import {
ADD_DISCUSSION_COMMENT_ERROR, ADD_DISCUSSION_COMMENT_ERROR,
...@@ -182,12 +182,12 @@ export default { ...@@ -182,12 +182,12 @@ export default {
updateImageDiffNoteInStore( updateImageDiffNoteInStore(
store, store,
{ {
data: { updateImageDiffNote }, data: { repositionImageDiffNote },
}, },
) { ) {
return updateStoreAfterUpdateImageDiffNote( return updateStoreAfterRepositionImageDiffNote(
store, store,
updateImageDiffNote, repositionImageDiffNote,
getDesignQuery, getDesignQuery,
this.designVariables, this.designVariables,
); );
...@@ -199,7 +199,7 @@ export default { ...@@ -199,7 +199,7 @@ export default {
); );
const mutationPayload = { const mutationPayload = {
optimisticResponse: updateImageDiffNoteOptimisticResponse(note, { optimisticResponse: repositionImageDiffNoteOptimisticResponse(note, {
position, position,
}), }),
variables: { variables: {
...@@ -208,7 +208,7 @@ export default { ...@@ -208,7 +208,7 @@ export default {
position, position,
}, },
}, },
mutation: updateImageDiffNoteMutation, mutation: repositionImageDiffNoteMutation,
update: this.updateImageDiffNoteInStore, update: this.updateImageDiffNoteInStore,
}; };
......
...@@ -101,7 +101,7 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) = ...@@ -101,7 +101,7 @@ const addImageDiffNoteToStore = (store, createImageDiffNote, query, variables) =
}); });
}; };
const updateImageDiffNoteInStore = (store, updateImageDiffNote, query, variables) => { const updateImageDiffNoteInStore = (store, repositionImageDiffNote, query, variables) => {
const sourceData = store.readQuery({ const sourceData = store.readQuery({
query, query,
variables, variables,
...@@ -111,12 +111,12 @@ const updateImageDiffNoteInStore = (store, updateImageDiffNote, query, variables ...@@ -111,12 +111,12 @@ const updateImageDiffNoteInStore = (store, updateImageDiffNote, query, variables
const design = extractDesign(draftData); const design = extractDesign(draftData);
const discussion = extractCurrentDiscussion( const discussion = extractCurrentDiscussion(
design.discussions, design.discussions,
updateImageDiffNote.note.discussion.id, repositionImageDiffNote.note.discussion.id,
); );
discussion.notes = { discussion.notes = {
...discussion.notes, ...discussion.notes,
nodes: [updateImageDiffNote.note, ...discussion.notes.nodes.slice(1)], nodes: [repositionImageDiffNote.note, ...discussion.notes.nodes.slice(1)],
}; };
}); });
...@@ -268,7 +268,7 @@ export const updateStoreAfterAddImageDiffNote = (store, data, query, queryVariab ...@@ -268,7 +268,7 @@ export const updateStoreAfterAddImageDiffNote = (store, data, query, queryVariab
} }
}; };
export const updateStoreAfterUpdateImageDiffNote = (store, data, query, queryVariables) => { export const updateStoreAfterRepositionImageDiffNote = (store, data, query, queryVariables) => {
if (hasErrors(data)) { if (hasErrors(data)) {
onError(data, UPDATE_IMAGE_DIFF_NOTE_ERROR); onError(data, UPDATE_IMAGE_DIFF_NOTE_ERROR);
} else { } else {
......
...@@ -107,12 +107,12 @@ export const designUploadOptimisticResponse = files => { ...@@ -107,12 +107,12 @@ export const designUploadOptimisticResponse = files => {
* @param {Object} note * @param {Object} note
* @param {Object} position * @param {Object} position
*/ */
export const updateImageDiffNoteOptimisticResponse = (note, { position }) => ({ export const repositionImageDiffNoteOptimisticResponse = (note, { position }) => ({
// False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26 // False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
__typename: 'Mutation', __typename: 'Mutation',
updateImageDiffNote: { repositionImageDiffNote: {
__typename: 'UpdateImageDiffNotePayload', __typename: 'RepositionImageDiffNotePayload',
note: { note: {
...note, ...note,
position: { position: {
......
---
title: Change the mutation and permissions for image note reposition
merge_request: 47161
author:
type: changed
...@@ -243,11 +243,11 @@ describe('Design overlay component', () => { ...@@ -243,11 +243,11 @@ describe('Design overlay component', () => {
}); });
}); });
describe('without [adminNote] permission', () => { describe('without [repositionNote] permission', () => {
const mockNoteNotAuthorised = { const mockNoteNotAuthorised = {
...notes[0], ...notes[0],
userPermissions: { userPermissions: {
adminNote: false, repositionNote: false,
}, },
}; };
...@@ -412,18 +412,18 @@ describe('Design overlay component', () => { ...@@ -412,18 +412,18 @@ describe('Design overlay component', () => {
describe('canMoveNote', () => { describe('canMoveNote', () => {
it.each` it.each`
adminNotePermission | canMoveNoteResult repositionNotePermission | canMoveNoteResult
${true} | ${true} ${true} | ${true}
${false} | ${false} ${false} | ${false}
${undefined} | ${false} ${undefined} | ${false}
`( `(
'returns [$canMoveNoteResult] when [adminNote permission] is [$adminNotePermission]', 'returns [$canMoveNoteResult] when [repositionNote permission] is [$repositionNotePermission]',
({ adminNotePermission, canMoveNoteResult }) => { ({ repositionNotePermission, canMoveNoteResult }) => {
createComponent(); createComponent();
const note = { const note = {
userPermissions: { userPermissions: {
adminNote: adminNotePermission, repositionNote: repositionNotePermission,
}, },
}; };
expect(wrapper.vm.canMoveNote(note)).toBe(canMoveNoteResult); expect(wrapper.vm.canMoveNote(note)).toBe(canMoveNoteResult);
......
...@@ -18,7 +18,7 @@ export default { ...@@ -18,7 +18,7 @@ export default {
}, },
createdAt: '2020-05-08T07:10:45Z', createdAt: '2020-05-08T07:10:45Z',
userPermissions: { userPermissions: {
adminNote: true, repositionNote: true,
}, },
resolved: false, resolved: false,
}, },
......
...@@ -3,7 +3,7 @@ import { ...@@ -3,7 +3,7 @@ import {
updateStoreAfterDesignsDelete, updateStoreAfterDesignsDelete,
updateStoreAfterAddImageDiffNote, updateStoreAfterAddImageDiffNote,
updateStoreAfterUploadDesign, updateStoreAfterUploadDesign,
updateStoreAfterUpdateImageDiffNote, updateStoreAfterRepositionImageDiffNote,
} from '~/design_management/utils/cache_update'; } from '~/design_management/utils/cache_update';
import { import {
designDeletionError, designDeletionError,
...@@ -26,11 +26,11 @@ describe('Design Management cache update', () => { ...@@ -26,11 +26,11 @@ describe('Design Management cache update', () => {
describe('error handling', () => { describe('error handling', () => {
it.each` it.each`
fnName | subject | errorMessage | extraArgs fnName | subject | errorMessage | extraArgs
${'updateStoreAfterDesignsDelete'} | ${updateStoreAfterDesignsDelete} | ${designDeletionError({ singular: true })} | ${[[design]]} ${'updateStoreAfterDesignsDelete'} | ${updateStoreAfterDesignsDelete} | ${designDeletionError({ singular: true })} | ${[[design]]}
${'updateStoreAfterAddImageDiffNote'} | ${updateStoreAfterAddImageDiffNote} | ${ADD_IMAGE_DIFF_NOTE_ERROR} | ${[]} ${'updateStoreAfterAddImageDiffNote'} | ${updateStoreAfterAddImageDiffNote} | ${ADD_IMAGE_DIFF_NOTE_ERROR} | ${[]}
${'updateStoreAfterUploadDesign'} | ${updateStoreAfterUploadDesign} | ${mockErrors[0]} | ${[]} ${'updateStoreAfterUploadDesign'} | ${updateStoreAfterUploadDesign} | ${mockErrors[0]} | ${[]}
${'updateStoreAfterUpdateImageDiffNote'} | ${updateStoreAfterUpdateImageDiffNote} | ${UPDATE_IMAGE_DIFF_NOTE_ERROR} | ${[]} ${'updateStoreAfterUpdateImageDiffNote'} | ${updateStoreAfterRepositionImageDiffNote} | ${UPDATE_IMAGE_DIFF_NOTE_ERROR} | ${[]}
`('$fnName handles errors in response', ({ subject, extraArgs, errorMessage }) => { `('$fnName handles errors in response', ({ subject, extraArgs, errorMessage }) => {
expect(createFlash).not.toHaveBeenCalled(); expect(createFlash).not.toHaveBeenCalled();
expect(() => subject(mockStore, { errors: mockErrors }, {}, ...extraArgs)).toThrow(); expect(() => subject(mockStore, { errors: mockErrors }, {}, ...extraArgs)).toThrow();
......
...@@ -3,7 +3,7 @@ import { ...@@ -3,7 +3,7 @@ import {
extractDiscussions, extractDiscussions,
findVersionId, findVersionId,
designUploadOptimisticResponse, designUploadOptimisticResponse,
updateImageDiffNoteOptimisticResponse, repositionImageDiffNoteOptimisticResponse,
isValidDesignFile, isValidDesignFile,
extractDesign, extractDesign,
extractDesignNoteId, extractDesignNoteId,
...@@ -112,7 +112,7 @@ describe('optimistic responses', () => { ...@@ -112,7 +112,7 @@ describe('optimistic responses', () => {
expect(designUploadOptimisticResponse([{ name: 'test' }])).toEqual(expectedResponse); expect(designUploadOptimisticResponse([{ name: 'test' }])).toEqual(expectedResponse);
}); });
it('correctly generated for updateImageDiffNoteOptimisticResponse', () => { it('correctly generated for repositionImageDiffNoteOptimisticResponse', () => {
const mockNote = { const mockNote = {
id: 'test-note-id', id: 'test-note-id',
}; };
...@@ -126,8 +126,8 @@ describe('optimistic responses', () => { ...@@ -126,8 +126,8 @@ describe('optimistic responses', () => {
const expectedResponse = { const expectedResponse = {
__typename: 'Mutation', __typename: 'Mutation',
updateImageDiffNote: { repositionImageDiffNote: {
__typename: 'UpdateImageDiffNotePayload', __typename: 'RepositionImageDiffNotePayload',
note: { note: {
...mockNote, ...mockNote,
position: mockPosition, position: mockPosition,
...@@ -135,7 +135,7 @@ describe('optimistic responses', () => { ...@@ -135,7 +135,7 @@ describe('optimistic responses', () => {
errors: [], errors: [],
}, },
}; };
expect(updateImageDiffNoteOptimisticResponse(mockNote, { position: mockPosition })).toEqual( expect(repositionImageDiffNoteOptimisticResponse(mockNote, { position: mockPosition })).toEqual(
expectedResponse, expectedResponse,
); );
}); });
......
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