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