Skip to content

Commit

Permalink
fixed bug which caused reports to be left uncleared for posts that we…
Browse files Browse the repository at this point in the history
…re already approved
  • Loading branch information
albogdano committed Jun 14, 2024
1 parent 4ccc760 commit 3f7295b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public String reply(@PathVariable String id, @PathVariable(required = false) Str
model.addAttribute("showPost", showPost);
model.addAttribute("answerslist", Collections.singletonList(answer));
// send email to the question author
utils.sendReplyNotifications(showPost, answer, req);
utils.sendReplyNotifications(showPost, answer, needsApproval, req);
model.addAttribute("newpost", getNewAnswerPayload(answer));
} else {
model.addAttribute("error", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public String post(@RequestParam(required = false) String location, @RequestPara
q.setId(qid);
q.setLocation(location);
q.create();
utils.sendNewPostNotifications(q, req);
utils.sendNewPostNotifications(q, needsApproval, req);
if (!StringUtils.isBlank(latlng)) {
Address addr = new Address(qid + Para.getConfig().separator() + Utils.type(Address.class));
addr.setAddress(address);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import com.erudika.scoold.core.Reply;
import com.erudika.scoold.core.Report;
import com.erudika.scoold.core.Revision;
import com.erudika.scoold.core.UnapprovedQuestion;
import com.erudika.scoold.core.UnapprovedReply;
import static com.erudika.scoold.utils.HttpUtils.getCookieValue;
import com.erudika.scoold.utils.avatars.AvatarFormat;
import com.erudika.scoold.utils.avatars.AvatarRepository;
Expand Down Expand Up @@ -686,7 +684,7 @@ public void sendUpdatedFavTagsNotifications(Post question, List<String> addedTag
}

@SuppressWarnings("unchecked")
public void sendNewPostNotifications(Post question, HttpServletRequest req) {
public void sendNewPostNotifications(Post question, boolean needApproval, HttpServletRequest req) {
if (question == null || req.getParameter("notificationsDisabled") != null) {
return;
}
Expand All @@ -695,7 +693,7 @@ public void sendNewPostNotifications(Post question, HttpServletRequest req) {
if (!isNewPostNotificationAllowed()) {
return;
}
boolean awaitingApproval = postsNeedApproval(req) || question instanceof UnapprovedQuestion;
boolean awaitingApproval = needApproval;
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> lang = getLang(req);
String name = postAuthor.getName();
Expand All @@ -717,7 +715,9 @@ public void sendNewPostNotifications(Post question, HttpServletRequest req) {
Set<String> emails = new HashSet<String>(getNotificationSubscribers(EMAIL_ALERTS_PREFIX + "new_post_subscribers"));
emails.addAll(getFavTagsSubscribers(question.getTags()));
sendEmailsToSubscribersInSpace(emails, question.getSpace(), subject, compileEmailTemplate(model));
createReportCopyOfNotificiation(name, postURL, subject, body, awaitingApproval);
if (!isMod(postAuthor)) {
createReportCopyOfNotificiation(name, postURL, subject, body, awaitingApproval);
}

if (awaitingApproval) {
Report rep = new Report();
Expand All @@ -733,14 +733,14 @@ public void sendNewPostNotifications(Post question, HttpServletRequest req) {
}
}

public void sendReplyNotifications(Post parentPost, Post reply, HttpServletRequest req) {
public void sendReplyNotifications(Post parentPost, Post reply, boolean needApproval, HttpServletRequest req) {
// send email notification to author of post except when the reply is by the same person
if (parentPost == null || reply == null) {
return;
}
Map<String, String> lang = getLang(req);
Profile replyAuthor = reply.getAuthor(); // the current user - same as utils.getAuthUser(req)
boolean awaitingApproval = postsNeedApproval(req) || reply instanceof UnapprovedReply;
boolean awaitingApproval = needApproval;
Map<String, Object> model = new HashMap<String, Object>();
String name = replyAuthor.getName();
String body = Utils.markdownToHtml(reply.getBody());
Expand Down Expand Up @@ -776,7 +776,7 @@ public void sendReplyNotifications(Post parentPost, Post reply, HttpServletReque
}
}

if (isReplyNotificationAllowed()) {
if (isReplyNotificationAllowed() && !isMod(replyAuthor)) {
createReportCopyOfNotificiation(name, postURL, subject, body, awaitingApproval);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/reports.vm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="col m12">
#if($showreport.properties.size() > 0)
#foreach($key in $showreport.properties.keySet())
#if($key != "key")
#if($key != "key" && $!showreport.properties.get($key))
<div><code><b>$!key</b>: $!showreport.properties.get($key)</code></div>
#end
#end
Expand Down

0 comments on commit 3f7295b

Please sign in to comment.