From 7a32dd9f249e411cca220646a51f8f087c75f7c8 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Tue, 8 Aug 2023 13:37:30 -0600 Subject: [PATCH] cherry pick for #23920 (#24205) --- store/sqlstore/user_store.go | 13 +------------ store/storetest/user_store.go | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 8d9093e08f..ddc68cc0d0 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -2028,19 +2028,8 @@ func (us SqlUserStore) DemoteUserToGuest(userID string) (_ *model.User, err erro return nil, err } - roles := user.GetRoles() - - newRoles := []string{} - for _, role := range roles { - if role == model.SystemUserRoleId { - newRoles = append(newRoles, model.SystemGuestRoleId) - } else if role != model.SystemAdminRoleId { - newRoles = append(newRoles, role) - } - } - curTime := model.GetMillis() - newRolesDBStr := strings.Join(newRoles, " ") + newRolesDBStr := model.SystemGuestRoleId query := us.getQueryBuilder().Update("Users"). Set("Roles", newRolesDBStr). Set("UpdateAt", curTime). diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index 138c3cfb14..566a145dca 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -5724,7 +5724,7 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) { updatedUser, err := ss.User().DemoteUserToGuest(user.Id) require.NoError(t, err) - require.Equal(t, "system_guest custom_role", updatedUser.Roles) + require.Equal(t, "system_guest", updatedUser.Roles) updatedTeamMember, nErr := ss.Team().GetMember(context.Background(), teamId, user.Id) require.NoError(t, nErr)