/// NOTE: These permissions are for UI cosmetics only!
/// They should be in sync with the backend Policies.
+import Round from './Round';
+
export const isAdmin = user => user && user.role === 'admin';
export const isSameUser = (user, subject) => user && subject && user.id === subject.id;
user && tournament && tournament.participants &&
tournament.participants.find(p => p.user && p.user.id == user.id);
+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);
+export const maySetSeed = (user, tournament) =>
+ isAdmin(user) || isParticipant(user, tournament);
+
export const mayViewProtocol = user =>
isAdmin(user);
+export const maySeeResults = (user, tournament, round) =>
+ isAdmin(user) || hasFinished(user, round) || Round.isComplete(tournament, round);