use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.
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;
}
use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.
the class AutoAccessManagerImplTest method shouldNotMakeOfferBeforeGrantingAccessIfOfferExists.
@Test
public void shouldNotMakeOfferBeforeGrantingAccessIfOfferExists() {
when(identifierHandlerMock.findRepositoryEntries(any(IdentifierKey.class), anyString())).thenReturn(listWithRespositotyEntryMock);
OfferAccess offerAccessDummy = mock(OfferAccess.class);
List<OfferAccess> offerAccess = Arrays.asList(offerAccessDummy);
when(acServiceMock.getValidOfferAccess(any(OLATResource.class), any(AccessMethod.class))).thenReturn(offerAccess);
sut.grantAccess(getPendingAdvanceOrders());
verify(acServiceMock, never()).createOffer(any(OLATResource.class), isNull());
verify(acServiceMock, never()).createOfferAccess(any(Offer.class), any(AccessMethod.class));
}
use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.
the class BusinessGroupDAOTest method findPublicGroups.
@Test
public void findPublicGroups() {
// create a group with an access control
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
BusinessGroup group = businessGroupDao.createAndPersist(null, "access-grp-1", "access-grp-1-desc", 0, 5, true, false, true, false, false);
// create and save an offer
Offer offer = acService.createOffer(group.getResource(), "TestBGWorkflow");
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);
dbInstance.commitAndCloseSession();
// retrieve the offer
// check the search with the views
BusinessGroupQueryParams queryAllParams = new BusinessGroupQueryParams();
queryAllParams.setPublicGroups(Boolean.TRUE);
List<OpenBusinessGroupRow> accessGroupViews = businessGroupDao.searchPublishedBusinessGroups(queryAllParams, identity);
Assert.assertNotNull(accessGroupViews);
Assert.assertTrue(accessGroupViews.size() >= 1);
Assert.assertTrue(contains(accessGroupViews, group));
for (OpenBusinessGroupRow accessGroup : accessGroupViews) {
OLATResource resource = resourceManager.findResourceById(accessGroup.getResourceKey());
List<Offer> offers = acService.findOfferByResource(resource, true, new Date());
Assert.assertNotNull(offers);
Assert.assertFalse(offers.isEmpty());
}
}
use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.
the class AccessTransactionTest method generateDatas.
@Test
public void generateDatas() {
// pick up a method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
AccessMethod method = methods.get(0);
StringBuilder sb = new StringBuilder();
sb.append("select v from repositoryentry as v ").append(" inner join fetch v.olatResource as ores").append(" inner join fetch v.statistics as statistics").append(" left join fetch v.lifecycle as lifecycle").append(" where ores.resName='CourseModule' and v.access>0");
List<RepositoryEntry> courses = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntry.class).getResultList();
List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 40000);
for (RepositoryEntry course : courses) {
try {
List<Offer> offers = acService.findOfferByResource(course.getOlatResource(), true, null);
if (offers.isEmpty()) {
OLATResource randomOres = course.getOlatResource();
Offer offer = acService.createOffer(randomOres, "Free " + course.getDisplayname());
offer.setAutoBooking(true);
OfferAccess link = acService.createOfferAccess(offer, method);
offer = acService.save(offer);
acService.saveOfferAccess(link);
dbInstance.commit();
int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
int length = (int) (Math.random() * 200);
int toIndex = Math.min(loadIdentities.size() - 1, fromIndex + length);
List<Identity> identities = loadIdentities.subList(fromIndex, toIndex);
for (Identity identity : identities) {
acService.isAccessible(course, identity, false, true);
dbInstance.commit();
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
dbInstance.commitAndCloseSession();
}
}
}
use of org.olat.resource.accesscontrol.OfferAccess in project openolat by klemens.
the class AccessConfigurationController method addMethod.
protected void addMethod(UserRequest ureq, AccessMethod method) {
boolean confirmationEmail = confirmationEmailEl.isVisible() && confirmationEmailEl.isAtLeastSelected(1);
Offer offer = acService.createOffer(resource, displayName);
offer.setConfirmationEmail(confirmationEmail);
OfferAccess link = acService.createOfferAccess(offer, method);
removeAsListenerAndDispose(newMethodCtrl);
AccessMethodHandler handler = acModule.getAccessMethodHandler(link.getMethod().getType());
if (handler != null) {
newMethodCtrl = handler.createConfigurationController(ureq, getWindowControl(), link);
}
if (newMethodCtrl != null) {
listenTo(newMethodCtrl);
String title = handler.getMethodName(getLocale());
cmc = new CloseableModalController(getWindowControl(), translate("close"), newMethodCtrl.getInitialComponent(), true, title);
cmc.activate();
listenTo(cmc);
} else {
OfferAccess newLink = acService.saveOfferAccess(link);
addConfiguration(newLink);
}
}
Aggregations