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