use of com.erudika.scoold.ScooldServer.PEOPLELINK in project scoold by Erudika.
the class ProfileController method get.
@GetMapping({ "", "/{id}/**" })
public String get(@PathVariable(required = false) String id, HttpServletRequest req, Model model) {
if (!utils.isAuthenticated(req) && StringUtils.isBlank(id)) {
return "redirect:" + SIGNINLINK + "?returnto=" + PROFILELINK;
}
Profile authUser = utils.getAuthUser(req);
Profile showUser;
boolean isMyProfile;
if (StringUtils.isBlank(id) || isMyid(authUser, Profile.id(id))) {
// requested userid !exists or = my userid => show my profile
showUser = authUser;
isMyProfile = true;
} else {
showUser = utils.getParaClient().read(Profile.id(id));
isMyProfile = isMyid(authUser, Profile.id(id));
}
if (showUser == null || !ParaObjectUtils.typesMatch(showUser)) {
return "redirect:" + PROFILELINK;
}
boolean protekted = !utils.isDefaultSpacePublic() && !utils.isAuthenticated(req);
boolean sameSpace = (utils.canAccessSpace(showUser, "default") && utils.canAccessSpace(authUser, "default")) || (authUser != null && showUser.getSpaces().stream().anyMatch(s -> utils.canAccessSpace(authUser, s)));
if (protekted || !sameSpace) {
return "redirect:" + PEOPLELINK;
}
Pager itemcount1 = utils.getPager("page1", req);
Pager itemcount2 = utils.getPager("page2", req);
List<? extends Post> questionslist = getQuestions(authUser, showUser, isMyProfile, itemcount1);
List<? extends Post> answerslist = getAnswers(authUser, showUser, isMyProfile, itemcount2);
model.addAttribute("path", "profile.vm");
model.addAttribute("title", utils.getLang(req).get("profile.title") + " - " + showUser.getName());
model.addAttribute("description", getUserDescription(showUser, itemcount1.getCount(), itemcount2.getCount()));
model.addAttribute("ogimage", avatarRepository.getLink(showUser, AvatarFormat.Profile));
model.addAttribute("includeGMapsScripts", utils.isNearMeFeatureEnabled());
model.addAttribute("showUser", showUser);
model.addAttribute("isMyProfile", isMyProfile);
model.addAttribute("badgesCount", showUser.getBadgesMap().size());
model.addAttribute("canEdit", isMyProfile || canEditProfile(authUser, id));
model.addAttribute("canEditAvatar", Config.getConfigBoolean("avatar_edits_enabled", true));
model.addAttribute("gravatarPicture", gravatarAvatarGenerator.getLink(showUser, AvatarFormat.Profile));
model.addAttribute("isGravatarPicture", gravatarAvatarGenerator.isLink(showUser.getPicture()));
model.addAttribute("itemcount1", itemcount1);
model.addAttribute("itemcount2", itemcount2);
model.addAttribute("questionslist", questionslist);
model.addAttribute("answerslist", answerslist);
model.addAttribute("nameEditsAllowed", Config.getConfigBoolean("name_edits_enabled", true));
return "base";
}
use of com.erudika.scoold.ScooldServer.PEOPLELINK in project scoold by Erudika.
the class PeopleController method bulkEdit.
@PostMapping("/bulk-edit")
public String bulkEdit(@RequestParam(required = false) String[] selectedUsers, @RequestParam(required = false) final String[] selectedSpaces, HttpServletRequest req) {
Profile authUser = utils.getAuthUser(req);
boolean isAdmin = utils.isAdmin(authUser);
String operation = req.getParameter("operation");
String selection = req.getParameter("selection");
if (isAdmin && ("all".equals(selection) || selectedUsers != null)) {
// find all user objects even if there are more than 10000 users in the system
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<Profile> profiles;
LinkedList<Map<String, Object>> toUpdate = new LinkedList<>();
List<String> spaces = (selectedSpaces == null || selectedSpaces.length == 0) ? Collections.emptyList() : Arrays.asList(selectedSpaces);
do {
String query = (selection == null || "selected".equals(selection)) ? Config._ID + ":(\"" + String.join("\" \"", selectedUsers) + "\")" : "*";
profiles = pc.findQuery(Utils.type(Profile.class), query, pager);
profiles.stream().filter(p -> !utils.isMod(p)).forEach(p -> {
if ("add".equals(operation)) {
p.getSpaces().addAll(spaces);
} else if ("remove".equals(operation)) {
p.getSpaces().removeAll(spaces);
} else {
p.setSpaces(new HashSet<String>(spaces));
}
Map<String, Object> profile = new HashMap<>();
profile.put(Config._ID, p.getId());
profile.put("spaces", p.getSpaces());
toUpdate.add(profile);
});
} while (!profiles.isEmpty());
// always patch outside the loop because we modify _docid values!!!
LinkedList<Map<String, Object>> batch = new LinkedList<>();
while (!toUpdate.isEmpty()) {
batch.add(toUpdate.pop());
if (batch.size() >= 100) {
// partial batch update
pc.invokePatch("_batch", batch, Map.class);
batch.clear();
}
}
if (!batch.isEmpty()) {
pc.invokePatch("_batch", batch, Map.class);
}
}
return "redirect:" + PEOPLELINK + (isAdmin ? "?" + req.getQueryString() : "");
}
Aggregations