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();
}
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);
}
}
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;
}
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));
}
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());
}
Aggregations