]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/permissions.js
round titles
[alttp.git] / resources / js / helpers / permissions.js
index 8b8c596100270d6c32c4e2b2ff08d2220e96ba08..b1de05180d2b1b9ea04f83a4921a9cbd56190162 100644 (file)
@@ -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,22 @@ 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 mayReportResult = (user, tournament) => {
+       if (!user || !tournament) return false;
+       if (tournament.type === 'open-async') return true;
+       return isRunner(user, tournament);
+};
+
+export const mayEditRound = (user, tournament) =>
+       !tournament.locked && isTournamentAdmin(user, tournament);
+
 export const mayLockRound = (user, tournament) =>
        !tournament.locked && isTournamentAdmin(user, tournament);
 
@@ -46,6 +77,9 @@ export const maySetSeed = (user, tournament, round) =>
        !round.locked &&
                (isRunner(user, tournament) || isTournamentAdmin(user, tournament));
 
+export const mayUpdateTournament = (user, tournament) =>
+       isAdmin(user) || isTournamentAdmin(user, tournament);
+
 export const mayViewProtocol = (user, tournament) =>
        isTournamentCrew(user, tournament);
 
@@ -53,7 +87,6 @@ export const maySeeResults = (user, tournament, round) =>
        round.locked ||
        hasFinished(user, round) ||
        isTournamentMonitor(user, tournament) ||
-       (isTournamentAdmin(user, tournament) && !isRunner(user, tournament)) ||
        Round.isComplete(tournament, round);
 
 // Users