Search in sources :

Example 86 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

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 87 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod 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());
    }
}
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) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 88 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod 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();
        }
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) Offer(org.olat.resource.accesscontrol.Offer) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 89 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

the class TransactionDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = velocity_root + "/transaction_details.html";
    FormLayoutContainer detailsLayout = FormLayoutContainer.createCustomFormLayout("transaction-details-layout", getTranslator(), page);
    formLayout.add(detailsLayout);
    detailsLayout.setRootForm(mainForm);
    AccessTransaction transaction = wrapper.getTransaction();
    DetailsForm detailsForm = new DetailsForm(ureq, getWindowControl(), transaction, mainForm);
    detailsLayout.add("simple", detailsForm.getInitialFormItem());
    AccessMethod method = transaction.getMethod();
    AccessMethodHandler handler = acModule.getAccessMethodHandler(method.getType());
    FormController controller = handler.createTransactionDetailsController(ureq, getWindowControl(), order, wrapper.getPart(), method, mainForm);
    if (controller != null) {
        uifactory.addSpacerElement("details-spacer", detailsLayout, false);
        detailsLayout.add("custom", controller.getInitialFormItem());
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 90 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod in project openolat by klemens.

the class AccessConfigurationController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (addMethods.contains(source)) {
        AccessMethod method = (AccessMethod) source.getUserObject();
        addMethod(ureq, method);
    } else if (source instanceof FormLink) {
        FormLink button = (FormLink) source;
        String cmd = button.getCmd();
        if ("delete".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            removeMethod(infos);
            fireEvent(ureq, Event.CHANGED_EVENT);
        } else if ("edit".equals(cmd)) {
            AccessInfo infos = (AccessInfo) source.getUserObject();
            editMethod(ureq, infos);
        }
    } else if (confirmationEmailEl == source) {
        setConfirmationEmail(confirmationEmailEl.isAtLeastSelected(1));
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6