use of org.mamute.model.interfaces.Moderatable in project mamute by caelum.
the class InformationDAOTest method should_get_pending_history.
@Test
public void should_get_pending_history() {
newQuestion(author);
Question question2 = newQuestion(author);
newChangesWithStatus(question2, 2, PENDING);
Question question3 = newQuestion(author);
newChangesWithStatus(question3, 3, PENDING);
ModeratableAndPendingHistory pending = informations.pendingByUpdatables(Question.class);
List<Moderatable> questions = pending.moderatables();
assertEquals(2, questions.size());
assertEquals(question2.getId(), questions.get(0).getId());
List<Information> pendingQuestion2 = pending.pendingInfoFor(questions.get(0));
assertEquals(2, pendingQuestion2.size());
List<Information> pendingQuestion3 = pending.pendingInfoFor(questions.get(1));
assertEquals(3, pendingQuestion3.size());
}
use of org.mamute.model.interfaces.Moderatable in project mamute by caelum.
the class HistoryController method publish.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Post
public void publish(Long moderatableId, String moderatableType, Long aprovedInformationId, String aprovedInformationType) {
Class<?> moderatableClass = urlMapping.getClassFor(moderatableType);
Information approved = informations.getById(aprovedInformationId, aprovedInformationType);
Moderatable moderatable = moderatables.getById(moderatableId, moderatableClass);
List<Information> pending = informations.pendingFor(moderatableId, moderatableClass);
if (!approved.isPending()) {
result.use(Results.http()).sendError(403);
return;
}
User approvedAuthor = approved.getAuthor();
refusePending(aprovedInformationId, pending);
currentUser.getCurrent().approve(moderatable, approved, environmentKarma);
ReputationEvent editAppoved = new ReputationEvent(EventType.EDIT_APPROVED, moderatable.getQuestion(), approvedAuthor);
int karma = calculator.karmaFor(editAppoved);
approvedAuthor.increaseKarma(karma);
reputationEvents.save(editAppoved);
result.redirectTo(this).history();
}
use of org.mamute.model.interfaces.Moderatable in project mamute by caelum.
the class AuthorRuleTest method should_allow_moderatable_author.
@Test
public void should_allow_moderatable_author() {
AuthorRule<Moderatable> rule = new AuthorRule<>();
User author = user("author", "author@brutal.com", 1l);
User other = user("other", "other@brutal.com", 2l);
Question question = new QuestionBuilder().withAuthor(author).build();
assertFalse(rule.isAllowed(other, question));
assertTrue(rule.isAllowed(author, question));
}
Aggregations