Search in sources :

Example 46 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class BusinessGroupMembershipProcessorTest method testUnlinkRepositoryEntry.

@Test
public void testUnlinkRepositoryEntry() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);
    businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.owner.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(coach, context, publisherData);
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove link between group and repository entry
    businessGroupService.removeResourceFrom(Collections.singletonList(businessGroup), re);
    dbInstance.commitAndCloseSession();
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
    waitForCondition(new CheckUnsubscription(id2, context, dbInstance, notificationManager), 5000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
    Assert.assertFalse(subscribedId1);
    boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
    Assert.assertFalse(subscribedId2);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 47 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup_with2Roles.

@Test
public void testUnlinkMemberOfBusinessGroup_with2Roles() {
    // create a group with members
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-4");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(member, "mbr-proc-2", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(member, businessGroup, GroupRoles.participant.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(businessGroup, "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    notificationManager.getOrCreatePublisher(context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove id1 as participant and check subscription
    businessGroupRelationDao.removeRole(member, businessGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // manually trigger the event
    businessGroupMembershipProcessor.event(new BusinessGroupModifiedEvent(BusinessGroupModifiedEvent.IDENTITY_REMOVED_EVENT, businessGroup, member));
    dbInstance.commitAndCloseSession();
    // check that subscription of member was not deleted because it's still coach
    boolean subscribed = notificationManager.isSubscribed(member, context);
    Assert.assertTrue(subscribed);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent) Test(org.junit.Test)

Example 48 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup.

@Test
public void testUnlinkMemberOfBusinessGroup() {
    // create a group with members
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(businessGroup, "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(coach, context, publisherData);
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove id1 and check subscription
    MailPackage mailing = new MailPackage(false);
    List<Identity> identitiesToRemove = Collections.singletonList(id1);
    businessGroupService.removeParticipants(coach, identitiesToRemove, businessGroup, mailing);
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
    Assert.assertFalse(subscribedId1);
    boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
    Assert.assertTrue(subscribedId2);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 49 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class WikiEditController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Component source, Event event) {
    if (source == previewLink) {
        // Preview as modal dialogue only if the config is valid
        RepositoryEntry re = getWikiRepoReference(moduleConfiguration, false);
        if (re == null) {
            // we cannot preview it, because the repository entry
            // had been deleted between the time when it was
            // chosen here, and now
            this.showError("error.repoentrymissing");
        } else {
            // File cpRoot =
            // FileResourceManager.getInstance().unzipFileResource(re.getOlatResource());
            Identity ident = ureq.getIdentity();
            boolean isOlatAdmin = ureq.getUserSession().getRoles().isOLATAdmin();
            boolean isResourceOwner = RepositoryManager.getInstance().isOwnerOfRepositoryEntry(ident, re);
            CourseEnvironment cenv = course.getCourseEnvironment();
            SubscriptionContext subsContext = WikiManager.createTechnicalSubscriptionContextForCourse(cenv, wikiCourseNode);
            WikiSecurityCallback callback = new WikiSecurityCallbackImpl(null, isOlatAdmin, false, false, isResourceOwner, subsContext);
            wikiCtr = WikiManager.getInstance().createWikiMainController(ureq, getWindowControl(), re.getOlatResource(), callback, null);
            cmcWikiCtr = new CloseableModalController(getWindowControl(), translate("command.close"), wikiCtr.getInitialComponent());
            this.listenTo(cmcWikiCtr);
            cmcWikiCtr.activate();
        }
    } else if (source == chooseButton || source == changeButton) {
        searchController = new ReferencableEntriesSearchController(getWindowControl(), ureq, WikiResource.TYPE_NAME, translate("command.choose"));
        this.listenTo(searchController);
        cmcSearchController = new CloseableModalController(getWindowControl(), translate("close"), searchController.getInitialComponent(), true, translate("command.create"));
        cmcSearchController.activate();
    } else if (source == editLink) {
        RepositoryEntry repositoryEntry = wikiCourseNode.getReferencedRepositoryEntry();
        if (repositoryEntry == null) {
            // do nothing
            return;
        }
        String bPath = "[RepositoryEntry:" + repositoryEntry.getKey() + "][Editor:0]";
        NewControllerFactory.getInstance().launch(bPath, ureq, getWindowControl());
    }
}
Also used : WikiSecurityCallbackImpl(org.olat.modules.wiki.WikiSecurityCallbackImpl) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) RepositoryEntry(org.olat.repository.RepositoryEntry) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) WikiSecurityCallback(org.olat.modules.wiki.WikiSecurityCallback) ReferencableEntriesSearchController(org.olat.repository.controllers.ReferencableEntriesSearchController)

Example 50 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class GroupfoldersWebDAVMergeSource method getGroupContainer.

private VFSContainer getGroupContainer(String name, BusinessGroup group, boolean isOwner) {
    String folderPath = collaborationManager.getFolderRelPath(group);
    // create container and set quota
    OlatRootFolderImpl localImpl = new OlatRootFolderImpl(folderPath, this);
    // already done in OlatRootFolderImpl localImpl.getBasefile().mkdirs(); // lazy initialize dirs
    String containerName = RequestUtil.normalizeFilename(name);
    NamedContainerImpl grpContainer = new GroupNamedContainer(containerName, localImpl);
    boolean writeAccess;
    if (!isOwner) {
        // check if participants have read/write access
        int folderAccess = CollaborationTools.FOLDER_ACCESS_ALL;
        Long lFolderAccess = collaborationManager.lookupFolderAccess(group);
        if (lFolderAccess != null) {
            folderAccess = lFolderAccess.intValue();
        }
        writeAccess = (folderAccess == CollaborationTools.FOLDER_ACCESS_ALL);
    } else {
        writeAccess = true;
    }
    VFSSecurityCallback secCallback;
    if (writeAccess) {
        SubscriptionContext sc = new SubscriptionContext(group, "toolfolder");
        secCallback = new FullAccessWithLazyQuotaCallback(folderPath, QuotaConstants.IDENTIFIER_DEFAULT_GROUPS, sc);
    } else {
        secCallback = new ReadOnlyCallback();
    }
    grpContainer.setLocalSecurityCallback(secCallback);
    return grpContainer;
}
Also used : FullAccessWithLazyQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithLazyQuotaCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Aggregations

SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)204 PublisherData (org.olat.core.commons.services.notifications.PublisherData)84 Identity (org.olat.core.id.Identity)72 Test (org.junit.Test)66 Publisher (org.olat.core.commons.services.notifications.Publisher)58 RepositoryEntry (org.olat.repository.RepositoryEntry)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)28 BusinessGroup (org.olat.group.BusinessGroup)28 ArrayList (java.util.ArrayList)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)20 HttpResponse (org.apache.http.HttpResponse)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)18 Forum (org.olat.modules.fo.Forum)18 File (java.io.File)16 HttpGet (org.apache.http.client.methods.HttpGet)16 CollaborationTools (org.olat.collaboration.CollaborationTools)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)14 Roles (org.olat.core.id.Roles)12