Repository: uclouvain/osis-portal

Issue:
AttributeError: 'NoneType' object has no attribute 'person_id'
https://sentry.osis.uclouvain.be/uclouvain/osis-portal/issues/33935/

```
AttributeError: 'NoneType' object has no attribute 'person_id'
  File "internship/decorators/global_view_decorators.py", line 39, in wrapper
    response = function(request, *args, **kwargs)
  File "internship/decorators/cohort_view_decorators.py", line 45, in wrapper
    if mdl_internship.internship_student_information.InternshipStudentInformation.objects.filter(cohort_id=cohort_id, person_id=student.person_id).count() > 0:

AttributeError: 'NoneType' object has no attribute 'person_id'
```


Discussion:

Resolving patch:
diff --git a/internship/views/hospital.py b/internship/views/hospital.py
--- a/internship/views/hospital.py
+++ b/internship/views/hospital.py
@@ -32,8 +32,8 @@
 
 
 @login_required
-@redirect_if_not_in_cohort
 @permission_required('internship.can_access_internship', raise_exception=True)
+@redirect_if_not_in_cohort
 def view_hospitals_list(request, cohort_id):
     cities = mdl_internship.organization_address.get_all_cities()
     name = ""
diff --git a/internship/views/main.py b/internship/views/main.py
--- a/internship/views/main.py
+++ b/internship/views/main.py
@@ -43,8 +43,8 @@
 from internship.decorators.global_view_decorators import redirect_if_multiple_registrations
 
 @login_required
-@redirect_if_multiple_registrations
 @permission_required('internship.can_access_internship', raise_exception=True)
+@redirect_if_multiple_registrations
 def view_cohort_selection(request):
     student = mdl_base.student.find_by_user(request.user)
     cohort_subscriptions = mdl_internship.internship_student_information.InternshipStudentInformation.objects.filter(person_id=student.person_id)
@@ -60,9 +60,9 @@ def view_cohort_selection(request):
         return redirect(view_internship_home, cohort_id=cohort_id)
 
 @login_required
+@permission_required('internship.can_access_internship', raise_exception=True)
 @redirect_if_multiple_registrations
 @redirect_if_not_in_cohort
-@permission_required('internship.can_access_internship', raise_exception=True)
 def view_internship_home(request, cohort_id):
     cohort = mdl_internship.cohort.Cohort.objects.get(pk=cohort_id)
     subscription_allowed = cohort.subscription_start_date <= datetime.date.today() and datetime.date.today() <= cohort.subscription_end_date
@@ -73,10 +73,10 @@ def view_internship_home(request, cohort_id):
             })
 
 @login_required
+@permission_required('internship.can_access_internship', raise_exception=True)
 @redirect_if_multiple_registrations
 @redirect_if_not_in_cohort
 @redirect_if_subscription_not_allowed
-@permission_required('internship.can_access_internship', raise_exception=True)
 def view_internship_selection(request, cohort_id, internship_id=-1, speciality_id=-1):
     cohort = mdl_internship.cohort.Cohort.objects.get(pk=cohort_id)
     if int(internship_id) < 1:
@@ -152,9 +152,9 @@ def zip_offers_formset_and_first_choices(formset, internships_offers, number_cho
     return zipped_data
 
 @login_required
+@permission_required('internship.can_access_internship', raise_exception=True)
 @redirect_if_multiple_registrations
 @redirect_if_not_in_cohort
-@permission_required('internship.can_access_internship', raise_exception=True)
 def assign_speciality_for_internship(request, cohort_id, internship_id):
     speciality_id = None
     if request.method == "POST":
diff --git a/internship/views/resume.py b/internship/views/resume.py
--- a/internship/views/resume.py
+++ b/internship/views/resume.py
@@ -46,9 +46,9 @@
 
 
 @login_required
+@permission_required('internship.can_access_internship', raise_exception=True)
 @redirect_if_multiple_registrations
 @redirect_if_not_in_cohort
-@permission_required('internship.can_access_internship', raise_exception=True)
 def view_student_resume(request, cohort_id):
     cohort      = mdl_internship_cohort.Cohort.objects.get(pk=cohort_id)
     student     = mdl_student.find_by_user(request.user)
@@ -76,8 +76,8 @@ def view_student_resume(request, cohort_id):
 
 
 @login_required
-@redirect_if_not_in_cohort
 @permission_required('internship.can_access_internship', raise_exception=True)
+@redirect_if_not_in_cohort
 def edit_student_information(request, cohort_id):
     cohort = mdl_internship_cohort.Cohort.objects.get(pk=cohort_id)
 


Test patch: