Search in sources :

Example 81 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserUpdatedEvent.

public void onSchoolDataWorkspaceUserUpdatedEvent(@Observes SchoolDataWorkspaceUserUpdatedEvent event) {
    UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if (userEntity != null) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
        if (workspaceEntity != null) {
            SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                String currentUserIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier();
                if (!StringUtils.equals(currentUserIdentifier, event.getUserIdentifier())) {
                    // WorkspaceUserEntity found, but it points to a new study program
                    UserSchoolDataIdentifier newUserIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
                    if (newUserIdentifier == null) {
                        logger.warning(String.format("Unable to update workspace user. UserSchoolDataIdentifier for %s/%s not found", event.getUserDataSource(), event.getUserIdentifier()));
                    } else {
                        WorkspaceUserEntity existingUser = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserSchoolDataIdentifierIncludeArchived(workspaceEntity, newUserIdentifier);
                        if (existingUser != null) {
                            if (!existingUser.getArchived().equals(workspaceUserEntity.getArchived())) {
                                if (existingUser.getArchived()) {
                                    workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingUser);
                                } else {
                                    workspaceUserEntityController.archiveWorkspaceUserEntity(existingUser);
                                }
                            }
                            workspaceUserEntityController.updateIdentifier(existingUser, workspaceUserEntity.getIdentifier());
                            // #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
                            if (event.getIsActive() && !existingUser.getActive()) {
                                workspaceUserEntityController.updateActive(existingUser, event.getIsActive());
                            }
                            workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
                        } else {
                            workspaceUserEntityController.updateUserSchoolDataIdentifier(workspaceUserEntity, newUserIdentifier);
                            // #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
                            if (event.getIsActive() && !workspaceUserEntity.getActive()) {
                                workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
                            }
                        }
                    }
                } else {
                    WorkspaceRoleEntity workspaceRoleEntity = workspaceController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getRoleDataSource(), event.getRoleIdentifier());
                    if (workspaceRoleEntity != null && !workspaceRoleEntity.getId().equals(workspaceUserEntity.getWorkspaceUserRole().getId())) {
                        workspaceUserEntityController.updateWorkspaceUserRole(workspaceUserEntity, workspaceRoleEntity);
                    }
                }
                if (!event.getIsActive() && workspaceUserEntity.getActive()) {
                    workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
                }
            }
        } else {
            logger.warning("could not update workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
        }
    } else {
        logger.warning("could not update workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 82 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class UserEntityController method listUserEntitiesByEmails.

public Collection<UserEntity> listUserEntitiesByEmails(Collection<String> emails) {
    if (emails == null || emails.isEmpty()) {
        return Collections.emptyList();
    }
    List<UserEmailEntity> userEmailEntities = userEmailEntityDAO.listByAddresses(emails);
    Map<Long, UserEntity> userEntities = new HashMap<>();
    for (UserEmailEntity userEmailEntity : userEmailEntities) {
        UserEntity userEntity = userEmailEntity.getUserSchoolDataIdentifier().getUserEntity();
        userEntities.put(userEntity.getId(), userEntity);
    }
    return userEntities.values();
}
Also used : HashMap(java.util.HashMap) UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 83 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class DefaultPermissionResolver method hasPermission.

@Override
public boolean hasPermission(String permission, ContextReference contextReference, User user) {
    Permission permissionEntity = permissionController.findByName(permission);
    if (permissionEntity == null) {
        logger.severe(String.format("Reference to missing permission %s", permission));
        return false;
    }
    UserEntity userEntity = getUserEntity(user);
    if (userEntity == null) {
        return hasEveryonePermission(permission, contextReference);
    }
    // Workspace access
    if (permissionEntity.getScope().equals(PermissionScope.WORKSPACE) && contextReference != null) {
        WorkspaceEntity workspaceEntity = resolveWorkspace(contextReference);
        if (workspaceEntity != null) {
            if (hasWorkspaceAccess(workspaceEntity, userEntity, permissionEntity)) {
                return true;
            }
        }
    }
    // Environment access
    return hasEnvironmentAccess(userEntity, permissionEntity);
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 84 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method retrieveForm.

@GET
@Path("/hops/{USERIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response retrieveForm(@PathParam("USERIDENTIFIER") String userIdentifierString) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    SchoolDataIdentifier userIdentifier = SchoolDataIdentifier.fromId(userIdentifierString);
    if (userIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity("Malformed identifier").build();
    }
    UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(userIdentifier);
    if (userEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("User not found").build();
    }
    User user = userController.findUserByIdentifier(userIdentifier);
    if (!vopsController.shouldShowStudies(user)) {
        return Response.ok(HopsRESTModel.nonOptedInHopsRESTModel()).build();
    }
    if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW_ANY_STUDENT_HOPS_FORM) && !Objects.equals(sessionController.getLoggedUser(), userIdentifier)) {
        return Response.status(Status.FORBIDDEN).entity("Can only look at own information").build();
    }
    HopsRESTModel response = createHopsRESTModelForStudent(userIdentifier);
    if (response == null) {
        return Response.status(Status.NOT_FOUND).entity("No HOPS form for non-students").build();
    }
    return Response.ok(response).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 85 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method getFileContent.

@GET
@Path("/files/{ID}/content")
@RESTPermit(handling = Handling.INLINE)
@Produces("*/*")
public Response getFileContent(@PathParam("ID") Long fileId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
    TranscriptOfRecordsFile file = transcriptOfRecordsFileController.findFileById(fileId);
    if (file == null) {
        return Response.status(Status.NOT_FOUND).entity("File not found").build();
    }
    boolean isLoggedUser = Objects.equals(file.getUserEntityId(), loggedUserEntity.getId());
    if (!isLoggedUser) {
        return Response.status(Status.FORBIDDEN).entity("Not your file").build();
    }
    StreamingOutput output = s -> transcriptOfRecordsFileController.outputFileToStream(file, s);
    String contentType = file.getContentType();
    return Response.ok().type(contentType).entity(output).build();
}
Also used : PluginSettingsController(fi.otavanopisto.muikku.controller.PluginSettingsController) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) EnvironmentRoleArchetype(fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype) Path(javax.ws.rs.Path) StringUtils(org.apache.commons.lang3.StringUtils) User(fi.otavanopisto.muikku.schooldata.entity.User) Consumes(javax.ws.rs.Consumes) PermissionController(fi.otavanopisto.muikku.controller.PermissionController) Map(java.util.Map) TranscriptofRecordsUserProperties(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptofRecordsUserProperties) CourseMetaController(fi.otavanopisto.muikku.schooldata.CourseMetaController) DELETE(javax.ws.rs.DELETE) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) UserGroupEntityController(fi.otavanopisto.muikku.users.UserGroupEntityController) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) StreamingOutput(javax.ws.rs.core.StreamingOutput) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) VopsLister(fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister) TranscriptofRecordsPermissions(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptofRecordsPermissions) GradingController(fi.otavanopisto.muikku.schooldata.GradingController) Objects(java.util.Objects) StudiesViewCourseChoiceController(fi.otavanopisto.muikku.plugins.transcriptofrecords.StudiesViewCourseChoiceController) List(java.util.List) UserEntityController(fi.otavanopisto.muikku.users.UserEntityController) Response(javax.ws.rs.core.Response) UserController(fi.otavanopisto.muikku.users.UserController) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceController(fi.otavanopisto.muikku.schooldata.WorkspaceController) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) EnvironmentUserController(fi.otavanopisto.muikku.users.EnvironmentUserController) Handling(fi.otavanopisto.security.rest.RESTPermit.Handling) ArrayList(java.util.ArrayList) SessionController(fi.otavanopisto.muikku.session.SessionController) Inject(javax.inject.Inject) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) IOException(java.io.IOException) TranscriptOfRecordsFileController(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsFileController) Stateful(javax.ejb.Stateful) RestCatchSchoolDataExceptions(fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions) PluginRESTService(fi.otavanopisto.muikku.plugin.PluginRESTService) WorkspaceUserEntityController(fi.otavanopisto.muikku.users.WorkspaceUserEntityController) RequestScoped(javax.enterprise.context.RequestScoped) PUT(javax.ws.rs.PUT) TranscriptOfRecordsController(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsController) Comparator(java.util.Comparator) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) StreamingOutput(javax.ws.rs.core.StreamingOutput) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)163 Path (javax.ws.rs.Path)101 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)88 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 GET (javax.ws.rs.GET)58 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)54 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)50 User (fi.otavanopisto.muikku.schooldata.entity.User)36 ArrayList (java.util.ArrayList)35 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)27 POST (javax.ws.rs.POST)26 Date (java.util.Date)24 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)22 HashMap (java.util.HashMap)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)18 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)14 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)14 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)13 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)12 PUT (javax.ws.rs.PUT)12