use of org.mamute.model.User in project mamute by caelum.
the class VerifyUsersController method verify.
@SuppressWarnings("unchecked")
@Post("/asjkdjnjsaknfknsdklglas")
public void verify(Result r) {
List<User> users = session.createCriteria(User.class).list();
List<User> invalid = new ArrayList<>();
for (User user : users) {
if (!isValid(user)) {
invalid.add(user);
}
}
r.include("invalid", invalid);
}
use of org.mamute.model.User in project mamute by caelum.
the class VerifyUsersController method isValid.
private boolean isValid(User user) {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<User>> errors = validator.validate(user);
if (!errors.isEmpty()) {
LOG.warn("The user " + user.getName() + " with id " + user.getId() + " has the errors bellow:");
for (ConstraintViolation<User> constraintViolation : errors) {
Object constraint = constraintViolation.getConstraintDescriptor().getAnnotation();
LOG.warn(constraint);
}
LOG.warn("------------------------------------------------");
return false;
}
return true;
}
use of org.mamute.model.User in project mamute by caelum.
the class WatchController method watch.
@Post
@CustomBrutauthRules(LoggedRule.class)
public void watch(Long watchableId, String type) {
Watchable watchable = watchers.findWatchable(watchableId, mapping.getClassFor(type));
User user = currentUser.getCurrent();
Watcher watcher = new Watcher(user);
watchers.addOrRemove(watchable, watcher);
result.nothing();
}
use of org.mamute.model.User 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.User in project mamute by caelum.
the class NewsController method showNews.
@Get
public void showNews(@Load News news, String sluggedTitle) {
User current = currentUser.getCurrent();
news.checkVisibilityFor(currentUser);
redirectToRightUrl(news, sluggedTitle);
viewCounter.ping(news);
boolean isWatching = watchers.ping(news, current);
result.include("commentsWithVotes", votes.previousVotesForComments(news, current));
result.include("currentVote", votes.previousVoteFor(news.getId(), current, News.class));
result.include("news", news);
result.include("isWatching", isWatching);
result.include("userMediumPhoto", true);
result.include("newsActive", true);
result.include("noDefaultActive", true);
}
Aggregations