use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
the class AutoAccessManagerImplTest method shouldMakeOfferBeforeGrantingAccessIfNotExists.
@Test
public void shouldMakeOfferBeforeGrantingAccessIfNotExists() {
when(identifierHandlerMock.findRepositoryEntries(any(IdentifierKey.class), anyString())).thenReturn(listWithRespositotyEntryMock);
when(repositoryEntryRelationDaoMock.hasRole(IDENTITY, repositoryEntryMock, GroupRoles.participant.name())).thenReturn(false);
when(acServiceMock.getValidOfferAccess(any(OLATResource.class), any(AccessMethod.class))).thenReturn(new ArrayList<>());
Offer offerMock = mock(Offer.class);
when(acServiceMock.createOffer(any(OLATResource.class), anyString())).thenReturn(offerMock);
List<AccessMethod> methods = Arrays.asList(accessMethodDummy);
when(acServiceMock.getAvailableMethodsByType(METHOD_CLASS)).thenReturn(methods);
Collection<AdvanceOrder> advanceOrders = getPendingAdvanceOrders();
sut.grantAccess(advanceOrders);
verify(acServiceMock, times(2)).createOffer(any(OLATResource.class), anyString());
verify(acServiceMock, times(2)).createOfferAccess(any(Offer.class), isA(AccessMethod.class));
}
use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
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));
}
use of org.olat.resource.accesscontrol.Offer in project OpenOLAT by OpenOLAT.
the class PublishStep01AccessForm method addMethod.
protected void addMethod(UserRequest ureq, AccessMethod method) {
Offer offer = acService.createOffer(resource, displayName);
OfferAccess link = acService.createOfferAccess(offer, method);
removeAsListenerAndDispose(newMethodCtrl);
AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(link.getMethod().getType());
if (methodHandler != null) {
newMethodCtrl = methodHandler.createConfigurationController(ureq, getWindowControl(), link);
}
if (newMethodCtrl != null) {
listenTo(newMethodCtrl);
String title = methodHandler.getMethodName(getLocale());
cmc = new CloseableModalController(getWindowControl(), translate("close"), newMethodCtrl.getInitialComponent(), true, title);
cmc.activate();
listenTo(cmc);
} else {
if (!offerAccess.contains(link)) {
offerAccess.add(link);
}
addConfiguration(link);
}
}
use of org.olat.resource.accesscontrol.Offer in project openolat by klemens.
the class ACFrontendManager method isAccessible.
/**
* The rule to access a business group:<br/>
* -No offer, access is free<br/>
* -Owners have always access to the resource<br/>
* -Tutors have access to the resource<br/>
* -Participants have access to the resource<br/>
* @param group
* @param forId
* @return
*/
@Override
public AccessResult isAccessible(BusinessGroup group, Identity forId, boolean allowNonInteractiveAccess) {
if (!accessModule.isEnabled()) {
return new AccessResult(true);
}
List<String> roles = businessGroupRelationDao.getRoles(forId, group);
if (roles.contains(GroupRoles.coach.name())) {
return new AccessResult(true);
}
if (roles.contains(GroupRoles.participant.name())) {
return new AccessResult(true);
}
Date now = dateNow();
OLATResource resource = OLATResourceManager.getInstance().findResourceable(group);
List<Offer> offers = accessManager.findOfferByResource(resource, true, now);
if (offers.isEmpty()) {
if (methodManager.isValidMethodAvailable(resource, null)) {
// not open for the moment: no valid offer at this date but some methods are defined
return new AccessResult(false);
} else {
return new AccessResult(true);
}
}
return isAccessible(forId, offers, allowNonInteractiveAccess);
}
use of org.olat.resource.accesscontrol.Offer in project openolat by klemens.
the class ACFrontendManager method isAccessible.
/**
* The rule to access the repository entry:<br/>
* -No offer, access is free<br/>
* -Owners have always access to the resource<br/>
* -Tutors have access to the resource<br/>
* -Participants have access to the resource<br/>
* @param entry
* @param forId
* @param knowMember give it if already know as a member
* @return
*/
@Override
public AccessResult isAccessible(RepositoryEntry entry, Identity forId, Boolean knowMember, boolean allowNonInteractiveAccess) {
if (!accessModule.isEnabled()) {
return new AccessResult(true);
}
boolean member;
if (knowMember == null) {
member = repositoryService.isMember(forId, entry);
} else {
member = knowMember.booleanValue();
}
if (member) {
return new AccessResult(true);
}
Date now = dateNow();
List<Offer> offers = accessManager.findOfferByResource(entry.getOlatResource(), true, now);
if (offers.isEmpty()) {
if (methodManager.isValidMethodAvailable(entry.getOlatResource(), null)) {
// not open for the moment: no valid offer at this date but some methods are defined
return new AccessResult(false);
} else {
return new AccessResult(true);
}
}
return isAccessible(forId, offers, allowNonInteractiveAccess);
}
Aggregations