Search in sources :

Example 26 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class CourseSignupRESTService method createSignupStudyProgramme.

/**
 * Creates a signup study programme.
 *
 * Organization information within entity is not used.
 */
@Path("/courses/{COURSEID:[0-9]*}/signupStudyProgrammes")
@POST
@RESTPermit(CourseSignupGroupPermissions.CREATE_SIGNUP_STUDYPROGRAMME)
public Response createSignupStudyProgramme(@PathParam("COURSEID") Long pathCourseId, fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudyProgramme entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Long courseId = entity.getCourseId();
    Long studyProgrammeId = entity.getStudyProgrammeId();
    if (courseId == null || studyProgrammeId == null || !courseId.equals(pathCourseId)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Course course = courseController.findCourseById(courseId);
    StudyProgramme studyProgramme = studyProgrammeController.findStudyProgrammeById(studyProgrammeId);
    if (course == null || studyProgramme == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    User loggedUser = sessionController.getUser();
    if (UserUtils.canAccessOrganization(loggedUser, course.getOrganization()) && UserUtils.canAccessOrganization(loggedUser, studyProgramme.getOrganization())) {
        return Response.ok(objectFactory.createModel(courseSignupStudyProgrammeDAO.create(course, studyProgramme))).build();
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 27 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class MatriculationRESTService method listExams.

@Path("/exams")
@GET
@RESTPermit(MatriculationPermissions.LIST_EXAMS)
public Response listExams(@QueryParam("onlyEligible") Boolean onlyEligible) {
    User loggedUser = sessionController.getUser();
    Student student = loggedUser instanceof Student ? (Student) loggedUser : null;
    List<MatriculationExam> exams = matriculationExamDao.listAll();
    Stream<MatriculationExam> examStream = exams.stream().filter(exam -> isVisible(exam, loggedUser));
    if (onlyEligible) {
        if (student != null) {
            examStream = examStream.filter(exam -> isEligible(student, exam));
        } else {
            // Caller is not student so they can't be eligible to enroll any exams
            return Response.ok(Collections.emptyList()).build();
        }
    }
    return Response.ok(examStream.map(exam -> restModel(exam, student)).collect(Collectors.toList())).build();
}
Also used : MatriculationPermissions(fi.otavanopisto.pyramus.rest.controller.permissions.MatriculationPermissions) Produces(javax.ws.rs.Produces) UserVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO) Date(java.util.Date) DegreeType(fi.otavanopisto.pyramus.domainmodel.matriculation.DegreeType) Path(javax.ws.rs.Path) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) MatriculationExamAttendanceStatus(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceStatus) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) LoggedIn(fi.otavanopisto.security.LoggedIn) EnumSet(java.util.EnumSet) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) Logger(java.util.logging.Logger) DateUtils(fi.otavanopisto.pyramus.framework.DateUtils) Collectors(java.util.stream.Collectors) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) MatriculationExamAttendance(fi.otavanopisto.pyramus.rest.model.MatriculationExamAttendance) MatriculationEligibilities(fi.otavanopisto.pyramus.rest.model.MatriculationEligibilities) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) StudentController(fi.otavanopisto.pyramus.rest.controller.StudentController) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PathParam(javax.ws.rs.PathParam) MatriculationExamAttendanceFunding(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding) SchoolType(fi.otavanopisto.pyramus.domainmodel.matriculation.SchoolType) GET(javax.ws.rs.GET) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) StudentStudyPeriodType(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriodType) MatriculationExamGrade(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade) Inject(javax.inject.Inject) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) User(fi.otavanopisto.pyramus.domainmodel.users.User) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) Status(javax.ws.rs.core.Response.Status) MatriculationExamEnrollmentDegreeStructure(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentDegreeStructure) POST(javax.ws.rs.POST) UserPermissions(fi.otavanopisto.pyramus.rest.controller.permissions.UserPermissions) StudentGroupStudentDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupStudentDAO) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) SessionController(fi.otavanopisto.pyramus.security.impl.SessionController) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) Handling(fi.otavanopisto.pyramus.rest.annotation.RESTPermit.Handling) Stateful(javax.ejb.Stateful) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) RESTSecurity(fi.otavanopisto.pyramus.rest.security.RESTSecurity) SettingUtils(fi.otavanopisto.pyramus.framework.SettingUtils) RequestScoped(javax.enterprise.context.RequestScoped) Collections(java.util.Collections) User(fi.otavanopisto.pyramus.domainmodel.users.User) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 28 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class MatriculationRESTService method listEligibilities.

@Path("/eligibility")
@GET
@LoggedIn
@RESTPermit(handling = Handling.INLINE)
public Response listEligibilities() {
    User loggedUser = sessionController.getUser();
    boolean upperSecondarySchoolCurriculum = false;
    if (loggedUser instanceof Student) {
        Student loggedStudent = (Student) loggedUser;
        upperSecondarySchoolCurriculum = hasGroupEligibility(loggedStudent);
    }
    return Response.ok(new MatriculationEligibilities(upperSecondarySchoolCurriculum)).build();
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) MatriculationEligibilities(fi.otavanopisto.pyramus.rest.model.MatriculationEligibilities) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET) LoggedIn(fi.otavanopisto.security.LoggedIn)

Example 29 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class SystemRESTService method getWhoAmI.

@GET
@Path("/whoami")
@RESTPermit(SystemPermissions.WHOAMI)
public Response getWhoAmI() {
    User loggedUser = sessionController.getUser();
    if (loggedUser == null) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<String> emails = new ArrayList<>();
    for (Email email : loggedUser.getContactInfo().getEmails()) {
        if (Boolean.TRUE.equals(email.getContactType().getNonUnique())) {
            continue;
        }
        emails.add(email.getAddress());
    }
    return Response.ok(new WhoAmI(loggedUser.getId(), loggedUser.getFirstName(), loggedUser.getLastName(), emails)).build();
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) ArrayList(java.util.ArrayList) WhoAmI(fi.otavanopisto.pyramus.rest.model.WhoAmI) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 30 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class PersonRESTService method getCredentials.

@Path("/persons/{ID:[0-9]*}/credentials")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getCredentials(@PathParam("ID") Long id) {
    Person person = personController.findPersonById(id);
    if (person == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { PersonPermissions.FIND_USERNAME })) {
        // Check that logged in user is the same we're modifying
        User user = sessionController.getUser();
        // User needs to be logged in for password change
        if (user == null) {
            return Response.status(Status.UNAUTHORIZED).build();
        }
        // Persons must match
        if (!user.getPerson().getId().equals(person.getId())) {
            return Response.status(Status.FORBIDDEN).build();
        }
        if (!restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, person, Style.OR)) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    // TODO: Support for multiple internal authentication providers
    List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
    if (internalAuthenticationProviders.size() == 1) {
        InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
        if (internalAuthenticationProvider != null) {
            UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
            String username = null;
            if (userIdentification != null) {
                username = internalAuthenticationProvider.getUsername(userIdentification.getExternalId());
            }
            UserCredentials credentials = new UserCredentials(null, username, null);
            return Response.ok(credentials).build();
        }
    }
    return Response.status(Status.NOT_FOUND).build();
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) UserCredentials(fi.otavanopisto.pyramus.rest.model.UserCredentials) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

User (fi.otavanopisto.pyramus.domainmodel.users.User)107 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)43 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)29 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)28 Path (javax.ws.rs.Path)28 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)24 Date (java.util.Date)23 UserDAO (fi.otavanopisto.pyramus.dao.users.UserDAO)22 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)21 HashSet (java.util.HashSet)18 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)15 StudentGroup (fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)15 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)14 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)14 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)14 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)13 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)12 StudentGroupUser (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser)12 GET (javax.ws.rs.GET)12 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)11