use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class CertificatesManagerImpl method getCertificatesForNotifications.
@Override
public List<Certificate> getCertificatesForNotifications(Identity identity, RepositoryEntry entry, Date lastNews) {
Roles roles = securityManager.getRoles(identity);
RepositoryEntrySecurity security = repositoryManager.isAllowed(identity, roles, entry);
if (!security.isEntryAdmin() && !security.isCourseCoach() && !security.isGroupCoach() && !security.isCourseParticipant() && !security.isGroupParticipant()) {
return Collections.emptyList();
}
StringBuilder sb = new StringBuilder();
sb.append("select cer from certificate cer").append(" inner join fetch cer.identity ident").append(" where cer.olatResource.key=:resourceKey and cer.last=true ");
// must be some kind of restrictions
boolean securityCheck = false;
List<Long> baseGroupKeys = null;
if (!security.isEntryAdmin()) {
sb.append(" and (");
boolean or = false;
if (security.isCourseCoach()) {
or = or(sb, or);
sb.append(" exists (select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append(" where ident.key=membership.identity.key and rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
securityCheck = true;
}
if (security.isGroupCoach()) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, entry, 0, -1);
if (groups.size() > 0) {
or = or(sb, or);
sb.append(" exists (select membership.identity.key from bgroupmember membership ").append(" where ident.key=membership.identity.key and membership.group.key in (:groups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
baseGroupKeys = new ArrayList<>(groups.size());
for (BusinessGroup group : groups) {
baseGroupKeys.add(group.getBaseGroup().getKey());
}
securityCheck = true;
}
}
if (security.isCourseParticipant() || security.isGroupParticipant()) {
or = or(sb, or);
sb.append(" ident.key=:identityKey");
securityCheck = true;
}
sb.append(")");
} else {
securityCheck = true;
}
if (!securityCheck) {
return Collections.emptyList();
}
sb.append(" order by cer.creationDate");
TypedQuery<Certificate> certificates = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Certificate.class).setParameter("resourceKey", entry.getOlatResource().getKey());
if (!security.isEntryAdmin()) {
if (security.isCourseCoach()) {
certificates.setParameter("repoKey", entry.getKey());
}
if (security.isCourseParticipant() || security.isGroupParticipant()) {
certificates.setParameter("identityKey", identity.getKey());
}
}
if (baseGroupKeys != null && !baseGroupKeys.isEmpty()) {
certificates.setParameter("groups", baseGroupKeys);
}
return certificates.getResultList();
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class OpenMeetingsCourseNode method isCoach.
private final boolean isCoach(RepositoryEntry re, Identity identity) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
int count = bgs.countBusinessGroups(params, re);
return count > 0;
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class BusinessGroupServiceImpl method removeResource.
@Override
public void removeResource(RepositoryEntryRef re) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> groups = findBusinessGroups(params, re, 0, -1);
removeResourceFrom(groups, re);
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class BusinessGroupServiceImpl method leave.
@Override
public void leave(Identity identity, RepositoryEntry entry, LeavingStatusList status, MailPackage mailing) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
params.setIdentity(identity);
params.setAttendee(true);
List<BusinessGroup> groups = businessGroupDAO.findBusinessGroups(params, entry, 0, -1);
List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
for (BusinessGroup group : groups) {
if (BusinessGroupManagedFlag.isManaged(group, BusinessGroupManagedFlag.membersmanagement)) {
status.setWarningManagedGroup(true);
} else if (businessGroupRelationDAO.countResources(group) > 1) {
status.setWarningGroupWithMultipleResources(true);
} else {
removeParticipant(identity, identity, group, mailing, null);
}
}
dbInstance.commit();
BusinessGroupModifiedEvent.fireDeferredEvents(events);
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class GroupfoldersWebDAVMergeSource method loadMergedContainers.
@Override
protected List<VFSContainer> loadMergedContainers() {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
Set<Long> addedGroupKeys = new HashSet<Long>();
Set<String> addedGroupNames = new HashSet<String>();
List<VFSContainer> containers = new ArrayList<>();
SearchBusinessGroupParams params = new SearchBusinessGroupParams(getIdentity(), true, false);
params.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> tutorGroups = bgs.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : tutorGroups) {
addContainer(group, addedGroupKeys, addedGroupNames, containers, true);
}
SearchBusinessGroupParams paramsParticipants = new SearchBusinessGroupParams(getIdentity(), false, true);
paramsParticipants.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> participantsGroups = bgs.findBusinessGroups(paramsParticipants, null, 0, -1);
for (BusinessGroup group : participantsGroups) {
addContainer(group, addedGroupKeys, addedGroupNames, containers, false);
}
return containers;
}
Aggregations