Search in sources :

Example 21 with UserSchoolDataIdentifier

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

the class FlagController method hasFlagPermission.

public boolean hasFlagPermission(Flag flag, SchoolDataIdentifier userIdentifier) {
    UserSchoolDataIdentifier owner = flag.getOwnerIdentifier();
    SchoolDataIdentifier ownerIdentfier = toIdentifier(owner);
    if (ownerIdentfier.equals(userIdentifier)) {
        return true;
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find school data user by identifier %s", userIdentifier));
        return false;
    }
    FlagShare flagShare = flagShareDAO.findByFlagAndUserIdentifier(flag, userSchoolDataIdentifier);
    if (flagShare != null) {
        return true;
    }
    return false;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) FlagShare(fi.otavanopisto.muikku.model.users.FlagShare)

Example 22 with UserSchoolDataIdentifier

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

the class FlagController method listByOwnedAndSharedStudentFlags.

public List<FlagStudent> listByOwnedAndSharedStudentFlags(SchoolDataIdentifier studentIdentifier, SchoolDataIdentifier userIdentifier) {
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find school data user by identifier %s", userIdentifier));
        return Collections.emptyList();
    }
    UserSchoolDataIdentifier studentSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(studentIdentifier);
    if (studentSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find school data user by identifier %s", studentIdentifier));
        return Collections.emptyList();
    }
    List<FlagStudent> flagStudents = flagStudentDAO.listByStudentIdentifier(studentSchoolDataIdentifier);
    List<FlagStudent> result = new ArrayList<>(flagStudents.size());
    for (FlagStudent flagStudent : flagStudents) {
        if (hasFlagPermission(flagStudent.getFlag(), userIdentifier)) {
            result.add(flagStudent);
        }
    }
    return result;
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) ArrayList(java.util.ArrayList) FlagStudent(fi.otavanopisto.muikku.model.users.FlagStudent)

Example 23 with UserSchoolDataIdentifier

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

the class UserEntityController method listUserEntityIdentifiersByDataSource.

public List<String> listUserEntityIdentifiersByDataSource(SchoolDataSource dataSource) {
    List<String> result = new ArrayList<>();
    List<UserSchoolDataIdentifier> identifiers = listUserSchoolDataIdentifiersByDataSource(dataSource);
    for (UserSchoolDataIdentifier indentifier : identifiers) {
        result.add(indentifier.getIdentifier());
    }
    return result;
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) ArrayList(java.util.ArrayList)

Example 24 with UserSchoolDataIdentifier

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

the class CoursePickerRESTService method createWorkspaceUser.

@POST
@Path("/workspaces/{ID}/signup")
@RESTPermit(handling = Handling.INLINE)
public Response createWorkspaceUser(@PathParam("ID") Long workspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceUserSignup entity) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_SIGNUP, workspaceEntity)) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
    Long workspaceStudentRoleId = getWorkspaceStudentRoleId();
    WorkspaceRoleEntity workspaceRole = roleController.findWorkspaceRoleEntityById(workspaceStudentRoleId);
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    Role role = roleController.findRoleByDataSourceAndRoleEntity(user.getSchoolDataSource(), workspaceRole);
    SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspace.getIdentifier(), workspace.getSchoolDataSource());
    SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifierIncludeArchived(workspaceEntity, userIdentifier);
    if (workspaceUserEntity != null && Boolean.TRUE.equals(workspaceUserEntity.getArchived())) {
        workspaceUserEntityController.unarchiveWorkspaceUserEntity(workspaceUserEntity);
    }
    if (workspaceUserEntity != null && Boolean.FALSE.equals(workspaceUserEntity.getActive())) {
        workspaceUserEntityController.updateActive(workspaceUserEntity, Boolean.TRUE);
        userIndexer.indexUser(workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity());
    }
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
    if (workspaceUser == null) {
        workspaceUser = workspaceController.createWorkspaceUser(workspace, user, role);
        waitForWorkspaceUserEntity(workspaceEntity, userIdentifier);
    } else {
        workspaceController.updateWorkspaceStudentActivity(workspaceUser, true);
    }
    // TODO: should this work based on permission? Permission -> Roles -> Recipients
    // TODO: Messaging should be moved into a CDI event listener
    List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
    List<UserEntity> teachers = new ArrayList<UserEntity>();
    String workspaceName = workspace.getName();
    if (!StringUtils.isBlank(workspace.getNameExtension())) {
        workspaceName += String.format(" (%s)", workspace.getNameExtension());
    }
    String userName = user.getNickName() == null ? user.getDisplayName() : String.format("%s \"%s\" %s (%s)", user.getFirstName(), user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
    for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
        teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
    workspaceController.createWorkspaceUserSignup(workspaceEntity, userSchoolDataIdentifier.getUserEntity(), new Date(), entity.getMessage());
    String caption = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.caption");
    caption = MessageFormat.format(caption, workspaceName);
    String workspaceLink = String.format("<a href=\"%s/workspace/%s\" >%s</a>", baseUrl, workspaceEntity.getUrlName(), workspaceName);
    SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
    String studentLink = String.format("<a href=\"%s/guider#userprofile/%s\" >%s</a>", baseUrl, studentIdentifier.toId(), userName);
    String content;
    if (StringUtils.isEmpty(entity.getMessage())) {
        content = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.content");
        content = MessageFormat.format(content, studentLink, workspaceLink);
    } else {
        content = localeController.getText(sessionController.getLocale(), "rest.workspace.joinWorkspace.joinNotification.contentwmessage");
        String blockquoteMessage = String.format("<blockquote>%s</blockquote>", entity.getMessage());
        content = MessageFormat.format(content, studentLink, workspaceLink, blockquoteMessage);
    }
    for (MessagingWidget messagingWidget : messagingWidgets) {
        // TODO: Category?
        messagingWidget.postMessage(userSchoolDataIdentifier.getUserEntity(), "message", caption, content, teachers);
    }
    List<String> teacherEmails = new ArrayList<>(teachers.size());
    for (UserEntity teacher : teachers) {
        String teacherEmail = userEmailEntityController.getUserDefaultEmailAddress(teacher, false);
        if (StringUtils.isNotBlank(teacherEmail)) {
            teacherEmails.add(teacherEmail);
        }
    }
    if (!teacherEmails.isEmpty()) {
        mailer.sendMail(MailType.HTML, teacherEmails, caption, content);
    }
    return Response.noContent().build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) Role(fi.otavanopisto.muikku.schooldata.entity.Role) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) MessagingWidget(fi.otavanopisto.muikku.controller.messaging.MessagingWidget) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 25 with UserSchoolDataIdentifier

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

the class PyramusSchoolDataUserListener method handlePyramusUserRemoved.

private void handlePyramusUserRemoved(SchoolDataIdentifier identifier) {
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(identifier.getDataSource(), identifier.getIdentifier());
    List<UserGroupUserEntity> userGroupUsers = userGroupEntityController.listUserGroupUsersByUserSchoolDataIdentifier(userSchoolDataIdentifier);
    for (UserGroupUserEntity userGroupUser : userGroupUsers) {
        UserGroupEntity userGroup = userGroupUser.getUserGroupEntity();
        StudentGroupType studentGroupType = identifierMapper.getStudentGroupType(userGroup.getIdentifier());
        if (studentGroupType == StudentGroupType.STUDYPROGRAMME) {
            fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
        }
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroupType(fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)

Aggregations

UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)37 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)14 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)10 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)10 ArrayList (java.util.ArrayList)10 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)9 EntityManager (javax.persistence.EntityManager)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)7 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)6 Path (javax.ws.rs.Path)6 FlagStudent (fi.otavanopisto.muikku.model.users.FlagStudent)5 User (fi.otavanopisto.muikku.schooldata.entity.User)5 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)3 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)3 Flag (fi.otavanopisto.muikku.model.users.Flag)2