Exemplo n.º 1
0
 @Test
 @Atomic(mode = TxMode.READ)
 public void membership() {
   assertEquals(
       Group.logged().getMembers().collect(Collectors.toSet()), Bennu.getInstance().getUserSet());
   assertTrue(Group.logged().isMember(user1));
   assertFalse(Group.logged().isMember(null));
 }
Exemplo n.º 2
0
 @PUT
 @Path("compile")
 @Consumes(MediaType.APPLICATION_JSON)
 public JsonObject compileCustomTask(JsonObject jsonCode) {
   accessControl(Group.managers());
   return getClassBean(jsonCode).compile();
 }
Exemplo n.º 3
0
 @PUT
 @Consumes(MediaType.APPLICATION_JSON)
 public Response addCustomTask(JsonObject jsonCode) {
   accessControl(Group.managers());
   getClassBean(jsonCode).run();
   return ok();
 }
Exemplo n.º 4
0
 @Test
 @Atomic(mode = TxMode.READ)
 public void loggedCompression() {
   assertEquals(Group.logged(), Group.logged().grant(user1));
   assertEquals(Group.logged(), user1.groupOf().or(Group.logged()));
   assertEquals(user1.groupOf(), Group.logged().and(user1.groupOf()));
   assertEquals(user1.groupOf(), user1.groupOf().and(Group.logged()));
   assertEquals(Group.logged(), user1.groupOf().or(Group.logged()));
 }
Exemplo n.º 5
0
  /**
   * Checks if person belongs to degree. The unit path format should be: IST.<DegreeAcronym>
   *
   * <p>Accepted roles: TEACHER and STUDENT
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws ExcepcaoPersistencia
   * @throws FenixServiceException
   */
  private static Boolean checkDegreeGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {
    String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");

    if (!groupCheckQuery.roleType.equals("TEACHER")
        && !groupCheckQuery.roleType.equals("STUDENT")) {
      throw new NonExistingServiceException();
    }

    Degree degree = getDegree(unitAcronyms);

    Group group;
    if (groupCheckQuery.roleType.equals("STUDENT")) {
      group = StudentGroup.get(degree, null);
    } else {
      group = TeacherGroup.get(degree);
    }

    return group.isMember(person.getUser());
  }
 public static TeacherCreditsFillingCE getValidCreditsPeriod(
     ExecutionSemester executionSemester, User user) {
   if (org.fenixedu.bennu.core.groups.Group.parse("creditsManager").isMember(user)) {
     return TeacherCreditsFillingForDepartmentAdmOfficeCE
         .getTeacherCreditsFillingForDepartmentAdmOffice(executionSemester.getAcademicInterval());
   }
   if (RoleType.TEACHER.isMember(user)) {
     return TeacherCreditsFillingForTeacherCE.getTeacherCreditsFillingForTeacher(
         executionSemester.getAcademicInterval());
   }
   throw new DomainException("invalid.role.type");
 }
Exemplo n.º 7
0
  /**
   * Checks if person belongs to curricular course. The unit path format should be:
   * IST{.<SubUnitAcronym>}.<DegreeAcronym>.<CurricularCourseAcronym>
   *
   * <p>Accepted roles: STUDENT and TEACHER
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws NonExistingServiceException
   * @throws ExcepcaoPersistencia
   */
  private static Boolean checkExecutionCourseGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {
    String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");

    if (!groupCheckQuery.roleType.equals("TEACHER")
        && !groupCheckQuery.roleType.equals("STUDENT")) {
      throw new NonExistingServiceException();
    }

    Degree degree = getDegree(unitAcronyms);
    for (DegreeCurricularPlan degreeCurricularPlan : degree.getActiveDegreeCurricularPlans()) {

      ExecutionSemester executionSemester =
          getExecutionPeriod(groupCheckQuery.year, groupCheckQuery.semester);

      CurricularCourse curricularCourse =
          degreeCurricularPlan.getCurricularCourseByAcronym(unitAcronyms[4]);

      if (curricularCourse != null) {
        List<ExecutionCourse> executionCourses =
            curricularCourse.getExecutionCoursesByExecutionPeriod(executionSemester);

        for (ExecutionCourse executionCourse : executionCourses) {
          Group group;

          if (groupCheckQuery.roleType.equals("TEACHER")) {
            group = TeacherGroup.get(executionCourse);
          } else {
            group = StudentGroup.get(executionCourse);
          }

          if (group.isMember(person.getUser())) {
            return true;
          }
        }
      }
    }

    return false;
  }
Exemplo n.º 8
0
 @Test
 @Atomic(mode = TxMode.WRITE)
 public void createPersistent() {
   assertTrue(Group.logged().toPersistentGroup() != null);
 }
Exemplo n.º 9
0
 @Test
 public void parse() {
   String expr = "logged";
   assertEquals(Group.parse(expr).getExpression(), expr);
 }
Exemplo n.º 10
0
 public void setMembers(Group members) {
   setMembersGroup(members.toPersistentGroup());
 }