From 3db09c6a1f9f33c47e64b2df1dcf80448f2052c1 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 11 Apr 2019 14:22:03 +1000 Subject: [PATCH] Give users access to the attachment manager without having to upload any files. Added the action_end_add_attach_to_reply hook. Added the action_end_remove_attach_from_reply hook. --- common/extend.go | 10 ++++++---- public/global.js | 4 +--- routes/reply.go | 14 ++++++++++++-- templates/topic_alt.html | 4 ++-- templates/topic_alt_posts.html | 4 ++-- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/common/extend.go b/common/extend.go index ce0b0d35..52995712 100644 --- a/common/extend.go +++ b/common/extend.go @@ -83,10 +83,12 @@ var hookTable = &HookTable{ "simple_forum_check_pre_perms": nil, "forum_check_pre_perms": nil, - "action_end_create_topic": nil, - "action_end_create_reply": nil, - "action_end_edit_reply": nil, - "action_end_delete_reply": nil, + "action_end_create_topic": nil, + "action_end_create_reply": nil, + "action_end_edit_reply": nil, + "action_end_delete_reply": nil, + "action_end_add_attach_to_reply": nil, + "action_end_remove_attach_from_reply": nil, "router_after_filters": nil, "router_pre_route": nil, diff --git a/public/global.js b/public/global.js index 608dcdb5..505b69d7 100644 --- a/public/global.js +++ b/public/global.js @@ -1076,9 +1076,7 @@ function mainInit(){ $("#mod_topic_mover .pane_row").click(function(){ modTopicMover.find(".pane_row").removeClass("pane_selected"); let fid = this.getAttribute("data-fid"); - if (fid == null) { - return; - } + if (fid == null) return; this.classList.add("pane_selected"); console.log("fid: " + fid); forumToMoveTo = fid; diff --git a/routes/reply.go b/routes/reply.go index 2c3e99ca..009fc596 100644 --- a/routes/reply.go +++ b/routes/reply.go @@ -368,7 +368,7 @@ func AddAttachToReplySubmit(w http.ResponseWriter, r *http.Request, user common. return common.NotFoundJS(w, r) } - _, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID) + lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID) if ferr != nil { return ferr } @@ -389,6 +389,11 @@ func AddAttachToReplySubmit(w http.ResponseWriter, r *http.Request, user common. return common.InternalErrorJS(errors.New("no paths for attachment add"), w, r) } + skip, rerr := lite.Hooks.VhookSkippable("action_end_add_attach_to_reply", reply.ID) + if skip || rerr != nil { + return rerr + } + var elemStr string for path, aids := range pathMap { elemStr += "\"" + path + "\":\"" + aids + "\"," @@ -420,7 +425,7 @@ func RemoveAttachFromReplySubmit(w http.ResponseWriter, r *http.Request, user co return common.NotFoundJS(w, r) } - _, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID) + lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID) if ferr != nil { return ferr } @@ -443,6 +448,11 @@ func RemoveAttachFromReplySubmit(w http.ResponseWriter, r *http.Request, user co } } + skip, rerr := lite.Hooks.VhookSkippable("action_end_remove_attach_from_reply", reply.ID) + if skip || rerr != nil { + return rerr + } + w.Write(successJSONBytes) return nil } diff --git a/templates/topic_alt.html b/templates/topic_alt.html index cc613434..d4158194 100644 --- a/templates/topic_alt.html +++ b/templates/topic_alt.html @@ -68,7 +68,7 @@ {{if .CurrentUser.Loggedin}} {{if .CurrentUser.Perms.EditTopic}} - {{if .Topic.Attachments}}
+
{{range .Topic.Attachments}}
{{if .Image}}{{end}} @@ -83,7 +83,7 @@ {{end}}
-
{{end}} +
{{end}}{{end}}
diff --git a/templates/topic_alt_posts.html b/templates/topic_alt_posts.html index b43a088a..b124de8f 100644 --- a/templates/topic_alt_posts.html +++ b/templates/topic_alt_posts.html @@ -10,7 +10,7 @@
{{.Content}}
{{if $.CurrentUser.Perms.EditReply}} - {{if .Attachments}}
+
{{range .Attachments}}
{{if .Image}}{{end}} @@ -25,7 +25,7 @@ {{end}}
-
{{end}} +
{{end}}{{end}}