X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=2565d44d04edd58f6000c3fc5c60e3326d7cd2f4;hb=ccaa2cf99468fea81efdf28aaa3fc72a278a95f6;hp=891803110ace4d65b34a7acb8d514a9f6676cd6e;hpb=c30ac282dde3d746d6a7762ee18c70b4416500b5;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index 8918031..2565d44 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,9 +13,15 @@ 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 mayViewProtocol = user => isAdmin(user); +export const maySeeResults = (user, tournament, round) => + isAdmin(user) || hasFinished(user, round) || Round.isComplete(tournament, round);