Added ten new plugin hooks and split topic_unknown out of the user_unknown phrase.
Added the user parameter to the action hooks to give plugins more contextual information. Added the action_end_edit_topic plugin hook. Added the action_end_delete_topic plugin hook. Added the action_end_lock_topic plugin hook. Added the action_end_unlock_topic plugin hook. Added the action_end_stick_topic plugin hook. Added the action_end_unstick_topic plugin hook. Added the action_end_move_topic plugin hook. Added the action_end_like_topic plugin hook. Added the action_end_like_reply plugin hook. Added the tasks_tick_topic_list plugin hook.
This commit is contained in:
parent
9179eb9711
commit
29d14a4a4a
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
* Gosora Plugin System
|
||||
* Copyright Azareal 2016 - 2019
|
||||
* Copyright Azareal 2016 - 2020
|
||||
*
|
||||
*/
|
||||
package common
|
||||
@ -84,14 +84,27 @@ var hookTable = &HookTable{
|
||||
"forum_check_pre_perms": nil,
|
||||
|
||||
"action_end_create_topic": nil,
|
||||
"action_end_edit_topic":nil,
|
||||
"action_end_delete_topic":nil,
|
||||
"action_end_lock_topic":nil,
|
||||
"action_end_unlock_topic": nil,
|
||||
"action_end_stick_topic": nil,
|
||||
"action_end_unstick_topic": nil,
|
||||
"action_end_move_topic": nil,
|
||||
"action_end_like_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,
|
||||
|
||||
"action_end_like_reply":nil,
|
||||
|
||||
"router_after_filters": nil,
|
||||
"router_pre_route": nil,
|
||||
|
||||
"tasks_tick_topic_list": nil,
|
||||
},
|
||||
map[string][]func(string) string{
|
||||
"preparse_preassign": nil,
|
||||
|
@ -112,6 +112,9 @@ func (tList *DefaultTopicList) Tick() error {
|
||||
tList.evenGroups = evenLists
|
||||
tList.evenLock.Unlock()
|
||||
|
||||
hTbl := GetHookTable()
|
||||
_, _ = hTbl.VhookSkippable("tasks_tick_topic_list", tList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -920,6 +920,7 @@
|
||||
"panel_logs_moderation_action_unknown":"Unknown action '%s' on elementType '%s' by <a href='%s'>%s</a>",
|
||||
|
||||
"user_unknown":"Unknown",
|
||||
"topic_unknown":"Unknown",
|
||||
|
||||
"panel_logs_administration_head":"Admin Action Logs",
|
||||
|
||||
|
@ -47,7 +47,7 @@ func handleUnknownUser(user *common.User, err error) *common.User {
|
||||
}
|
||||
func handleUnknownTopic(topic *common.Topic, err error) *common.Topic {
|
||||
if err != nil {
|
||||
return &common.Topic{Title: phrases.GetTmplPhrase("user_unknown"), Link: common.BuildTopicURL("unknown", 0)}
|
||||
return &common.Topic{Title: phrases.GetTmplPhrase("topic_unknown"), Link: common.BuildTopicURL("unknown", 0)}
|
||||
}
|
||||
return topic
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
|
||||
}
|
||||
|
||||
counters.PostCounter.Bump()
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_create_reply", reply.ID)
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_create_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
@ -261,7 +261,7 @@ func ReplyEditSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
return common.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_edit_reply", reply.ID)
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_edit_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
@ -316,7 +316,7 @@ func ReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User,
|
||||
return common.InternalErrorJSQ(err, w, r, isJs)
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_delete_reply", reply.ID)
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_delete_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
@ -389,7 +389,7 @@ 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)
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_add_attach_to_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
@ -452,7 +452,7 @@ func RemoveAttachFromReplySubmit(w http.ResponseWriter, r *http.Request, user co
|
||||
}
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_remove_attach_from_reply", reply.ID)
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_remove_attach_from_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
@ -597,7 +597,7 @@ func ReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -629,6 +629,11 @@ func ReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
return common.InternalErrorJSQ(err, w, r, isJs)
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_like_reply", reply.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
||||
if !isJs {
|
||||
http.Redirect(w, r, "/topic/"+strconv.Itoa(reply.ParentID), http.StatusSeeOther)
|
||||
} else {
|
||||
|
@ -651,7 +651,7 @@ func EditTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -689,6 +689,11 @@ func EditTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
return common.InternalErrorJSQ(err, w, r, isJs)
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_edit_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
||||
if !isJs {
|
||||
http.Redirect(w, r, "/topic/"+strconv.Itoa(tid), http.StatusSeeOther)
|
||||
} else {
|
||||
@ -736,7 +741,7 @@ func DeleteTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -761,6 +766,12 @@ func DeleteTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
|
||||
return common.InternalErrorJSQ(err,w,r,isJs)
|
||||
}*/
|
||||
|
||||
// TODO: Do a bulk delete action hook?
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_delete_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
||||
log.Printf("Topic #%d was deleted by UserID #%d", tid, user.ID)
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
@ -768,39 +779,39 @@ func DeleteTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
|
||||
}
|
||||
|
||||
func StickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
|
||||
topic, rerr := topicActionPre(stid, "pin", w, r, user)
|
||||
topic, lite,rerr := topicActionPre(stid, "pin", w, r, user)
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
if !user.Perms.ViewTopic || !user.Perms.PinTopic {
|
||||
return common.NoPermissions(w, r, user)
|
||||
}
|
||||
return topicActionPost(topic.Stick(), "stick", w, r, topic, user)
|
||||
return topicActionPost(topic.Stick(), "stick", w, r, lite,topic, user)
|
||||
}
|
||||
|
||||
func topicActionPre(stid string, action string, w http.ResponseWriter, r *http.Request, user common.User) (*common.Topic, common.RouteError) {
|
||||
func topicActionPre(stid string, action string, w http.ResponseWriter, r *http.Request, user common.User) (*common.Topic, *common.HeaderLite, common.RouteError) {
|
||||
tid, err := strconv.Atoi(stid)
|
||||
if err != nil {
|
||||
return nil, common.PreError(phrases.GetErrorPhrase("id_must_be_integer"), w, r)
|
||||
return nil, nil,common.PreError(phrases.GetErrorPhrase("id_must_be_integer"), w, r)
|
||||
}
|
||||
|
||||
topic, err := common.Topics.Get(tid)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, common.PreError("The topic you tried to "+action+" doesn't exist.", w, r)
|
||||
return nil, nil,common.PreError("The topic you tried to "+action+" doesn't exist.", w, r)
|
||||
} else if err != nil {
|
||||
return nil, common.InternalError(err, w, r)
|
||||
return nil, nil,common.InternalError(err, w, r)
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return nil, ferr
|
||||
return nil, nil,ferr
|
||||
}
|
||||
|
||||
return topic, nil
|
||||
return topic, lite, nil
|
||||
}
|
||||
|
||||
func topicActionPost(err error, action string, w http.ResponseWriter, r *http.Request, topic *common.Topic, user common.User) common.RouteError {
|
||||
func topicActionPost(err error, action string, w http.ResponseWriter, r *http.Request, lite *common.HeaderLite, topic *common.Topic, user common.User) common.RouteError {
|
||||
if err != nil {
|
||||
return common.InternalError(err, w, r)
|
||||
}
|
||||
@ -808,19 +819,23 @@ func topicActionPost(err error, action string, w http.ResponseWriter, r *http.Re
|
||||
if err != nil {
|
||||
return common.InternalError(err, w, r)
|
||||
}
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_"+action+"_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
http.Redirect(w, r, "/topic/"+strconv.Itoa(topic.ID), http.StatusSeeOther)
|
||||
return nil
|
||||
}
|
||||
|
||||
func UnstickTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
|
||||
topic, rerr := topicActionPre(stid, "unpin", w, r, user)
|
||||
topic, lite, rerr := topicActionPre(stid, "unpin", w, r, user)
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
if !user.Perms.ViewTopic || !user.Perms.PinTopic {
|
||||
return common.NoPermissions(w, r, user)
|
||||
}
|
||||
return topicActionPost(topic.Unstick(), "unstick", w, r, topic, user)
|
||||
return topicActionPost(topic.Unstick(), "unstick", w, r, lite,topic, user)
|
||||
}
|
||||
|
||||
func LockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
||||
@ -856,7 +871,7 @@ func LockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) c
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -873,6 +888,12 @@ func LockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) c
|
||||
if err != nil {
|
||||
return common.InternalErrorJSQ(err, w, r, isJs)
|
||||
}
|
||||
|
||||
// TODO: Do a bulk lock action hook?
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_lock_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
}
|
||||
|
||||
if len(tids) == 1 {
|
||||
@ -882,14 +903,14 @@ func LockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User) c
|
||||
}
|
||||
|
||||
func UnlockTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, stid string) common.RouteError {
|
||||
topic, rerr := topicActionPre(stid, "unlock", w, r, user)
|
||||
topic, lite,rerr := topicActionPre(stid, "unlock", w, r, user)
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
if !user.Perms.ViewTopic || !user.Perms.CloseTopic {
|
||||
return common.NoPermissions(w, r, user)
|
||||
}
|
||||
return topicActionPost(topic.Unlock(), "unlock", w, r, topic, user)
|
||||
return topicActionPost(topic.Unlock(), "unlock", w, r, lite,topic, user)
|
||||
}
|
||||
|
||||
// ! JS only route
|
||||
@ -929,7 +950,7 @@ func MoveTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
if !user.Perms.ViewTopic || !user.Perms.MoveTopic {
|
||||
return common.NoPermissionsJS(w, r, user)
|
||||
}
|
||||
_, ferr = common.SimpleForumUserCheck(w, r, &user, fid)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, fid)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -947,6 +968,12 @@ func MoveTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
if err != nil {
|
||||
return common.InternalErrorJS(err, w, r)
|
||||
}
|
||||
|
||||
// TODO: Do a bulk move action hook?
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_move_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
}
|
||||
|
||||
if len(tids) == 1 {
|
||||
@ -979,7 +1006,7 @@ func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
}
|
||||
|
||||
// TODO: Add hooks to make use of headerLite
|
||||
_, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
lite, ferr := common.SimpleForumUserCheck(w, r, &user, topic.ParentID)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -1012,6 +1039,11 @@ func LikeTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s
|
||||
return common.InternalErrorJSQ(err, w, r, isJs)
|
||||
}
|
||||
|
||||
skip, rerr := lite.Hooks.VhookSkippable("action_end_like_topic", topic.ID, &user)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
||||
if !isJs {
|
||||
http.Redirect(w, r, "/topic/"+strconv.Itoa(tid), http.StatusSeeOther)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user