MM-30882: Fix read-after-write issue for demoting user (#16911)
* MM-30882: Fix read-after-write issue for demoting user In (*App).DemoteUserToGuest, we would demote a user, and then immediately read it back to do future operations from the user. This reading back of the user had the effect of sticking the old value into the cache after which it would never be updated. There was another issue along with this, which was when the invalidation message would broadcast across the cluster, it would hit the cache invalidation problem where an unrelated store call would miss the cache because it was invalidated, and then again read from replica and stick the old value. To fix all these, we return the new value directly from the store method to avoid having the app to read it again. And we add a map in the localcache layer which tracks invalidations made, and then switch to use master if it's true. The core change is fairly limited, but due to changing the store method signatures, a lot of code needed to be updated to pass "context.Background". Therefore the PR just "appears" to be big, but the main changes are limited to app/user.go, sqlstore/user_store.go and user_layer.go https://mattermost.atlassian.net/browse/MM-30882 ```release-note Fix an issue where demoting a user to guest would not take effect in an environment with read replicas. ``` * Fix concurrent map access * Fixing mistakes * fix tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
49907d3081
Коммит
021c90f29f
@@ -5,9 +5,12 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
model "github.com/mattermost/mattermost-server/v5/model"
|
||||
store "github.com/mattermost/mattermost-server/v5/store"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
store "github.com/mattermost/mattermost-server/v5/store"
|
||||
)
|
||||
|
||||
// UserStore is an autogenerated mock type for the UserStore type
|
||||
@@ -228,26 +231,12 @@ func (_m *UserStore) DeactivateGuests() ([]string, error) {
|
||||
}
|
||||
|
||||
// DemoteUserToGuest provides a mock function with given fields: userID
|
||||
func (_m *UserStore) DemoteUserToGuest(userID string) error {
|
||||
func (_m *UserStore) DemoteUserToGuest(userID string) (*model.User, error) {
|
||||
ret := _m.Called(userID)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(userID)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id
|
||||
func (_m *UserStore) Get(id string) (*model.User, error) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 *model.User
|
||||
if rf, ok := ret.Get(0).(func(string) *model.User); ok {
|
||||
r0 = rf(id)
|
||||
r0 = rf(userID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.User)
|
||||
@@ -256,7 +245,30 @@ func (_m *UserStore) Get(id string) (*model.User, error) {
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(id)
|
||||
r1 = rf(userID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: ctx, id
|
||||
func (_m *UserStore) Get(ctx context.Context, id string) (*model.User, error) {
|
||||
ret := _m.Called(ctx, id)
|
||||
|
||||
var r0 *model.User
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) *model.User); ok {
|
||||
r0 = rf(ctx, id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.User)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = rf(ctx, id)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -356,13 +368,13 @@ func (_m *UserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.Use
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllProfilesInChannel provides a mock function with given fields: channelId, allowFromCache
|
||||
func (_m *UserStore) GetAllProfilesInChannel(channelId string, allowFromCache bool) (map[string]*model.User, error) {
|
||||
ret := _m.Called(channelId, allowFromCache)
|
||||
// GetAllProfilesInChannel provides a mock function with given fields: ctx, channelId, allowFromCache
|
||||
func (_m *UserStore) GetAllProfilesInChannel(ctx context.Context, channelId string, allowFromCache bool) (map[string]*model.User, error) {
|
||||
ret := _m.Called(ctx, channelId, allowFromCache)
|
||||
|
||||
var r0 map[string]*model.User
|
||||
if rf, ok := ret.Get(0).(func(string, bool) map[string]*model.User); ok {
|
||||
r0 = rf(channelId, allowFromCache)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, bool) map[string]*model.User); ok {
|
||||
r0 = rf(ctx, channelId, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(map[string]*model.User)
|
||||
@@ -370,8 +382,8 @@ func (_m *UserStore) GetAllProfilesInChannel(channelId string, allowFromCache bo
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, bool) error); ok {
|
||||
r1 = rf(channelId, allowFromCache)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok {
|
||||
r1 = rf(ctx, channelId, allowFromCache)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -603,13 +615,13 @@ func (_m *UserStore) GetKnownUsers(userID string) ([]string, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetMany provides a mock function with given fields: ids
|
||||
func (_m *UserStore) GetMany(ids []string) ([]*model.User, error) {
|
||||
ret := _m.Called(ids)
|
||||
// GetMany provides a mock function with given fields: ctx, ids
|
||||
func (_m *UserStore) GetMany(ctx context.Context, ids []string) ([]*model.User, error) {
|
||||
ret := _m.Called(ctx, ids)
|
||||
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func([]string) []*model.User); ok {
|
||||
r0 = rf(ids)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []string) []*model.User); ok {
|
||||
r0 = rf(ctx, ids)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.User)
|
||||
@@ -617,8 +629,8 @@ func (_m *UserStore) GetMany(ids []string) ([]*model.User, error) {
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func([]string) error); ok {
|
||||
r1 = rf(ids)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok {
|
||||
r1 = rf(ctx, ids)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -672,13 +684,13 @@ func (_m *UserStore) GetProfileByGroupChannelIdsForUser(userId string, channelId
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetProfileByIds provides a mock function with given fields: userIds, options, allowFromCache
|
||||
func (_m *UserStore) GetProfileByIds(userIds []string, options *store.UserGetByIdsOpts, allowFromCache bool) ([]*model.User, error) {
|
||||
ret := _m.Called(userIds, options, allowFromCache)
|
||||
// GetProfileByIds provides a mock function with given fields: ctx, userIds, options, allowFromCache
|
||||
func (_m *UserStore) GetProfileByIds(ctx context.Context, userIds []string, options *store.UserGetByIdsOpts, allowFromCache bool) ([]*model.User, error) {
|
||||
ret := _m.Called(ctx, userIds, options, allowFromCache)
|
||||
|
||||
var r0 []*model.User
|
||||
if rf, ok := ret.Get(0).(func([]string, *store.UserGetByIdsOpts, bool) []*model.User); ok {
|
||||
r0 = rf(userIds, options, allowFromCache)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []string, *store.UserGetByIdsOpts, bool) []*model.User); ok {
|
||||
r0 = rf(ctx, userIds, options, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.User)
|
||||
@@ -686,8 +698,8 @@ func (_m *UserStore) GetProfileByIds(userIds []string, options *store.UserGetByI
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func([]string, *store.UserGetByIdsOpts, bool) error); ok {
|
||||
r1 = rf(userIds, options, allowFromCache)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, []string, *store.UserGetByIdsOpts, bool) error); ok {
|
||||
r1 = rf(ctx, userIds, options, allowFromCache)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -2829,7 +2829,7 @@ func testSaveTeamMemberMaxMembers(t *testing.T, ss store.Store) {
|
||||
require.Equal(t, maxUsersPerTeam, int(totalMemberCount), "should have 5 team members again, had %v instead", totalMemberCount)
|
||||
|
||||
// Deactivating a user should make them stop counting against max members
|
||||
user2, nErr := ss.User().Get(userIds[1])
|
||||
user2, nErr := ss.User().Get(context.Background(), userIds[1])
|
||||
require.NoError(t, nErr)
|
||||
user2.DeleteAt = 1234
|
||||
_, nErr = ss.User().Update(user2, true)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -226,7 +227,7 @@ func testUserStoreUpdateUpdateAt(t *testing.T, ss store.Store) {
|
||||
_, err = ss.User().UpdateUpdateAt(u1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
user, err := ss.User().Get(u1.Id)
|
||||
user, err := ss.User().Get(context.Background(), u1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Less(t, u1.UpdateAt, user.UpdateAt, "UpdateAt not updated correctly")
|
||||
}
|
||||
@@ -243,7 +244,7 @@ func testUserStoreUpdateFailedPasswordAttempts(t *testing.T, ss store.Store) {
|
||||
err = ss.User().UpdateFailedPasswordAttempts(u1.Id, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
user, err := ss.User().Get(u1.Id)
|
||||
user, err := ss.User().Get(context.Background(), u1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, user.FailedAttempts, "FailedAttempts not updated correctly")
|
||||
}
|
||||
@@ -276,19 +277,19 @@ func testUserStoreGet(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, nErr)
|
||||
|
||||
t.Run("fetch empty id", func(t *testing.T) {
|
||||
_, err := ss.User().Get("")
|
||||
_, err := ss.User().Get(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("fetch user 1", func(t *testing.T) {
|
||||
actual, err := ss.User().Get(u1.Id)
|
||||
actual, err := ss.User().Get(context.Background(), u1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, u1, actual)
|
||||
require.False(t, actual.IsBot)
|
||||
})
|
||||
|
||||
t.Run("fetch user 2, also a bot", func(t *testing.T) {
|
||||
actual, err := ss.User().Get(u2.Id)
|
||||
actual, err := ss.User().Get(context.Background(), u2.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, u2, actual)
|
||||
require.True(t, actual.IsBot)
|
||||
@@ -1272,7 +1273,7 @@ func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
t.Run("all profiles in channel 1, no caching", func(t *testing.T) {
|
||||
var profiles map[string]*model.User
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(c1.Id, false)
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(context.Background(), c1.Id, false)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]*model.User{
|
||||
u1.Id: sanitized(u1),
|
||||
@@ -1283,7 +1284,7 @@ func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
t.Run("all profiles in channel 2, no caching", func(t *testing.T) {
|
||||
var profiles map[string]*model.User
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(c2.Id, false)
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(context.Background(), c2.Id, false)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]*model.User{
|
||||
u1.Id: sanitized(u1),
|
||||
@@ -1292,7 +1293,7 @@ func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
t.Run("all profiles in channel 2, caching", func(t *testing.T) {
|
||||
var profiles map[string]*model.User
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(c2.Id, true)
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(context.Background(), c2.Id, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]*model.User{
|
||||
u1.Id: sanitized(u1),
|
||||
@@ -1301,7 +1302,7 @@ func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
t.Run("all profiles in channel 2, caching [repeated]", func(t *testing.T) {
|
||||
var profiles map[string]*model.User
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(c2.Id, true)
|
||||
profiles, err = ss.User().GetAllProfilesInChannel(context.Background(), c2.Id, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]*model.User{
|
||||
u1.Id: sanitized(u1),
|
||||
@@ -1521,37 +1522,37 @@ func testUserStoreGetProfilesByIds(t *testing.T, ss store.Store) {
|
||||
defer func() { require.NoError(t, ss.User().PermanentDelete(u4.Id)) }()
|
||||
|
||||
t.Run("get u1 by id, no caching", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{u1.Id}, nil, false)
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{u1.Id}, nil, false)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*model.User{u1}, users)
|
||||
})
|
||||
|
||||
t.Run("get u1 by id, caching", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{u1.Id}, nil, true)
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{u1.Id}, nil, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*model.User{u1}, users)
|
||||
})
|
||||
|
||||
t.Run("get u1, u2, u3 by id, no caching", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{u1.Id, u2.Id, u3.Id}, nil, false)
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{u1.Id, u2.Id, u3.Id}, nil, false)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*model.User{u1, u2, u3}, users)
|
||||
})
|
||||
|
||||
t.Run("get u1, u2, u3 by id, caching", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{u1.Id, u2.Id, u3.Id}, nil, true)
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{u1.Id, u2.Id, u3.Id}, nil, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*model.User{u1, u2, u3}, users)
|
||||
})
|
||||
|
||||
t.Run("get unknown id, caching", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{"123"}, nil, true)
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{"123"}, nil, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*model.User{}, users)
|
||||
})
|
||||
|
||||
t.Run("should only return users with UpdateAt greater than the since time", func(t *testing.T) {
|
||||
users, err := ss.User().GetProfileByIds([]string{u1.Id, u2.Id, u3.Id, u4.Id}, &store.UserGetByIdsOpts{
|
||||
users, err := ss.User().GetProfileByIds(context.Background(), []string{u1.Id, u2.Id, u3.Id, u4.Id}, &store.UserGetByIdsOpts{
|
||||
Since: u2.CreateAt,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
@@ -4835,7 +4836,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", updatedUser.Roles)
|
||||
require.True(t, user.UpdateAt < updatedUser.UpdateAt)
|
||||
@@ -4881,7 +4882,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user system_admin", updatedUser.Roles)
|
||||
|
||||
@@ -4912,7 +4913,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", updatedUser.Roles)
|
||||
})
|
||||
@@ -4937,7 +4938,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", updatedUser.Roles)
|
||||
|
||||
@@ -4977,7 +4978,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", updatedUser.Roles)
|
||||
|
||||
@@ -5022,7 +5023,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user custom_role", updatedUser.Roles)
|
||||
|
||||
@@ -5088,7 +5089,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
|
||||
err = ss.User().PromoteGuestToUser(user1.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user1.Id)
|
||||
updatedUser, err := ss.User().Get(context.Background(), user1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", updatedUser.Roles)
|
||||
|
||||
@@ -5102,7 +5103,7 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
|
||||
require.False(t, updatedChannelMember.SchemeGuest)
|
||||
require.True(t, updatedChannelMember.SchemeUser)
|
||||
|
||||
notUpdatedUser, err := ss.User().Get(user2.Id)
|
||||
notUpdatedUser, err := ss.User().Get(context.Background(), user2.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", notUpdatedUser.Roles)
|
||||
|
||||
@@ -5148,19 +5149,17 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
require.True(t, user.UpdateAt < updatedUser.UpdateAt)
|
||||
|
||||
updatedTeamMember, nErr := ss.Team().GetMember(teamId, user.Id)
|
||||
updatedTeamMember, nErr := ss.Team().GetMember(teamId, updatedUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.True(t, updatedTeamMember.SchemeGuest)
|
||||
require.False(t, updatedTeamMember.SchemeUser)
|
||||
|
||||
updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
|
||||
updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, updatedUser.Id)
|
||||
require.NoError(t, nErr)
|
||||
require.True(t, updatedChannelMember.SchemeGuest)
|
||||
require.False(t, updatedChannelMember.SchemeUser)
|
||||
@@ -5194,9 +5193,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
|
||||
@@ -5225,9 +5222,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, ss.User().PermanentDelete(user.Id)) }()
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
})
|
||||
@@ -5250,9 +5245,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr := ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: user.Id, SchemeGuest: false, SchemeUser: true}, 999)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
|
||||
@@ -5290,9 +5283,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
|
||||
@@ -5335,9 +5326,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest custom_role", updatedUser.Roles)
|
||||
|
||||
@@ -5401,9 +5390,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user2.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = ss.User().DemoteUserToGuest(user1.Id)
|
||||
require.NoError(t, err)
|
||||
updatedUser, err := ss.User().Get(user1.Id)
|
||||
updatedUser, err := ss.User().DemoteUserToGuest(user1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_guest", updatedUser.Roles)
|
||||
|
||||
@@ -5417,7 +5404,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
|
||||
require.True(t, updatedChannelMember.SchemeGuest)
|
||||
require.False(t, updatedChannelMember.SchemeUser)
|
||||
|
||||
notUpdatedUser, err := ss.User().Get(user2.Id)
|
||||
notUpdatedUser, err := ss.User().Get(context.Background(), user2.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "system_user", notUpdatedUser.Roles)
|
||||
|
||||
@@ -5493,19 +5480,19 @@ func testDeactivateGuests(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []string{guest1.Id, guest2.Id}, ids)
|
||||
|
||||
u, err := ss.User().Get(guest1.Id)
|
||||
u, err := ss.User().Get(context.Background(), guest1.Id)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, u.DeleteAt, int64(0))
|
||||
|
||||
u, err = ss.User().Get(guest2.Id)
|
||||
u, err = ss.User().Get(context.Background(), guest2.Id)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, u.DeleteAt, int64(0))
|
||||
|
||||
u, err = ss.User().Get(guest3.Id)
|
||||
u, err = ss.User().Get(context.Background(), guest3.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, u.DeleteAt, int64(10))
|
||||
|
||||
u, err = ss.User().Get(regularUser.Id)
|
||||
u, err = ss.User().Get(context.Background(), regularUser.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, u.DeleteAt, int64(0))
|
||||
})
|
||||
@@ -5523,7 +5510,7 @@ func testUserStoreResetLastPictureUpdate(t *testing.T, ss store.Store) {
|
||||
err = ss.User().UpdateLastPictureUpdate(u1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
user, err := ss.User().Get(u1.Id)
|
||||
user, err := ss.User().Get(context.Background(), u1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotZero(t, user.LastPictureUpdate)
|
||||
@@ -5537,7 +5524,7 @@ func testUserStoreResetLastPictureUpdate(t *testing.T, ss store.Store) {
|
||||
|
||||
ss.User().InvalidateProfileCacheForUser(u1.Id)
|
||||
|
||||
user2, err := ss.User().Get(u1.Id)
|
||||
user2, err := ss.User().Get(context.Background(), u1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, user2.UpdateAt > user.UpdateAt)
|
||||
|
||||
Ссылка в новой задаче
Block a user