MM-14757/14758: Restricts deleting team and channel members if the team or channel is group constrained. (#10553)
* MM-14757/14758: Update APIs to reject removals from group-constrained teams. * MM-14757/14758: Tests API changes. * MM-14757/14758: Allow users to leave channals and teams. * MM-14757/14758: Updates translation key order. * MM-14757/14758: Adds user to team before setting it to group-constrained b/c of new add restrictions.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f93ba3cd23
Коммит
100433f4cc
@@ -1218,6 +1218,11 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if channel.GroupConstrained != nil && *channel.GroupConstrained && (c.Params.UserId != c.App.Session.UserId) {
|
||||||
|
c.Err = model.NewAppError("removeChannelMember", "api.channel.remove_member.group_constrained.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if c.Params.UserId != c.App.Session.UserId {
|
if c.Params.UserId != c.App.Session.UserId {
|
||||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
||||||
|
|||||||
@@ -2228,6 +2228,20 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, th.SystemAdminUser.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
// If the channel is group-constrained the user cannot be removed
|
||||||
|
privateChannel.GroupConstrained = model.NewBool(true)
|
||||||
|
_, err := th.App.UpdateChannel(privateChannel)
|
||||||
|
require.Nil(t, err)
|
||||||
|
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||||
|
require.Equal(t, "api.channel.remove_member.group_constrained.app_error", resp.Error.Id)
|
||||||
|
|
||||||
|
// If the channel is group-constrained user can remove self
|
||||||
|
_, resp = th.SystemAdminClient.RemoveUserFromChannel(privateChannel.Id, th.SystemAdminUser.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Test on preventing removal of user from a direct channel
|
// Test on preventing removal of user from a direct channel
|
||||||
directChannel, resp := Client.CreateDirectChannel(user1.Id, user2.Id)
|
directChannel, resp := Client.CreateDirectChannel(user1.Id, user2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|||||||
11
api4/team.go
11
api4/team.go
@@ -535,6 +535,17 @@ func removeTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
team, err := c.App.GetTeam(c.Params.TeamId)
|
||||||
|
if err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if team.GroupConstrained != nil && *team.GroupConstrained && (c.Params.UserId != c.App.Session.UserId) {
|
||||||
|
c.Err = model.NewAppError("removeTeamMember", "api.team.remove_member.group_constrained.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := c.App.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId, c.App.Session.UserId); err != nil {
|
if err := c.App.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId, c.App.Session.UserId); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1712,6 +1712,20 @@ func TestRemoveTeamMember(t *testing.T) {
|
|||||||
|
|
||||||
_, resp = th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
|
_, resp = th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
_, resp = th.SystemAdminClient.AddTeamMember(th.BasicTeam.Id, th.SystemAdminUser.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
// If the team is group-constrained the user cannot be removed
|
||||||
|
th.BasicTeam.GroupConstrained = model.NewBool(true)
|
||||||
|
_, err := th.App.UpdateTeam(th.BasicTeam)
|
||||||
|
require.Nil(t, err)
|
||||||
|
_, resp = th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
|
||||||
|
require.Equal(t, "api.team.remove_member.group_constrained.app_error", resp.Error.Id)
|
||||||
|
|
||||||
|
// Can remove self even if team is group-constrained
|
||||||
|
_, resp = th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, th.SystemAdminUser.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTeamStats(t *testing.T) {
|
func TestGetTeamStats(t *testing.T) {
|
||||||
|
|||||||
@@ -295,6 +295,10 @@
|
|||||||
"id": "api.channel.remove_channel_member.type.app_error",
|
"id": "api.channel.remove_channel_member.type.app_error",
|
||||||
"translation": "Unable to remove user from a channel."
|
"translation": "Unable to remove user from a channel."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.remove_member.group_constrained.app_error",
|
||||||
|
"translation": "Unable to remove a user from a group-constrained channel."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.channel.remove_member.removed",
|
"id": "api.channel.remove_member.removed",
|
||||||
"translation": "%v removed from the channel."
|
"translation": "%v removed from the channel."
|
||||||
@@ -1846,6 +1850,10 @@
|
|||||||
"id": "api.team.move_channel.success",
|
"id": "api.team.move_channel.success",
|
||||||
"translation": "This channel has been moved to this team from %v."
|
"translation": "This channel has been moved to this team from %v."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.team.remove_member.group_constrained.app_error",
|
||||||
|
"translation": "Unable to remove a user from a group-constrained team."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.team.remove_team_icon.get_team.app_error",
|
"id": "api.team.remove_team_icon.get_team.app_error",
|
||||||
"translation": "An error occurred getting the team"
|
"translation": "An error occurred getting the team"
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user