Commit 3bd37bc4 authored by Phil Hughes's avatar Phil Hughes

Shows delete button if permissions are correct

[ci skip]
parent 86700b97
...@@ -19,6 +19,10 @@ export default { ...@@ -19,6 +19,10 @@ export default {
required: true, required: true,
type: Boolean, type: Boolean,
}, },
canDestroy: {
required: true,
type: Boolean,
},
issuableRef: { issuableRef: {
type: String, type: String,
required: true, required: true,
...@@ -134,6 +138,7 @@ export default { ...@@ -134,6 +138,7 @@ export default {
:updated-at="state.updatedAt" :updated-at="state.updatedAt"
:task-status="state.taskStatus" /> :task-status="state.taskStatus" />
<edit-actions <edit-actions
v-if="canUpdate && showForm" /> v-if="canUpdate && showForm"
:can-destroy="canDestroy" />
</div> </div>
</template> </template>
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
props: {
canDestroy: {
type: Boolean,
required: true,
},
},
data() { data() {
return { return {
deleteLoading: false, deleteLoading: false,
...@@ -50,6 +56,7 @@ ...@@ -50,6 +56,7 @@
Cancel Cancel
</button> </button>
<button <button
v-if="canDestroy"
class="btn btn-danger pull-right append-right-default" class="btn btn-danger pull-right append-right-default"
:class="{ disabled: deleteLoading }" :class="{ disabled: deleteLoading }"
type="button" type="button"
......
...@@ -22,12 +22,14 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -22,12 +22,14 @@ document.addEventListener('DOMContentLoaded', () => {
const issuableDescriptionTextarea = issuableElement.querySelector('.js-task-list-field'); const issuableDescriptionTextarea = issuableElement.querySelector('.js-task-list-field');
const { const {
canUpdate, canUpdate,
canDestroy,
endpoint, endpoint,
issuableRef, issuableRef,
} = issuableElement.dataset; } = issuableElement.dataset;
return { return {
canUpdate: gl.utils.convertPermissionToBoolean(canUpdate), canUpdate: gl.utils.convertPermissionToBoolean(canUpdate),
canDestroy: gl.utils.convertPermissionToBoolean(canDestroy),
endpoint, endpoint,
issuableRef, issuableRef,
initialTitle: issuableTitleElement.innerHTML, initialTitle: issuableTitleElement.innerHTML,
...@@ -56,6 +58,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -56,6 +58,7 @@ document.addEventListener('DOMContentLoaded', () => {
return createElement('issuable-app', { return createElement('issuable-app', {
props: { props: {
canUpdate: this.canUpdate, canUpdate: this.canUpdate,
canDestroy: this.canDestroy,
endpoint: this.endpoint, endpoint: this.endpoint,
issuableRef: this.issuableRef, issuableRef: this.issuableRef,
initialTitle: this.initialTitle, initialTitle: this.initialTitle,
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
.detail-page-description.content-block .detail-page-description.content-block
#js-issuable-app{ "data" => { "endpoint" => namespace_project_issue_path(@project.namespace, @project, @issue), #js-issuable-app{ "data" => { "endpoint" => namespace_project_issue_path(@project.namespace, @project, @issue),
"can-update" => can?(current_user, :update_issue, @issue).to_s, "can-update" => can?(current_user, :update_issue, @issue).to_s,
"can-destroy" => can?(current_user, :destroy_issue, @issue).to_s,
"issuable-ref" => @issue.to_reference, "issuable-ref" => @issue.to_reference,
} } } }
%h2.title= markdown_field(@issue, :title) %h2.title= markdown_field(@issue, :title)
......
...@@ -28,12 +28,13 @@ describe('Issuable output', () => { ...@@ -28,12 +28,13 @@ describe('Issuable output', () => {
vm = new IssuableDescriptionComponent({ vm = new IssuableDescriptionComponent({
propsData: { propsData: {
canUpdate: true, canUpdate: true,
canDestroy: true,
endpoint: '/gitlab-org/gitlab-shell/issues/9/rendered_title', endpoint: '/gitlab-org/gitlab-shell/issues/9/rendered_title',
issuableRef: '#1', issuableRef: '#1',
initialTitle: '', initialTitle: '',
initialDescriptionHtml: '', initialDescriptionHtml: '',
initialDescriptionText: '', initialDescriptionText: '',
showForm: true, showForm: false,
}, },
}).$mount(); }).$mount();
}); });
...@@ -62,6 +63,31 @@ describe('Issuable output', () => { ...@@ -62,6 +63,31 @@ describe('Issuable output', () => {
}); });
}); });
it('shows actions if permissions are correct', (done) => {
vm.showForm = true;
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.btn'),
).not.toBeNull();
done();
});
});
it('does not show actions if permissions are incorrect', (done) => {
vm.showForm = true;
vm.canUpdate = false;
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.btn'),
).toBeNull();
done();
});
});
describe('updateIssuable', () => { describe('updateIssuable', () => {
it('correctly updates issuable data', (done) => { it('correctly updates issuable data', (done) => {
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
......
...@@ -10,7 +10,11 @@ describe('Edit Actions components', () => { ...@@ -10,7 +10,11 @@ describe('Edit Actions components', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
vm = new Component().$mount(); vm = new Component({
propsData: {
canDestroy: true,
},
}).$mount();
Vue.nextTick(done); Vue.nextTick(done);
}); });
...@@ -25,6 +29,18 @@ describe('Edit Actions components', () => { ...@@ -25,6 +29,18 @@ describe('Edit Actions components', () => {
).toBe(0); ).toBe(0);
}); });
it('does not render delete button if canUpdate is false', (done) => {
vm.canDestroy = false;
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.btn-danger'),
).toBeNull();
done();
});
});
describe('updateIssuable', () => { describe('updateIssuable', () => {
it('sends update.issauble event when clicking save button', () => { it('sends update.issauble event when clicking save button', () => {
vm.$el.querySelector('.btn-save').click(); vm.$el.querySelector('.btn-save').click();
......
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