Search in sources :

Example 21 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class QuestionController method delete.

@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req) {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    if (!utils.canEdit(showPost, authUser) || showPost == null) {
        return "redirect:" + req.getRequestURI();
    }
    if (!showPost.isReply()) {
        if ((utils.isMine(showPost, authUser) || utils.isMod(authUser))) {
            showPost.delete();
            return "redirect:" + questionslink + "?success=true&code=16";
        }
    } else if (showPost.isReply()) {
        if (utils.isMine(showPost, authUser) || utils.isMod(authUser)) {
            Post parent = pc.read(showPost.getParentid());
            parent.setAnswercount(parent.getAnswercount() - 1);
            parent.update();
            showPost.delete();
        }
    }
    return "redirect:" + showPost.getPostLink(false, false);
}
Also used : Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 22 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class QuestionsController method post.

@PostMapping("/questions/ask")
public String post(@RequestParam(required = false) String location, @RequestParam(required = false) String latlng, @RequestParam(required = false) String address, HttpServletRequest req, Model model) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        Question q = utils.populate(req, new Question(), "title", "body", "tags|,", "location");
        q.setCreatorid(authUser.getId());
        Map<String, String> error = utils.validate(q);
        if (error.isEmpty()) {
            q.setLocation(location);
            String qid = q.create();
            if (!StringUtils.isBlank(latlng)) {
                Address addr = new Address();
                addr.setAddress(address);
                addr.setCountry(location);
                addr.setLatlng(latlng);
                addr.setParentid(qid);
                addr.setCreatorid(authUser.getId());
                pc.create(addr);
            }
            authUser.setLastseen(System.currentTimeMillis());
        } else {
            model.addAttribute("error", error);
            model.addAttribute("path", "questions.vm");
            model.addAttribute("includeGMapsScripts", true);
            model.addAttribute("askSelected", "navbtn-hover");
            return "base";
        }
        return "redirect:" + q.getPostLink(false, false);
    }
    return "redirect:" + signinlink + "?returnto=" + questionslink + "/ask";
}
Also used : Address(com.erudika.para.core.Address) Question(com.erudika.scoold.core.Question) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 23 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class ReportsController method delete.

@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        Report rep = pc.read(id);
        if (rep != null && utils.isAdmin(authUser)) {
            rep.delete();
        }
    }
    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 24 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class CommentController method sendCommentNotification.

private void sendCommentNotification(Post parentPost, Comment comment, Profile commentAuthor) {
    // send email notification to author of post except when the comment is by the same person
    if (parentPost != null && comment != null && !StringUtils.equals(parentPost.getCreatorid(), comment.getCreatorid())) {
        Profile authorProfile = pc.read(parentPost.getCreatorid());
        if (authorProfile != null && authorProfile.getCommentEmailsEnabled()) {
            User author = authorProfile.getUser();
            if (author != null) {
                Map<String, Object> model = new HashMap<String, Object>();
                String name = commentAuthor.getName();
                String body = Utils.markdownToHtml(Utils.abbreviate(comment.getComment(), 255));
                String pic = Utils.formatMessage("<img src='{0}' width='25'>", commentAuthor.getPicture());
                String postURL = getServerURL() + parentPost.getPostLink(false, false);
                model.put("logourl", Config.getConfigParam("small_logo_url", "https://scoold.com/logo.png"));
                model.put("heading", Utils.formatMessage("New comment on <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
                model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", pic, name, body));
                emailer.sendEmail(Arrays.asList(author.getEmail()), name + " commented on your post", Utils.compileMustache(model, utils.loadEmailTemplate("notify")));
            }
        }
    }
}
Also used : User(com.erudika.para.core.User) HashMap(java.util.HashMap) Profile(com.erudika.scoold.core.Profile)

Example 25 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class CommentController method deleteAjax.

@PostMapping("/{id}/delete")
public void deleteAjax(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Comment comment = pc.read(id);
        Profile authUser = utils.getAuthUser(req);
        boolean isMod = utils.isMod(authUser);
        if (comment != null && (comment.getCreatorid().equals(authUser.getId()) || isMod)) {
            // check parent and correct (for multi-parent-object pages)
            comment.delete();
            if (!isMod) {
                utils.addBadgeAndUpdate(authUser, DISCIPLINED, true);
            }
        }
    }
    res.setStatus(200);
}
Also used : Comment(com.erudika.scoold.core.Comment) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

Profile (com.erudika.scoold.core.Profile)30 PostMapping (org.springframework.web.bind.annotation.PostMapping)20 Post (com.erudika.scoold.core.Post)12 ParaObject (com.erudika.para.core.ParaObject)4 Pager (com.erudika.para.utils.Pager)4 Reply (com.erudika.scoold.core.Reply)4 Report (com.erudika.scoold.core.Report)4 HashMap (java.util.HashMap)4 User (com.erudika.para.core.User)3 Comment (com.erudika.scoold.core.Comment)3 Question (com.erudika.scoold.core.Question)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Translation (com.erudika.para.core.Translation)2 Feedback (com.erudika.scoold.core.Feedback)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Address (com.erudika.para.core.Address)1 Revision (com.erudika.scoold.core.Revision)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1