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