Search in sources :

Example 1 with Pseudonym

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

the class ForumPseudonymsAdminController method doDelete.

private void doDelete(PseudonymStatistics row) {
    Pseudonym pseudonym = forumManager.getPseudonymByKey(row.getKey());
    forumManager.deletePseudonym(pseudonym);
}
Also used : Pseudonym(org.olat.modules.fo.Pseudonym)

Example 2 with Pseudonym

use of org.olat.modules.fo.Pseudonym in project openolat by klemens.

the class MessageEditController method commitMessage.

private void commitMessage(UserRequest ureq) {
    // if msg exist -> persist uploads directly to final dest
    if (message.getKey() != null) {
        message = fm.loadMessage(message.getKey());
    }
    // set values from form to message
    message.setTitle(titleEl.getValue());
    String body = bodyEl.getValue();
    body = body.replace("<p>&nbsp;", "<p>");
    message.setBody(body.trim());
    if (usePseudonymEl != null && (usePseudonymEl.isAtLeastSelected(1) || guestOnly)) {
        String password = passwordEl.getValue();
        String pseudonym = pseudonymEl.getValue();
        if (StringHelper.containsNonWhitespace(password)) {
            List<Pseudonym> protectedPseudonyms = fm.getPseudonyms(pseudonym);
            if (protectedPseudonyms.isEmpty()) {
                fm.createProtectedPseudonym(pseudonym, password);
                ureq.getUserSession().putEntry("FOPseudo-" + pseudonym, password);
            } else {
                // we double check the password
                boolean authenticated = false;
                for (Pseudonym protectedPseudonym : protectedPseudonyms) {
                    if (fm.authenticatePseudonym(protectedPseudonym, password)) {
                        ureq.getUserSession().putEntry("FOPseudo-" + protectedPseudonym.getPseudonym(), password);
                        authenticated = true;
                        break;
                    }
                }
                if (!authenticated) {
                    validateFormLogic(ureq);
                    return;
                }
            }
        }
        message.setPseudonym(pseudonym);
        if (guestOnly) {
            ureq.getUserSession().putEntry("FOPseudo" + forum.getKey(), message.getPseudonym());
        }
    } else if (message.getCreator() != null && message.getCreator().equals(getIdentity())) {
        message.setPseudonym(null);
    }
    if (editMode == EditMode.newThread) {
        if (foCallback.mayOpenNewThread()) {
            // save a new thread
            fm.addTopMessage(message);
            fm.markNewMessageAsRead(getIdentity(), forum, message);
            persistTempUploadedFiles(message);
            // if notification is enabled -> notify the publisher about news
            notifiySubscription();
            addLoggingResourceable(LoggingResourceable.wrap(message));
            // commit before sending events
            DBFactory.getInstance().commit();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, message.getKey(), message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_CREATE, getClass());
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.edit) {
        boolean children = fm.countMessageChildren(message.getKey()) > 0;
        if (foCallback.mayEditMessageAsModerator() || (userIsMsgCreator && !children)) {
            message.setModifier(getIdentity());
            message = fm.updateMessage(message, true);
            persistTempUploadedFiles(message);
            notifiySubscription();
            // commit before sending events
            DBFactory.getInstance().commit();
            Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.CHANGED_MESSAGE, threadTopKey, message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_EDIT, getClass(), LoggingResourceable.wrap(message));
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.reply) {
        fm.replyToMessage(message, parentMessage);
        fm.markNewMessageAsRead(getIdentity(), forum, message);
        persistTempUploadedFiles(message);
        notifiySubscription();
        Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
        // commit before sending events
        DBFactory.getInstance().commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, threadTopKey, message.getKey(), getIdentity());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
        ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_REPLY_MESSAGE_CREATE, getClass(), LoggingResourceable.wrap(message));
    }
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Pseudonym(org.olat.modules.fo.Pseudonym)

Example 3 with Pseudonym

use of org.olat.modules.fo.Pseudonym in project openolat by klemens.

the class ForumManager method deletePseudonym.

public void deletePseudonym(Pseudonym pseudonym) {
    Pseudonym reloadedPseudonym = dbInstance.getCurrentEntityManager().getReference(PseudonymImpl.class, pseudonym.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedPseudonym);
}
Also used : Pseudonym(org.olat.modules.fo.Pseudonym)

Example 4 with Pseudonym

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

the class MessageEditController method validatePseudonymProtected.

/**
 * No password:
 * <ul>
 *  <li>exists pseudonym with password: error</li>
 *  <li>doesn't exist pseudonym with passwort -> can use the pseudonym</li>
 * </ul>
 * With password:
 * <ul>
 *  <li>exists pseudonym with password + password wrong: error</li>
 *  <li>exists pseudonym with password + password ok: ok</li>
 *  <li>exists pseudonym with password + password wrong: error</li>
 * </ul>
 *
 * @param value
 * @param password
 * @return
 */
private boolean validatePseudonymProtected(String value, String password) {
    boolean allOk = true;
    if (StringHelper.containsNonWhitespace(password)) {
        List<Pseudonym> pseudonyms = fm.getPseudonyms(value);
        if (pseudonyms.size() > 0) {
            boolean authenticated = false;
            for (Pseudonym pseudonym : pseudonyms) {
                if (fm.authenticatePseudonym(pseudonym, password)) {
                    authenticated = true;
                    break;
                }
            }
            if (!authenticated) {
                passwordEl.setErrorKey("error.pseudonym.authentication", null);
                allOk &= false;
            }
        } else if (fm.isPseudonymInUseInForums(value)) {
            pseudonymEl.setErrorKey("error.pseudonym", null);
            allOk &= false;
        }
    } else if (fm.isPseudonymProtected(value)) {
        pseudonymEl.setErrorKey("error.pseudonym.protected", null);
        allOk &= false;
    }
    return allOk;
}
Also used : Pseudonym(org.olat.modules.fo.Pseudonym)

Example 5 with Pseudonym

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

the class MessageEditController method commitMessage.

private void commitMessage(UserRequest ureq) {
    // if msg exist -> persist uploads directly to final dest
    if (message.getKey() != null) {
        message = fm.loadMessage(message.getKey());
    }
    // set values from form to message
    message.setTitle(titleEl.getValue());
    String body = bodyEl.getValue();
    body = body.replace("<p>&nbsp;", "<p>");
    message.setBody(body.trim());
    if (usePseudonymEl != null && (usePseudonymEl.isAtLeastSelected(1) || guestOnly)) {
        String password = passwordEl.getValue();
        String pseudonym = pseudonymEl.getValue();
        if (StringHelper.containsNonWhitespace(password)) {
            List<Pseudonym> protectedPseudonyms = fm.getPseudonyms(pseudonym);
            if (protectedPseudonyms.isEmpty()) {
                fm.createProtectedPseudonym(pseudonym, password);
                ureq.getUserSession().putEntry("FOPseudo-" + pseudonym, password);
            } else {
                // we double check the password
                boolean authenticated = false;
                for (Pseudonym protectedPseudonym : protectedPseudonyms) {
                    if (fm.authenticatePseudonym(protectedPseudonym, password)) {
                        ureq.getUserSession().putEntry("FOPseudo-" + protectedPseudonym.getPseudonym(), password);
                        authenticated = true;
                        break;
                    }
                }
                if (!authenticated) {
                    validateFormLogic(ureq);
                    return;
                }
            }
        }
        message.setPseudonym(pseudonym);
        if (guestOnly) {
            ureq.getUserSession().putEntry("FOPseudo" + forum.getKey(), message.getPseudonym());
        }
    } else if (message.getCreator() != null && message.getCreator().equals(getIdentity())) {
        message.setPseudonym(null);
    }
    if (editMode == EditMode.newThread) {
        if (foCallback.mayOpenNewThread()) {
            // save a new thread
            fm.addTopMessage(message);
            fm.markNewMessageAsRead(getIdentity(), forum, message);
            persistTempUploadedFiles(message);
            // if notification is enabled -> notify the publisher about news
            notifiySubscription();
            addLoggingResourceable(LoggingResourceable.wrap(message));
            // commit before sending events
            DBFactory.getInstance().commit();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, message.getKey(), message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_CREATE, getClass());
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.edit) {
        boolean children = fm.countMessageChildren(message.getKey()) > 0;
        if (foCallback.mayEditMessageAsModerator() || (userIsMsgCreator && !children)) {
            message.setModifier(getIdentity());
            message = fm.updateMessage(message, true);
            persistTempUploadedFiles(message);
            notifiySubscription();
            // commit before sending events
            DBFactory.getInstance().commit();
            Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
            ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.CHANGED_MESSAGE, threadTopKey, message.getKey(), getIdentity());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_EDIT, getClass(), LoggingResourceable.wrap(message));
        } else {
            showWarning("may.not.save.msg.as.author");
        }
    } else if (editMode == EditMode.reply) {
        fm.replyToMessage(message, parentMessage);
        fm.markNewMessageAsRead(getIdentity(), forum, message);
        persistTempUploadedFiles(message);
        notifiySubscription();
        Long threadTopKey = message.getThreadtop() == null ? null : message.getThreadtop().getKey();
        // commit before sending events
        DBFactory.getInstance().commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.NEW_MESSAGE, threadTopKey, message.getKey(), getIdentity());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
        ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_REPLY_MESSAGE_CREATE, getClass(), LoggingResourceable.wrap(message));
    }
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Pseudonym(org.olat.modules.fo.Pseudonym)

Aggregations

Pseudonym (org.olat.modules.fo.Pseudonym)8 ForumChangedEvent (org.olat.modules.fo.ForumChangedEvent)2