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