mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix: send 403 if you try to edit another's post
This also fixes the glitch that you click on "Edit post" and the contribution form is empty.
This commit is contained in:
parent
6c947f782d
commit
7c278d7c7f
@ -10,41 +10,37 @@
|
|||||||
<script>
|
<script>
|
||||||
import HcContributionForm from '~/components/ContributionForm/ContributionForm'
|
import HcContributionForm from '~/components/ContributionForm/ContributionForm'
|
||||||
import PostQuery from '~/graphql/PostQuery'
|
import PostQuery from '~/graphql/PostQuery'
|
||||||
|
import { mapGetters } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
HcContributionForm,
|
HcContributionForm,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
user() {
|
...mapGetters({
|
||||||
return this.$store.getters['auth/user']
|
user: 'auth/user',
|
||||||
},
|
}),
|
||||||
author() {
|
|
||||||
return this.contribution ? this.contribution.author : {}
|
|
||||||
},
|
|
||||||
contribution() {
|
|
||||||
return this.Post ? this.Post[0] : {}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
watch: {
|
async asyncData(context) {
|
||||||
contribution() {
|
const {
|
||||||
if (this.author.id !== this.user.id) {
|
app,
|
||||||
throw new Error(`You can't edit that!`)
|
store,
|
||||||
}
|
error,
|
||||||
},
|
params: { id },
|
||||||
},
|
} = context
|
||||||
apollo: {
|
let client = app.apolloProvider.defaultClient
|
||||||
Post: {
|
const {
|
||||||
query() {
|
data: {
|
||||||
return PostQuery(this.$i18n)
|
Post: [contribution],
|
||||||
},
|
},
|
||||||
variables() {
|
} = await client.query({
|
||||||
return {
|
query: PostQuery(app.$i18n),
|
||||||
id: this.$route.params.id,
|
variables: { id },
|
||||||
}
|
})
|
||||||
},
|
if (contribution.author.id !== store.getters['auth/user'].id) {
|
||||||
fetchPolicy: 'cache-and-network',
|
error({ statusCode: 403, message: "You can't edit that!" })
|
||||||
},
|
}
|
||||||
|
return { contribution }
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user