use of org.mamute.model.User in project mamute by caelum.
the class RemoveAnythingFlaggedByModeratorTest method should_not_handle_normal_user.
@Test
public void should_not_handle_normal_user() throws Exception {
User normal = user("normal", "normal@brutal.com");
RemoveAnythingFlaggedByModerator removeFlaggedByModerator = new RemoveAnythingFlaggedByModerator(new LoggedUser(normal, null));
Comment comment = comment(author, "blablablablba");
assertFalse(removeFlaggedByModerator.shouldHandle(comment));
assertTrue(comment.isVisible());
}
use of org.mamute.model.User in project mamute by caelum.
the class RssFeedFactoryTest method should_generate_feed.
@Test
public void should_generate_feed() throws IOException {
DefaultEnvironment env = new DefaultEnvironment(new EnvironmentType("mamute"));
QuestionRssEntryFactory factory = new QuestionRssEntryFactory(env);
RssFeedFactory rssFeedFactory = new RssFeedFactory(env, factory);
QuestionBuilder builder = new QuestionBuilder();
DateTimeUtils.setCurrentMillisFixed(100);
User user1 = user("author1", "author@email");
user1.setPhotoUri(new URL("http://imagemsuser1.com"));
Question question1 = builder.withAuthor(user1).withTitle("first question").withDescription("question").withId(1l).build();
User user2 = user("author2", "author@email");
user2.setPhotoUri(new URL("http://imagemsuser2.com"));
Question question2 = builder.withId(2l).withTitle("second question").withAuthor(user2).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();
rssFeedFactory.build(Arrays.<RssContent>asList(question1, question2), output, "title", "description");
output.close();
String xml = new String(output.toByteArray());
assertTrue(xml.contains("first question"));
assertTrue(xml.contains("second question"));
assertTrue(xml.contains("http://imagemsuser1.com"));
assertTrue(xml.contains("http://imagemsuser2.com"));
DateTimeUtils.setCurrentMillisSystem();
}
use of org.mamute.model.User in project mamute by caelum.
the class BrutalAdsTest method should_return_true_if_user_have_less_then_50_karma.
@Test
public void should_return_true_if_user_have_less_then_50_karma() {
User user = user("Leo", "leo@leo.com");
user.increaseKarma(20);
LoggedUser loggedUser = new LoggedUser(user, null);
BrutalAds brutalAds = new BrutalAds(loggedUser);
assertTrue(brutalAds.shouldShowAds());
}
use of org.mamute.model.User in project mamute by caelum.
the class NotificationMailer method buildEmail.
public Email buildEmail(NotificationMail notificationMail) {
DateTimeFormatter dateFormat = forPattern("MMM, dd").withLocale(new Locale("pt", "br"));
EmailAction action = notificationMail.getAction();
User to = notificationMail.getTo();
Email email = templates.template(notificationMail.getEmailTemplate(), bundle.getMessage("site.name"), action.getMainThread().getTitle()).with("emailAction", action).with("dateFormat", dateFormat).with("sanitizer", POLICY).with("bundle", bundle).with("watcher", to).with("linkerHelper", new LinkToHelper(router, brutalEnv)).with("logoUrl", env.get("mail_logo_url")).to(to.getName(), to.getEmail());
return email;
}
use of org.mamute.model.User in project mamute by caelum.
the class VotingMachine method unRegister.
public void unRegister(Votable votable, Vote current, Class<?> votableType) {
User voter = current.getAuthor();
User votableAuthor = votable.getAuthor();
ReputationEventContext eventContext = votes.contextOf(votable);
if (votable.getAuthor().getId().equals(voter.getId())) {
throw new IllegalArgumentException("an author can't unvote its own votable since it can't even vote on it");
}
Vote previous = votes.previousVoteFor(votable.getId(), voter, votableType);
boolean shouldCountKarma = voteChecker.shouldCountKarma(voter, votableAuthor, current);
/* O previous vai sempre existir nessa caso !! ( o ideal :] ) */
if (previous != null) {
ReputationEvent receivedVote = new ReceivedVoteEvent(previous.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
votableAuthor.descreaseKarma(karmaCalculator.karmaFor(receivedVote));
ReputationEvent votedAtSomething = new VotedAtSomethingEvent(previous, eventContext).reputationEvent();
voter.descreaseKarma(karmaCalculator.karmaFor(votedAtSomething));
reputationEvents.delete(receivedVote);
reputationEvents.delete(votedAtSomething);
votable.remove(previous);
}
// ReputationEvent receivedVote = new ReceivedVoteEvent(current.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
// votableAuthor.increaseKarma(karmaCalculator.karmaFor(receivedVote));
// ReputationEvent votedAtSomething = new VotedAtSomethingEvent(current, eventContext).reputationEvent();
// voter.increaseKarma(karmaCalculator.karmaFor(votedAtSomething));
// reputationEvents.save(receivedVote);
// reputationEvents.save(votedAtSomething);
// if (votable.getVoteCount() <= -5) {
// votable.getQuestion().remove();
// retrieveDownvote.retrieveKarma(votable.getVotes());
// }
}
Aggregations