Search in sources :

Example 66 with Profile

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

the class QuestionController method modApprove.

@PostMapping("/{id}/approve")
public String modApprove(@PathVariable String id, HttpServletRequest req) {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    if (utils.isMod(authUser)) {
        if (showPost instanceof UnapprovedQuestion) {
            showPost.setType(Utils.type(Question.class));
            pc.create(showPost);
            utils.sendNewPostNotifications(showPost, req);
        } else if (showPost instanceof UnapprovedReply) {
            showPost.setType(Utils.type(Reply.class));
            pc.create(showPost);
        }
    }
    return "redirect:" + showPost.getPostLink(false, false);
}
Also used : UnapprovedReply(com.erudika.scoold.core.UnapprovedReply) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Post(com.erudika.scoold.core.Post) Question(com.erudika.scoold.core.Question) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 67 with Profile

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

the class QuestionController method delete.

@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req, Model model) {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    if (!utils.canEdit(showPost, authUser) || showPost == null) {
        model.addAttribute("post", showPost);
        return "redirect:" + req.getRequestURI();
    }
    if (!showPost.isReply()) {
        if ((utils.isMine(showPost, authUser) && utils.canDelete(showPost, authUser)) || utils.isMod(authUser)) {
            showPost.delete();
            model.addAttribute("deleted", true);
            return "redirect:" + QUESTIONSLINK + "?success=true&code=16";
        }
    } else if (showPost.isReply()) {
        Post parent = pc.read(showPost.getParentid());
        if ((utils.isMine(showPost, authUser) && utils.canDelete(showPost, authUser, parent.getAnswerid())) || utils.isMod(authUser)) {
            parent.setAnswercount(parent.getAnswercount() - 1);
            parent.setAnswerid(showPost.getId().equals(parent.getAnswerid()) ? "" : parent.getAnswerid());
            parent.update();
            showPost.delete();
            model.addAttribute("deleted", true);
        }
    }
    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)

Example 68 with Profile

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

the class ReportsController method delete.

@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        Report rep = pc.read(id);
        if (rep != null && utils.isAdmin(authUser)) {
            rep.delete();
        }
    }
    if (!utils.isAjaxRequest(req)) {
        return "redirect:" + REPORTSLINK;
    }
    return "base";
}
Also used : Report(com.erudika.scoold.core.Report) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 69 with Profile

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

the class ScooldUtils method fetchProfiles.

public void fetchProfiles(List<? extends ParaObject> objects) {
    if (objects == null || objects.isEmpty()) {
        return;
    }
    Map<String, String> authorids = new HashMap<String, String>(objects.size());
    Map<String, Profile> authors = new HashMap<String, Profile>(objects.size());
    for (ParaObject obj : objects) {
        if (obj.getCreatorid() != null) {
            authorids.put(obj.getId(), obj.getCreatorid());
        }
    }
    List<String> ids = new ArrayList<String>(new HashSet<String>(authorids.values()));
    if (ids.isEmpty()) {
        return;
    }
    // read all post authors in batch
    for (ParaObject author : pc.readAll(ids)) {
        authors.put(author.getId(), (Profile) author);
    }
    // add system profile
    authors.put(API_USER.getId(), API_USER);
    // set author object for each post
    for (ParaObject obj : objects) {
        if (obj instanceof Post) {
            ((Post) obj).setAuthor(authors.get(authorids.get(obj.getId())));
        } else if (obj instanceof Revision) {
            ((Revision) obj).setAuthor(authors.get(authorids.get(obj.getId())));
        }
    }
}
Also used : Revision(com.erudika.scoold.core.Revision) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParaObject(com.erudika.para.core.ParaObject) Post(com.erudika.scoold.core.Post) ArrayList(java.util.ArrayList) Profile(com.erudika.scoold.core.Profile)

Example 70 with Profile

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

the class AvatarRepositoryProxyTest method setUp.

@Before
public void setUp() {
    this.gravatarAvatarGeneratorFake = mock(GravatarAvatarGenerator.class);
    this.profile = new Profile();
    this.profile.setUser(new User());
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile) Before(org.junit.Before)

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