Repository: ocadotechnology/codeforlife-portal

Issue:
The forms in dashboard aren't working for non-admin teachers
Ex: Add a class
Edit account...




Discussion:
Note: The forms on the teacher dashboard are the only ones which aren't working. For some reason, all the other ones across the site work fine.
Update: Everything works fine for admin teachers. For non admin teachers, the 'Add class' form and 'Update account details' form do not work: whether the form is valid or not, the page will reload at the top of the page and nothing will happen - no error or success messages.
The issue can be found both on staging and locally.
Same problem in production :'( - Need test to make sure it doesn't happen anymore

Resolving patch:
diff --git a/portal/views/teacher/dashboard.py b/portal/views/teacher/dashboard.py
--- a/portal/views/teacher/dashboard.py
+++ b/portal/views/teacher/dashboard.py
@@ -87,8 +87,8 @@ def dashboard_teacher_view(request, is_admin):
 
     backup_tokens = check_backup_tokens(request)
 
-    if can_process_forms(request, is_admin):
-        if 'update_school' in request.POST:
+    if request.method == 'POST':
+        if can_process_update_school_form(request, is_admin):
             anchor = 'school-details'
             update_school_form = OrganisationForm(request.POST, user=request.user, current_school=school)
             anchor = process_update_school_form(request, school, anchor)
@@ -127,8 +127,8 @@ def dashboard_teacher_view(request, is_admin):
     })
 
 
-def can_process_forms(request, is_admin):
-    return request.method == 'POST' and is_admin
+def can_process_update_school_form(request, is_admin):
+    return 'update_school' in request.POST and is_admin
 
 
 def check_backup_tokens(request):


Test patch:
diff --git a/portal/tests/test_class.py b/portal/tests/test_class.py
--- a/portal/tests/test_class.py
+++ b/portal/tests/test_class.py
@@ -84,6 +84,24 @@ def test_create_dashboard(self):
 
         assert is_class_created_message_showing(selenium, class_name)
 
+    def test_create_dashboard_non_admin(self):
+        email_1, password_1 = signup_teacher_directly()
+        email_2, password_2 = signup_teacher_directly()
+        name, postcode = create_organisation_directly(email_1)
+        klass_1, class_name_1, access_code_1 = create_class_directly(email_1)
+        create_school_student_directly(access_code_1)
+        join_teacher_to_organisation(email_2, name, postcode)
+        klass_2, class_name_2, access_code_2 = create_class_directly(email_2)
+        create_school_student_directly(access_code_2)
+
+        page = self.go_to_homepage() \
+            .go_to_login_page() \
+            .login(email_2, password_2)
+
+        page, class_name_3 = create_class(page)
+
+        assert is_class_created_message_showing(selenium, class_name_3)
+
     def test_delete_empty(self):
         email, password = signup_teacher_directly()
         create_organisation_directly(email)
diff --git a/portal/tests/test_teacher.py b/portal/tests/test_teacher.py
--- a/portal/tests/test_teacher.py
+++ b/portal/tests/test_teacher.py
@@ -44,7 +44,7 @@
 from base_test import BaseTest
 from pageObjects.portal.home_page import HomePage
 from utils.teacher import signup_teacher, signup_teacher_directly, signup_duplicate_teacher_fail
-from utils.organisation import create_organisation_directly
+from utils.organisation import create_organisation_directly, join_teacher_to_organisation
 from utils.classes import create_class_directly
 from utils.student import create_school_student_directly
 from utils.messages import is_email_verified_message_showing, is_teacher_details_updated_message_showing, \
@@ -140,6 +140,34 @@ def test_edit_details(self):
             'last_name': 'Koch',
         })
 
+    def test_edit_details_non_admin(self):
+        email_1, password_1 = signup_teacher_directly()
+        email_2, password_2 = signup_teacher_directly()
+        name, postcode = create_organisation_directly(email_1)
+        klass_1, class_name_1, access_code_1 = create_class_directly(email_1)
+        create_school_student_directly(access_code_1)
+        join_teacher_to_organisation(email_2, name, postcode)
+        klass_2, class_name_2, access_code_2 = create_class_directly(email_2)
+        create_school_student_directly(access_code_2)
+
+        selenium.get(self.live_server_url)
+        page = HomePage(selenium).go_to_login_page().login(email_2, password_2)
+
+        page = page.change_teacher_details({
+            'title': 'Mr',
+            'first_name': 'Florian',
+            'last_name': 'Aucomte',
+            'current_password': 'Password1',
+        })
+        assert self.is_dashboard_page(page)
+        assert is_teacher_details_updated_message_showing(selenium)
+
+        assert page.check_account_details({
+            'title': 'Mr',
+            'first_name': 'Florian',
+            'last_name': 'Aucomte',
+        })
+
     def test_change_email(self):
         email, password = signup_teacher_directly()
         create_organisation_directly(email)