Search in sources :

Example 51 with Profile

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

the class ScooldUtils method getSpaceFilteredQuery.

public String getSpaceFilteredQuery(HttpServletRequest req) {
    Profile authUser = getAuthUser(req);
    String currentSpace = getSpaceIdFromCookie(authUser, req);
    return getSpaceFilteredQuery(authUser, currentSpace);
}
Also used : Profile(com.erudika.scoold.core.Profile)

Example 52 with Profile

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

the class RevisionsController method get.

@GetMapping("/{postid}")
public String get(@PathVariable String postid, HttpServletRequest req, HttpServletResponse res, Model model) {
    Post showPost = utils.getParaClient().read(postid);
    if (showPost == null) {
        return "redirect:" + QUESTIONSLINK;
    }
    // https://github.com/Erudika/scoold/issues/254
    res.setHeader("X-Robots-Tag", "noindex, nofollow");
    Profile authUser = utils.getAuthUser(req);
    if (!utils.canAccessSpace(authUser, showPost.getSpace())) {
        return "redirect:" + QUESTIONSLINK;
    }
    Pager itemcount = utils.getPager("page", req);
    List<Revision> revisionslist = showPost.getRevisions(itemcount);
    // we need the first revision on the next page for diffing
    List<Revision> nextPage = showPost.getRevisions(new Pager(itemcount.getPage() + 1, itemcount.getLimit()));
    utils.fetchProfiles(revisionslist);
    model.addAttribute("path", "revisions.vm");
    model.addAttribute("title", utils.getLang(req).get("revisions.title"));
    model.addAttribute("showPost", showPost);
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("revisionslist", revisionslist);
    model.addAttribute("lastOnPage", nextPage.isEmpty() ? null : nextPage.get(0));
    return "base";
}
Also used : Revision(com.erudika.scoold.core.Revision) Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.core.utils.Pager) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 53 with Profile

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

the class SettingsController method post.

@PostMapping
public String post(@RequestParam(required = false) String tags, @RequestParam(required = false) String latlng, @RequestParam(required = false) String replyEmailsOn, @RequestParam(required = false) String commentEmailsOn, @RequestParam(required = false) String oldpassword, @RequestParam(required = false) String newpassword, @RequestParam(required = false) String newpostEmailsOn, @RequestParam(required = false) String favtagsEmailsOn, @RequestParam(required = false) List<String> favspaces, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        setFavTags(authUser, tags);
        setFavSpaces(authUser, favspaces);
        if (!StringUtils.isBlank(latlng)) {
            authUser.setLatlng(latlng);
        }
        setAnonymity(authUser, req.getParameter("anon"));
        setDarkMode(authUser, req.getParameter("dark"));
        authUser.setReplyEmailsEnabled(Boolean.valueOf(replyEmailsOn) && utils.isReplyNotificationAllowed());
        authUser.setCommentEmailsEnabled(Boolean.valueOf(commentEmailsOn) && utils.isCommentNotificationAllowed());
        authUser.setFavtagsEmailsEnabled(Boolean.valueOf(favtagsEmailsOn) && utils.isFavTagsNotificationAllowed());
        authUser.update();
        if (Boolean.valueOf(newpostEmailsOn) && utils.isNewPostNotificationAllowed()) {
            utils.subscribeToNewPosts(authUser.getUser());
        } else {
            utils.unsubscribeFromNewPosts(authUser.getUser());
        }
        if (resetPasswordAndUpdate(authUser.getUser(), oldpassword, newpassword)) {
            utils.clearSession(req, res);
            return "redirect:" + SETTINGSLINK + "?passChanged=true";
        }
    }
    return "redirect:" + SETTINGSLINK;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 54 with Profile

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

the class TagsController method delete.

@PostMapping("/delete")
public String delete(@RequestParam String tag, HttpServletRequest req, HttpServletResponse res) {
    Profile authUser = utils.getAuthUser(req);
    if (utils.isMod(authUser)) {
        Tag t = pc.read(Utils.type(Tag.class), new Tag(tag).getId());
        if (t != null) {
            pc.delete(t);
            logger.info("User {} ({}) deleted tag '{}'.", authUser.getName(), authUser.getCreatorid(), t.getTag());
            Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
            List<Question> questionslist;
            do {
                questionslist = pc.findTagged(Utils.type(Question.class), new String[] { t.getTag() }, pager);
                for (Question q : questionslist) {
                    t.setCount(t.getCount() + 1);
                    q.setTags(Optional.ofNullable(q.getTags()).orElse(Collections.emptyList()).stream().filter(ts -> !ts.equals(t.getTag())).distinct().collect(Collectors.toList()));
                    logger.debug("Removed tag {} from {} out of {} questions.", t.getTag(), questionslist.size(), pager.getCount());
                }
                if (!questionslist.isEmpty()) {
                    pc.updateAll(questionslist);
                }
            } while (!questionslist.isEmpty());
        }
    }
    if (utils.isAjaxRequest(req)) {
        res.setStatus(200);
        return "blank";
    } else {
        return "redirect:" + TAGSLINK + "?" + req.getQueryString();
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) SIGNINLINK(com.erudika.scoold.ScooldServer.SIGNINLINK) Question(com.erudika.scoold.core.Question) RequestParam(org.springframework.web.bind.annotation.RequestParam) LoggerFactory(org.slf4j.LoggerFactory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ParaClient(com.erudika.para.client.ParaClient) Pager(com.erudika.para.core.utils.Pager) Controller(org.springframework.stereotype.Controller) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Model(org.springframework.ui.Model) GetMapping(org.springframework.web.bind.annotation.GetMapping) Config(com.erudika.para.core.utils.Config) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) Utils(com.erudika.para.core.utils.Utils) List(java.util.List) Tag(com.erudika.para.core.Tag) TAGSLINK(com.erudika.scoold.ScooldServer.TAGSLINK) Optional(java.util.Optional) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) Pager(com.erudika.para.core.utils.Pager) Question(com.erudika.scoold.core.Question) Tag(com.erudika.para.core.Tag) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 55 with Profile

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

the class TagsController method get.

@GetMapping
public String get(@RequestParam(required = false, defaultValue = "count") String sortby, HttpServletRequest req, Model model) {
    Pager itemcount = utils.getPager("page", req);
    itemcount.setSortby(sortby);
    Profile authUser = utils.getAuthUser(req);
    String currentSpace = utils.getSpaceIdFromCookie(authUser, req);
    List<Tag> tagslist = Collections.emptyList();
    if (utils.canAccessSpace(authUser, currentSpace)) {
        tagslist = pc.findTags("", itemcount);
    } else if (!utils.isDefaultSpacePublic()) {
        return "redirect:" + SIGNINLINK + "?returnto=" + TAGSLINK;
    }
    model.addAttribute("path", "tags.vm");
    model.addAttribute("title", utils.getLang(req).get("tags.title"));
    model.addAttribute("tagsSelected", "navbtn-hover");
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("tagslist", tagslist);
    return "base";
}
Also used : Pager(com.erudika.para.core.utils.Pager) Tag(com.erudika.para.core.Tag) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Profile (com.erudika.scoold.core.Profile)85 PostMapping (org.springframework.web.bind.annotation.PostMapping)47 Post (com.erudika.scoold.core.Post)29 ParaObject (com.erudika.para.core.ParaObject)25 User (com.erudika.para.core.User)19 Pager (com.erudika.para.core.utils.Pager)19 HashMap (java.util.HashMap)15 LinkedHashMap (java.util.LinkedHashMap)15 Question (com.erudika.scoold.core.Question)13 Reply (com.erudika.scoold.core.Reply)13 Report (com.erudika.scoold.core.Report)11 IOException (java.io.IOException)11 List (java.util.List)11 Map (java.util.Map)11 UnapprovedReply (com.erudika.scoold.core.UnapprovedReply)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 Sysprop (com.erudika.para.core.Sysprop)9 Config (com.erudika.para.core.utils.Config)9 Utils (com.erudika.para.core.utils.Utils)9 Comment (com.erudika.scoold.core.Comment)9