@Override
 public boolean check(UserContext user, Session source) {
   return super.check(user, source)
       && (user.getCurrentAuthority().hasRight(Right.HQLReportAdd)
           || SavedHQL.hasQueries(
               Flag.APPEARANCE_ADMINISTRATION,
               user.getCurrentAuthority().hasRight(Right.HQLReportsAdminOnly)));
 }
 public Long getLastSessionId(SessionContext context) {
   Long lastSessionId = (Long) context.getAttribute("sessionId");
   if (lastSessionId == null) {
     UserContext user = context.getUser();
     if (user != null) {
       Long sessionId = user.getCurrentAcademicSessionId();
       if (sessionId != null) lastSessionId = sessionId;
     }
   }
   return lastSessionId;
 }
 private Long getStatusPageSessionId(SessionContext context)
     throws SectioningException, PageAccessException {
   UserContext user = context.getUser();
   if (user == null)
     throw new PageAccessException(
         context.isHttpSessionNew()
             ? MSG.exceptionHttpSessionExpired()
             : MSG.exceptionLoginRequired());
   if (user.getCurrentAcademicSessionId() == null) {
     Long sessionId = getLastSessionId(context);
     if (sessionId != null) return sessionId;
   } else {
     return user.getCurrentAcademicSessionId();
   }
   throw new SectioningException(MSG.exceptionNoAcademicSession());
 }
    @Override
    public boolean check(UserContext user, TimetableManager source) {
      for (Department d : source.getDepartments()) {
        if (d.getSessionId().equals(user.getCurrentAcademicSessionId())) {
          return permissionSession.check(user, d.getSession());
        }
      }

      return true;
    }
    @Override
    public boolean check(UserContext user, Session source) {
      if (!permissionSession.check(user, source)) return false;

      // Is there a mapping to show?
      if (EventDateMapping.hasMapping(source.getUniqueId())) return true;

      // Is there a mapping to add?
      if (user.getCurrentAuthority().hasRight(Right.EventDateMappingEdit)
          && permissionEventDateMappingEdit.check(user, source)) return true;

      return false;
    }
 private OnlineSectioningLog.Entity currentUser(SessionContext context) {
   UserContext user = context.getUser();
   UniTimePrincipal principal = (UniTimePrincipal) context.getAttribute("user");
   if (user != null) {
     return OnlineSectioningLog.Entity.newBuilder()
         .setExternalId(user.getExternalUserId())
         .setName(user.getName() == null ? user.getUsername() : user.getName())
         .setType(
             context.hasPermission(Right.StudentSchedulingAdvisor)
                 ? OnlineSectioningLog.Entity.EntityType.MANAGER
                 : OnlineSectioningLog.Entity.EntityType.STUDENT)
         .build();
   } else if (principal != null) {
     return OnlineSectioningLog.Entity.newBuilder()
         .setExternalId(principal.getExternalId())
         .setName(principal.getName())
         .setType(OnlineSectioningLog.Entity.EntityType.STUDENT)
         .build();
   } else {
     return null;
   }
 }
    @Override
    public boolean check(UserContext user, Session source) {
      if (user instanceof UserContext.Chameleon) return false;

      return User.findByUserName(user.getUsername()) != null;
    }
 @Override
 public boolean check(UserContext user, SavedHQL source) {
   if (source.isSet(SavedHQL.Flag.ADMIN_ONLY))
     return user.getCurrentAuthority().hasRight(Right.HQLReportsAdminOnly);
   return true;
 }