From 1b8185b2c7f70e23f2b3bf275bdadbe4c6bdb4a8 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 6 Apr 2020 09:46:59 +0200 Subject: [PATCH] fixing bug creating teams for trial users --- rowers/dataprepnodjango.py | 2 +- rowers/models.py | 10 ++++++---- rowers/rower_rules.py | 5 +++-- rowers/tasks.py | 1 - rowers/templates/paidplans.html | 17 ++++++++--------- rowers/views/teamviews.py | 3 ++- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/rowers/dataprepnodjango.py b/rowers/dataprepnodjango.py index 7b1fe782..4516ae54 100644 --- a/rowers/dataprepnodjango.py +++ b/rowers/dataprepnodjango.py @@ -750,7 +750,7 @@ def update_workout_field_sql(workoutid,fieldname,value,debug=False): table = 'rowers_workout' query = "UPDATE %s SET %s = %s WHERE `id` = %s;" % (table,fieldname,value,workoutid) - + with engine.connect() as conn, conn.begin(): result = conn.execute(query) diff --git a/rowers/models.py b/rowers/models.py index 38dbab45..4a70cde5 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -363,10 +363,12 @@ class Team(models.Model): "Basic user cannot be team manager" ) - if not can_add_team(manager): - raise ValidationError( - "Pro and Self-Coach users cannot have more than one team" - ) + if not self.id: + # new model instance + if not can_add_team(manager): + raise ValidationError( + "Pro and Self-Coach users cannot have more than one team" + ) super(Team, self).save(*args,**kwargs) diff --git a/rowers/rower_rules.py b/rowers/rower_rules.py index ff4e5ed1..c66a37ee 100644 --- a/rowers/rower_rules.py +++ b/rowers/rower_rules.py @@ -142,6 +142,7 @@ def is_protrial(user): return False + ispromember = is_promember | is_protrial can_have_teams = ispromember | is_coach @@ -151,7 +152,7 @@ def can_add_team(user): if is_coach(user): return True - if ispromember(user): + if ispromember(user) or is_planmember(user): otherteams = user.rower.get_managed_teams() if otherteams.count() == 0: return True @@ -628,7 +629,7 @@ def is_team_member(user,team): def can_view_team(user,team): # user based - below untested if user.rower.rowerplan == 'basic' and team.manager.rower.rowerplan != 'coach': - return False + return is_plantrial(user) or is_protrial(user) # team is public if team.private == 'open': return True diff --git a/rowers/tasks.py b/rowers/tasks.py index 8cd72879..638d9ceb 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -186,7 +186,6 @@ def handle_strava_sync(stravatoken,workoutid,filename,name,activity_type,descrip except TypeError: act = client.update_activity(res.id,activity_type=activity_type, description=description) - result = update_workout_field_sql(workoutid,'uploadedtostrava',res.id,debug=debug) try: os.remove(filename) diff --git a/rowers/templates/paidplans.html b/rowers/templates/paidplans.html index 9e475c00..e0a5ecae 100644 --- a/rowers/templates/paidplans.html +++ b/rowers/templates/paidplans.html @@ -106,8 +106,8 @@ Create and manage groups.   - ✔ - ✔ + ✔ (max 1) + ✔ (max 1) ✔ ✔ @@ -311,17 +311,17 @@

Coach and Self-Coach Membership

- +

Rowsandall.com's Training Planning functionality is part of the paid "Self-Coach" and "Coach" plans.

- +

On the "Self-Coach" plan, you can plan your own sessions.

- +

On the "Coach" plan, you can establish teams, see workouts done by athletes on your team, and plan individual and group sessions for your athletes.

- +

The Coach plan functionality listed is available to the coach only. Individual athletes can purchase upgrades to "Pro" and "Self-Coach" plans. @@ -331,7 +331,7 @@ The Coach plans come in two versions: free and paid. On the free coach plan, you can only have athletes who are on the PRO paid plans or higher, and you cannot upload any workouts to your own account. Some of the advanced Analysis functionality - becomes available when the athlete group is larger than 4. + becomes available when the athlete group is larger than 4. On the paid plans, your athletes can be on the free plan, and you have full access to the site functionality for your own workouts and those of your athletes. @@ -363,7 +363,7 @@

Do not hesitate to contact us at info@rowsandall.com with any payment related question you have.

- + @@ -372,4 +372,3 @@ {% block sidebar %} {% include 'menu_help.html' %} {% endblock %} - diff --git a/rowers/views/teamviews.py b/rowers/views/teamviews.py index 16a8cc60..f0850a33 100644 --- a/rowers/views/teamviews.py +++ b/rowers/views/teamviews.py @@ -651,7 +651,8 @@ def team_edit_view(request, team_id=0): }) @login_required() -@user_passes_test(can_add_team,login_url="/rowers/paidplans",redirect_field_name=None) +@user_passes_test(can_add_team,login_url="/rowers/paidplans",redirect_field_name=None, + message="You need to upgrade or log in to access this functionality") def team_create_view(request): r = getrequestrower(request)