Search in sources :

Example 1 with ModerationLog

use of net.jforum.entities.ModerationLog in project jforum2 by rafaelsteil.

the class AjaxAction method savePost.

public void savePost() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(this.request.getIntParameter("id"));
    String originalMessage = post.getText();
    if (!PostCommon.canEditPost(post)) {
        post = PostCommon.preparePostForDisplay(post);
    } else {
        post.setText(this.request.getParameter("value"));
        postDao.update(post);
        SearchFacade.update(post);
        post = PostCommon.preparePostForDisplay(post);
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
        ModerationHelper helper = new ModerationHelper();
        this.request.addParameter("log_original_message", originalMessage);
        this.request.addParameter("post_id", String.valueOf(post.getId()));
        this.request.addParameter("topic_id", String.valueOf(post.getTopicId()));
        ModerationLog log = helper.buildModerationLogFromRequest();
        log.getPosterUser().setId(post.getUserId());
        helper.saveModerationLog(log);
    }
    if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
        PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
    }
    this.setTemplateName(TemplateKeys.AJAX_LOAD_POST);
    this.context.put("post", post);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog)

Example 2 with ModerationLog

use of net.jforum.entities.ModerationLog in project jforum2 by rafaelsteil.

the class ModerationHelper method lockUnlockTopics.

private void lockUnlockTopics(int status) {
    String[] topics = JForumExecutionContext.getRequest().getParameterValues("topic_id");
    if (topics != null && topics.length > 0) {
        int[] ids = new int[topics.length];
        ModerationLog log = this.buildModerationLogFromRequest();
        for (int i = 0; i < topics.length; i++) {
            ids[i] = Integer.parseInt(topics[i]);
            log.setTopicId(ids[i]);
            this.saveModerationLog(log);
        }
        DataAccessDriver.getInstance().newTopicDAO().lockUnlock(ids, status);
        // Clear the cache
        Topic t = DataAccessDriver.getInstance().newTopicDAO().selectById(ids[0]);
        TopicRepository.clearCache(t.getForumId());
    }
}
Also used : ModerationLog(net.jforum.entities.ModerationLog) Topic(net.jforum.entities.Topic)

Example 3 with ModerationLog

use of net.jforum.entities.ModerationLog in project jforum2 by rafaelsteil.

the class ModerationHelper method moveTopicsSave.

public int moveTopicsSave(String successUrl) {
    int status = SUCCESS;
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_MOVE)) {
        status = FAILURE;
    } else {
        RequestContext request = JForumExecutionContext.getRequest();
        String topics = request.getParameter("topics");
        if (topics != null) {
            int fromForumId = Integer.parseInt(request.getParameter("forum_id"));
            int toForumId = Integer.parseInt(request.getParameter("to_forum"));
            String[] topicList = topics.split(",");
            DataAccessDriver.getInstance().newForumDAO().moveTopics(topicList, fromForumId, toForumId);
            ModerationLog log = this.buildModerationLogFromRequest();
            for (int i = 0; i < topicList.length; i++) {
                int topicId = Integer.parseInt(topicList[i]);
                log.setTopicId(topicId);
                this.saveModerationLog(log);
            }
            ForumRepository.reloadForum(fromForumId);
            ForumRepository.reloadForum(toForumId);
            TopicRepository.clearCache(fromForumId);
            TopicRepository.clearCache(toForumId);
            TopicRepository.loadMostRecentTopics();
            TopicRepository.loadHottestTopics();
        }
    }
    if (status == FAILURE) {
        this.denied();
    } else {
        this.moderationDone(successUrl);
    }
    return status;
}
Also used : ModerationLog(net.jforum.entities.ModerationLog) RequestContext(net.jforum.context.RequestContext)

Example 4 with ModerationLog

use of net.jforum.entities.ModerationLog in project jforum2 by rafaelsteil.

the class PostAction method editSave.

public void editSave() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    Post post = postDao.selectById(this.request.getIntParameter("post_id"));
    if (!PostCommon.canEditPost(post)) {
        this.cannotEdit();
        return;
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    String originalMessage = post.getText();
    post = PostCommon.fillPostFromRequest(post, true);
    // The user wants to preview the message before posting it?
    if ("1".equals(this.request.getParameter("preview"))) {
        this.context.put("preview", true);
        Post postPreview = new Post(post);
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.edit(true, post);
    } else {
        AttachmentCommon attachments = new AttachmentCommon(this.request, post.getForumId());
        try {
            attachments.preProcess();
        } catch (AttachmentException e) {
            JForumExecutionContext.enableRollback();
            post.setText(this.request.getParameter("message"));
            this.context.put("errorMessage", e.getMessage());
            this.context.put("post", post);
            this.edit(false, post);
            return;
        }
        Topic t = TopicRepository.getTopic(new Topic(post.getTopicId()));
        if (t == null) {
            t = topicDao.selectById(post.getTopicId());
        }
        if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
            return;
        }
        if (t.getStatus() == Topic.STATUS_LOCKED && !SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT)) {
            this.topicLocked();
            return;
        }
        postDao.update(post);
        // Attachments
        attachments.editAttachments(post.getId(), post.getForumId());
        attachments.insertAttachments(post);
        // The first message (the one which originated the topic) was changed
        if (t.getFirstPostId() == post.getId()) {
            t.setTitle(post.getSubject());
            int newType = this.request.getIntParameter("topic_type");
            boolean changeType = SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS) && newType != t.getType();
            if (changeType) {
                t.setType(newType);
            }
            // Poll
            Poll poll = PollCommon.fillPollFromRequest();
            if (poll != null && !t.isVote()) {
                // They added a poll
                poll.setTopicId(t.getId());
                if (!this.ensurePollMinimumOptions(post, poll)) {
                    return;
                }
                pollDao.addNew(poll);
                t.setVoteId(poll.getId());
            } else if (poll != null) {
                if (!this.ensurePollMinimumOptions(post, poll)) {
                    return;
                }
                // They edited the poll in the topic
                Poll existing = pollDao.selectById(t.getVoteId());
                PollChanges changes = new PollChanges(existing, poll);
                if (changes.hasChanges()) {
                    poll.setId(existing.getId());
                    poll.setChanges(changes);
                    pollDao.update(poll);
                }
            } else if (t.isVote()) {
                // They deleted the poll from the topic
                pollDao.delete(t.getVoteId());
                t.setVoteId(0);
            }
            topicDao.update(t);
            if (changeType) {
                TopicRepository.addTopic(t);
            } else {
                TopicRepository.updateTopic(t);
            }
        }
        if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
            ModerationHelper helper = new ModerationHelper();
            this.request.addParameter("log_original_message", originalMessage);
            ModerationLog log = helper.buildModerationLogFromRequest();
            log.getPosterUser().setId(post.getUserId());
            helper.saveModerationLog(log);
        }
        if (this.request.getParameter("notify") == null) {
            topicDao.removeSubscription(post.getTopicId(), SessionFacade.getUserSession().getUserId());
        }
        String path = this.request.getContextPath() + "/posts/list/";
        int start = ViewCommon.getStartPage();
        if (start > 0) {
            path += start + "/";
        }
        path += post.getTopicId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) + "#" + post.getId();
        JForumExecutionContext.setRedirect(path);
        if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
            PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
        }
    }
}
Also used : Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) TopicDAO(net.jforum.dao.TopicDAO) AttachmentException(net.jforum.exceptions.AttachmentException) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) PollChanges(net.jforum.entities.PollChanges) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 5 with ModerationLog

use of net.jforum.entities.ModerationLog in project jforum2 by rafaelsteil.

the class PostAction method delete.

public void delete() {
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE)) {
        this.setTemplateName(TemplateKeys.POSTS_CANNOT_DELETE);
        this.context.put("message", I18n.getMessage("CannotRemovePost"));
        return;
    }
    // Post
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post p = postDao.selectById(this.request.getIntParameter("post_id"));
    if (p.getId() == 0) {
        this.postNotFound();
        return;
    }
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    Topic t = topicDao.selectRaw(p.getTopicId());
    if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
        return;
    }
    postDao.delete(p);
    DataAccessDriver.getInstance().newUserDAO().decrementPosts(p.getUserId());
    // Karma
    KarmaDAO karmaDao = DataAccessDriver.getInstance().newKarmaDAO();
    karmaDao.updateUserKarma(p.getUserId());
    // Attachments
    new AttachmentCommon(this.request, p.getForumId()).deleteAttachments(p.getId(), p.getForumId());
    // It was the last remaining post in the topic?
    int totalPosts = topicDao.getTotalPosts(p.getTopicId());
    if (totalPosts > 0) {
        // Topic
        topicDao.decrementTotalReplies(p.getTopicId());
        int maxPostId = topicDao.getMaxPostId(p.getTopicId());
        if (maxPostId > -1) {
            topicDao.setLastPostId(p.getTopicId(), maxPostId);
        }
        int minPostId = topicDao.getMinPostId(p.getTopicId());
        if (minPostId > -1) {
            topicDao.setFirstPostId(p.getTopicId(), minPostId);
        }
        // Forum
        ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
        maxPostId = fm.getMaxPostId(p.getForumId());
        if (maxPostId > -1) {
            fm.setLastPost(p.getForumId(), maxPostId);
        }
        String returnPath = this.request.getContextPath() + "/posts/list/";
        int page = ViewCommon.getStartPage();
        if (page > 0) {
            int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
            if (totalPosts % postsPerPage == 0) {
                page -= postsPerPage;
            }
            returnPath += page + "/";
        }
        JForumExecutionContext.setRedirect(returnPath + p.getTopicId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
        // Update the cache
        if (TopicRepository.isTopicCached(t)) {
            t = topicDao.selectById(t.getId());
            TopicRepository.updateTopic(t);
        }
    } else {
        // Ok, all posts were removed. Time to say goodbye
        TopicsCommon.deleteTopic(p.getTopicId(), p.getForumId(), false);
        JForumExecutionContext.setRedirect(this.request.getContextPath() + "/forums/show/" + p.getForumId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    }
    this.request.addOrReplaceParameter("log_original_message", p.getText());
    ModerationHelper moderationHelper = new ModerationHelper();
    ModerationLog moderationLog = moderationHelper.buildModerationLogFromRequest();
    moderationLog.getPosterUser().setId(p.getUserId());
    moderationHelper.saveModerationLog(moderationLog);
    PostRepository.remove(t.getId(), p.getId());
    TopicRepository.loadMostRecentTopics();
    TopicRepository.loadHottestTopics();
    ForumRepository.reloadForum(p.getForumId());
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) KarmaDAO(net.jforum.dao.KarmaDAO) TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Aggregations

ModerationLog (net.jforum.entities.ModerationLog)9 Topic (net.jforum.entities.Topic)5 PostDAO (net.jforum.dao.PostDAO)4 TopicDAO (net.jforum.dao.TopicDAO)4 Post (net.jforum.entities.Post)4 Iterator (java.util.Iterator)2 List (java.util.List)2 RequestContext (net.jforum.context.RequestContext)2 ForumDAO (net.jforum.dao.ForumDAO)2 User (net.jforum.entities.User)2 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 KarmaDAO (net.jforum.dao.KarmaDAO)1 ModerationLogDAO (net.jforum.dao.ModerationLogDAO)1 PollDAO (net.jforum.dao.PollDAO)1 Poll (net.jforum.entities.Poll)1 PollChanges (net.jforum.entities.PollChanges)1 AttachmentException (net.jforum.exceptions.AttachmentException)1