Search in sources :

Example 1 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class GroupForumIndexer method checkAccess.

/**
 * @see org.olat.search.service.indexer.Indexer#checkAccess(org.olat.core.id.context.ContextEntry, org.olat.core.id.context.BusinessControl, org.olat.core.id.Identity, org.olat.core.id.Roles)
 */
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry ce = businessControl.popLauncherContextEntry();
    Long resourceableId = ce.getOLATResourceable().getResourceableId();
    Message message = ForumManager.getInstance().loadMessage(resourceableId);
    if (message == null)
        return false;
    Message threadtop = message.getThreadtop();
    if (threadtop == null) {
        threadtop = message;
    }
    boolean isMessageHidden = Status.getStatus(threadtop.getStatusCode()).isHidden();
    // assumes that if is owner then is moderator so it is allowed to see the hidden forum threads
    // here it is checked if the identity is owner of the forum tool but it has no way to find out whether is owner of the group that owns the forum tool
    boolean isOwner = BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, contextEntry.getOLATResourceable());
    if (isMessageHidden && !isOwner) {
        return false;
    }
    return super.checkAccess(contextEntry, businessControl, identity, roles);
}
Also used : Message(org.olat.modules.fo.Message) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 2 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class DialogCourseNodeIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry ce = businessControl.popLauncherContextEntry();
    if (ce == null || ce.getOLATResourceable() == null || ce.getOLATResourceable().getResourceableId() == null) {
        // it's the node itself
        return true;
    }
    OLATResourceable ores = ce.getOLATResourceable();
    if (isLogDebugEnabled())
        logDebug("OLATResourceable=" + ores);
    if (ores.getResourceableTypeName().startsWith("path=")) {
        // => it is a file element, typeName format: 'path=/test1/test2/readme.txt'
        return true;
    } else if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(Message.class))) {
        // it is message => check message access
        Long resourceableId = ores.getResourceableId();
        Message message = ForumManager.getInstance().loadMessage(resourceableId);
        Message threadtop = message.getThreadtop();
        if (threadtop == null) {
            threadtop = message;
        }
        boolean isMessageHidden = Status.getStatus(threadtop.getStatusCode()).isHidden();
        // TODO: (LD) fix this!!! - the contextEntry is not the right context for this check
        if (isMessageHidden) {
            boolean isOwner = BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, contextEntry.getOLATResourceable());
            return isOwner;
        }
        return true;
    } else {
        logWarn("In DialogCourseNode unkown OLATResourceable=" + ores, null);
        return false;
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 3 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class FOCourseNodeIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry ce = businessControl.popLauncherContextEntry();
    if (ce == null || ce.getOLATResourceable() == null || ce.getOLATResourceable().getResourceableId() == null) {
        // it's the node itself
        return true;
    }
    Long resourceableId = ce.getOLATResourceable().getResourceableId();
    Message message = ForumManager.getInstance().loadMessage(resourceableId);
    if (message != null) {
        Message threadtop = message.getThreadtop();
        if (threadtop == null) {
            threadtop = message;
        }
        boolean isMessageHidden = Status.getStatus(threadtop.getStatusCode()).isHidden();
        // TODO: (LD) fix this!!! - the contextEntry is not the right context for this check
        if (isMessageHidden && !BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, contextEntry.getOLATResourceable())) {
            return false;
        }
    }
    return super.checkAccess(contextEntry, businessControl, identity, roles);
}
Also used : Message(org.olat.modules.fo.Message) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 4 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class NotificationsTest method createMessage.

private Message createMessage(Identity id, Forum fo) {
    ForumManager fm = ForumManager.getInstance();
    Message m1 = fm.createMessage(fo, id, false);
    m1.setTitle("Thread-1");
    m1.setBody("Body of Thread-1");
    fm.addTopMessage(m1);
    return m1;
}
Also used : Message(org.olat.modules.fo.Message) ForumManager(org.olat.modules.fo.manager.ForumManager)

Example 5 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class NotificationsTest method testGetBusinessGroupForumNotifications.

@Test
public void testGetBusinessGroupForumNotifications() throws IOException, URISyntaxException {
    // create a business group with forum notifications
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-not-4-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(id, "Notifications 1", "REST forum notifications for group", null, null, false, false, null);
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
    tools.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    Forum groupForum = tools.getForum();
    dbInstance.commitAndCloseSession();
    // publish
    String businessPath = "[BusinessGroup:" + group.getKey() + "][toolforum:0]";
    SubscriptionContext forumSubContext = new SubscriptionContext("BusinessGroup", group.getKey(), "toolforum");
    PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), groupForum.getKey().toString(), businessPath);
    notificationManager.subscribe(id, forumSubContext, forumPdata);
    Message message = createMessage(id, groupForum);
    notificationManager.markPublisherNews(forumSubContext, null, true);
    dbInstance.commitAndCloseSession();
    // get the notification
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id.getName(), "A6B7C8"));
    UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
    HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
    Assert.assertNotNull(infos);
    Assert.assertEquals(1, infos.size());
    SubscriptionInfoVO infoVO = infos.get(0);
    Assert.assertNotNull(infoVO.getItems());
    Assert.assertEquals(1, infoVO.getItems().size());
    SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
    Assert.assertNotNull(itemVO);
    Assert.assertEquals(group.getKey(), itemVO.getGroupKey());
    Assert.assertEquals(message.getKey(), itemVO.getMessageKey());
}
Also used : Message(org.olat.modules.fo.Message) BusinessGroup(org.olat.group.BusinessGroup) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) PublisherData(org.olat.core.commons.services.notifications.PublisherData) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) Forum(org.olat.modules.fo.Forum) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) CollaborationTools(org.olat.collaboration.CollaborationTools) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Aggregations

Message (org.olat.modules.fo.Message)108 Identity (org.olat.core.id.Identity)18 OLATResourceable (org.olat.core.id.OLATResourceable)16 ErrorEditMessage (org.olat.modules.fo.ui.events.ErrorEditMessage)16 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)12 Date (java.util.Date)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 ICourse (org.olat.course.ICourse)8 FOCourseNode (org.olat.course.nodes.FOCourseNode)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 PublisherData (org.olat.core.commons.services.notifications.PublisherData)5