Search in sources :

Example 21 with Offer

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));
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) AutoAccessMethod(org.olat.resource.accesscontrol.provider.auto.model.AutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Offer(org.olat.resource.accesscontrol.Offer) AdvanceOrder(org.olat.resource.accesscontrol.provider.auto.AdvanceOrder) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 22 with Offer

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));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) BusinessGroup(org.olat.group.BusinessGroup) Offer(org.olat.resource.accesscontrol.Offer) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 23 with Offer

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);
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) Offer(org.olat.resource.accesscontrol.Offer) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 24 with Offer

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);
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) AccessResult(org.olat.resource.accesscontrol.AccessResult) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 25 with Offer

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);
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) AccessResult(org.olat.resource.accesscontrol.AccessResult) Date(java.util.Date)

Aggregations

Offer (org.olat.resource.accesscontrol.Offer)38 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)16 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)12 Test (org.junit.Test)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Identity (org.olat.core.id.Identity)6 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)4 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)4 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)4 AccessResult (org.olat.resource.accesscontrol.AccessResult)3 ClientActionRequiredException (com.paypal.exception.ClientActionRequiredException)2 HttpErrorException (com.paypal.exception.HttpErrorException)2 InvalidCredentialException (com.paypal.exception.InvalidCredentialException)2 InvalidResponseDataException (com.paypal.exception.InvalidResponseDataException)2 MissingCredentialException (com.paypal.exception.MissingCredentialException)2 SSLConfigurationException (com.paypal.exception.SSLConfigurationException)2