MM-56513 Prevent deactivated users to be added as channel members (#25954)

* Prevent deactivated users to be added as channel members

* remove "deactivated" from error message
This commit is contained in:
Elias Nahum 2024-02-06 09:34:19 +08:00 committed by GitHub
parent 5c63bb7e0f
commit 9ff26f7b4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View File

@ -1695,6 +1695,10 @@ func (a *App) AddChannelMember(c request.CTX, userID string, channel *model.Chan
return nil, err
}
if user.DeleteAt > 0 {
return nil, model.NewAppError("AddChannelMember", "app.channel.add_member.deleted_user.app_error", nil, "", http.StatusForbidden)
}
var userRequestor *model.User
if opts.UserRequestorID != "" {
if userRequestor, err = a.GetUser(opts.UserRequestorID); err != nil {

View File

@ -764,6 +764,22 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
}
}
func TestAddChannelMemberDeletedUser(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.CreateUser()
_, err := th.App.AddTeamMember(th.Context, th.BasicTeam.Id, user.Id)
require.Nil(t, err)
deactivated, err := th.App.UpdateActive(th.Context, user, false)
require.Greater(t, deactivated.DeleteAt, int64(0))
require.Nil(t, err)
_, err = th.App.AddChannelMember(th.Context, user.Id, th.BasicChannel, ChannelMemberOpts{})
require.NotNil(t, err)
}
func TestAppUpdateChannelScheme(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()

View File

@ -4854,6 +4854,10 @@
"id": "app.bot.permenent_delete.bad_id",
"translation": "Unable to delete the bot."
},
{
"id": "app.channel.add_member.deleted_user.app_error",
"translation": "Unable to add thr user as a member of the channel."
},
{
"id": "app.channel.analytics_type_count.app_error",
"translation": "Unable to get channel type counts."