[MM-32281] SqlRoleStore/GetByName: add context to allow read from master (#17176)
* role_store/GetByName: add context * propagate context in the app layer * propagate context in the app layer * add missing import Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9eceeaa8db
Коммит
28ff4dc8d0
@@ -1116,7 +1116,7 @@ func (th *TestHelper) SaveDefaultRolePermissions() map[string][]string {
|
||||
"channel_user",
|
||||
"channel_admin",
|
||||
} {
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(context.Background(), roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1133,7 +1133,7 @@ func (th *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
for roleName, permissions := range data {
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(context.Background(), roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1158,7 +1158,7 @@ func (th *TestHelper) RestoreDefaultRolePermissions(data map[string][]string) {
|
||||
func (th *TestHelper) RemovePermissionFromRole(permission string, roleName string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(context.Background(), roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
@@ -1190,7 +1190,7 @@ func (th *TestHelper) RemovePermissionFromRole(permission string, roleName strin
|
||||
func (th *TestHelper) AddPermissionToRole(permission string, roleName string) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
role, err1 := th.App.GetRoleByName(roleName)
|
||||
role, err1 := th.App.GetRoleByName(context.Background(), roleName)
|
||||
if err1 != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err1)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -596,7 +597,7 @@ func TestPatchGroupChannel(t *testing.T) {
|
||||
assert.NotNil(t, groupSyncable)
|
||||
assert.True(t, groupSyncable.AutoAdd)
|
||||
|
||||
role, err := th.App.GetRoleByName("channel_user")
|
||||
role, err := th.App.GetRoleByName(context.Background(), "channel_user")
|
||||
require.Nil(t, err)
|
||||
originalPermissions := role.Permissions
|
||||
_, err = th.App.PatchRole(role, &model.RolePatch{Permissions: &[]string{}})
|
||||
|
||||
@@ -56,7 +56,7 @@ func getRoleByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
role, err := c.App.GetRoleByName(c.Params.RoleName)
|
||||
role, err := c.App.GetRoleByName(r.Context(), c.Params.RoleName)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -180,7 +181,7 @@ func TestPatchRole(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
|
||||
// Cannot edit a system admin
|
||||
adminRole, err := th.App.Srv().Store.Role().GetByName("system_admin")
|
||||
adminRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_admin")
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(adminRole.Id)
|
||||
|
||||
@@ -188,7 +189,7 @@ func TestPatchRole(t *testing.T) {
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
// Cannot give other roles read / write to system roles or manage roles because only system admin can do these actions
|
||||
systemManager, err := th.App.Srv().Store.Role().GetByName("system_manager")
|
||||
systemManager, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_manager")
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store.Job().Delete(systemManager.Id)
|
||||
|
||||
@@ -271,7 +272,7 @@ func TestPatchRole(t *testing.T) {
|
||||
license.Features.GuestAccountsPermissions = model.NewBool(false)
|
||||
th.App.Srv().SetLicense(license)
|
||||
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName("system_guest")
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
received, resp = client.PatchRole(guestRole.Id, patch)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
@@ -281,7 +282,7 @@ func TestPatchRole(t *testing.T) {
|
||||
license := model.NewTestLicense()
|
||||
license.Features.GuestAccountsPermissions = model.NewBool(true)
|
||||
th.App.Srv().SetLicense(license)
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName("system_guest")
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
_, resp = client.PatchRole(guestRole.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user