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();
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations