Automatic Merge
Этот коммит содержится в:
@@ -6673,6 +6673,34 @@ func TestDemoteUserToGuest(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("cannot demote bot account", func(t *testing.T) {
|
||||||
|
th.App.Srv().SetLicense(model.NewTestLicense("guest_accounts"))
|
||||||
|
|
||||||
|
prevBotCreation := *th.App.Config().ServiceSettings.EnableBotAccountCreation
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||||
|
})
|
||||||
|
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.EnableBotAccountCreation = prevBotCreation
|
||||||
|
})
|
||||||
|
|
||||||
|
createdBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||||
|
Username: "botdemote" + model.NewId(),
|
||||||
|
DisplayName: "Demote Test Bot",
|
||||||
|
Description: "test",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
defer func() {
|
||||||
|
appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
}()
|
||||||
|
|
||||||
|
demoteResp, err := th.SystemAdminClient.DemoteUserToGuest(context.Background(), createdBot.UserId)
|
||||||
|
CheckBadRequestStatus(t, demoteResp)
|
||||||
|
CheckErrorID(t, err, "api.user.demote_user_to_guest.bot_not_allowed.app_error")
|
||||||
|
})
|
||||||
|
|
||||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||||
_, _, err := c.GetUser(context.Background(), user.Id, "")
|
_, _, err := c.GetUser(context.Background(), user.Id, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -2570,6 +2570,10 @@ func (a *App) PromoteGuestToUser(c request.CTX, user *model.User, requestorId st
|
|||||||
// DemoteUserToGuest Convert user's roles and all his membership's roles from
|
// DemoteUserToGuest Convert user's roles and all his membership's roles from
|
||||||
// regular user roles to guest roles.
|
// regular user roles to guest roles.
|
||||||
func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError {
|
func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError {
|
||||||
|
if user.IsBot {
|
||||||
|
return model.NewAppError("DemoteUserToGuest", "api.user.demote_user_to_guest.bot_not_allowed.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
demotedUser, nErr := a.ch.srv.userService.DemoteUserToGuest(user)
|
demotedUser, nErr := a.ch.srv.userService.DemoteUserToGuest(user)
|
||||||
a.InvalidateCacheForUser(user.Id)
|
a.InvalidateCacheForUser(user.Id)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
|
|||||||
@@ -1844,6 +1844,18 @@ func TestDemoteUserToGuest(t *testing.T) {
|
|||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
|
t.Run("Must reject bot user", func(t *testing.T) {
|
||||||
|
bot := th.CreateBot()
|
||||||
|
user, err := th.App.GetUser(bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.True(t, user.IsBot)
|
||||||
|
|
||||||
|
appErr := th.App.DemoteUserToGuest(th.Context, user)
|
||||||
|
require.NotNil(t, appErr)
|
||||||
|
assert.Equal(t, "api.user.demote_user_to_guest.bot_not_allowed.app_error", appErr.Id)
|
||||||
|
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Must invalidate channel stats cache when demoting a user", func(t *testing.T) {
|
t.Run("Must invalidate channel stats cache when demoting a user", func(t *testing.T) {
|
||||||
user := th.CreateUser()
|
user := th.CreateUser()
|
||||||
require.Equal(t, "system_user", user.Roles)
|
require.Equal(t, "system_user", user.Roles)
|
||||||
|
|||||||
@@ -4130,6 +4130,10 @@
|
|||||||
"id": "api.user.demote_user_to_guest.already_guest.app_error",
|
"id": "api.user.demote_user_to_guest.already_guest.app_error",
|
||||||
"translation": "Unable to convert the user to guest because is already a guest."
|
"translation": "Unable to convert the user to guest because is already a guest."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.user.demote_user_to_guest.bot_not_allowed.app_error",
|
||||||
|
"translation": "Bot accounts cannot be converted to guest accounts."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.user.email_to_ldap.not_available.app_error",
|
"id": "api.user.email_to_ldap.not_available.app_error",
|
||||||
"translation": "AD/LDAP not available on this server."
|
"translation": "AD/LDAP not available on this server."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user