use of org.olat.resource.accesscontrol.model.AccessMethod in project OpenOLAT by OpenOLAT.
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);
}
}
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
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 klemens.
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 klemens.
the class ACMethodManagerTest method testOfferAccess.
@Test
public void testOfferAccess() {
// create a resource and an offer
OLATResource randomOres = createResource();
Offer offer = acService.createOffer(randomOres, "TestOfferAccess");
offer = acService.save(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
assertNotNull(methods);
assertEquals(1, methods.size());
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// retrieve the link
List<OfferAccess> retrievedOfferAccess = acMethodManager.getOfferAccess(offer, true);
assertNotNull(retrievedOfferAccess);
assertEquals(1, retrievedOfferAccess.size());
OfferAccess retrievedAccess = retrievedOfferAccess.get(0);
assertNotNull(retrievedAccess);
assertNotNull(retrievedAccess.getMethod());
assertEquals(method, retrievedAccess.getMethod());
assertNotNull(retrievedAccess.getOffer());
Assert.assertEquals(offer, retrievedAccess.getOffer());
}
use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.
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);
}
Aggregations