use of org.mamute.model.interfaces.Flaggable 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.interfaces.Flaggable in project mamute by caelum.
the class RemoveSolutionFlaggedByModeratorTest method should_not_handle_flag_of_normal_user.
@Test
public void should_not_handle_flag_of_normal_user() {
RemoveSolutionFlaggedByModerator action = new RemoveSolutionFlaggedByModerator(loggedUser);
Flaggable flaggable = new AnswerChild();
assertFalse(action.shouldHandle(flaggable));
}
use of org.mamute.model.interfaces.Flaggable in project mamute by caelum.
the class FlaggableDAOTest method setup.
@Before
public void setup() {
flaggedInvisible.remove();
addFlags(commentWithOneFlag, 1, author);
addFlags(commentWithTwo, 2, author);
addFlags(flaggedInvisible, 2, author);
session.save(author);
session.save(anyone);
session.save(commentWithTwo);
session.save(flaggedInvisible);
session.save(commentWithOneFlag);
session.save(java);
session.save(question);
session.flush();
flaggables = new FlaggableDAO(session, meta);
questions = new QuestionDAO(session, new InvisibleForUsersRule(new LoggedUser(anyone, null)));
List<Class<? extends Flaggable>> moderatableTypes = new ArrayList<>();
moderatableTypes.add(Question.class);
moderatableTypes.add(Answer.class);
moderatableTypes.add(Comment.class);
moderatableTypes.add(News.class);
when(meta.getFlaggableTypes()).thenReturn(moderatableTypes);
}
use of org.mamute.model.interfaces.Flaggable in project mamute by caelum.
the class FlagTriggerTest method should_trigger_correct_actions.
@Test
public void should_trigger_correct_actions() {
FlagAction neverExecuteAction = mock(FlagAction.class);
FlagAction alwaysExecuteAction = mock(FlagAction.class);
Flaggable flaggable = mock(Flaggable.class);
when(neverExecuteAction.shouldHandle(Mockito.any(Flaggable.class))).thenReturn(false);
when(alwaysExecuteAction.shouldHandle(Mockito.any(Flaggable.class))).thenReturn(true);
FlagTrigger flagTrigger = new FlagTrigger(Arrays.asList(neverExecuteAction, alwaysExecuteAction));
flagTrigger.fire(flaggable);
verify(neverExecuteAction, never()).fire(flaggable);
verify(alwaysExecuteAction, times(1)).fire(flaggable);
}
Aggregations