1 /// NOTE: These permissions are for UI cosmetics only!
2 /// They should be in sync with the backend Policies.
4 import Round from './Round';
6 export const isAdmin = user => user && user.role === 'admin';
8 export const isSameUser = (user, subject) => user && subject && user.id === subject.id;
12 export const isParticipant = (user, tournament) =>
13 user && tournament && tournament.participants &&
14 tournament.participants.find(p => p.user && p.user.id == user.id);
16 export const hasFinished = (user, round) =>
17 user && round && round.results &&
18 round.results.find(r => r.user_id == user.id && r.has_finished);
20 export const mayAddRounds = (user, tournament) =>
21 isAdmin(user) || (!tournament.locked && isParticipant(user, tournament));
23 export const maySetSeed = (user, tournament) =>
24 isAdmin(user) || isParticipant(user, tournament);
26 export const mayViewProtocol = user =>
29 export const maySeeResults = (user, tournament, round) =>
30 isAdmin(user) || hasFinished(user, round) || Round.isComplete(tournament, round);
34 export const mayEditStreamLink = (user, subject) =>
35 isAdmin(user) || isSameUser(user, subject);