verify event permission in UI, fix #213

This commit is contained in:
lesion 2022-12-02 14:31:41 +01:00
parent d3b6adf4e0
commit 593cf6c6d6
No known key found for this signature in database
GPG key ID: 352918250B012177

View file

@ -91,17 +91,33 @@ export default {
WhereInput,
DateInput
},
validate({ store }) {
return (store.state.auth.loggedIn || store.state.settings.allow_anon_event)
validate({ store, params, error }) {
// should we allow anon event?
if(!store.state.settings.allow_anon_event && !store.state.auth.loggedIn) {
return error({ statusCode: 401, message: 'Not allowed'})
}
// do not allow edit to anon users
if (params.edit && !store.state.auth.loggedIn) {
return error({ statusCode: 401, message: 'Not allowed'})
}
return true
},
async asyncData({ params, $axios, error }) {
async asyncData({ params, $axios, error, $auth, store }) {
if (params.edit) {
const data = { event: { place: {}, media: [] } }
data.id = params.edit
data.edit = true
let event
try {
event = await $axios.$get('/event/' + data.id)
if (!$auth.user.is_admin && $auth.user.id !== event.userId) {
error({ statusCode: 401, message: 'Not allowed' })
return {}
}
} catch (e) {
error({ statusCode: 404, message: 'Event not found!' })
return {}