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