Search in sources :

Example 31 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project openolat by klemens.

the class GTACourseNode method validateInternalConfiguration.

private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
    List<StatusDescription> sdList = new ArrayList<>(5);
    ModuleConfiguration config = getModuleConfiguration();
    boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
    if (hasScoring) {
        if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
            addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
            addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    // at least one step
    if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
        addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
    }
    if (cev != null) {
        // check assignment
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
        ICourse course = CourseFactory.loadCourse(courseRe);
        if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
            File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(taskDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                } else {
                    addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                }
            } else {
                List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
                if (taskList == null || taskList.isEmpty()) {
                    if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                        addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    } else {
                        addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    }
                } else {
                    String[] filenames = taskDirectory.list();
                    for (TaskDefinition taskDef : taskList) {
                        boolean found = false;
                        for (String filename : filenames) {
                            if (filename.equals(taskDef.getFilename())) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                        }
                    }
                }
            }
        }
        // check solutions
        if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
            File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(solutionDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                } else {
                    addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                }
            }
        }
        List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
        if (participants.size() > 0) {
            UserManager um = CoreSpringFactory.getImpl(UserManager.class);
            StringBuilder sb = new StringBuilder();
            for (IdentityRef participant : participants) {
                String fullname = um.getUserDisplayName(participant.getKey());
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(fullname);
            }
            String[] params = new String[] { getShortTitle(), sb.toString() };
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
            sd.setDescriptionForUnit(getIdent());
            sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
            sdList.add(sd);
        }
    }
    return sdList;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) StatusDescription(org.olat.course.editor.StatusDescription) UserManager(org.olat.user.UserManager) IdentityRef(org.olat.basesecurity.IdentityRef) GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 32 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project openolat by klemens.

the class BusinessGroupMembershipProcessor method processResourceRemoved.

private void processResourceRemoved(Long groupKey, Long repoKey) {
    BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
    RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repoKey);
    OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
    List<Long> memberKeys = businessGroupRelationDao.getMemberKeys(Collections.singletonList(groupRef), GroupRoles.coach.name(), GroupRoles.participant.name());
    for (Long memberKey : memberKeys) {
        IdentityRef member = new IdentityRefImpl(memberKey);
        List<String> remaingRoles = repositoryEntryRelationDao.getRoles(member, entryRef);
        if (remaingRoles.isEmpty()) {
            notificationsManager.unsubscribeAllForIdentityAndResId(member, resource.getResourceableId());
        }
    }
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) OLATResource(org.olat.resource.OLATResource) BusinessGroupRefImpl(org.olat.group.model.BusinessGroupRefImpl) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 33 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project openolat by klemens.

the class LDAPLoginManagerImpl method syncRole.

private void syncRole(LDAPUser ldapUser, String role) {
    IdentityRef identityRef = ldapUser.getCachedIdentity();
    List<String> roleList = securityManager.getRolesAsString(identityRef);
    if (!roleList.contains(role)) {
        Identity identity = securityManager.loadIdentityByKey(identityRef.getKey());
        Roles roles = securityManager.getRoles(identity);
        switch(role) {
            case Constants.GROUP_AUTHORS:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), true, false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_USERMANAGERS:
                roles = new Roles(roles.isOLATAdmin(), true, roles.isGroupManager(), roles.isAuthor(), false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_GROUPMANAGERS:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), true, roles.isAuthor(), false, roles.isInstitutionalResourceManager(), roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_POOL_MANAGER:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), roles.isAuthor(), false, roles.isInstitutionalResourceManager(), true, false);
                securityManager.updateRoles(null, identity, roles);
                break;
            case Constants.GROUP_INST_ORES_MANAGER:
                roles = new Roles(roles.isOLATAdmin(), roles.isUserManager(), roles.isGroupManager(), roles.isAuthor(), false, true, roles.isPoolAdmin(), false);
                securityManager.updateRoles(null, identity, roles);
                break;
        }
    }
}
Also used : IdentityRef(org.olat.basesecurity.IdentityRef) Roles(org.olat.core.id.Roles) GroupRoles(org.olat.basesecurity.GroupRoles) Identity(org.olat.core.id.Identity)

Example 34 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project openolat by klemens.

the class LDAPLoginManagerImpl method doSyncGroupByAttribute.

private void doSyncGroupByAttribute(List<LDAPUser> ldapUsers, Map<String, LDAPGroup> cnToGroupMap) {
    for (LDAPUser ldapUser : ldapUsers) {
        List<String> groupIds = ldapUser.getGroupIds();
        List<String> coachedGroupIds = ldapUser.getCoachedGroupIds();
        if ((groupIds != null && groupIds.size() > 0) || (coachedGroupIds != null && coachedGroupIds.size() > 0)) {
            IdentityRef identity = ldapUser.getCachedIdentity();
            if (identity == null) {
                log.error("Identity with dn=" + ldapUser.getDn() + " not found");
            } else {
                if (groupIds != null && groupIds.size() > 0) {
                    for (String groupId : groupIds) {
                        if (!cnToGroupMap.containsKey(groupId)) {
                            cnToGroupMap.put(groupId, new LDAPGroup(groupId));
                        }
                        cnToGroupMap.get(groupId).getParticipants().add(ldapUser);
                    }
                }
                if (coachedGroupIds != null && coachedGroupIds.size() > 0) {
                    for (String coachedGroupId : coachedGroupIds) {
                        if (!cnToGroupMap.containsKey(coachedGroupId)) {
                            cnToGroupMap.put(coachedGroupId, new LDAPGroup(coachedGroupId));
                        }
                        cnToGroupMap.get(coachedGroupId).getCoaches().add(ldapUser);
                    }
                }
            }
        }
    }
}
Also used : IdentityRef(org.olat.basesecurity.IdentityRef) LDAPUser(org.olat.ldap.model.LDAPUser) LDAPGroup(org.olat.ldap.model.LDAPGroup)

Example 35 with IdentityRef

use of org.olat.basesecurity.IdentityRef in project openolat by klemens.

the class LDAPLoginManagerImpl method syncBusinessGroup.

private void syncBusinessGroup(LdapContext ctx, BusinessGroup businessGroup, LDAPGroup ldapGroup, Map<String, LDAPUser> dnToIdentityKeyMap, LDAPError errors) {
    List<Identity> currentMembers = businessGroupRelationDao.getMembers(businessGroup, GroupRoles.coach.name(), GroupRoles.participant.name());
    Set<Long> currentMemberKeys = new HashSet<>();
    for (Identity currentMember : currentMembers) {
        currentMemberKeys.add(currentMember.getKey());
    }
    List<LDAPUser> coaches = new ArrayList<>(ldapGroup.getCoaches());
    List<LDAPUser> participants = new ArrayList<>(ldapGroup.getParticipants());
    // transfer member cn's to the participants list
    for (String member : ldapGroup.getMembers()) {
        try {
            LDAPUser ldapUser = getLDAPUser(ctx, member, dnToIdentityKeyMap, errors);
            dnToIdentityKeyMap.get(member);
            if (ldapUser != null && !participants.contains(ldapUser)) {
                participants.add(ldapUser);
            }
        } catch (Exception e) {
            log.error("Cannot retrieve this LDAP group member: " + member, e);
        }
    }
    // transfer to ldap user flagged as coach to the coach list
    for (Iterator<LDAPUser> participantIt = participants.iterator(); participantIt.hasNext(); ) {
        LDAPUser participant = participantIt.next();
        if (participant.isCoach()) {
            if (!coaches.contains(participant)) {
                coaches.add(participant);
            }
            participantIt.remove();
        }
    }
    int count = 0;
    for (LDAPUser participant : participants) {
        IdentityRef memberIdentity = participant.getCachedIdentity();
        if (memberIdentity != null && memberIdentity.getKey() != null) {
            syncMembership(businessGroup, memberIdentity, false);
            currentMemberKeys.remove(memberIdentity.getKey());
        }
        if (count % 20 == 0) {
            dbInstance.commitAndCloseSession();
        }
        count++;
    }
    for (LDAPUser coach : coaches) {
        IdentityRef memberIdentity = coach.getCachedIdentity();
        if (memberIdentity != null && memberIdentity.getKey() != null) {
            syncMembership(businessGroup, memberIdentity, true);
            currentMemberKeys.remove(memberIdentity.getKey());
        }
        if (count % 20 == 0) {
            dbInstance.commitAndCloseSession();
        }
        count++;
    }
    for (Long currentMemberKey : currentMemberKeys) {
        Identity currentMember = securityManager.loadIdentityByKey(currentMemberKey);
        List<String> roles = businessGroupRelationDao.getRoles(currentMember, businessGroup);
        for (String role : roles) {
            businessGroupRelationDao.removeRole(currentMember, businessGroup, role);
        }
        if (count % 20 == 0) {
            dbInstance.commitAndCloseSession();
        }
        count++;
    }
    dbInstance.commitAndCloseSession();
}
Also used : ArrayList(java.util.ArrayList) LDAPUser(org.olat.ldap.model.LDAPUser) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) IdentityRef(org.olat.basesecurity.IdentityRef) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Aggregations

IdentityRef (org.olat.basesecurity.IdentityRef)36 ArrayList (java.util.ArrayList)18 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)18 Identity (org.olat.core.id.Identity)8 BusinessGroupRef (org.olat.group.BusinessGroupRef)8 LDAPUser (org.olat.ldap.model.LDAPUser)8 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)6 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)6 OLATResource (org.olat.resource.OLATResource)6 HashMap (java.util.HashMap)4 AuthenticationException (javax.naming.AuthenticationException)4 NamingException (javax.naming.NamingException)4 Attributes (javax.naming.directory.Attributes)4 GroupRoles (org.olat.basesecurity.GroupRoles)4 Roles (org.olat.core.id.Roles)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)3 File (java.io.File)2