Search in sources :

Example 21 with RepositoryEntrySecurity

use of org.olat.repository.model.RepositoryEntrySecurity in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method createHelpCourseLaunchController.

/**
 * Create a user locale dependent help-course run controller
 *
 * @param ureq The user request
 * @param wControl The current window controller
 * @return The help-course run controller
 */
public static Controller createHelpCourseLaunchController(UserRequest ureq, WindowControl wControl) {
    // Find repository entry for this course
    String helpCourseSoftKey = CoreSpringFactory.getImpl(CourseModule.class).getHelpCourseSoftKey();
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry entry = null;
    if (StringHelper.containsNonWhitespace(helpCourseSoftKey)) {
        entry = rm.lookupRepositoryEntryBySoftkey(helpCourseSoftKey, false);
    }
    if (entry == null) {
        Translator translator = Util.createPackageTranslator(CourseFactory.class, ureq.getLocale());
        wControl.setError(translator.translate("error.helpcourse.not.configured"));
        // create empty main controller
        LayoutMain3ColsController emptyCtr = new LayoutMain3ColsController(ureq, wControl, null, null, null);
        return emptyCtr;
    } else {
        // Increment launch counter
        rs.incrementLaunchCounter(entry);
        ICourse course = loadCourse(entry);
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(entry);
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
        RepositoryEntrySecurity reSecurity = new RepositoryEntrySecurity(false, false, false, false, false, false, false, true, false);
        RunMainController launchC = new RunMainController(ureq, bwControl, null, course, entry, reSecurity, null);
        return launchC;
    }
}
Also used : Translator(org.olat.core.gui.translator.Translator) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) RunMainController(org.olat.course.run.RunMainController) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 22 with RepositoryEntrySecurity

use of org.olat.repository.model.RepositoryEntrySecurity 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)

Aggregations

RepositoryEntrySecurity (org.olat.repository.model.RepositoryEntrySecurity)22 RepositoryEntry (org.olat.repository.RepositoryEntry)16 WindowControl (org.olat.core.gui.control.WindowControl)14 MainLayoutController (org.olat.core.gui.control.generic.layout.MainLayoutController)12 UserRequest (org.olat.core.gui.UserRequest)10 TooledStackedPanel (org.olat.core.gui.components.stack.TooledStackedPanel)10 Controller (org.olat.core.gui.control.Controller)10 AssessmentMode (org.olat.course.assessment.AssessmentMode)10 RuntimeControllerCreator (org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator)10 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)6 Roles (org.olat.core.id.Roles)6 ContextEntry (org.olat.core.id.context.ContextEntry)6 RepositoryManager (org.olat.repository.RepositoryManager)6 RepositoryService (org.olat.repository.RepositoryService)6 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 UserSession (org.olat.core.util.UserSession)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)4