[MM-34838] Remove Ancillary Permissions That Are Purposefully Being Removed (#17466)
* remove ancillary permissions * Start writing tests * Move Ancillary Permissions to FrontEnd * remove function * remove test * clean up * fix comment * Update api4/permission.go Co-authored-by: Martin Kraft <martinkraft@gmail.com> * Update api4/permission.go * Update api4/permission.go * license info * Add Tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Martin Kraft <martinkraft@gmail.com>
Этот коммит содержится в:
@@ -131,6 +131,8 @@ type Routes struct {
|
|||||||
|
|
||||||
RemoteCluster *mux.Router // 'api/v4/remotecluster'
|
RemoteCluster *mux.Router // 'api/v4/remotecluster'
|
||||||
SharedChannels *mux.Router // 'api/v4/sharedchannels'
|
SharedChannels *mux.Router // 'api/v4/sharedchannels'
|
||||||
|
|
||||||
|
Permissions *mux.Router // 'api/v4/permissions'
|
||||||
}
|
}
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
@@ -250,6 +252,8 @@ func Init(configservice configservice.ConfigService, globalOptionsFunc app.AppOp
|
|||||||
api.BaseRoutes.RemoteCluster = api.BaseRoutes.ApiRoot.PathPrefix("/remotecluster").Subrouter()
|
api.BaseRoutes.RemoteCluster = api.BaseRoutes.ApiRoot.PathPrefix("/remotecluster").Subrouter()
|
||||||
api.BaseRoutes.SharedChannels = api.BaseRoutes.ApiRoot.PathPrefix("/sharedchannels").Subrouter()
|
api.BaseRoutes.SharedChannels = api.BaseRoutes.ApiRoot.PathPrefix("/sharedchannels").Subrouter()
|
||||||
|
|
||||||
|
api.BaseRoutes.Permissions = api.BaseRoutes.ApiRoot.PathPrefix("/permissions").Subrouter()
|
||||||
|
|
||||||
api.InitUser()
|
api.InitUser()
|
||||||
api.InitBot()
|
api.InitBot()
|
||||||
api.InitTeam()
|
api.InitTeam()
|
||||||
@@ -289,6 +293,7 @@ func Init(configservice configservice.ConfigService, globalOptionsFunc app.AppOp
|
|||||||
api.InitImport()
|
api.InitImport()
|
||||||
api.InitRemoteCluster()
|
api.InitRemoteCluster()
|
||||||
api.InitSharedChannels()
|
api.InitSharedChannels()
|
||||||
|
api.InitPermissions()
|
||||||
api.InitExport()
|
api.InitExport()
|
||||||
|
|
||||||
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
|
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
|
||||||
|
|||||||
33
api4/permission.go
Обычный файл
33
api4/permission.go
Обычный файл
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package api4
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (api *API) InitPermissions() {
|
||||||
|
api.BaseRoutes.Permissions.Handle("/ancillary", api.ApiSessionRequired(appendAncillaryPermissions)).Methods("GET")
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendAncillaryPermissions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
keys, ok := r.URL.Query()["subsection_permissions"]
|
||||||
|
|
||||||
|
if !ok || len(keys[0]) < 1 {
|
||||||
|
c.SetInvalidUrlParam("subsection_permissions")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
permissions := strings.Split(keys[0], ",")
|
||||||
|
b, err := json.Marshal(model.AddAncillaryPermissions(permissions))
|
||||||
|
if err != nil {
|
||||||
|
c.SetJSONEncodingError()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Write(b)
|
||||||
|
}
|
||||||
42
api4/permissions_test.go
Обычный файл
42
api4/permissions_test.go
Обычный файл
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package api4
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetAncillaryPermissions(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
var subsectionPermissions []string
|
||||||
|
var expectedAncillaryPermissions []string
|
||||||
|
t.Run("Valid Case, Passing in SubSection Permissions", func(t *testing.T) {
|
||||||
|
subsectionPermissions = []string{model.PERMISSION_SYSCONSOLE_READ_REPORTING_SITE_STATISTICS.Id}
|
||||||
|
expectedAncillaryPermissions = []string{model.PERMISSION_GET_ANALYTICS.Id}
|
||||||
|
actualAncillaryPermissions, resp := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, append(subsectionPermissions, expectedAncillaryPermissions...), actualAncillaryPermissions)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Invalid Case, Passing in SubSection Permissions That Don't Exist", func(t *testing.T) {
|
||||||
|
subsectionPermissions = []string{"All", "The", "Things", "She", "Said", "Running", "Through", "My", "Head"}
|
||||||
|
expectedAncillaryPermissions = []string{}
|
||||||
|
actualAncillaryPermissions, resp := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, append(subsectionPermissions, expectedAncillaryPermissions...), actualAncillaryPermissions)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Invalid Case, Passing in nothing", func(t *testing.T) {
|
||||||
|
subsectionPermissions = []string{}
|
||||||
|
expectedAncillaryPermissions = []string{}
|
||||||
|
_, resp := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -163,9 +163,6 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ancillaryPermissions := model.AddAncillaryPermissions(*patch.Permissions)
|
|
||||||
*patch.Permissions = append(*patch.Permissions, ancillaryPermissions...)
|
|
||||||
|
|
||||||
*patch.Permissions = model.UniqueStrings(*patch.Permissions)
|
*patch.Permissions = model.UniqueStrings(*patch.Permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -573,6 +573,10 @@ func (c *Client4) GetSharedChannelsRoute() string {
|
|||||||
return "/sharedchannels"
|
return "/sharedchannels"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetPermissionsRoute() string {
|
||||||
|
return "/permissions"
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
|
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
|
||||||
return c.DoApiRequest(http.MethodGet, c.ApiUrl+url, "", etag)
|
return c.DoApiRequest(http.MethodGet, c.ApiUrl+url, "", etag)
|
||||||
}
|
}
|
||||||
@@ -6312,3 +6316,16 @@ func (c *Client4) GetRemoteClusterInfo(remoteID string) (RemoteClusterInfo, *Res
|
|||||||
|
|
||||||
return rci, BuildResponse(r)
|
return rci, BuildResponse(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetAncillaryPermissions(subsectionPermissions []string) ([]string, *Response) {
|
||||||
|
var returnedPermissions []string
|
||||||
|
url := fmt.Sprintf("%s/ancillary?subsection_permissions=%s", c.GetPermissionsRoute(), strings.Join(subsectionPermissions, ","))
|
||||||
|
r, appErr := c.DoApiGet(url, "")
|
||||||
|
if appErr != nil {
|
||||||
|
return returnedPermissions, BuildErrorResponse(r, appErr)
|
||||||
|
}
|
||||||
|
defer closeBody(r)
|
||||||
|
|
||||||
|
json.NewDecoder(r.Body).Decode(&returnedPermissions)
|
||||||
|
return returnedPermissions, BuildResponse(r)
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user