Commit 3a7bf9c3 authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Mark Florian

Allow only users with `adminNote` permission to edit the design note

parent 52cdad05
...@@ -108,7 +108,7 @@ export default { ...@@ -108,7 +108,7 @@ export default {
</span> </span>
</div> </div>
<button <button
v-if="!isEditing" v-if="!isEditing && note.userPermissions.adminNote"
v-gl-tooltip v-gl-tooltip
type="button" type="button"
title="Edit comment" title="Edit comment"
......
...@@ -5,7 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -5,7 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
import Pagination from './pagination.vue'; import Pagination from './pagination.vue';
import DeleteButton from '../delete_button.vue'; import DeleteButton from '../delete_button.vue';
import permissionsQuery from '../../graphql/queries/permissions.query.graphql'; import permissionsQuery from '../../graphql/queries/design_permissions.query.graphql';
import appDataQuery from '../../graphql/queries/appData.query.graphql'; import appDataQuery from '../../graphql/queries/appData.query.graphql';
import { DESIGNS_ROUTE_NAME } from '../../router/constants'; import { DESIGNS_ROUTE_NAME } from '../../router/constants';
......
#import "./diffRefs.fragment.graphql" #import "./diffRefs.fragment.graphql"
#import "~/graphql_shared/fragments/author.fragment.graphql" #import "~/graphql_shared/fragments/author.fragment.graphql"
#import "./notePermissions.fragment.graphql" #import "./note_permissions.fragment.graphql"
fragment DesignNote on Note { fragment DesignNote on Note {
id id
......
fragment DesignNotePermissions on NotePermissions { fragment DesignNotePermissions on NotePermissions {
adminNote adminNote
} }
\ No newline at end of file
...@@ -9,7 +9,7 @@ import DesignDestroyer from '../components/design_destroyer.vue'; ...@@ -9,7 +9,7 @@ import DesignDestroyer from '../components/design_destroyer.vue';
import DesignVersionDropdown from '../components/upload/design_version_dropdown.vue'; import DesignVersionDropdown from '../components/upload/design_version_dropdown.vue';
import DesignDropzone from '../components/upload/design_dropzone.vue'; import DesignDropzone from '../components/upload/design_dropzone.vue';
import uploadDesignMutation from '../graphql/mutations/uploadDesign.mutation.graphql'; import uploadDesignMutation from '../graphql/mutations/uploadDesign.mutation.graphql';
import permissionsQuery from '../graphql/queries/permissions.query.graphql'; import permissionsQuery from '../graphql/queries/design_permissions.query.graphql';
import getDesignListQuery from '../graphql/queries/get_design_list.query.graphql'; import getDesignListQuery from '../graphql/queries/get_design_list.query.graphql';
import allDesignsMixin from '../mixins/all_designs'; import allDesignsMixin from '../mixins/all_designs';
import { import {
......
---
title: Allow only users with `adminNote` permission to edit the design note
merge_request: 32035
author:
type: fixed
...@@ -50,17 +50,7 @@ exports[`Design note component should match the snapshot 1`] = ` ...@@ -50,17 +50,7 @@ exports[`Design note component should match the snapshot 1`] = `
</span> </span>
</div> </div>
<button <!---->
class="note-action-button js-note-edit btn btn-transparent qa-note-edit-button"
title="Edit comment"
type="button"
>
<gl-icon-stub
class="link-highlight"
name="pencil"
size="16"
/>
</button>
</div> </div>
<div <div
......
...@@ -12,6 +12,9 @@ const note = { ...@@ -12,6 +12,9 @@ const note = {
id: 'author-id', id: 'author-id',
}, },
body: 'test', body: 'test',
userPermissions: {
adminNote: false,
},
}; };
HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
...@@ -93,55 +96,75 @@ describe('Design note component', () => { ...@@ -93,55 +96,75 @@ describe('Design note component', () => {
expect(scrollIntoViewMock).toHaveBeenCalled(); expect(scrollIntoViewMock).toHaveBeenCalled();
}); });
it('should open an edit form on edit button click', () => { it('should not render edit icon when user does not have a permission', () => {
createComponent({ createComponent({
note, note,
}); });
findEditButton().trigger('click'); expect(findEditButton().exists()).toBe(false);
return wrapper.vm.$nextTick().then(() => {
expect(findReplyForm().exists()).toBe(true);
expect(findNoteContent().exists()).toBe(false);
});
}); });
describe('when edit form is rendered', () => { describe('when user has a permission to edit note', () => {
beforeEach(() => { it('should open an edit form on edit button click', () => {
createComponent( createComponent({
{ note: {
note, ...note,
userPermissions: {
adminNote: true,
},
}, },
{ isEditing: true }, });
);
});
it('should not render note content and should render reply form', () => {
expect(findNoteContent().exists()).toBe(false);
expect(findReplyForm().exists()).toBe(true);
});
it('hides the form on hideForm event', () => { findEditButton().trigger('click');
findReplyForm().vm.$emit('cancelForm');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findReplyForm().exists()).toBe(false); expect(findReplyForm().exists()).toBe(true);
expect(findNoteContent().exists()).toBe(true); expect(findNoteContent().exists()).toBe(false);
}); });
}); });
it('calls a mutation on submitForm event and hides a form', () => { describe('when edit form is rendered', () => {
findReplyForm().vm.$emit('submitForm'); beforeEach(() => {
expect(mutate).toHaveBeenCalled(); createComponent(
{
note: {
...note,
userPermissions: {
adminNote: true,
},
},
},
{ isEditing: true },
);
});
it('should not render note content and should render reply form', () => {
expect(findNoteContent().exists()).toBe(false);
expect(findReplyForm().exists()).toBe(true);
});
it('hides the form on hideForm event', () => {
findReplyForm().vm.$emit('cancelForm');
return mutate() return wrapper.vm.$nextTick().then(() => {
.then(() => {
return wrapper.vm.$nextTick();
})
.then(() => {
expect(findReplyForm().exists()).toBe(false); expect(findReplyForm().exists()).toBe(false);
expect(findNoteContent().exists()).toBe(true); expect(findNoteContent().exists()).toBe(true);
}); });
});
it('calls a mutation on submitForm event and hides a form', () => {
findReplyForm().vm.$emit('submitForm');
expect(mutate).toHaveBeenCalled();
return mutate()
.then(() => {
return wrapper.vm.$nextTick();
})
.then(() => {
expect(findReplyForm().exists()).toBe(false);
expect(findNoteContent().exists()).toBe(true);
});
});
}); });
}); });
}); });
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