[MM-24594] api4/channel: add/remove member & get public/deleted chs for local-mode (#14590)
* [MM-24146] Add unix socket listener for mmctl local mode (#14296) * add unix socket listener for mmctl local mode * add a constant for local-mode socket path * reflect review comments * [MM-24401] Base approach for Local Mode (#14333) * add unix socket listener for mmctl local mode * First working PoC * Adds the channel list endpoint * Add team list endpoint * Add a LocalClient to the api test helper and start local mode * Add helper to test with both SystemAdmin and Local clients * Add some docs * Adds TestForAllClients test helper * Incorporating @ashishbhate's proposal for adding test names to the helpers * Fix init errors after merge * Adds create channel tests * Always init local mode to allow for enabling-disabling it via config * Check the RemoteAddr of the request before marking session as local * Mark the request as errored if it's local and the origin is remote * Set the socket permissions to read/write when initialising * Fix linter * Replace RemoteAddr check to ditch connections with the IP:PORT shape Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Fix translations order * [MM-24832] Migrate plugin endpoints to local mode (#14543) * [MM-24832] Migrate plugin endpoints to local mode * Fix client reference in helper * [MM-24776] Migrate config endpoints to local mode (#14544) * [MM-24776] Migrate get config endpoint to local mode * [MM-24777] Migrate update config endpoint to local mode * Fix update config to bypass RestrictSystemAdmin flag * Add patchConfig endpoint * MM-24774/MM-24755: local mode for addLicense and removeLicense (#14491) Automatic Merge * api4/channel: add/remove member & get public/deleted chs for local-mode * api4/channel_local: reflect review comments Co-authored-by: Miguel de la Cruz <miguel@mcrx.me> Co-authored-by: Ashish Bhate <bhate.ashish@gmail.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1b95b82b18
Коммит
0965e8485a
@@ -668,6 +668,7 @@ func TestGetChannel(t *testing.T) {
|
||||
func TestGetDeletedChannelsForTeam(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Client := th.Client
|
||||
team := th.BasicTeam
|
||||
|
||||
@@ -681,16 +682,20 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
|
||||
publicChannel1 := th.CreatePublicChannel()
|
||||
Client.DeleteChannel(publicChannel1.Id)
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+1, "should be 1 deleted channel")
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
channels, resp = client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+1, "should be 1 deleted channel")
|
||||
})
|
||||
|
||||
publicChannel2 := th.CreatePublicChannel()
|
||||
Client.DeleteChannel(publicChannel2.Id)
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+2, "should be 2 deleted channels")
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
channels, resp = client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+2, "should be 2 deleted channels")
|
||||
})
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
@@ -713,6 +718,12 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+3)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
channels, resp = client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, numInitialChannelsForTeam+2)
|
||||
})
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, channels, 1, "should be one channel per page")
|
||||
@@ -779,8 +790,10 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
|
||||
_, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp = client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetPublicChannelsByIdsForTeam(t *testing.T) {
|
||||
@@ -2316,11 +2329,13 @@ func TestAddChannelMember(t *testing.T) {
|
||||
_, resp = Client.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(publicChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp = client.AddChannelMember(publicChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = client.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
// Check the appropriate permissions are enforced.
|
||||
defaultRolePermissions := th.SaveDefaultRolePermissions()
|
||||
@@ -2370,9 +2385,11 @@ func TestAddChannelMember(t *testing.T) {
|
||||
_, appErr := th.App.UpdateChannel(privateChannel)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// User is not in associated groups so shouldn't be allowed
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user.Id)
|
||||
CheckErrorMessage(t, resp, "api.channel.add_members.user_denied")
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
// User is not in associated groups so shouldn't be allowed
|
||||
_, resp = client.AddChannelMember(privateChannel.Id, user.Id)
|
||||
CheckErrorMessage(t, resp, "api.channel.add_members.user_denied")
|
||||
})
|
||||
|
||||
// Associate group to team
|
||||
_, appErr = th.App.UpsertGroupSyncable(&model.GroupSyncable{
|
||||
@@ -2386,8 +2403,10 @@ func TestAddChannelMember(t *testing.T) {
|
||||
_, appErr = th.App.UpsertGroupMember(th.Group.Id, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user.Id)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp = client.AddChannelMember(privateChannel.Id, user.Id)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddChannelMemberAddMyself(t *testing.T) {
|
||||
@@ -2595,8 +2614,11 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
_, resp = Client.RemoveUserFromChannel(private.Id, th.BasicUser.Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.RemoveUserFromChannel(private.Id, th.BasicUser.Id)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.AddUserToChannel(th.BasicUser, private)
|
||||
_, resp = client.RemoveUserFromChannel(private.Id, th.BasicUser.Id)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
th.LoginBasic()
|
||||
th.UpdateUserToNonTeamAdmin(user1, team)
|
||||
@@ -2610,21 +2632,23 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS.Id, model.CHANNEL_USER_ROLE_ID)
|
||||
|
||||
// Check that a regular channel user can remove other users.
|
||||
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
// Check that a regular channel user can remove other users.
|
||||
privateChannel := th.CreateChannelWithClient(client, model.CHANNEL_PRIVATE)
|
||||
_, resp = client.AddChannelMember(privateChannel.Id, user1.Id)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = client.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
// Restrict the permission for adding users to Channel Admins
|
||||
th.AddPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS.Id, model.CHANNEL_ADMIN_ROLE_ID)
|
||||
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS.Id, model.CHANNEL_USER_ROLE_ID)
|
||||
|
||||
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||
CheckNoError(t, resp)
|
||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user2.Id)
|
||||
@@ -2677,11 +2701,10 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
groupChannel, resp := Client.CreateGroupChannel([]string{user1.Id, user2.Id, user3.Id})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = Client.RemoveUserFromChannel(groupChannel.Id, user1.Id)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.RemoveUserFromChannel(groupChannel.Id, user1.Id)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp = client.RemoveUserFromChannel(groupChannel.Id, user1.Id)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAutocompleteChannels(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user