use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testIsValidMethodAvailable.
@Test
public void testIsValidMethodAvailable() {
// create a resource and an offer
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestIsValidMethodAvailable");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create a link offer to gui method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
// create a link offer to gui method
List<AccessMethod> methodsNonGUI = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod methodNonGUI = methodsNonGUI.get(0);
OfferAccess accessNonGUI = acMethodManager.createOfferAccess(offer, methodNonGUI);
acMethodManager.save(accessNonGUI);
dbInstance.commitAndCloseSession();
boolean isAvailable = acMethodManager.isValidMethodAvailable(randomOres, null);
assertTrue(isAvailable);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testSeveralOfferAccess.
@Test
public void testSeveralOfferAccess() {
// create some resources and offers
OLATResource randomOres1 = createResource();
Offer offer1 = acService.createOffer(randomOres1, "TestSeveralOfferAccess 1");
offer1 = acService.save(offer1);
OLATResource randomOres2 = createResource();
Offer offer2 = acService.createOffer(randomOres2, "TestSeveralOfferAccess 2");
offer2 = acService.save(offer2);
OLATResource randomOres3 = createResource();
Offer offer3 = acService.createOffer(randomOres3, "TestSeveralOfferAccess 3");
offer3 = acService.save(offer3);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> tokenMethods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(tokenMethods);
assertEquals(1, tokenMethods.size());
AccessMethod tokenMethod = tokenMethods.get(0);
List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
assertNotNull(freeMethods);
assertEquals(1, freeMethods.size());
AccessMethod freeMethod = freeMethods.get(0);
OfferAccess access1 = acMethodManager.createOfferAccess(offer1, tokenMethod);
acMethodManager.save(access1);
OfferAccess access2 = acMethodManager.createOfferAccess(offer2, tokenMethod);
acMethodManager.save(access2);
OfferAccess access3_1 = acMethodManager.createOfferAccess(offer3, tokenMethod);
acMethodManager.save(access3_1);
OfferAccess access3_2 = acMethodManager.createOfferAccess(offer3, freeMethod);
acMethodManager.save(access3_2);
dbInstance.commitAndCloseSession();
// retrieve the link to offer 1
List<OfferAccess> retrievedOfferAccess = acMethodManager.getOfferAccess(offer1, true);
assertNotNull(retrievedOfferAccess);
assertEquals(1, retrievedOfferAccess.size());
OfferAccess retrievedAccess = retrievedOfferAccess.get(0);
assertNotNull(retrievedAccess);
assertNotNull(retrievedAccess.getMethod());
assertEquals(tokenMethod, retrievedAccess.getMethod());
assertNotNull(retrievedAccess.getOffer());
assertEquals(offer1, retrievedAccess.getOffer());
dbInstance.commitAndCloseSession();
{
// retrieve the links to offer 3
List<OfferAccess> retrievedOfferAccess3 = acMethodManager.getOfferAccess(offer3, true);
assertNotNull(retrievedOfferAccess3);
assertEquals(2, retrievedOfferAccess3.size());
// 3_1
OfferAccess retrievedAccess3_1 = retrievedOfferAccess3.get(0);
assertNotNull(retrievedAccess3_1);
assertNotNull(retrievedAccess3_1.getMethod());
if (access3_1.equals(retrievedAccess3_1)) {
assertEquals(tokenMethod, retrievedAccess3_1.getMethod());
} else {
assertEquals(freeMethod, retrievedAccess3_1.getMethod());
}
assertNotNull(retrievedAccess3_1.getOffer());
assertEquals(offer3, retrievedAccess3_1.getOffer());
// 3_2
OfferAccess retrievedAccess3_2 = retrievedOfferAccess3.get(1);
assertNotNull(retrievedAccess3_2);
assertNotNull(retrievedAccess3_2.getMethod());
if (access3_2.equals(retrievedAccess3_2)) {
assertEquals(freeMethod, retrievedAccess3_2.getMethod());
} else {
assertEquals(tokenMethod, retrievedAccess3_2.getMethod());
}
assertNotNull(retrievedAccess3_2.getOffer());
assertEquals(offer3, retrievedAccess3_2.getOffer());
dbInstance.commitAndCloseSession();
}
{
// retrieve the links by resource
List<Offer> offers = new ArrayList<>();
offers.add(offer1);
offers.add(offer2);
offers.add(offer3);
List<OfferAccess> retrievedAllOfferAccess = acMethodManager.getOfferAccess(offers, true);
assertNotNull(retrievedAllOfferAccess);
assertEquals(4, retrievedAllOfferAccess.size());
dbInstance.commitAndCloseSession();
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testIsValidMethodAvailable_nonGui.
@Test
public void testIsValidMethodAvailable_nonGui() {
// create a resource and an offer
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestIsValidMethodAvailableNonGui");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(ShibbolethAutoAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
boolean isAvailable = acMethodManager.isValidMethodAvailable(randomOres, null);
assertFalse(isAvailable);
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testDeleteOfferAccess.
@Test
public void testDeleteOfferAccess() {
// create some resources and offers
OLATResource randomOres1 = createResource();
Offer offer = acService.createOffer(randomOres1, "TestDeleteOfferAccess");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create two link offer to method
List<AccessMethod> tokenMethods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(tokenMethods);
assertEquals(1, tokenMethods.size());
AccessMethod tokenMethod = tokenMethods.get(0);
List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
assertNotNull(freeMethods);
assertEquals(1, freeMethods.size());
AccessMethod freeMethod = freeMethods.get(0);
OfferAccess access3_1 = acMethodManager.createOfferAccess(offer, tokenMethod);
acMethodManager.save(access3_1);
OfferAccess access3_2 = acMethodManager.createOfferAccess(offer, freeMethod);
acMethodManager.save(access3_2);
dbInstance.commitAndCloseSession();
// delete one of them
acMethodManager.delete(access3_2);
dbInstance.commitAndCloseSession();
// retrieve
List<OfferAccess> retrievedOfferAccess = acMethodManager.getOfferAccess(offer, true);
assertNotNull(retrievedOfferAccess);
assertEquals(1, retrievedOfferAccess.size());
assertEquals(access3_1, retrievedOfferAccess.get(0));
}
Aggregations