Search in sources :

Example 1 with Information

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

the class HistoryController method reject.

@Post
public void reject(Long informationId, String typeName) {
    Information informationRefused = informations.getById(informationId, typeName);
    informationRefused.moderate(currentUser.getCurrent(), UpdateStatus.REFUSED);
    Long moderatableId = informationRefused.getModeratable().getId();
    if (typeName.equals(AnswerInformation.class.getSimpleName())) {
        result.redirectTo(this).similarAnswers(moderatableId);
    } else if (typeName.equals(QuestionInformation.class.getSimpleName())) {
        result.redirectTo(this).similarQuestions(moderatableId);
    }
}
Also used : AnswerInformation(org.mamute.model.AnswerInformation) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Post(br.com.caelum.vraptor.Post)

Example 2 with Information

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

the class UpdatablesAndPendingHistoryTest method should_build_group_informations_by_updatable.

@Test
public void should_build_group_informations_by_updatable() {
    List<Object[]> updatableAndInformations = new ArrayList<>();
    User author = user("name", "emaiil");
    QuestionInformationBuilder builder = new QuestionInformationBuilder().with(author);
    QuestionInformation info1 = builder.withTitle("title1").build();
    QuestionInformation info2 = builder.withTitle("title2").build();
    Question question1 = new Question(info1, author);
    question1.setId(1l);
    QuestionInformation info3 = builder.withTitle("title3").build();
    QuestionInformation info4 = builder.withTitle("title4").build();
    Question question2 = new Question(info3, author);
    question2.setId(2l);
    updatableAndInformations.add(new Object[] { question1, info1 });
    updatableAndInformations.add(new Object[] { question1, info2 });
    updatableAndInformations.add(new Object[] { question2, info3 });
    updatableAndInformations.add(new Object[] { question2, info4 });
    ModeratableAndPendingHistory updatablesAndPendingHistory = new ModeratableAndPendingHistory(updatableAndInformations);
    List<Information> pendingInfoForQ1 = updatablesAndPendingHistory.pendingInfoFor(question1);
    List<Information> pendingInfoForQ2 = updatablesAndPendingHistory.pendingInfoFor(question2);
    assertEquals(2, pendingInfoForQ1.size());
    assertEquals("title1", ((QuestionInformation) pendingInfoForQ1.get(0)).getTitle());
    assertEquals("title2", ((QuestionInformation) pendingInfoForQ1.get(1)).getTitle());
    assertEquals(2, pendingInfoForQ2.size());
    assertEquals("title3", ((QuestionInformation) pendingInfoForQ2.get(0)).getTitle());
    assertEquals("title4", ((QuestionInformation) pendingInfoForQ2.get(1)).getTitle());
}
Also used : User(org.mamute.model.User) ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) QuestionInformationBuilder(org.mamute.model.QuestionInformationBuilder) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) Information(org.mamute.model.Information) QuestionInformation(org.mamute.model.QuestionInformation) QuestionInformation(org.mamute.model.QuestionInformation) Test(org.junit.Test)

Example 3 with Information

use of org.mamute.model.Information 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 4 with Information

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

the class AnswerTest method should_approve_answer_info.

@Test
public void should_approve_answer_info() throws Exception {
    Question myQuestion = question.withTitle("question title").withDescription("description").withAuthor(author).build();
    Answer answer = answer("blablablab", myQuestion, author);
    Information approved = new AnswerInformation(notMarked("blablabalblab"), new LoggedUser(editUser, null), answer, "");
    answer.approve(approved);
    assertEquals(approved, answer.getInformation());
    assertEquals(editUser, answer.getLastTouchedBy());
}
Also used : Answer(org.mamute.model.Answer) Question(org.mamute.model.Question) LoggedUser(org.mamute.model.LoggedUser) AnswerInformation(org.mamute.model.AnswerInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Example 5 with Information

use of org.mamute.model.Information 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)

Aggregations

Information (org.mamute.model.Information)7 AnswerInformation (org.mamute.model.AnswerInformation)5 QuestionInformation (org.mamute.model.QuestionInformation)5 Test (org.junit.Test)4 Post (br.com.caelum.vraptor.Post)3 ModeratableAndPendingHistory (org.mamute.model.ModeratableAndPendingHistory)3 Question (org.mamute.model.Question)3 Answer (org.mamute.model.Answer)2 LoggedUser (org.mamute.model.LoggedUser)2 User (org.mamute.model.User)2 Moderatable (org.mamute.model.interfaces.Moderatable)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 ArrayList (java.util.ArrayList)1 NewsInformation (org.mamute.model.NewsInformation)1 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)1 ReputationEvent (org.mamute.model.ReputationEvent)1