2021-04-21 11:35:47 -04:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
2024-10-04 13:12:32 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
2021-04-21 11:35:47 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (api *API) InitPermissions() {
|
2024-07-15 10:52:03 -04:00
|
|
|
api.BaseRoutes.Permissions.Handle("/ancillary", api.APISessionRequired(appendAncillaryPermissionsPost)).Methods(http.MethodPost)
|
2021-04-21 11:35:47 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-10 10:12:56 -04:00
|
|
|
func appendAncillaryPermissionsPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
permissions, err := model.NonSortedArrayFromJSON(r.Body)
|
|
|
|
|
if err != nil || len(permissions) < 1 {
|
|
|
|
|
c.Err = model.NewAppError("appendAncillaryPermissionsPost", model.PayloadParseError, nil, "", http.StatusBadRequest).Wrap(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
b, err := json.Marshal(model.AddAncillaryPermissions(permissions))
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.SetJSONEncodingError(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-10-04 13:12:32 -04:00
|
|
|
if _, err := w.Write(b); err != nil {
|
|
|
|
|
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
|
|
|
|
}
|
2024-07-10 10:12:56 -04:00
|
|
|
}
|