Search in sources :

Example 26 with Profile

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

the class FeedbackController method replyAjax.

@PostMapping({ "/{id}", "/{id}/{title}" })
public String replyAjax(@PathVariable String id, @PathVariable(required = false) String title, HttpServletRequest req, HttpServletResponse res, Model model) throws IOException {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    if (showPost != null && !showPost.isClosed() && !showPost.isReply()) {
        //create new answer
        Reply answer = utils.populate(req, new Reply(), "body");
        Map<String, String> error = utils.validate(answer);
        if (!error.containsKey("body")) {
            answer.setTitle(showPost.getTitle());
            answer.setCreatorid(authUser.getId());
            answer.setParentid(showPost.getId());
            answer.create();
            showPost.setAnswercount(showPost.getAnswercount() + 1);
            if (showPost.getAnswercount() >= MAX_REPLIES_PER_POST) {
                showPost.setCloserid("0");
            }
            // update without adding revisions
            pc.update(showPost);
            utils.addBadgeAndUpdate(authUser, Profile.Badge.EUREKA, answer.getCreatorid().equals(showPost.getCreatorid()));
            answer.setAuthor(authUser);
            model.addAttribute("showPost", showPost);
            model.addAttribute("answerslist", Collections.singletonList(answer));
            return "reply";
        }
    }
    if (utils.isAjaxRequest(req)) {
        res.setStatus(200);
        return "base";
    } else {
        return "redirect:" + feedbacklink + "/" + id;
    }
}
Also used : Post(com.erudika.scoold.core.Post) Reply(com.erudika.scoold.core.Reply) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 27 with Profile

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

the class PeopleController method get.

@GetMapping
public String get(@RequestParam(required = false, defaultValue = Config._TIMESTAMP) String sortby, HttpServletRequest req, Model model) {
    Pager itemcount = utils.getPager("page", req);
    itemcount.setSortby(sortby);
    List<Profile> userlist = utils.getParaClient().findQuery(Utils.type(Profile.class), "*", itemcount);
    model.addAttribute("path", "people.vm");
    model.addAttribute("title", utils.getLang(req).get("people.title"));
    model.addAttribute("peopleSelected", "navbtn-hover");
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("userlist", userlist);
    return "base";
}
Also used : Pager(com.erudika.para.utils.Pager) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 28 with Profile

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

the class ProfileController method edit.

@PostMapping("/{id}")
public String edit(@PathVariable(required = false) String id, @RequestParam(required = false) String name, @RequestParam(required = false) String location, @RequestParam(required = false) String website, @RequestParam(required = false) String aboutme, @RequestParam(required = false) String picture, HttpServletRequest req) {
    Profile authUser = utils.getAuthUser(req);
    String showId = StringUtils.isBlank(id) ? authUser.getId() : id;
    if (canEditProfile(authUser, showId)) {
        Profile showUser = utils.getParaClient().read(Profile.id(id));
        boolean update = false;
        if (!StringUtils.isBlank(name)) {
            showUser.setName(name);
            update = true;
        }
        if (!StringUtils.isBlank(location)) {
            showUser.setLocation(location);
            update = true;
        }
        if (!StringUtils.isBlank(website)) {
            showUser.setWebsite(website);
            update = true;
        }
        if (!StringUtils.isBlank(aboutme)) {
            showUser.setAboutme(aboutme);
            update = true;
        }
        if (!StringUtils.isBlank(picture)) {
            showUser.setPicture(picture);
            update = true;
        }
        boolean isComplete = showUser.isComplete() && isMyid(authUser, showUser.getId());
        if (update || utils.addBadgeOnce(authUser, Badge.NICEPROFILE, isComplete)) {
            showUser.update();
        }
    }
    return "redirect:" + profilelink;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 29 with Profile

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

the class ProfileController method mods.

@PostMapping(path = "/{id}", params = { "makemod" })
public String mods(@PathVariable String id, @RequestParam Boolean makemod, HttpServletRequest req) {
    Profile authUser = utils.getAuthUser(req);
    if (!isMyid(authUser, Profile.id(id))) {
        Profile showUser = utils.getParaClient().read(Profile.id(id));
        if (showUser != null) {
            boolean isShowUserAdmin = User.Groups.ADMINS.toString().equals(showUser.getGroups());
            boolean isShowUserMod = User.Groups.MODS.toString().equals(showUser.getGroups());
            if (makemod && utils.isAdmin(authUser) && !isShowUserAdmin) {
                showUser.setGroups(isShowUserMod ? USERS.toString() : MODS.toString());
                showUser.update();
            }
        }
    }
    return "redirect:" + profilelink + "/" + id;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 30 with Profile

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

the class QuestionController method close.

@PostMapping("/{id}/close")
public String close(@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 (utils.isMod(authUser)) {
        if (showPost.isClosed()) {
            showPost.setCloserid(null);
        } else {
            showPost.setCloserid(authUser.getId());
        }
        showPost.update();
    }
    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)

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