]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/permissions.js
allow admins to lock/unlock rounds
[alttp.git] / resources / js / helpers / permissions.js
index b7d7cfdd616b72ba5a0f271805e87e19d708d61d..32662944a90412639878392d3e32663f6e3e59fe 100644 (file)
@@ -13,18 +13,36 @@ 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) || isParticipant(user, tournament);
+       isAdmin(user) || (!tournament.locked && isParticipant(user, tournament));
+
+export const mayLockRound = (user, tournament) =>
+       isAdmin(user) || (!tournament.locked && isTournamentAdmin(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);