[APIV4] POST /hooks/outgoing/{hook_id}/regen_token - regentoken endpoint for apiV4 (#5783)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
4efefa0ff6
Коммит
3d14573b8c
@@ -23,6 +23,7 @@ func InitWebhook() {
|
||||
|
||||
BaseRoutes.OutgoingHooks.Handle("", ApiSessionRequired(createOutgoingHook)).Methods("POST")
|
||||
BaseRoutes.OutgoingHooks.Handle("", ApiSessionRequired(getOutgoingHooks)).Methods("GET")
|
||||
BaseRoutes.OutgoingHook.Handle("/regen_token", ApiSessionRequired(regenOutgoingHookToken)).Methods("POST")
|
||||
}
|
||||
|
||||
func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -287,3 +288,36 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Write([]byte(model.OutgoingWebhookListToJson(hooks)))
|
||||
}
|
||||
|
||||
func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireHookId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
hook, err := app.GetOutgoingWebhook(c.Params.HookId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !app.SessionHasPermissionToTeam(c.Session, hook.TeamId, model.PERMISSION_MANAGE_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.Session.UserId != hook.CreatorId && !app.SessionHasPermissionToTeam(c.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if rhook, err := app.RegenOutgoingWebhookToken(hook); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(rhook.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user