Search in sources :

Example 16 with OfferAccess

use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.

the class AutoAccessManagerImpl method getOrCreateOfferAccess.

private OfferAccess getOrCreateOfferAccess(OLATResource resource, RepositoryEntry entry, AccessMethod method) {
    OfferAccess offerAccess;
    List<OfferAccess> offerAccesses = acService.getValidOfferAccess(resource, method);
    if (offerAccesses.isEmpty()) {
        offerAccess = createOfferAccess(resource, entry, method);
    } else {
        offerAccess = offerAccesses.get(0);
    }
    return offerAccess;
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess)

Example 17 with OfferAccess

use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.

the class RepositoryIndexer method checkAccess.

/**
 * @see org.olat.search.service.indexer.Indexer#checkAccess(org.olat.core.id.context.ContextEntry, org.olat.core.id.context.BusinessControl, org.olat.core.id.Identity, org.olat.core.id.Roles)
 */
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    boolean debug = isLogDebugEnabled();
    if (debug)
        logDebug("checkAccess for businessControl=" + businessControl + "  identity=" + identity + "  roles=" + roles);
    Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
    if (repositoryEntry == null) {
        return false;
    }
    if (roles.isGuestOnly()) {
        if (repositoryEntry.getAccess() != RepositoryEntry.ACC_USERS_GUESTS) {
            return false;
        }
    }
    boolean isOwner = repositoryManager.isOwnerOfRepositoryEntry(identity, repositoryEntry);
    boolean isAllowedToLaunch = false;
    if (!isOwner) {
        isAllowedToLaunch = repositoryManager.isAllowedToLaunch(identity, roles, repositoryEntry);
        if (isAllowedToLaunch) {
            List<ContextEntry> entries = businessControl.getEntriesDownTheControls();
            if (entries.size() > 1) {
                boolean hasAccess = false;
                ACService acService = CoreSpringFactory.getImpl(ACService.class);
                AccessResult acResult = acService.isAccessible(repositoryEntry, identity, false);
                if (acResult.isAccessible()) {
                    hasAccess = true;
                } else if (!acResult.getAvailableMethods().isEmpty()) {
                    for (OfferAccess offer : acResult.getAvailableMethods()) {
                        String type = offer.getMethod().getType();
                        if (type.equals(FreeAccessHandler.METHOD_TYPE) || type.equals(PaypalAccessHandler.METHOD_TYPE)) {
                            hasAccess = true;
                        }
                    }
                }
                isAllowedToLaunch = hasAccess;
            }
        }
    }
    if (debug)
        logDebug("isOwner=" + isOwner + "  isAllowedToLaunch=" + isAllowedToLaunch);
    if (isOwner || isAllowedToLaunch) {
        Indexer repositoryEntryIndexer = getRepositoryEntryIndexer(repositoryEntry);
        if (debug)
            logDebug("repositoryEntryIndexer=" + repositoryEntryIndexer);
        if (repositoryEntryIndexer != null) {
            return super.checkAccess(contextEntry, businessControl, identity, roles) && repositoryEntryIndexer.checkAccess(contextEntry, businessControl, identity, roles);
        }
    }
    return false;
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) Indexer(org.olat.search.service.indexer.Indexer) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RepositoryEntry(org.olat.repository.RepositoryEntry) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 18 with OfferAccess

use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.

the class BusinessGroupDAOTest method findPublicGroupsLimitedDate.

@Test
public void findPublicGroupsLimitedDate() {
    // create a group with an access control limited by a valid date
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
    BusinessGroup groupVisible = businessGroupDao.createAndPersist(null, "access-grp-2", "access-grp-2-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer offer = acService.createOffer(groupVisible.getResource(), "TestBGWorkflow");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    offer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 2);
    offer.setValidTo(cal.getTime());
    assertNotNull(offer);
    offer = acService.save(offer);
    acMethodManager.enableMethod(TokenAccessMethod.class, true);
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    // create a group with an access control limited by dates in the past
    BusinessGroup oldGroup = businessGroupDao.createAndPersist(null, "access-grp-3", "access-grp-3-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer oldOffer = acService.createOffer(oldGroup.getResource(), "TestBGWorkflow");
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidTo(cal.getTime());
    assertNotNull(oldOffer);
    oldOffer = acService.save(oldOffer);
    OfferAccess oldAccess = acMethodManager.createOfferAccess(oldOffer, method);
    acMethodManager.save(oldAccess);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    BusinessGroupQueryParams paramsAll = new BusinessGroupQueryParams();
    paramsAll.setPublicGroups(Boolean.TRUE);
    List<BusinessGroupRow> accessGroups = businessGroupDao.searchBusinessGroupsWithMemberships(paramsAll, id);
    Assert.assertNotNull(accessGroups);
    Assert.assertTrue(accessGroups.size() >= 1);
    Assert.assertTrue(contains(accessGroups, groupVisible));
    Assert.assertFalse(contains(accessGroups, oldGroup));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) BusinessGroup(org.olat.group.BusinessGroup) Offer(org.olat.resource.accesscontrol.Offer) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 19 with OfferAccess

use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.

the class CourseCreationHelper method finalizeWorkflow.

/**
 * Finalizes the course creation workflow via wizard.
 * @param ureq
 */
public void finalizeWorkflow(final UserRequest ureq) {
    // --------------------------
    // 1. insert the course nodes
    // --------------------------
    // single page node
    CourseNode singlePageNode = null;
    if (courseConfig.isCreateSinglePage()) {
        singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator.translate("cce.informationpage.descr"));
        if (singlePageNode instanceof SPCourseNode) {
            final String relPath = CourseEditorHelper.createUniqueRelFilePathFromShortTitle(singlePageNode, course.getCourseFolderContainer());
            HTMLDocumentHelper.createHtmlDocument(course, relPath, courseConfig.getSinglePageText(translator));
            ((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, relPath);
        }
    }
    // enrollment node
    CourseNode enCourseNode = null;
    if (courseConfig.isCreateEnrollment()) {
        enCourseNode = CourseExtensionHelper.createEnrollmentNode(course, translator.translate("cce.enrollment"), translator.translate("cce.enrollment.descr"));
    }
    // download folder node
    CourseNode downloadFolderNode = null;
    if (courseConfig.isCreateDownloadFolder()) {
        downloadFolderNode = CourseExtensionHelper.createDownloadFolderNode(course, translator.translate("cce.downloadfolder"), translator.translate("cce.downloadfolder.descr"));
    }
    // forum node
    CourseNode forumNode = null;
    if (courseConfig.isCreateForum()) {
        forumNode = CourseExtensionHelper.createForumNode(course, translator.translate("cce.forum"), translator.translate("cce.forum.descr"));
    }
    // contact form node
    CourseNode contactNode = null;
    if (courseConfig.isCreateContactForm()) {
        contactNode = CourseExtensionHelper.createContactFormNode(course, translator.translate("cce.contactform"), translator.translate("cce.contactform.descr"));
        if (contactNode instanceof COCourseNode) {
            final List<String> emails = new ArrayList<String>();
            String subject = translator.translate("cce.contactform.subject") + " " + courseConfig.getCourseTitle();
            String email = ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());
            if (StringHelper.containsNonWhitespace(email)) {
                emails.add(email);
            }
            COCourseNode cocn = (COCourseNode) contactNode;
            cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_EMAILTOADRESSES, emails);
            cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT, subject);
        }
    }
    // enrollment node
    if (courseConfig.isCreateEnrollment()) {
        // --------------------------
        // 2. setup enrollment
        // --------------------------
        final String groupBaseName = createGroupBaseName();
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        // get default context for learning groups
        // create n learning groups with m allowed members
        String comma = "";
        String tmpGroupList = "";
        String groupNamesList = "";
        for (int i = 0; i < courseConfig.getGroupCount(); i++) {
            // create group
            String name = groupBaseName + " " + (i + 1);
            BusinessGroup learningGroup = bgs.createBusinessGroup(ureq.getIdentity(), name, null, 0, courseConfig.getSubscriberCount(), courseConfig.getEnableWaitlist(), courseConfig.getEnableFollowup(), addedEntry);
            // enable the contact collaboration tool
            CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(learningGroup);
            ct.setToolEnabled(CollaborationTools.TOOL_CONTACT, true);
            // append to current learning group list
            groupNamesList = tmpGroupList + comma + learningGroup.getName();
            enCourseNode.getModuleConfiguration().set(ENCourseNode.CONFIG_GROUPNAME, groupNamesList);
            if (i == 0) {
                comma = ",";
            }
            tmpGroupList = (String) enCourseNode.getModuleConfiguration().get(ENCourseNode.CONFIG_GROUPNAME);
        }
        // set signout property
        enCourseNode.getModuleConfiguration().set(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED, courseConfig.getEnableSignout());
        // access limits on chosen course elements
        if (courseConfig.getEnableAccessLimit()) {
            if (courseConfig.isEnableAclContactForm()) {
                if (contactNode instanceof COCourseNode) {
                    Condition c = ((COCourseNode) contactNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((COCourseNode) contactNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclSinglePage()) {
                if (singlePageNode instanceof SPCourseNode) {
                    Condition c = ((SPCourseNode) singlePageNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((SPCourseNode) singlePageNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclForum()) {
                if (forumNode instanceof FOCourseNode) {
                    Condition c = ((FOCourseNode) forumNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((FOCourseNode) forumNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
            if (courseConfig.isEnableAclDownloadFolder()) {
                if (downloadFolderNode instanceof BCCourseNode) {
                    Condition c = ((BCCourseNode) downloadFolderNode).getPreConditionVisibility();
                    c.setEasyModeGroupAccess(groupNamesList);
                    ((BCCourseNode) downloadFolderNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
                    // calculate expression from easy mode form
                    String condString = c.getConditionFromEasyModeConfiguration();
                    c.setConditionExpression(condString);
                    c.setExpertMode(false);
                }
            }
        }
    }
    // --------------------------
    if (courseConfig.getPublish()) {
        CourseAccessAndProperties accessAndProps = courseConfig.getAccessAndProperties();
        RepositoryManager manager = RepositoryManager.getInstance();
        addedEntry = manager.setAccessAndProperties(accessAndProps.getRepositoryEntry(), accessAndProps.getAccess(), accessAndProps.isMembersOnly(), accessAndProps.isCanCopy(), accessAndProps.isCanReference(), accessAndProps.isCanDownload());
        addedEntry = manager.setLeaveSetting(addedEntry, accessAndProps.getSetting());
        List<OfferAccess> offerAccess = accessAndProps.getOfferAccess();
        ACService acService = CoreSpringFactory.getImpl(ACService.class);
        for (OfferAccess newLink : offerAccess) {
            acService.saveOfferAccess(newLink);
        }
    }
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    course.getRunStructure().getRootNode().setShortTitle(addedEntry.getDisplayname());
    course.getRunStructure().getRootNode().setLongTitle(addedEntry.getDisplayname());
    CourseFactory.saveCourse(course.getResourceableId());
    final CourseEditorTreeModel cetm = course.getEditorTreeModel();
    final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
    rootNode.setShortTitle(addedEntry.getDisplayname());
    rootNode.setLongTitle(addedEntry.getDisplayname());
    course.getEditorTreeModel().nodeConfigChanged(course.getRunStructure().getRootNode());
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
    // --------------------------
    // 3.2 publish the course
    // --------------------------
    // fetch publish process
    final PublishProcess pp = PublishProcess.getInstance(course, cetm, ureq.getLocale());
    final StatusDescription[] sds;
    // create publish node list
    List<String> nodeIds = new ArrayList<String>();
    nodeIds.add(cetm.getRootNode().getIdent());
    for (int i = 0; i < cetm.getRootNode().getChildCount(); i++) {
        nodeIds.add(cetm.getRootNode().getChildAt(i).getIdent());
    }
    pp.createPublishSetFor(nodeIds);
    PublishSetInformations set = pp.testPublishSet(ureq.getLocale());
    sds = set.getWarnings();
    boolean isValid = sds.length == 0;
    if (!isValid) {
        // no error and no warnings -> return immediate
        log.error("Course Publishing failed", new AssertionError());
    }
    pp.applyPublishSet(ureq.getIdentity(), ureq.getLocale(), true);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    // save catalog entry
    if (getConfiguration().getSelectedCatalogEntry() != null) {
        CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
        CatalogEntry newEntry = cm.createCatalogEntry();
        newEntry.setRepositoryEntry(addedEntry);
        newEntry.setName(addedEntry.getDisplayname());
        newEntry.setDescription(addedEntry.getDescription());
        newEntry.setType(CatalogEntry.TYPE_LEAF);
        newEntry.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
        // save entry
        cm.addCatalogEntry(getConfiguration().getSelectedCatalogEntry(), newEntry);
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) ArrayList(java.util.ArrayList) CatalogEntry(org.olat.repository.CatalogEntry) FOCourseNode(org.olat.course.nodes.FOCourseNode) PublishProcess(org.olat.course.editor.PublishProcess) StatusDescription(org.olat.course.editor.StatusDescription) RepositoryManager(org.olat.repository.RepositoryManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) SPCourseNode(org.olat.course.nodes.SPCourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) Condition(org.olat.course.condition.Condition) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) SPCourseNode(org.olat.course.nodes.SPCourseNode) CourseAccessAndProperties(org.olat.course.editor.CourseAccessAndProperties) PublishSetInformations(org.olat.course.editor.PublishSetInformations) CatalogManager(org.olat.repository.manager.CatalogManager) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) CollaborationTools(org.olat.collaboration.CollaborationTools) ACService(org.olat.resource.accesscontrol.ACService)

Example 20 with OfferAccess

use of org.olat.resource.accesscontrol.OfferAccess in project OpenOLAT by OpenOLAT.

the class AutoAccessManagerImpl method createOfferAccess.

private OfferAccess createOfferAccess(OLATResource resource, RepositoryEntry entry, AccessMethod method) {
    OfferAccess offerAccess;
    String displayName = entry.getDisplayname();
    Offer offer = acService.createOffer(resource, displayName);
    offer.setAutoBooking(true);
    offerAccess = acService.createOfferAccess(offer, method);
    acService.save(offer);
    acService.saveOfferAccess(offerAccess);
    return offerAccess;
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) Offer(org.olat.resource.accesscontrol.Offer)

Aggregations

OfferAccess (org.olat.resource.accesscontrol.OfferAccess)44 Offer (org.olat.resource.accesscontrol.Offer)18 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)16 OLATResource (org.olat.resource.OLATResource)14 Test (org.junit.Test)12 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)12 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 BusinessGroup (org.olat.group.BusinessGroup)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 Identity (org.olat.core.id.Identity)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 ACService (org.olat.resource.accesscontrol.ACService)6 IdentifierKey (org.olat.resource.accesscontrol.provider.auto.IdentifierKey)6 AutoAccessMethod (org.olat.resource.accesscontrol.provider.auto.model.AutoAccessMethod)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)4 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)4 CatalogEntry (org.olat.repository.CatalogEntry)4