X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=cde0d05d7fd293f7114b6d7553ffb1144a9ffaa6;hb=3a774bb649734fc3a2135ec1b52cef9a049880ee;hp=f86b5851c94c4553486b3f2b741678de9c345197;hpb=a748d5724c8acff6e3bb3fe6c20aa5968b65d58a;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index f86b585..cde0d05 100644 --- a/resources/js/helpers/permissions.js +++ b/resources/js/helpers/permissions.js @@ -9,6 +9,21 @@ export const isSameUser = (user, subject) => user && subject && user.id === subj // Tournaments +export const isApplicant = (user, tournament) => { + if (!user || !tournament || !tournament.applications) { + return false; + } + return tournament.applications.find(p => p.user && p.user.id == user.id); +}; + +export const isDeniedApplicant = (user, tournament) => { + if (!user || !tournament || !tournament.applications) { + return false; + } + const applicant = tournament.applications.find(p => p.user && p.user.id == user.id); + return applicant && applicant.denied; +}; + export const isParticipant = (user, tournament) => user && tournament && tournament.participants && tournament.participants.find(p => p.user && p.user.id == user.id); @@ -36,27 +51,34 @@ export const hasFinished = (user, round) => round.results.find(r => r.user_id == user.id && r.has_finished); export const mayAddRounds = (user, tournament) => - isAdmin(user) || (!tournament.locked && - (isRunner(user, tournament) || isTournamentAdmin(user, tournament))); + !tournament.locked && + (isRunner(user, tournament) || isTournamentAdmin(user, tournament)); + +export const mayApply = (user, tournament) => + user && tournament && tournament.accept_applications && + !isRunner(user, tournament) && !isApplicant(user, tournament); export const mayLockRound = (user, tournament) => - isAdmin(user) || (!tournament.locked && isTournamentAdmin(user, tournament)); + !tournament.locked && isTournamentAdmin(user, tournament); export const maySetSeed = (user, tournament, round) => - isAdmin(user) || (!round.locked && - (isRunner(user, tournament) || isTournamentAdmin(user, tournament))); + !round.locked && + (isRunner(user, tournament) || isTournamentAdmin(user, tournament)); export const mayViewProtocol = (user, tournament) => - isAdmin(user) || isTournamentCrew(user, tournament); + isTournamentCrew(user, tournament); export const maySeeResults = (user, tournament, round) => - isAdmin(user) || hasFinished(user, round) || - isTournamentMonitor(user, tournament) || Round.isComplete(tournament, round); + round.locked || + hasFinished(user, round) || + isTournamentMonitor(user, tournament) || + (isTournamentAdmin(user, tournament) && !isRunner(user, tournament)) || + Round.isComplete(tournament, round); // Users export const mayEditNickname = (user, subject) => - isAdmin(user) || isSameUser(user, subject); + isSameUser(user, subject); export const mayEditStreamLink = (user, subject) => - isAdmin(user) || isSameUser(user, subject); + isSameUser(user, subject);