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";
}
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);
}
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);
}
}
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";
}
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:/";
}
Aggregations