Search in sources :

Example 1 with PEOPLELINK

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";
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) SIGNINLINK(com.erudika.scoold.ScooldServer.SIGNINLINK) Question(com.erudika.scoold.core.Question) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Pager(com.erudika.para.core.utils.Pager) Controller(org.springframework.stereotype.Controller) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Badge(com.erudika.scoold.core.Profile.Badge) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Model(org.springframework.ui.Model) MODS(com.erudika.para.core.User.Groups.MODS) com.erudika.scoold.utils.avatars(com.erudika.scoold.utils.avatars) 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) PEOPLELINK(com.erudika.scoold.ScooldServer.PEOPLELINK) Post(com.erudika.scoold.core.Post) HttpServletResponse(javax.servlet.http.HttpServletResponse) PROFILELINK(com.erudika.scoold.ScooldServer.PROFILELINK) User(com.erudika.para.core.User) Utils(com.erudika.para.core.utils.Utils) List(java.util.List) USERS(com.erudika.para.core.User.Groups.USERS) Reply(com.erudika.scoold.core.Reply) Profile(com.erudika.scoold.core.Profile) Pager(com.erudika.para.core.utils.Pager) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with PEOPLELINK

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() : "");
}
Also used : SIGNINLINK(com.erudika.scoold.ScooldServer.SIGNINLINK) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ParaClient(com.erudika.para.client.ParaClient) Pager(com.erudika.para.core.utils.Pager) Controller(org.springframework.stereotype.Controller) HashSet(java.util.HashSet) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Model(org.springframework.ui.Model) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) LinkedList(java.util.LinkedList) Config(com.erudika.para.core.utils.Config) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) ParaObject(com.erudika.para.core.ParaObject) PEOPLELINK(com.erudika.scoold.ScooldServer.PEOPLELINK) HttpServletResponse(javax.servlet.http.HttpServletResponse) Utils(com.erudika.para.core.utils.Utils) HttpUtils(com.erudika.scoold.utils.HttpUtils) List(java.util.List) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) HashMap(java.util.HashMap) Profile(com.erudika.scoold.core.Profile) LinkedList(java.util.LinkedList) Pager(com.erudika.para.core.utils.Pager) ParaObject(com.erudika.para.core.ParaObject) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

Config (com.erudika.para.core.utils.Config)2 Pager (com.erudika.para.core.utils.Pager)2 Utils (com.erudika.para.core.utils.Utils)2 PEOPLELINK (com.erudika.scoold.ScooldServer.PEOPLELINK)2 SIGNINLINK (com.erudika.scoold.ScooldServer.SIGNINLINK)2 Profile (com.erudika.scoold.core.Profile)2 ScooldUtils (com.erudika.scoold.utils.ScooldUtils)2 List (java.util.List)2 Inject (javax.inject.Inject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Controller (org.springframework.stereotype.Controller)2 Model (org.springframework.ui.Model)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RequestParam (org.springframework.web.bind.annotation.RequestParam)2 ParaClient (com.erudika.para.client.ParaClient)1 ParaObject (com.erudika.para.core.ParaObject)1 User (com.erudika.para.core.User)1