Files
mostlymatter/api4/notify_admin.go
Allan Guwatudde bd42f0cd8c [MM-45564] - Notify Admin v2 (#20777)
* [MM-45564] - Notify Admin v2

* add dummy data

* update dummy data

* add store methods

* experiment with recurring task

* complete saving of the notification

* make improvements

* make improvements

* add store layer tests

* fix lint

* update store layer tests

* add app layer unit tests

* add store layers

* add app layer tests

* fix lint

* fix lint

* fix tests

* fix tests lint

* fix lint

* fix lint

* fix retry layer test

* add notifications manual trigger

* filter notifications based on current plan

* add test case

* temp change

* feedback impl

* fix translations

* change job scheduler

* refactor job

* fix store layer tests

* extract i18n

* fix lint

* fix translations

* fix translations

* add license statement for new file

* feedback impl-2

* fix lint

* update make file

* add intl ids

* improve

* fix lint

* feedback impl

* move code and rename files

* fix lint

* feedback impl

* add config for trigger notifications api

* fix tests

* tmp change

* undo temp changes

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2022-09-02 13:52:48 +03:00

58 строки
1.6 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"encoding/json"
"net/http"
"github.com/mattermost/mattermost-server/v6/model"
)
func handleNotifyAdmin(c *Context, w http.ResponseWriter, r *http.Request) {
var notifyAdminRequest *model.NotifyAdminToUpgradeRequest
err := json.NewDecoder(r.Body).Decode(&notifyAdminRequest)
if err != nil {
c.SetInvalidParamWithErr("notifyAdminRequest", err)
return
}
userId := c.AppContext.Session().UserId
appErr := c.App.SaveAdminNotification(userId, notifyAdminRequest)
if appErr != nil {
c.Err = appErr
return
}
ReturnStatusOK(w)
}
func handleTriggerNotifyAdminPosts(c *Context, w http.ResponseWriter, r *http.Request) {
if !*c.App.Config().ServiceSettings.EnableAPITriggerAdminNotifications {
c.Err = model.NewAppError("Api4.handleTriggerNotifyAdminPosts", "api.cloud.app_error", nil, "Manual triggering of notifications not allowed", http.StatusForbidden)
return
}
var notifyAdminRequest *model.NotifyAdminToUpgradeRequest
err := json.NewDecoder(r.Body).Decode(&notifyAdminRequest)
if err != nil {
c.SetInvalidParamWithErr("notifyAdminRequest", err)
return
}
// only system admins can manually trigger these notifications
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
c.SetPermissionError(model.PermissionManageSystem)
return
}
appErr := c.App.SendNotifyAdminPosts(c.AppContext, "", "", notifyAdminRequest.TrialNotification)
if appErr != nil {
c.Err = appErr
return
}
ReturnStatusOK(w)
}