X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=b7d7cfdd616b72ba5a0f271805e87e19d708d61d;hb=09c1644b5f64d7423905ae1be8f79da0b482289a;hp=ecc1e620e2796fdef58275cab0ed57bed8131fb8;hpb=edd0e97bfdc544114f30bf4c13a929631c44a555;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index ecc1e62..b7d7cfd 100644 --- a/resources/js/helpers/permissions.js +++ b/resources/js/helpers/permissions.js @@ -1,6 +1,8 @@ /// NOTE: These permissions are for UI cosmetics only! /// They should be in sync with the backend Policies. +import Round from './Round'; + export const isAdmin = user => user && user.role === 'admin'; export const isSameUser = (user, subject) => user && subject && user.id === subject.id; @@ -11,5 +13,18 @@ export const isParticipant = (user, tournament) => user && tournament && tournament.participants && tournament.participants.find(p => p.user && p.user.id == user.id); +export const hasFinished = (user, round) => + user && round && round.results && + round.results.find(r => r.user_id == user.id && r.has_finished); + export const mayAddRounds = (user, tournament) => isAdmin(user) || isParticipant(user, tournament); + +export const maySetSeed = (user, tournament) => + isAdmin(user) || isParticipant(user, tournament); + +export const mayViewProtocol = user => + isAdmin(user); + +export const maySeeResults = (user, tournament, round) => + isAdmin(user) || hasFinished(user, round) || Round.isComplete(tournament, round);