Search in sources :

Example 1 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class RemoveAnythingFlaggedByModeratorTest method should_not_handle_not_logged_user.

@Test
public void should_not_handle_not_logged_user() throws Exception {
    RemoveAnythingFlaggedByModerator removeFlaggedByModerator = new RemoveAnythingFlaggedByModerator(new LoggedUser(null, null));
    Comment comment = comment(author, "blablablablba");
    assertFalse(removeFlaggedByModerator.shouldHandle(comment));
    assertTrue(comment.isVisible());
}
Also used : Comment(org.mamute.model.Comment) LoggedUser(org.mamute.model.LoggedUser) RemoveAnythingFlaggedByModerator(org.mamute.model.flag.RemoveAnythingFlaggedByModerator) Test(org.junit.Test)

Example 2 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class RemoveAnythingFlaggedByModeratorTest method should_remove_comment_after_moderator_flag.

@Test
public void should_remove_comment_after_moderator_flag() {
    RemoveAnythingFlaggedByModerator removeFlaggedByModerator = new RemoveAnythingFlaggedByModerator(new LoggedUser(user, null));
    Comment comment = comment(author, "blablablablba");
    removeFlaggedByModerator.fire(comment);
    assertFalse(comment.isVisible());
}
Also used : Comment(org.mamute.model.Comment) LoggedUser(org.mamute.model.LoggedUser) RemoveAnythingFlaggedByModerator(org.mamute.model.flag.RemoveAnythingFlaggedByModerator) Test(org.junit.Test)

Example 3 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class RemoveAnythingFlaggedByModeratorTest method should_not_handle_normal_user.

@Test
public void should_not_handle_normal_user() throws Exception {
    User normal = user("normal", "normal@brutal.com");
    RemoveAnythingFlaggedByModerator removeFlaggedByModerator = new RemoveAnythingFlaggedByModerator(new LoggedUser(normal, null));
    Comment comment = comment(author, "blablablablba");
    assertFalse(removeFlaggedByModerator.shouldHandle(comment));
    assertTrue(comment.isVisible());
}
Also used : Comment(org.mamute.model.Comment) User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) LoggedUser(org.mamute.model.LoggedUser) RemoveAnythingFlaggedByModerator(org.mamute.model.flag.RemoveAnythingFlaggedByModerator) Test(org.junit.Test)

Example 4 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class FlagController method topFlagged.

@CustomBrutauthRules(ModeratorOnlyRule.class)
@Get
public void topFlagged() {
    List<FlaggableAndFlagCount> flaggedQuestions = flaggables.flaggedButVisible(Question.class);
    List<FlaggableAndFlagCount> flaggedAnswers = flaggables.flaggedButVisible(Answer.class);
    List<FlaggableAndFlagCount> flaggedComments = flaggables.flaggedButVisible(Comment.class);
    List<Question> commentQuestions = new ArrayList<>();
    Iterator<FlaggableAndFlagCount> iterator = flaggedComments.iterator();
    while (iterator.hasNext()) {
        Comment comment = (Comment) iterator.next().getFlaggable();
        Question q = questions.fromCommentId(comment.getId());
        if (q != null) {
            commentQuestions.add(q);
            continue;
        }
        Answer answerFromComment = answers.fromCommentId(comment.getId());
        if (answerFromComment != null) {
            commentQuestions.add(answerFromComment.getQuestion());
            continue;
        }
        // some flags may be related to news (not questions nor answers)
        iterator.remove();
    }
    result.include("questions", flaggedQuestions);
    result.include("answers", flaggedAnswers);
    result.include("comments", flaggedComments);
    result.include("commentQuestions", commentQuestions);
}
Also used : Comment(org.mamute.model.Comment) Answer(org.mamute.model.Answer) FlaggableAndFlagCount(org.mamute.dto.FlaggableAndFlagCount) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Get(br.com.caelum.vraptor.Get)

Example 5 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class AnswerDAO method delete.

public void delete(Answer answer) {
    answer.getQuestion().subtractAnswer();
    session.delete(answer);
    for (Comment comment : answer.getAllComments()) {
        session.delete(comment);
    }
}
Also used : Comment(org.mamute.model.Comment)

Aggregations

Comment (org.mamute.model.Comment)14 Test (org.junit.Test)9 Question (org.mamute.model.Question)4 Answer (org.mamute.model.Answer)3 LoggedUser (org.mamute.model.LoggedUser)3 User (org.mamute.model.User)3 RemoveAnythingFlaggedByModerator (org.mamute.model.flag.RemoveAnythingFlaggedByModerator)3 Flag (org.mamute.model.Flag)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 FlaggableAndFlagCount (org.mamute.dto.FlaggableAndFlagCount)1 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)1 CommentsAndVotes (org.mamute.model.CommentsAndVotes)1 ReputationEventContext (org.mamute.model.ReputationEventContext)1 VisibleCommentList (org.mamute.model.VisibleCommentList)1 Vote (org.mamute.model.Vote)1 MassiveVote (org.mamute.model.vote.MassiveVote)1