Search in sources :

Example 56 with User

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);
}
Also used : User(org.mamute.model.User) ArrayList(java.util.ArrayList) Post(br.com.caelum.vraptor.Post)

Example 57 with User

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;
}
Also used : User(org.mamute.model.User) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator)

Example 58 with User

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();
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 59 with User

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();
}
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 60 with User

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);
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) News(org.mamute.model.News) Get(br.com.caelum.vraptor.Get)

Aggregations

User (org.mamute.model.User)97 Test (org.junit.Test)56 Question (org.mamute.model.Question)28 LoggedUser (org.mamute.model.LoggedUser)25 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)9 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)9 Answer (org.mamute.model.Answer)9 LoginMethod (org.mamute.model.LoginMethod)9 Post (br.com.caelum.vraptor.Post)7 Before (org.junit.Before)7 Tag (org.mamute.model.Tag)7 QuestionInformation (org.mamute.model.QuestionInformation)6 Email (org.apache.commons.mail.Email)5 UserPersonalInfo (org.mamute.dto.UserPersonalInfo)5 ReputationEvent (org.mamute.model.ReputationEvent)5 ArrayList (java.util.ArrayList)4 Watcher (org.mamute.model.watch.Watcher)4 DateTime (org.joda.time.DateTime)3 Elements (org.jsoup.select.Elements)3 DaoManager (org.mamute.integration.util.DaoManager)3