X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=21016f1a08f6786fecfdcbe775717ace91b8279b;hb=eebc6384e56336b66ec250fc2aea3be6171d53ff;hp=2565d44d04edd58f6000c3fc5c60e3326d7cd2f4;hpb=c59d0714d62f9028135cc9cff829d16b91e5fb4f;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index 2565d44..21016f1 100644 --- a/resources/js/helpers/permissions.js +++ b/resources/js/helpers/permissions.js @@ -13,15 +13,33 @@ export const isParticipant = (user, tournament) => user && tournament && tournament.participants && tournament.participants.find(p => p.user && p.user.id == user.id); +export const isRunner = (user, tournament) => { + const p = isParticipant(user, tournament); + return p && p.roles && p.roles.includes('runner'); +}; + +export const isTournamentAdmin = (user, tournament) => { + const p = isParticipant(user, tournament); + return p && p.roles && p.roles.includes('admin'); +}; + 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) || (!tournament.locked && isParticipant(user, tournament)); + +export const maySetSeed = (user, tournament) => isAdmin(user) || isParticipant(user, tournament); -export const mayViewProtocol = user => - isAdmin(user); +export const mayViewProtocol = (user, tournament) => + isAdmin(user) || isTournamentAdmin(user, tournament); export const maySeeResults = (user, tournament, round) => isAdmin(user) || hasFinished(user, round) || Round.isComplete(tournament, round); + +// Users + +export const mayEditStreamLink = (user, subject) => + isAdmin(user) || isSameUser(user, subject);