mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
It was a good decision in hindsight to keep the public module as 0.x because this would have been a breaking change again. https://mattermost.atlassian.net/browse/MM-53032 ```release-note Changed the Go module path from github.com/mattermost/mattermost-server/server/v8 to github.com/mattermost/mattermost/server/v8. For the public facing module, it's path is also changed from github.com/mattermost/mattermost-server/server/public to github.com/mattermost/mattermost/server/public ```
58 lines
1.6 KiB
Go
58 lines
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/public/model"
|
|
)
|
|
|
|
func handleNotifyAdmin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
var notifyAdminRequest *model.NotifyAdminToUpgradeRequest
|
|
err := json.NewDecoder(r.Body).Decode(¬ifyAdminRequest)
|
|
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(¬ifyAdminRequest)
|
|
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)
|
|
}
|