def test_access_edit_learning_unit_proposal_as_central_manager(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) a_person = self.create_person_with_permission_and_group(CENTRAL_MANAGER_GROUP) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy) self.assertTrue(perms.is_eligible_to_edit_proposal(a_proposal, a_person))
def test_access_edit_learning_unit_proposal_as_faculty_manager(self): generated_container = GenerateContainer(start_year=self.academic_yr_1, end_year=self.academic_yr_1) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year luy = generated_container_first_year.learning_unit_year_full faculty_managers = [ create_person_with_permission_and_group(FACULTY_MANAGER_GROUP), create_person_with_permission_and_group(UE_FACULTY_MANAGER_GROUP) ] a_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.CENTRAL.name, type=proposal_type.ProposalType.SUPPRESSION.name, learning_unit_year=luy) generate_modification_transformation_proposal_calendars([ self.academic_yr, self.academic_yr_1, self.academic_yr_2, self.academic_yr_6 ]) for manager in faculty_managers: a_proposal.state = proposal_state.ProposalState.CENTRAL.name a_proposal.save() PersonEntityFactory(entity=an_requirement_entity, person=manager) self.assertFalse(perms.is_eligible_to_edit_proposal(None, manager)) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, manager)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, manager)) for tag in ProposalType.choices(): a_proposal.type = tag[0] a_proposal.save() if a_proposal.type != ProposalType.MODIFICATION: self.assertTrue( perms.is_eligible_to_edit_proposal( a_proposal, manager)) else: self.assertFalse( perms.is_eligible_to_edit_proposal( a_proposal, manager))
def test_access_edit_learning_unit_proposal_as_central_manager(self): a_person = self.create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=requirement_entity, person=a_person) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy) self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person))
def f_can_edit_learning_unit_proposal(request, learning_unit_year_id): proposal = proposal_learning_unit.find_by_learning_unit_year( learning_unit_year_id) pers = get_object_or_404(Person, user=request.user) if not business_perms.is_eligible_to_edit_proposal(proposal, pers): raise PermissionDenied( "User has not sufficient rights to edit proposal.") return view_func(request, learning_unit_year_id)
def test_access_edit_learning_unit_proposal_of_current_academic_year_as_faculty_manager(self): a_person = self.create_person_with_permission_and_group(FACULTY_MANAGER_GROUP) generated_container = GenerateContainer(start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[0] luy = generated_container_first_year.learning_unit_year_full an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=an_requirement_entity, person=a_person) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.FACULTY.name) self.assertFalse(perms.is_eligible_to_edit_proposal(a_proposal, a_person))
def test_access_edit_learning_unit_proposal_as_faculty_manager(self): generated_container = GenerateContainer( start_year=self.academic_yr_1.year, end_year=self.academic_yr_1.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.CENTRAL.name, type=proposal_type.ProposalType.SUPPRESSION.name, learning_unit_year=luy) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) PersonEntityFactory(entity=an_requirement_entity, person=a_person) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.CENTRAL.name a_proposal.save() self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) for a_type, _ in proposal_type.CHOICES: a_proposal.type = a_type a_proposal.save() if a_proposal.type != ProposalType.MODIFICATION: self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) else: self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person))
def get_learning_unit_identification_context(learning_unit_year_id, person): context = get_common_context_learning_unit_year(learning_unit_year_id, person) learning_unit_year = context['learning_unit_year'] proposal = proposal_learning_unit.find_by_learning_unit_year( learning_unit_year) context[ 'learning_container_year_partims'] = learning_unit_year.get_partims_related( ) context['organization'] = get_organization_from_learning_unit_year( learning_unit_year) context['campus'] = get_campus_from_learning_unit_year(learning_unit_year) context['experimental_phase'] = True context['show_subtype'] = show_subtype(learning_unit_year) context.update(get_all_attributions(learning_unit_year)) context['components'] = get_components_identification(learning_unit_year) context['proposal'] = proposal context[ 'proposal_folder_entity_version'] = mdl_base.entity_version.get_by_entity_and_date( proposal.folder.entity, None) if proposal else None context['differences'] = _get_difference_of_proposal(proposal) # perms learning unit context['can_propose'] = is_eligible_to_create_modification_proposal( learning_unit_year, person) context['can_edit_date'] = is_eligible_for_modification_end_date( learning_unit_year, person) context['can_edit'] = is_eligible_for_modification(learning_unit_year, person) context['can_delete'] = can_delete_learning_unit_year( learning_unit_year, person) # perms proposal context['can_cancel_proposal'] = is_eligible_for_cancel_of_proposal( proposal, person) context['can_edit_learning_unit_proposal'] = is_eligible_to_edit_proposal( proposal, person) return context