Skip to content

Commit

Permalink
Show delete button for personal contents #525
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne committed Apr 11, 2019
1 parent 00b73bf commit 4bf25c4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
22 changes: 18 additions & 4 deletions src/components/generics/modals/ModalConfirmation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

<slot />

<div v-if="promise && promise.error" class="notification is-danger">
{{ promise.error }}
</div>

</div>
<div slot="footer">
<button
Expand Down Expand Up @@ -55,12 +51,30 @@
}
},
watch: {
'promise.error': 'onError'
},
methods: {
show() {
this.$refs.modalWindow.show();
},
hide() {
this.$refs.modalWindow.hide();
},
onError() {
if (!this.promise.error) {
return;
}
if (!this.promise.error.response || !this.promise.error.response.data) {
window.alert('Unexpected error');
} else if (!this.promise.error.response.data.errors) {
window.alert(!this.promise.error.response.data);
} else {
// $gettext('Only document less than 24h old can be deleted', 'API message')
window.alert(this.$gettext(this.promise.error.response.data.errors[0].description));
}
}
}
};
Expand Down
22 changes: 11 additions & 11 deletions src/views/document/utils/boxes/ToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
<hr>

<!-- Moderator zone -->
<div v-if="$user.isModerator && isEditable">

<template v-if="isEditable && $user.isModerator">
<tool-box-button
v-if="documentType !== 'profile'"
@click="lockDocumentAction"
Expand All @@ -72,27 +71,28 @@
icon="object-group"
:label="$gettext('Merge with other document')" />

<tool-box-button
v-if="document.available_langs.length > 1 && documentType !== 'profile'"
@click="$refs.DeleteLocaleWindow.show()"
:icon="['fas','trash']"
:label="$gettext('Delete this locale')" />

<tool-box-button
v-if="documentType === 'profile'"
@click="lockAccountAction"
icon="user-lock"
:class="{'lock-button-red':isAccountBlocked}"
:label="isAccountBlocked ? $gettext('Unblock account') : $gettext('Block account')" />
</template>

<template v-if="isDeletable">
<tool-box-button
v-if="document.available_langs.length > 1"
@click="$refs.DeleteLocaleWindow.show()"
:icon="['fas','trash']"
:label="$gettext('Delete this locale')" />

<tool-box-button
v-if="documentType !== 'profile'"
@click="$refs.deleteDocumentWindow.show()"
:icon="['fas','trash']"
:label="$gettext('Delete this document')" />
</template>

<hr>
</div>
<hr v-if="isDeletable || (isEditable && $user.isModerator)">

<license-box :document="document" />

Expand Down
43 changes: 43 additions & 0 deletions src/views/document/utils/is-editable-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@ export default {
mixins: [viewModeMixin],

computed: {
isDeletable() {
// first of all, if it's not editable, you can't delete it.
if (!this.isEditable) {
return false;
}

// note that some code is quite redundant, as isEditable will do most part of the job.
// But as rules may changes, it's way more safe to explicitly write this rules

// Each type of doc has it's own logic for all users (normal, or moderators)
if (this.documentType === 'outing') {
// outing, if user is associated
for (const user of this.document.associations.users) {
if (user.document_id === this.$user.id) {
return true;
}
}
} else if (this.documentType === 'image') {
// image : it must be own user personnal image. Collaborative image can't be deleted
if (['personal', 'copyright'].includes(this.document.image_type) && this.document.creator.user_id === this.$user.id) {
return true;
}
} else if (this.documentType === 'xreport') {
// xreport : is the current user the author ?
if (this.document.author.user_id === this.$user.id) {
return true;
}
} else if (this.documentType === 'article') {
// article : it must be personal
if (this.document.article_type === 'personal' && this.document.author.user_id === this.$user.id) {
return true;
}
}

// finally, moderator can delete everything but profile and areas
if (this.documentType !== 'profile' && this.documentType !== 'area' && this.$user.isModerator) {
return true;
}

// all other cas : no
return false;
},

isEditable() {
if (!this.$user.isLogged || !this.isNormalView) {
return false;
Expand Down
1 change: 0 additions & 1 deletion src/views/document/utils/windows/DeleteDocumentWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
.then(() => {
this.$router.push({ name: this.documentType + 's' });
});
// TODO feedback error
}
}
};
Expand Down

0 comments on commit 4bf25c4

Please sign in to comment.