From 1c75feae601b753f1dd30a15c49794c9de1a05fb Mon Sep 17 00:00:00 2001 From: Jiayi Zheng Date: Wed, 7 Dec 2016 21:50:46 +0100 Subject: [PATCH 1/3] Move delete button for status into a component --- src/components/delete_button/delete_button.js | 16 +++++++++++++++ .../delete_button/delete_button.vue | 20 +++++++++++++++++++ src/components/status/status.js | 12 +++-------- src/components/status/status.vue | 13 +----------- 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 src/components/delete_button/delete_button.js create mode 100644 src/components/delete_button/delete_button.vue diff --git a/src/components/delete_button/delete_button.js b/src/components/delete_button/delete_button.js new file mode 100644 index 00000000..5f824899 --- /dev/null +++ b/src/components/delete_button/delete_button.js @@ -0,0 +1,16 @@ +const DeleteButton = { + props: [ 'status' ], + methods: { + deleteStatus () { + const confirmed = confirm('Do you really want to delete this status?') + if (confirmed) { + this.$store.dispatch('deleteStatus', { id: this.status.id }) + } + } + }, + computed: { + canDelete () { return this.status.user.rights.delete_others_notice || this.status.user.id == this.$store.state.users.currentUser.id } + } +} + +export default DeleteButton diff --git a/src/components/delete_button/delete_button.vue b/src/components/delete_button/delete_button.vue new file mode 100644 index 00000000..304f8a63 --- /dev/null +++ b/src/components/delete_button/delete_button.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/src/components/status/status.js b/src/components/status/status.js index 8b2561cf..27911478 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -1,6 +1,7 @@ import Attachment from '../attachment/attachment.vue' import FavoriteButton from '../favorite_button/favorite_button.vue' import RetweetButton from '../retweet_button/retweet_button.vue' +import DeleteButton from '../delete_button/delete_button.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' const Status = { @@ -20,25 +21,18 @@ const Status = { }, loggedIn () { return !!this.$store.state.users.currentUser - }, - deleted () { return this.statusoid.deleted }, - canDelete () { return this.statusoid.user.rights.delete_others_notice || this.statusoid.user.id == this.$store.state.users.currentUser.id } + } }, components: { Attachment, FavoriteButton, RetweetButton, + DeleteButton, PostStatusForm }, methods: { toggleReplying () { this.replying = !this.replying - }, - deleteStatus () { - const confirmed = confirm('Do you really want to delete this status?') - if (confirmed) { - this.$store.dispatch('deleteStatus', { id: this.status.id }) - } } } } diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 6b9bca5b..42499407 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -52,11 +52,7 @@ -
- - - -
+ @@ -130,11 +126,4 @@ .status-el:last-child .status { border: none } - - .icon-cancel,.delete-status { - cursor: pointer; - &:hover { - color: $red; - } - } From c24e44a8f22be1620b103b75ebd255cd610e143e Mon Sep 17 00:00:00 2001 From: Jiayi Zheng Date: Thu, 8 Dec 2016 20:26:05 +0100 Subject: [PATCH 2/3] Fixes user right check --- src/components/delete_button/delete_button.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/delete_button/delete_button.js b/src/components/delete_button/delete_button.js index 5f824899..990c32ad 100644 --- a/src/components/delete_button/delete_button.js +++ b/src/components/delete_button/delete_button.js @@ -9,7 +9,8 @@ const DeleteButton = { } }, computed: { - canDelete () { return this.status.user.rights.delete_others_notice || this.status.user.id == this.$store.state.users.currentUser.id } + currentUser () { return this.$store.state.users.currentUser }, + canDelete () { return this.currentUser.delete_others_notice || this.status.user.id == this.currentUser.id } } } From d98f73092152734e5d3f7322b059232d08caae9b Mon Sep 17 00:00:00 2001 From: Jiayi Zheng Date: Mon, 19 Dec 2016 17:03:02 +0100 Subject: [PATCH 3/3] Fixes currentUser rights --- src/components/delete_button/delete_button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/delete_button/delete_button.js b/src/components/delete_button/delete_button.js index 990c32ad..726509d0 100644 --- a/src/components/delete_button/delete_button.js +++ b/src/components/delete_button/delete_button.js @@ -10,7 +10,7 @@ const DeleteButton = { }, computed: { currentUser () { return this.$store.state.users.currentUser }, - canDelete () { return this.currentUser.delete_others_notice || this.status.user.id == this.currentUser.id } + canDelete () { return this.currentUser.rights.delete_others_notice || this.status.user.id == this.currentUser.id } } }