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);
}
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;
}
}
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);
}
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;
}
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());
}
Aggregations