Search in sources :

Example 91 with AccessMethod

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

the class PublishStep01AccessForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer headersLayout = FormLayoutContainer.createCustomFormLayout("access", getTranslator(), velocity_root + "/publish_courseaccess.html");
    formLayout.add(headersLayout);
    headersLayout.contextPut("catalogEnabled", repositoryModule.isCatalogEnabled());
    FormLayoutContainer publishLayout = FormLayoutContainer.createDefaultFormLayout("publish", getTranslator());
    formLayout.add(publishLayout);
    publishLayout.setFormTitle(translate("rentry.publish"));
    publishLayout.setFormContextHelp("Course Settings#_zugriff");
    publishLayout.setElementCssClass("o_sel_repositoryentry_access");
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedKeys = new String[] { OAU_KEY, OAUG_KEY, MEMBERSONLY_KEY };
    } else {
        publishedKeys = new String[] { OAU_KEY, MEMBERSONLY_KEY };
    }
    String resourceType = entry.getOlatResource().getResourceableTypeName();
    if (TestFileResource.TYPE_NAME.equals(resourceType) || SurveyFileResource.TYPE_NAME.equals(resourceType) || ScormCPFileResource.TYPE_NAME.equals(resourceType)) {
        String warning = translate("warn.resource.need.course");
        flc.contextPut("off_warn", warning);
    }
    if (CourseModule.ORES_TYPE_COURSE.equals(resourceType)) {
        publishLayout.setFormDescription(translate("rentry.publish.course.desc"));
    } else {
        publishLayout.setFormDescription(translate("rentry.publish.other.desc"));
    }
    if (resourceType != null) {
        handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(resourceType);
    }
    // make configuration read only when managed by external system
    final boolean managedSettings = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.settings);
    final boolean managedAccess = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.access);
    String[] yesNoValues = new String[] { translate("yes"), translate("no") };
    authorsSwitch = uifactory.addRadiosHorizontal("authorsSwitch", "rentry.publish.authors", publishLayout, yesNoKeys, yesNoValues);
    authorsSwitch.setEnabled(!managedAccess);
    authorsSwitch.addActionListener(FormEvent.ONCHANGE);
    authorConfigLayout = FormLayoutContainer.createBareBoneFormLayout("authorConfigLayout", getTranslator());
    publishLayout.add(authorConfigLayout);
    canReference = uifactory.addCheckboxesVertical("cif_canReference", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canReference") }, 1);
    canReference.setEnabled(!managedSettings);
    canCopy = uifactory.addCheckboxesVertical("cif_canCopy", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canCopy") }, 1);
    canCopy.setEnabled(!managedSettings);
    canDownload = uifactory.addCheckboxesVertical("cif_canDownload", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canDownload") }, 1);
    canDownload.setEnabled(!managedSettings);
    canDownload.setVisible(handler.supportsDownload());
    uifactory.addSpacerElement("authorSpacer", authorConfigLayout, true);
    String[] publishedValues;
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.users_guests"), translate("cif.access.membersonly") };
    } else {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.membersonly") };
    }
    usersSwitch = uifactory.addRadiosHorizontal("usersSwitch", "rentry.publish.users", publishLayout, yesNoKeys, yesNoValues);
    usersSwitch.addActionListener(FormEvent.ONCHANGE);
    usersSwitch.setEnabled(!managedAccess);
    userConfigLayout = FormLayoutContainer.createBareBoneFormLayout("userConfigLayout", getTranslator());
    publishLayout.add(userConfigLayout);
    publishedForUsers = uifactory.addDropdownSingleselect("publishedForUsers", null, userConfigLayout, publishedKeys, publishedValues, null);
    publishedForUsers.setEnabled(!managedAccess);
    publishedForUsers.addActionListener(FormEvent.ONCHANGE);
    uifactory.addSpacerElement("userSpacer", userConfigLayout, true);
    // Part 2
    FormLayoutContainer membershipLayout = FormLayoutContainer.createDefaultFormLayout("membership", getTranslator());
    formLayout.add(membershipLayout);
    membershipLayout.setFormTitle(translate("rentry.leaving.title"));
    String[] leaveValues = new String[] { translate("rentry.leave.atanytime"), translate("rentry.leave.afterenddate"), translate("rentry.leave.never") };
    final boolean managedLeaving = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
    leaveEl = uifactory.addDropdownSingleselect("entry.leave", "rentry.leave.option", membershipLayout, leaveKeys, leaveValues, null);
    boolean found = false;
    for (String leaveKey : leaveKeys) {
        if (leaveKey.equals(entry.getAllowToLeaveOption().name())) {
            leaveEl.select(leaveKey, true);
            found = true;
        }
    }
    if (!found) {
        if (managedLeaving) {
            leaveEl.select(RepositoryEntryAllowToLeaveOptions.never.name(), true);
        } else {
            RepositoryEntryAllowToLeaveOptions defaultOption = repositoryModule.getAllowToLeaveDefaultOption();
            leaveEl.select(defaultOption.name(), true);
        }
    }
    leaveEl.setEnabled(!managedLeaving);
    // Part 3
    accessLayout = FormLayoutContainer.createCustomFormLayout("accessConfig", getTranslator(), velocity_root + "/access_configuration.html");
    formLayout.add(accessLayout);
    accessLayout.setVisible(entry.getAccess() == RepositoryEntry.ACC_USERS || loginModule.isGuestLoginLinksEnabled() && entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS || entry.isMembersOnly());
    accessLayout.setFormTitle(translate("accesscontrol.title"));
    HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
    accessLayout.put("acMethodsLabelHelp", acMethodsLabelHelp);
    if (editable) {
        List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
        for (AccessMethod method : methods) {
            AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(method.getType());
            if (methodHandler.isPaymentMethod() && !allowPaymentMethod) {
                continue;
            }
            String title = methodHandler.getMethodName(getLocale());
            FormLink add = uifactory.addFormLink("create." + methodHandler.getType(), title, null, accessLayout, Link.LINK | Link.NONTRANSLATED);
            add.setUserObject(method);
            add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
            addMethods.add(add);
            accessLayout.add(add.getName(), add);
        }
        accessLayout.contextPut("methods", addMethods);
    }
    String[] onValues = new String[] { "" };
    confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", accessLayout, onKeys, onValues);
    confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
    confirmationEmailEl.setVisible(false);
    String confPage = velocity_root + "/configuration_list.html";
    confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
    accessLayout.add(confControllerContainer);
    loadConfigurations();
    boolean confirmationEmail = false;
    for (AccessInfo info : confControllers) {
        confirmationEmail |= info.getLink().getOffer().isConfirmationEmail();
    }
    if (confirmationEmail) {
        confirmationEmailEl.select(onKeys[0], true);
    }
    confControllerContainer.contextPut("confControllers", confControllers);
    confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
    initFormData();
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) RepositoryEntryAllowToLeaveOptions(org.olat.repository.RepositoryEntryAllowToLeaveOptions) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 92 with AccessMethod

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

the class PublishStep01AccessForm method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    super.formInnerEvent(ureq, source, event);
    if (source == authorsSwitch) {
        if (authorsSwitch.getSelectedKey().equals(YES_KEY)) {
            authorConfigLayout.setVisible(true);
        } else {
            authorConfigLayout.setVisible(false);
            if (!publishedForUsers.getSelectedKey().equals(MEMBERSONLY_KEY)) {
                usersSwitch.select(NO_KEY, false);
                userConfigLayout.setVisible(false);
            }
        }
    } else if (source == usersSwitch || source == publishedForUsers) {
        if (usersSwitch.getSelectedKey().equals(YES_KEY)) {
            userConfigLayout.setVisible(true);
            accessLayout.setVisible(true);
            if (publishedForUsers.getSelectedKey().equals(MEMBERSONLY_KEY)) {
                authorConfigLayout.setVisible(false);
                authorsSwitch.select(NO_KEY, false);
                authorsSwitch.setEnabled(false);
            } else {
                authorsSwitch.select(YES_KEY, false);
                authorsSwitch.setEnabled(true);
                authorConfigLayout.setVisible(true);
            }
        } else {
            userConfigLayout.setVisible(false);
            accessLayout.setVisible(false);
            authorsSwitch.setEnabled(true);
        }
    } else if (addMethods.contains(source)) {
        AccessMethod method = (AccessMethod) source.getUserObject();
        addMethod(ureq, method);
    } else if (confirmationEmailEl == source) {
        for (AccessInfo info : confControllers) {
            if (!offerAccess.contains(info.getLink())) {
                offerAccess.add(info.getLink());
            }
        }
    } else if (source instanceof FormLink) {
        FormLink button = (FormLink) source;
        String cmd = button.getCmd();
        if ("delete".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            OfferAccess deleteOffer = infos.getLink();
            offerAccess.remove(deleteOffer);
            if (deleteOffer.getKey() != null) {
                deletedOfferAccess.add(deleteOffer);
            }
            confControllers.remove(infos);
            updateConfirmationEmail();
            fireEvent(ureq, Event.CHANGED_EVENT);
        } else if ("edit".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            editMethod(ureq, infos);
        }
    }
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6