Search in sources :

Example 11 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class TranslateController method delete.

@PostMapping("/delete/{id}")
public String delete(@PathVariable String id, HttpServletRequest req, Model model) {
    if (id != null && utils.isAuthenticated(req)) {
        Translation trans = (Translation) pc.read(id);
        Profile authUser = utils.getAuthUser(req);
        if (authUser.getId().equals(trans.getCreatorid()) || utils.isAdmin(authUser)) {
            utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
            pc.delete(trans);
        }
        if (!utils.isAjaxRequest(req)) {
            return "redirect:" + req.getRequestURI();
        }
    }
    return "base";
}
Also used : Translation(com.erudika.para.core.Translation) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 12 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class QuestionController method edit.

@PostMapping("/{id}/edit")
public String edit(@PathVariable String id, @RequestParam(required = false) String title, @RequestParam(required = false) String body, @RequestParam(required = false) String tags, HttpServletRequest req) {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    if (!utils.canEdit(showPost, authUser) || showPost == null) {
        return "redirect:" + req.getRequestURI();
    }
    Post beforeUpdate = null;
    try {
        beforeUpdate = (Post) BeanUtils.cloneBean(showPost);
    } catch (Exception ex) {
        logger.error(null, ex);
    }
    if (!StringUtils.isBlank(title) && title.length() > 10) {
        showPost.setTitle(title);
    }
    if (!StringUtils.isBlank(body)) {
        showPost.setBody(body);
    }
    if (!StringUtils.isBlank(tags) && showPost.isQuestion()) {
        showPost.setTags(Arrays.asList(StringUtils.split(tags, ",")));
    }
    showPost.setLasteditby(authUser.getId());
    //note: update only happens if something has changed
    if (!showPost.equals(beforeUpdate)) {
        showPost.update();
        utils.addBadgeOnceAndUpdate(authUser, Badge.EDITOR, true);
    }
    return "redirect:" + showPost.getPostLink(false, false);
}
Also used : Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) IOException(java.io.IOException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 13 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class ReportsController method create.

@PostMapping
public void create(HttpServletRequest req, HttpServletResponse res) {
    Report rep = utils.populate(req, new Report(), "link", "description", "parentid", "subType", "authorName");
    Map<String, String> error = utils.validate(rep);
    if (error.isEmpty()) {
        if (utils.isAuthenticated(req)) {
            Profile authUser = utils.getAuthUser(req);
            rep.setAuthorName(authUser.getName());
            rep.setCreatorid(authUser.getId());
            utils.addBadgeAndUpdate(authUser, REPORTER, true);
        } else {
            //allow anonymous reports
            rep.setAuthorName(utils.getLang(req).get("anonymous"));
        }
        rep.create();
        res.setStatus(200);
    } else {
        res.setStatus(400);
    }
}
Also used : Report(com.erudika.scoold.core.Report) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 14 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class ReportsController method close.

@PostMapping("/{id}/close")
public String close(@PathVariable String id, @RequestParam(required = false, defaultValue = "") String solution, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        Report report = pc.read(id);
        if (report != null && !report.getClosed() && utils.isMod(authUser)) {
            report.setClosed(true);
            report.setSolution(solution);
            report.update();
        }
    }
    if (!utils.isAjaxRequest(req)) {
        return "redirect:" + reportslink;
    }
    return "base";
}
Also used : Report(com.erudika.scoold.core.Report) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 15 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class ReportsController method createCSPViolationReport.

@PostMapping("/cspv")
@SuppressWarnings("unchecked")
public String createCSPViolationReport(HttpServletRequest req) throws IOException {
    if (Config.getConfigBoolean("csp_reports_enabled", false)) {
        Report rep = new Report();
        rep.setDescription("CSP Violation Report");
        rep.setSubType(Report.ReportType.OTHER);
        rep.setLink("-");
        rep.setAuthorName("Scoold");
        Map<String, Object> body = ParaObjectUtils.getJsonReader(Map.class).readValue(req.getInputStream());
        if (body != null && !body.isEmpty()) {
            rep.setProperties((Map<String, Object>) (body.containsKey("csp-report") ? body.get("csp-report") : body));
        }
        rep.create();
    }
    return "redirect:/";
}
Also used : Report(com.erudika.scoold.core.Report) Map(java.util.Map) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)40 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 HashMap (java.util.HashMap)6 Report (com.erudika.scoold.core.Report)4 Map (java.util.Map)4 RegisteredService (org.apereo.cas.services.RegisteredService)4 ResponseEntity (org.springframework.http.ResponseEntity)4 Translation (com.erudika.para.core.Translation)3 Reply (com.erudika.scoold.core.Reply)3 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Comment (com.erudika.scoold.core.Comment)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Locale (java.util.Locale)2 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)2