Refactor: func StringInSlice to slices.Contains (#24262)
* Refactor: Use generic to change func StringInSlice to Contains * Refactor: Use generic to change func stringNotInSlice to Contains Make utils.go (dir server/public/utils) and func Contains * Refactor: Move func Contains from channels/utils to public/utils Move func Contains from channels/utils to public/utils Fix import declarations line * Docs: Add a description of the Contains function * Test: add TestContains Add a test code for a Contain function
Этот коммит содержится в:
@@ -14,6 +14,8 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
@@ -722,7 +724,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
}
|
||||
roleValid := utils.StringInSlice(role, roleNamesAll)
|
||||
roleValid := pUtils.Contains(roleNamesAll, role)
|
||||
if !roleValid {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
@@ -85,7 +87,7 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
}
|
||||
roleValid := utils.StringInSlice(role, roleNamesAll)
|
||||
roleValid := pUtils.Contains(roleNamesAll, role)
|
||||
if !roleValid {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
|
||||
Ссылка в новой задаче
Block a user