X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;fp=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=cde0d05d7fd293f7114b6d7553ffb1144a9ffaa6;hb=3a774bb649734fc3a2135ec1b52cef9a049880ee;hp=8b8c596100270d6c32c4e2b2ff08d2220e96ba08;hpb=8d97d023740e438361e659c6e133418e33343178;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index 8b8c596..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); @@ -39,6 +54,10 @@ export const mayAddRounds = (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) => !tournament.locked && isTournamentAdmin(user, tournament);