passing tests - user / workouts permissions done
This commit is contained in:
@@ -51,6 +51,7 @@ ispromember = is_promember | is_protrial
|
||||
def can_plan(user):
|
||||
return user.rower.rowerplan in ['plan','coach','freecoach']
|
||||
|
||||
# checks if rower is coach of user
|
||||
@rules.predicate
|
||||
def is_coach_user(user,rower):
|
||||
try:
|
||||
@@ -67,7 +68,7 @@ def is_coach_user(user,rower):
|
||||
newcoaches = group.get_coaches()
|
||||
for coach in newcoaches:
|
||||
coaches.append(coach)
|
||||
print(coaches)
|
||||
|
||||
for coach in coaches:
|
||||
if rower == coach:
|
||||
return True
|
||||
@@ -126,36 +127,16 @@ def is_workout_user(user,workout):
|
||||
if workout.user == r:
|
||||
return True
|
||||
|
||||
coaches = []
|
||||
for group in workout.user.coachinggroups.all():
|
||||
coach = group.coachingrole
|
||||
coaches.append(coach)
|
||||
for coach in coaches:
|
||||
if r == coach and workout.privacy == 'visible':
|
||||
return True
|
||||
|
||||
return False
|
||||
return is_coach_user(workout.user.user,user.rower)
|
||||
|
||||
|
||||
@rules.predicate
|
||||
def can_view_workout(user,workout):
|
||||
if user.is_anonymous:
|
||||
if workout.privacy != 'private':
|
||||
return True
|
||||
return False
|
||||
|
||||
try:
|
||||
r = user.rower
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
teams = workout.user.team.all()
|
||||
|
||||
for team in teams:
|
||||
if team in r.team.all():
|
||||
return True
|
||||
|
||||
if workout.privacy != 'private':
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
rules.add_perm('workout.change_workout',is_workout_user) # replaces checkworkoutuser
|
||||
rules.add_perm('workout.view_workout',can_view_workout) # replaces checkworkoutuserview
|
||||
|
||||
@@ -166,6 +147,7 @@ rules.add_perm('workout.view_workout',can_view_workout) # replaces checkworkoutu
|
||||
# PLANNING permissions
|
||||
|
||||
# checkaccessplanuser (models.py)
|
||||
# getrequestrower, getrequestplanrower
|
||||
|
||||
# TEAM permissions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user