use of org.olat.modules.fo.Message in project openolat by klemens.
the class DialogCourseNodeIndexer method doIndexAllMessages.
private void doIndexAllMessages(SearchResourceContext parentResourceContext, Forum forum, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
// loop over all messages of a forum
List<Message> messages = ForumManager.getInstance().getMessagesByForum(forum);
for (Message message : messages) {
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(message);
searchResourceContext.setDocumentType(TYPE_MESSAGE);
Document document = ForumMessageDocument.createDocument(searchResourceContext, message);
indexWriter.addDocument(document);
}
}
use of org.olat.modules.fo.Message in project openolat by klemens.
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 klemens.
the class MessageListController method doDeleteMessage.
private void doDeleteMessage(UserRequest ureq, MessageView message) {
boolean userIsMsgCreator = message.isAuthor();
if (foCallback.mayDeleteMessageAsModerator() || (userIsMsgCreator && forumManager.countMessageChildren(message.getKey()) == 0)) {
Message reloadedMessage = forumManager.getMessageById(message.getKey());
if (reloadedMessage != null) {
// this delete the topic / thread
if (reloadedMessage.getParent() == null) {
forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
// delete topics
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
// back to thread list
fireEvent(ureq, new DeleteThreadEvent());
ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_THREAD, reloadedMessage.getKey(), reloadedMessage.getKey(), getIdentity());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
} else {
Message threadTop = reloadedMessage.getThreadtop();
forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
threadTop = forumManager.updateMessage(threadTop, true);
if (thread != null) {
// update with the fresh version
thread = threadTop;
}
showInfo("deleteok");
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
// reload
reloadModelAfterDelete(ureq, message);
fireEvent(ureq, new DeleteMessageEvent());
ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_MESSAGE, threadTop.getKey(), message.getKey(), getIdentity());
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
}
}
} else {
showWarning("may.not.delete.msg.as.author");
}
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class MessageListController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == exportCtrl) {
if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
if (event == Event.CHANGED_EVENT) {
StepsRunContext runContext = exportCtrl.getRunContext();
Message originTopMessage = (Message) runContext.get(SendMailStepForm.START_THREADTOP);
originTopMessage = forumManager.loadMessage(originTopMessage.getKey());
if (originTopMessage != null) {
// refresh origin thread
fireEvent(ureq, new SelectMessageEvent(SelectMessageEvent.SELECT_THREAD, originTopMessage.getKey()));
} else {
fireEvent(ureq, Event.BACK_EVENT);
}
}
getWindowControl().pop();
removeAsListenerAndDispose(exportCtrl);
exportCtrl = null;
}
} else if (source == confirmDeleteCtrl) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
MessageView deletedMessage = (MessageView) confirmDeleteCtrl.getUserObject();
doDeleteMessage(ureq, deletedMessage);
}
} else if (editMessageCtrl == source) {
// edit done -> save
if (event instanceof ErrorEditMessage) {
handleEditError(ureq);
} else {
Message message = editMessageCtrl.getMessage();
if (message != null) {
if (thread != null && thread.getKey().equals(message.getKey())) {
thread = message;
}
reloadModel(ureq, message);
} else {
showInfo("header.cannoteditmessage");
}
}
cmc.deactivate();
} else if (replyMessageCtrl == source) {
if (event instanceof ErrorEditMessage) {
handleEditError(ureq);
} else {
Message reply = replyMessageCtrl.getMessage();
if (reply != null) {
reloadModel(ureq, reply);
} else {
showInfo("header.cannotsavemessage");
}
}
cmc.deactivate();
} else if (messageTableCtrl == source) {
if (event instanceof SelectMessageEvent) {
SelectMessageEvent sme = (SelectMessageEvent) event;
doSelectTheOne(ureq, sme.getMessageKey());
}
} else if (moveCtrl == source) {
if (event instanceof SelectMessageEvent) {
SelectMessageEvent sme = (SelectMessageEvent) event;
doFinalizeMove(ureq, moveCtrl.getSelectView(), sme.getMessageKey());
cmc.deactivate();
}
} else if (confirmSplitCtrl == source) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
MessageView splitedMessage = (MessageView) confirmSplitCtrl.getUserObject();
doSplitThread(ureq, splitedMessage);
}
} else if (source == cmc) {
cleanUp();
}
super.event(ureq, source, event);
}
use of org.olat.modules.fo.Message in project openolat by klemens.
the class MessageListController method doSplitThread.
private void doSplitThread(UserRequest ureq, MessageView message) {
if (foCallback.mayEditMessageAsModerator()) {
Message reloadedMessage = forumManager.getMessageById(message.getKey());
Message newTopMessage = forumManager.splitThread(reloadedMessage);
// do logging
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_SPLIT, getClass(), LoggingResourceable.wrap(newTopMessage));
showInfo("new.thread.location");
// open the new thread
fireEvent(ureq, new SelectMessageEvent(SelectMessageEvent.SELECT_THREAD, newTopMessage.getKey()));
} else {
showWarning("may.not.split.thread");
}
}
Aggregations