Search in sources :

Example 1 with Moderatable

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());
}
Also used : ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) Question(org.mamute.model.Question) Moderatable(org.mamute.model.interfaces.Moderatable) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Example 2 with Moderatable

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();
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) ReputationEvent(org.mamute.model.ReputationEvent) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Moderatable(org.mamute.model.interfaces.Moderatable) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 3 with Moderatable

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));
}
Also used : AuthorRule(org.mamute.auth.rules.AuthorRule) User(org.mamute.model.User) QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question) Moderatable(org.mamute.model.interfaces.Moderatable) Test(org.junit.Test)

Aggregations

Moderatable (org.mamute.model.interfaces.Moderatable)3 Test (org.junit.Test)2 AnswerInformation (org.mamute.model.AnswerInformation)2 Information (org.mamute.model.Information)2 Question (org.mamute.model.Question)2 QuestionInformation (org.mamute.model.QuestionInformation)2 User (org.mamute.model.User)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 Post (br.com.caelum.vraptor.Post)1 AuthorRule (org.mamute.auth.rules.AuthorRule)1 QuestionBuilder (org.mamute.builder.QuestionBuilder)1 LoggedUser (org.mamute.model.LoggedUser)1 ModeratableAndPendingHistory (org.mamute.model.ModeratableAndPendingHistory)1 ReputationEvent (org.mamute.model.ReputationEvent)1