Skip to content

Commit

Permalink
fixed visibility of unapproved questions and answers even if posts_ne…
Browse files Browse the repository at this point in the history
…ed_approval is set to false, #422
  • Loading branch information
albogdano committed Dec 3, 2023
1 parent 291df01 commit 53d000b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private Object getUserDescription(Profile showUser, Long questions, Long answers
public List<? extends Post> getQuestions(Profile authUser, Profile showUser, boolean isMyProfile, Pager itemcount) {
itemcount.setSortby("votes");
String spaceFilter = getSpaceFilter(authUser, isMyProfile);
if (CONF.postsNeedApproval() && (isMyProfile || utils.isMod(authUser))) {
if (isMyProfile || utils.isMod(authUser)) {
return pc.findQuery("", getTypeQuery(Utils.type(Question.class), Utils.type(Sticky.class),
Utils.type(UnapprovedQuestion.class)) + " AND " + getAuthorQuery(showUser) + spaceFilter, itemcount);
} else {
Expand All @@ -488,7 +488,7 @@ public List<? extends Post> getQuestions(Profile authUser, Profile showUser, boo
public List<? extends Post> getAnswers(Profile authUser, Profile showUser, boolean isMyProfile, Pager itemcount) {
itemcount.setSortby("votes");
String spaceFilter = getSpaceFilter(authUser, isMyProfile);
if (CONF.postsNeedApproval() && (isMyProfile || utils.isMod(authUser))) {
if (isMyProfile || utils.isMod(authUser)) {
return pc.findQuery("", getTypeQuery(Utils.type(Reply.class), Utils.type(UnapprovedReply.class))
+ " AND " + getAuthorQuery(showUser) + spaceFilter, itemcount);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.erudika.scoold.utils.ScooldUtils;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -95,6 +96,9 @@ public String get(@RequestParam(required = false, defaultValue = Config._TIMESTA
model.addAttribute("reportsSelected", "navbtn-hover");
model.addAttribute("itemcount", itemcount);
model.addAttribute("reportslist", reportslist);
Pager count = new Pager(1);
pc.findQuery("", "type:(" + Utils.type(UnapprovedQuestion.class) + " OR " + Utils.type(UnapprovedReply.class) + ")", count);
model.addAttribute("unapprovedCount", count.getCount());
return "base";
}

Expand Down Expand Up @@ -255,13 +259,15 @@ public String cleanupUnapproved(HttpServletRequest req, HttpServletResponse res)
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
if (utils.isAdmin(authUser)) {
List<String> toDelete = new LinkedList<>();
pc.readEverything(pager -> {
pager.setSelect(Collections.singletonList(Config._ID));
List<ParaObject> objects = pc.findQuery("", Config._TYPE + ":" + Utils.type(UnapprovedQuestion.class) +
" OR " + Config._TYPE + ":" + Utils.type(UnapprovedReply.class), pager);
pc.deleteAll(objects.stream().map(r -> r.getId()).collect(Collectors.toList()));
toDelete.addAll(objects.stream().map(r -> r.getId()).collect(Collectors.toList()));
return objects;
});
pc.deleteAll(toDelete);
}
}
return "redirect:" + REPORTSLINK;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/reports.vm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</a>
#if ($isAdmin)
<a href="$reportslink/$!showreport.id/delete" title="Delete" class="btn-flat red-text delete-report">
<strong>$!lang.get("delete")</strong>
<strong><i class="fa fa-trash-o"></i>&nbsp;$!lang.get("delete")</strong>
</a>
#end
</div>
Expand Down Expand Up @@ -110,7 +110,7 @@
<h2>$!lang.get("reports.title") #showcount($itemcount.count)</h2>
</div>
<div class="col m4 right-align">
#if ($isAdmin && $scooldUtils.config.postsNeedApproval())
#if ($isAdmin && $unapprovedCount > 0)
<span class="mrm">
<a href="$reportslink/cleanup-unapproved" class="red-text post-refresh rusure">
<i class="fa fa-trash-o"></i> $!lang.get('reports.cleanup')
Expand Down

0 comments on commit 53d000b

Please sign in to comment.