[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>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-04-21 18:01:02 +03:00
коммит произвёл GitHub
родитель 9eceeaa8db
Коммит 28ff4dc8d0
37 изменённых файлов: 225 добавлений и 198 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package app
import (
"context"
"fmt"
"sort"
"testing"
@@ -185,7 +186,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) {
// Check the migration matches what's expected.
for name, permissions := range expected1 {
role, err := th.App.GetRoleByName(name)
role, err := th.App.GetRoleByName(context.Background(), name)
assert.Nil(t, err)
assert.Equal(t, role.Permissions, permissions, fmt.Sprintf("role %q didn't match", name))
}
@@ -218,7 +219,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) {
assert.Equal(t, len(roles2), len(roleNames))
for name, permissions := range expected1 {
role, err := th.App.GetRoleByName(name)
role, err := th.App.GetRoleByName(context.Background(), name)
assert.Nil(t, err)
assert.Equal(t, permissions, role.Permissions)
}
@@ -317,7 +318,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) {
assert.Equal(t, len(roles3), len(roleNames))
for name, permissions := range expected2 {
role, err := th.App.GetRoleByName(name)
role, err := th.App.GetRoleByName(context.Background(), name)
assert.Nil(t, err)
assert.Equal(t, permissions, role.Permissions, fmt.Sprintf("'%v' did not have expected permissions", name))
}
@@ -335,7 +336,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) {
assert.Equal(t, len(roles4), len(roleNames))
for name, permissions := range expected1 {
role, err := th.App.GetRoleByName(name)
role, err := th.App.GetRoleByName(context.Background(), name)
assert.Nil(t, err)
assert.Equal(t, permissions, role.Permissions)
}
@@ -396,7 +397,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) {
expectedSystemAdmin := allPermissionIDs
sort.Strings(expectedSystemAdmin)
role1, err1 := th.App.GetRoleByName(model.SYSTEM_ADMIN_ROLE_ID)
role1, err1 := th.App.GetRoleByName(context.Background(), model.SYSTEM_ADMIN_ROLE_ID)
assert.Nil(t, err1)
sort.Strings(role1.Permissions)
assert.Equal(t, expectedSystemAdmin, role1.Permissions, fmt.Sprintf("'%v' did not have expected permissions", model.SYSTEM_ADMIN_ROLE_ID))
@@ -408,7 +409,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) {
th.ResetEmojisMigration()
th.App.DoEmojisPermissionsMigration()
role2, err2 := th.App.GetRoleByName(model.TEAM_ADMIN_ROLE_ID)
role2, err2 := th.App.GetRoleByName(context.Background(), model.TEAM_ADMIN_ROLE_ID)
assert.Nil(t, err2)
expected2 := []string{
model.PERMISSION_REMOVE_USER_FROM_TEAM.Id,
@@ -442,7 +443,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) {
sort.Strings(role2.Permissions)
assert.Equal(t, expected2, role2.Permissions, fmt.Sprintf("'%v' did not have expected permissions", model.TEAM_ADMIN_ROLE_ID))
systemAdmin1, systemAdminErr1 := th.App.GetRoleByName(model.SYSTEM_ADMIN_ROLE_ID)
systemAdmin1, systemAdminErr1 := th.App.GetRoleByName(context.Background(), model.SYSTEM_ADMIN_ROLE_ID)
assert.Nil(t, systemAdminErr1)
sort.Strings(systemAdmin1.Permissions)
assert.Equal(t, expectedSystemAdmin, systemAdmin1.Permissions, fmt.Sprintf("'%v' did not have expected permissions", model.SYSTEM_ADMIN_ROLE_ID))
@@ -454,7 +455,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) {
th.ResetEmojisMigration()
th.App.DoEmojisPermissionsMigration()
role3, err3 := th.App.GetRoleByName(model.SYSTEM_USER_ROLE_ID)
role3, err3 := th.App.GetRoleByName(context.Background(), model.SYSTEM_USER_ROLE_ID)
assert.Nil(t, err3)
expected3 := []string{
model.PERMISSION_LIST_PUBLIC_TEAMS.Id,
@@ -470,7 +471,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) {
sort.Strings(role3.Permissions)
assert.Equal(t, expected3, role3.Permissions, fmt.Sprintf("'%v' did not have expected permissions", model.SYSTEM_USER_ROLE_ID))
systemAdmin2, systemAdminErr2 := th.App.GetRoleByName(model.SYSTEM_ADMIN_ROLE_ID)
systemAdmin2, systemAdminErr2 := th.App.GetRoleByName(context.Background(), model.SYSTEM_ADMIN_ROLE_ID)
assert.Nil(t, systemAdminErr2)
sort.Strings(systemAdmin2.Permissions)
assert.Equal(t, expectedSystemAdmin, systemAdmin2.Permissions, fmt.Sprintf("'%v' did not have expected permissions", model.SYSTEM_ADMIN_ROLE_ID))