Example #1
0
 def test_can_user_edit_administartive_data_group_central_manager_no_entity_linked(
         self):
     """With permission + Group central manager + No linked to the right entity + Not program manager ==> Refused """
     _add_to_group(self.user, CENTRAL_MANAGER_GROUP)
     self.assertFalse(
         can_user_edit_administrative_data(self.user,
                                           self.education_group_year))
Example #2
0
 def test_can_user_edit_administrative_data_no_permission(self):
     """Without permission/group, we cannot access to administrative data ==> Refused"""
     user_without_perm = UserFactory()
     PersonFactory(user=user_without_perm)
     self.assertFalse(
         can_user_edit_administrative_data(user_without_perm,
                                           self.education_group_year))
Example #3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        pgm_mgrs = ProgramManager.objects.filter(
            education_group=self.object.education_group,
        ).order_by("person__last_name", "person__first_name")

        mandataries = Mandatary.objects.filter(
            mandate__education_group=self.object.education_group,
            start_date__lte=self.object.academic_year.end_date,
            end_date__gte=self.object.academic_year.start_date
        ).order_by(
            'mandate__function',
            'person__last_name',
            'person__first_name'
        ).select_related("person", "mandate")

        course_enrollment_dates = OfferYearCalendar.objects.filter(
            education_group_year=self.object,
            academic_calendar__reference=academic_calendar_type.COURSE_ENROLLMENT,
            academic_calendar__academic_year=self.object.academic_year
        ).first()

        context.update({
            'course_enrollment_dates': course_enrollment_dates,
            'mandataries': mandataries,
            'pgm_mgrs': pgm_mgrs,
            "can_edit_administrative_data": can_user_edit_administrative_data(self.request.user, self.object)
        })
        context.update(get_sessions_dates(self.object))

        return context
Example #4
0
def education_group_edit_administrative_data(request, education_group_year_id):
    education_group_year = get_object_or_404(EducationGroupYear, pk=education_group_year_id)

    assert_category_of_education_group_year(education_group_year, (education_group_categories.TRAINING,))

    if not education_group_business.can_user_edit_administrative_data(request.user, education_group_year):
        raise PermissionDenied("Only program managers of the education group OR central manager "
                               "linked to entity can edit.")

    formset_session = AdministrativeDataFormset(request.POST or None,
                                                form_kwargs={'education_group_year': education_group_year})

    offer_year_calendar = mdl.offer_year_calendar.search(education_group_year_id=education_group_year_id,
                                                         academic_calendar_reference=academic_calendar_type.COURSE_ENROLLMENT).first()

    course_enrollment = CourseEnrollmentForm(request.POST or None, instance=offer_year_calendar)

    course_enrollment_validity = course_enrollment.is_valid()
    formset_session_validity = formset_session.is_valid()

    if course_enrollment_validity and formset_session_validity:
        formset_session.save()
        course_enrollment.save()
        messages.add_message(request, messages.SUCCESS, _('The administrative data has been successfully modified'))
        return HttpResponseRedirect(reverse('education_group_administrative', args=(education_group_year_id,)))

    return layout.render(request, "education_group/tab_edit_administrative_data.html", locals())
Example #5
0
def education_group_administrative_data(request, education_group_year_id):
    education_group_year = get_object_or_404(EducationGroupYear, pk=education_group_year_id)

    assert_category_of_education_group_year(education_group_year, (education_group_categories.TRAINING,))

    education_group_year_root_id = request.GET.get('root')
    parent = _get_education_group_root(education_group_year_root_id, education_group_year)

    context = {'parent': parent,
               'education_group_year': education_group_year,
               'course_enrollment': get_dates(academic_calendar_type.COURSE_ENROLLMENT, education_group_year),
               'mandataries': mdl.mandatary.find_by_education_group_year(education_group_year),
               'pgm_mgrs': mdl.program_manager.find_by_education_group(education_group_year.education_group)}
    context.update({'exam_enrollments': get_sessions_dates(academic_calendar_type.EXAM_ENROLLMENTS,
                                                           education_group_year)})
    context.update({'scores_exam_submission': get_sessions_dates(academic_calendar_type.SCORES_EXAM_SUBMISSION,
                                                                 education_group_year)})
    context.update({'dissertation_submission': get_sessions_dates(academic_calendar_type.DISSERTATION_SUBMISSION,
                                                                  education_group_year)})
    context.update({'deliberation': get_sessions_dates(academic_calendar_type.DELIBERATION,
                                                       education_group_year)})
    context.update({'scores_exam_diffusion': get_sessions_dates(academic_calendar_type.SCORES_EXAM_DIFFUSION,
                                                                education_group_year)})
    context.update({"can_edit_administrative_data":  education_group_business.can_user_edit_administrative_data(
                                                                                request.user, education_group_year)})
    return layout.render(request, "education_group/tab_administrative_data.html", context)
Example #6
0
 def test_can_user_edit_administrative_data_with_permission_and_pgrm_manager(
         self):
     """With permission and program manager of education group ==> Allowed"""
     ProgramManagerFactory(
         person=self.person,
         education_group=self.education_group_year.education_group)
     self.assertTrue(
         can_user_edit_administrative_data(self.user,
                                           self.education_group_year))
 def test_can_user_edit_administartive_data_group_central_manager_no_entity_linked_but_program_manager(self):
     """
     With permission + Group central manager + Linked to the parent entity (with_child FALSE) + IS
     program manager ==> Allowed
     """
     _add_to_group(self.user, CENTRAL_MANAGER_GROUP)
     PersonEntityFactory(person=self.person, entity=self.root_entity, with_child=False)
     ProgramManagerFactory(person=self.person, education_group=self.education_group_year.education_group)
     self.assertTrue(can_user_edit_administrative_data(self.user, self.education_group_year))
Example #8
0
 def test_can_user_edit_administartive_data_group_central_manager_parent_entity_linked_no_child(
         self):
     """With permission + Group central manager + Linked to the parent entity (with child FALSE) ==> Refused """
     _add_to_group(self.user, CENTRAL_MANAGER_GROUP)
     PersonEntityFactory(person=self.person,
                         entity=self.root_entity,
                         with_child=False)
     self.assertFalse(
         can_user_edit_administrative_data(self.user,
                                           self.education_group_year))
Example #9
0
 def test_can_user_edit_administartive_data_group_central_manager_entity_linked(
         self):
     """With permission + Group central manager + Linked to the right entity ==> Allowed """
     _add_to_group(self.user, CENTRAL_MANAGER_GROUP)
     PersonEntityFactory(person=self.person,
                         entity=self.chim_entity,
                         with_child=False)
     self.assertTrue(
         can_user_edit_administrative_data(self.user,
                                           self.education_group_year))
Example #10
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context.update({
            'course_enrollment': get_dates(academic_calendar_type.COURSE_ENROLLMENT, self.object),
            'mandataries': mdl.mandatary.find_by_education_group_year(self.object),
            'pgm_mgrs': mdl.program_manager.find_by_education_group(self.object.education_group),
            'exam_enrollments': get_sessions_dates(academic_calendar_type.EXAM_ENROLLMENTS, self.object),
            'scores_exam_submission': get_sessions_dates(academic_calendar_type.SCORES_EXAM_SUBMISSION, self.object),
            'dissertation_submission': get_sessions_dates(academic_calendar_type.DISSERTATION_SUBMISSION, self.object),
            'deliberation': get_sessions_dates(academic_calendar_type.DELIBERATION, self.object),
            'scores_exam_diffusion': get_sessions_dates(academic_calendar_type.SCORES_EXAM_DIFFUSION, self.object),
            "can_edit_administrative_data": can_user_edit_administrative_data(self.request.user, self.object)
        })

        return context
Example #11
0
 def test_can_user_edit_administrative_data_with_permission_no_pgrm_manager(
         self):
     """With permission but no program manager of education group ==> Refused"""
     self.assertFalse(
         can_user_edit_administrative_data(self.user,
                                           self.education_group_year))