Add metric warning support (announcement bar and DM) (#14483)
* Admin. Advisory: Add warning for number of active users metric status Co-authored-by: Catalin Tomai <catalin.tomai@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
56fb31f06f
Коммит
549e5b57cd
@@ -54,6 +54,9 @@ func (api *API) InitSystem() {
|
||||
api.BaseRoutes.ApiRoot.Handle("/server_busy", api.ApiSessionRequired(setServerBusy)).Methods("POST")
|
||||
api.BaseRoutes.ApiRoot.Handle("/server_busy", api.ApiSessionRequired(getServerBusyExpires)).Methods("GET")
|
||||
api.BaseRoutes.ApiRoot.Handle("/server_busy", api.ApiSessionRequired(clearServerBusy)).Methods("DELETE")
|
||||
|
||||
api.BaseRoutes.ApiRoot.Handle("/warn_metrics/status", api.ApiSessionRequired(getWarnMetricsStatus)).Methods("GET")
|
||||
api.BaseRoutes.ApiRoot.Handle("/warn_metrics/ack/{warn_metric_id:[A-Za-z0-9-_]+}", api.ApiHandler(sendWarnMetricAckEmail)).Methods("POST")
|
||||
}
|
||||
|
||||
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -544,3 +547,61 @@ func getServerBusyExpires(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
w.Write([]byte(c.App.Srv().Busy.ToJson()))
|
||||
}
|
||||
|
||||
func getWarnMetricsStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
license := c.App.Srv().License()
|
||||
if license != nil {
|
||||
mlog.Debug("License is present, skip.")
|
||||
return
|
||||
}
|
||||
|
||||
status, err := c.App.GetWarnMetricsStatus()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapWarnMetricStatusToJson(status)))
|
||||
}
|
||||
|
||||
func sendWarnMetricAckEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("sendWarnMetricAckEmail", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
license := c.App.Srv().License()
|
||||
if license != nil {
|
||||
mlog.Debug("License is present, skip.")
|
||||
return
|
||||
}
|
||||
|
||||
user, appErr := c.App.GetUser(c.App.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
ack := model.SendWarnMetricAckFromJson(r.Body)
|
||||
if ack == nil {
|
||||
c.SetInvalidParam("ack")
|
||||
return
|
||||
}
|
||||
|
||||
appErr = c.App.NotifyAndSetWarnMetricAck(c.Params.WarnMetricId, user, ack.ForceAck, false)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user