Search in sources :

Example 86 with SearchBusinessGroupParams

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();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Certificate(org.olat.course.certificate.Certificate)

Example 87 with SearchBusinessGroupParams

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;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Example 88 with SearchBusinessGroupParams

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);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Example 89 with SearchBusinessGroupParams

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);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent)

Example 90 with SearchBusinessGroupParams

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;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) HashSet(java.util.HashSet)

Aggregations

SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)92 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)26 BusinessGroupService (org.olat.group.BusinessGroupService)18 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)16 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)16 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)16 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)16 RepositoryEntry (org.olat.repository.RepositoryEntry)16 HashSet (java.util.HashSet)12 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)10 Roles (org.olat.core.id.Roles)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)6 ICourse (org.olat.course.ICourse)6