X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fhelpers%2Fpermissions.js;h=18d03bffce1c6be3f56d04de783b42d734578588;hb=cd36cb0ba2718e6bfa08765e7702d57dfe7fd733;hp=8b8c596100270d6c32c4e2b2ff08d2220e96ba08;hpb=eca3f0074e6f9e882b91893e554ce249e25338de;p=alttp.git diff --git a/resources/js/helpers/permissions.js b/resources/js/helpers/permissions.js index 8b8c596..18d03bf 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,13 @@ 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 mayHandleApplications = (user, tournament) => + tournament && tournament.accept_applications && isTournamentAdmin(user, tournament); + export const mayLockRound = (user, tournament) => !tournament.locked && isTournamentAdmin(user, tournament);