package net.sourceforge.fenixedu.predicates; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.Lesson; import net.sourceforge.fenixedu.domain.LessonInstance; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.PunctualRoomsOccupationComment; import net.sourceforge.fenixedu.domain.PunctualRoomsOccupationRequest; import net.sourceforge.fenixedu.domain.PunctualRoomsOccupationStateInstant; import net.sourceforge.fenixedu.domain.ResourceAllocationRole; import net.sourceforge.fenixedu.domain.SchoolClass; import net.sourceforge.fenixedu.domain.Shift; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.injectionCode.AccessControlPredicate; public class ResourceAllocationRolePredicates { // Lesson Predicates public static final AccessControlPredicate checkPermissionsToManageLessons = new AccessControlPredicate() { public boolean evaluate(Lesson lesson) { ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(AccessControl.getPerson()); return true; } }; // Shift Predicates public static final AccessControlPredicate checkPermissionsToManageShifts = new AccessControlPredicate() { public boolean evaluate(Shift shift) { ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(AccessControl.getPerson()); return true; } }; // SchoolClass Predicates public static final AccessControlPredicate checkPermissionsToManageSchoolClass = new AccessControlPredicate() { public boolean evaluate(SchoolClass schoolClass) { ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(AccessControl.getPerson()); return true; } }; // Lesson Instance Predicates public static final AccessControlPredicate checkPermissionsToManageLessonInstances = new AccessControlPredicate() { public boolean evaluate(LessonInstance lessonInstance) { ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(AccessControl.getPerson()); return true; } }; public static final AccessControlPredicate checkPermissionsToManageLessonInstancesWithTeacherCheck = new AccessControlPredicate() { public boolean evaluate(LessonInstance lessonInstance) { Person loggedPerson = AccessControl.getPerson(); if (loggedPerson.hasRole(RoleType.DEPARTMENT_ADMINISTRATIVE_OFFICE)) { return true; } ExecutionCourse executionCourse = lessonInstance.getLesson().getExecutionCourse(); if (loggedPerson.hasTeacher() && loggedPerson.hasRole(RoleType.TEACHER) && loggedPerson.getTeacher().hasProfessorshipForExecutionCourse(executionCourse)) { return true; } if (!loggedPerson.hasTeacher() && loggedPerson.getProfessorships().size() > 0 && loggedPerson.hasProfessorshipForExecutionCourse(executionCourse)) { return true; } ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(loggedPerson); return true; } }; // Punctual Rooms Occupation Management Predicates public static final AccessControlPredicate checkPermissionsToManagePunctualRoomsOccupationRequests = new AccessControlPredicate() { public boolean evaluate(PunctualRoomsOccupationRequest request) { Person loggedPerson = AccessControl.getPerson(); if (loggedPerson.hasRole(RoleType.TEACHER) || loggedPerson.hasAnyProfessorships()) { return true; } ResourceAllocationRole.checkIfPersonHasPermissionToManageSchedulesAllocation(loggedPerson); return true; } }; public static final AccessControlPredicate checkPermissionsToManagePunctualRoomsOccupationComments = new AccessControlPredicate() { public boolean evaluate(PunctualRoomsOccupationComment comment) { return checkPermissionsToManagePunctualRoomsOccupationRequests.evaluate(comment.getRequest()); } }; public static final AccessControlPredicate checkPermissionsToManagePunctualRoomsOccupationStateInstants = new AccessControlPredicate() { public boolean evaluate(PunctualRoomsOccupationStateInstant stateInstant) { return checkPermissionsToManagePunctualRoomsOccupationRequests.evaluate(stateInstant.getRequest()); } }; // Resource Allocation Access Groups Predicates public static final AccessControlPredicate checkPermissionsToManageAccessGroups = new AccessControlPredicate() { public boolean evaluate(ResourceAllocationRole role) { ResourceAllocationRole.checkIfPersonIsResourceAllocationSuperUser(AccessControl.getPerson()); return true; } }; }