Search in sources :

Example 1 with Flag

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

the class FlagController method addFlag.

@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_FLAG)
@Post
public void addFlag(String flaggableType, Long flaggableId, FlagType flagType, String reason) {
    Class<?> clazz = urlMapping.getClassFor(flaggableType);
    if (flagType == null) {
        result.use(http()).sendError(400);
        return;
    }
    if (flags.alreadyFlagged(loggedUser.getCurrent(), flaggableId, clazz)) {
        // conflict
        result.use(http()).sendError(409);
        return;
    }
    Flaggable flaggable = flaggables.getById(flaggableId, clazz);
    flagTrigger.fire(flaggable);
    Flag flag = new Flag(flagType, loggedUser.getCurrent());
    if (flagType.equals(FlagType.OTHER)) {
        flag.setReason(reason);
    }
    flags.save(flag);
    flaggable.add(flag);
    result.nothing();
}
Also used : Flaggable(org.mamute.model.interfaces.Flaggable) Flag(org.mamute.model.Flag) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 2 with Flag

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

the class FlaggableDAOTest method addFlags.

private void addFlags(Flaggable comment, int n, User author) {
    for (int i = 0; i < n; i++) {
        Flag flag = flag(FlagType.RUDE, author);
        session.save(flag);
        comment.add(flag);
    }
}
Also used : Flag(org.mamute.model.Flag)

Example 3 with Flag

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

the class FlagDaoTest method createCommentWithFlag.

private Comment createCommentWithFlag(User author) {
    Comment comment = new Comment(author, notMarked("my comment my comment my comment"));
    Flag flag = new Flag(FlagType.RUDE, author);
    comment.add(flag);
    session.save(flag);
    session.save(comment);
    return comment;
}
Also used : Comment(org.mamute.model.Comment) Flag(org.mamute.model.Flag)

Example 4 with Flag

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

the class CommentTest method should_verify_that_user_flagged_a_comment.

@Test
public void should_verify_that_user_flagged_a_comment() {
    User author = user("name", "email@email", 1l);
    User other = user("other", "other@brutal.com", 2l);
    User commentAuthor = user("name", "email@email", 1l);
    Comment comment = comment(commentAuthor, "comment");
    Flag flag = new Flag(FlagType.RUDE, author);
    comment.add(flag);
    assertTrue(comment.alreadyFlaggedBy(author));
    assertFalse(comment.alreadyFlaggedBy(other));
}
Also used : Comment(org.mamute.model.Comment) User(org.mamute.model.User) Flag(org.mamute.model.Flag) Test(org.junit.Test)

Example 5 with Flag

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

the class FlagTest method should_set_reason_in_flag_with_type_other.

@Test
public void should_set_reason_in_flag_with_type_other() {
    Flag flag = flag(FlagType.OTHER, user("author", "author@brutal.com"));
    String reason = "blabla";
    flag.setReason(reason);
    assertEquals(reason, flag.getReason());
}
Also used : Flag(org.mamute.model.Flag) Test(org.junit.Test)

Aggregations

Flag (org.mamute.model.Flag)7 Test (org.junit.Test)4 Comment (org.mamute.model.Comment)2 User (org.mamute.model.User)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 Post (br.com.caelum.vraptor.Post)1 Question (org.mamute.model.Question)1 Flaggable (org.mamute.model.interfaces.Flaggable)1