Improved post edit guard

This commit is contained in:
Grzegorz Leoniec 2019-02-05 11:04:41 +01:00
parent 63925e4046
commit bfb8afc662
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377

View File

@ -21,14 +21,21 @@ export default {
HcContributionForm
},
computed: {
user() {
return this.$store.getters['auth/user']
},
author() {
return this.contribution ? this.contribution.author : {}
},
contribution() {
if (!this.Post || !this.Post[0].id) {
return
}
if (this.Post[0].author.id !== this.$store.getters['auth/user'].id) {
return this.Post ? this.Post[0] : {}
}
},
watch: {
contribution() {
if (this.author.id !== this.user.id) {
throw new Error(`You can't edit that!`)
}
return this.Post[0]
}
},
apollo: {