Skip to content

Commit 36a5838

Browse files
committed
added a couple of new webhook events - question.approve and answer.approve to trigger when a mod approves a post
1 parent 598f45a commit 36a5838

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/main/java/com/erudika/scoold/controllers/QuestionController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,17 @@ public String modApprove(@PathVariable String id, HttpServletRequest req) {
275275
if (utils.isMod(authUser)) {
276276
if (showPost instanceof UnapprovedQuestion) {
277277
showPost.setType(Utils.type(Question.class));
278+
showPost.setApprovedby(authUser);
278279
pc.create(showPost);
279280
// this notification here is redundant
280281
//utils.sendNewPostNotifications(showPost, req);
282+
utils.triggerHookEvent("question.approve", showPost);
281283
} else if (showPost instanceof UnapprovedReply) {
282284
showPost.setType(Utils.type(Reply.class));
285+
showPost.setApprovedby(authUser);
283286
addRepOnReplyOnce(pc.read(showPost.getParentid()), (Profile) pc.read(showPost.getCreatorid()), true);
284287
pc.create(showPost);
288+
utils.triggerHookEvent("answer.approve", showPost);
285289
}
286290
utils.deleteReportsAfterModAction(showPost);
287291
}

src/main/java/com/erudika/scoold/core/Post.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public abstract class Post extends Sysprop {
8686

8787
private transient Profile author;
8888
private transient Profile lastEditor;
89+
private transient Profile approvedby;
8990
private transient List<Comment> comments;
9091
private transient Pager itemcount;
9192
private transient Vote vote;
@@ -108,6 +109,14 @@ public void setApprovalTimestamp(Long approvalTimestamp) {
108109
this.approvalTimestamp = approvalTimestamp;
109110
}
110111

112+
public Profile getApprovedby() {
113+
return approvedby;
114+
}
115+
116+
public void setApprovedby(Profile approvedby) {
117+
this.approvedby = approvedby;
118+
}
119+
111120
public Boolean getDeprecated() {
112121
if (deprecated == null || isReply()) {
113122
deprecated = false;

src/main/java/com/erudika/scoold/utils/ScooldUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ public final class ScooldUtils {
146146
"question.create",
147147
"question.close",
148148
"question.view",
149+
"question.approve",
149150
"answer.create",
150151
"answer.accept",
152+
"answer.approve",
151153
"report.create",
152154
"comment.create",
153155
"user.signin",

0 commit comments

Comments
 (0)