Search in sources :

Example 1 with SimpleBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.

the class HistoryController method history.

@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Get
public void history() {
    ModeratableAndPendingHistory pendingQuestions = informations.pendingByUpdatables(Question.class);
    result.include("questions", pendingQuestions);
    ModeratableAndPendingHistory pendingAnswers = informations.pendingByUpdatables(Answer.class);
    result.include("answers", pendingAnswers);
}
Also used : ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) Get(br.com.caelum.vraptor.Get) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 2 with SimpleBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.

the class FlagController method addFlag.

@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_FLAG)
@Post
public void addFlag(String flaggableType, Long flaggableId, FlagType flagType, String reason) {
    Class<?> clazz = urlMapping.getClassFor(flaggableType);
    if (flagType == null) {
        result.use(http()).sendError(400);
        return;
    }
    if (flags.alreadyFlagged(loggedUser.getCurrent(), flaggableId, clazz)) {
        // conflict
        result.use(http()).sendError(409);
        return;
    }
    Flaggable flaggable = flaggables.getById(flaggableId, clazz);
    flagTrigger.fire(flaggable);
    Flag flag = new Flag(flagType, loggedUser.getCurrent());
    if (flagType.equals(FlagType.OTHER)) {
        flag.setReason(reason);
    }
    flags.save(flag);
    flaggable.add(flag);
    result.nothing();
}
Also used : Flaggable(org.mamute.model.interfaces.Flaggable) Flag(org.mamute.model.Flag) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 3 with SimpleBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules 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 4 with SimpleBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.

the class CommentController method comment.

@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_COMMENT)
@CustomBrutauthRules({ InputRule.class, InactiveQuestionRequiresMoreKarmaRule.class })
@Post
public void comment(Long id, String onWhat, MarkedText comment, boolean watching) {
    User current = currentUser.getCurrent();
    Comment newComment = new Comment(current, comment);
    Class<?> type = getType(onWhat);
    validator.validate(newComment);
    validator.onErrorUse(Results.http()).setStatusCode(400);
    org.mamute.model.Post commentable = comments.loadCommentable(type, id);
    commentable.add(newComment);
    comments.save(newComment);
    Watchable watchable = commentable.getMainThread();
    notificationManager.sendEmailsAndInactivate(new EmailAction(newComment, commentable));
    if (watching) {
        watchers.add(watchable, new Watcher(current));
    } else {
        watchers.removeIfWatching(watchable, new Watcher(current));
    }
    result.include("post", commentable);
    result.include("type", onWhat);
    result.forwardTo(BrutalTemplatesController.class).comment(newComment);
}
Also used : Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher) org.mamute.model(org.mamute.model) EmailAction(org.mamute.mail.action.EmailAction) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Aggregations

SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)4 Post (br.com.caelum.vraptor.Post)3 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 EmailAction (org.mamute.mail.action.EmailAction)1 org.mamute.model (org.mamute.model)1 AnswerInformation (org.mamute.model.AnswerInformation)1 Flag (org.mamute.model.Flag)1 Information (org.mamute.model.Information)1 LoggedUser (org.mamute.model.LoggedUser)1 ModeratableAndPendingHistory (org.mamute.model.ModeratableAndPendingHistory)1 QuestionInformation (org.mamute.model.QuestionInformation)1 ReputationEvent (org.mamute.model.ReputationEvent)1 User (org.mamute.model.User)1 Flaggable (org.mamute.model.interfaces.Flaggable)1 Moderatable (org.mamute.model.interfaces.Moderatable)1 Watchable (org.mamute.model.interfaces.Watchable)1 Watcher (org.mamute.model.watch.Watcher)1