diff --git a/api/v4/source/sharedchannels.yaml b/api/v4/source/sharedchannels.yaml index cd34a43e71..f0d7042e47 100644 --- a/api/v4/source/sharedchannels.yaml +++ b/api/v4/source/sharedchannels.yaml @@ -65,6 +65,16 @@ required: true schema: type: string + - name: include_unconfirmed + in: query + description: Include those Shared channel remotes that are unconfirmed + schema: + type: boolean + - name: exclude_confirmed + in: query + description: Show only those Shared channel remotes that are not confirmed yet + schema: + type: boolean - name: exclude_home in: query description: Show only those Shared channel remotes that were shared with this server diff --git a/server/channels/api4/shared_channel.go b/server/channels/api4/shared_channel.go index d8cbcf4114..d051b252cb 100644 --- a/server/channels/api4/shared_channel.go +++ b/server/channels/api4/shared_channel.go @@ -116,10 +116,12 @@ func getSharedChannelRemotesByRemoteCluster(c *Context, w http.ResponseWriter, r } filter := model.SharedChannelRemoteFilterOpts{ - RemoteId: c.Params.RemoteId, - ExcludeHome: c.Params.ExcludeHome, - ExcludeRemote: c.Params.ExcludeRemote, - IncludeDeleted: c.Params.IncludeDeleted, + RemoteId: c.Params.RemoteId, + IncludeUnconfirmed: c.Params.IncludeUnconfirmed, + ExcludeConfirmed: c.Params.ExcludeConfirmed, + ExcludeHome: c.Params.ExcludeHome, + ExcludeRemote: c.Params.ExcludeRemote, + IncludeDeleted: c.Params.IncludeDeleted, } sharedChannelRemotes, err := c.App.GetSharedChannelRemotes(c.Params.Page, c.Params.PerPage, filter) if err != nil { diff --git a/server/channels/api4/shared_channel_test.go b/server/channels/api4/shared_channel_test.go index 866272d29c..1d01dde3b3 100644 --- a/server/channels/api4/shared_channel_test.go +++ b/server/channels/api4/shared_channel_test.go @@ -313,6 +313,20 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { _, err = th.App.ShareChannel(th.Context, sc4) require.NoError(t, err) + c5 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, th.BasicTeam.Id) + sc5 := &model.SharedChannel{ + ChannelId: c5.Id, + TeamId: th.BasicTeam.Id, + ShareName: "shared_5", + ShareDisplayName: "Shared Channel 5", + CreatorId: th.BasicUser.Id, + RemoteId: rc1.RemoteId, + Home: false, + } + + _, err = th.App.ShareChannel(th.Context, sc5) + require.NoError(t, err) + // for the pagination test, we need to get the channelId of the // second SharedChannelRemote that belongs to RC1, sorted by ID, // so we accumulate those SharedChannelRemotes on creation and @@ -321,7 +335,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { sharedChannelRemotesFromRC1 := []*model.SharedChannelRemote{} // create the shared channel remotes - for _, sc := range []*model.SharedChannel{sc1, sc2, sc3, sc4} { + for _, sc := range []*model.SharedChannel{sc1, sc2, sc3, sc4, sc5} { scr := &model.SharedChannelRemote{ Id: model.NewId(), ChannelId: sc.ChannelId, @@ -330,6 +344,10 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { IsInviteConfirmed: true, RemoteId: sc.RemoteId, } + // scr for c5 is not confirmed yet + if sc.ChannelId == sc5.ChannelId { + scr.IsInviteConfirmed = false + } _, err = th.App.SaveSharedChannelRemote(scr) require.NoError(t, err) @@ -355,9 +373,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { Name string Client *model.Client4 RemoteId string - ExcludeHome bool - ExcludeRemote bool - IncludeDeleted bool + Filter model.SharedChannelRemoteFilterOpts Page int PerPage int ExpectedStatusCode int @@ -396,7 +412,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { Name: "should return the complete list of shared channel remotes for a remote cluster, including deleted", Client: th.SystemAdminClient, RemoteId: rc1.RemoteId, - IncludeDeleted: true, + Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true}, Page: 0, PerPage: 100, ExpectedStatusCode: http.StatusOK, @@ -407,7 +423,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { Name: "should return only the shared channel remotes homed localy", Client: th.SystemAdminClient, RemoteId: rc1.RemoteId, - ExcludeRemote: true, + Filter: model.SharedChannelRemoteFilterOpts{ExcludeRemote: true}, Page: 0, PerPage: 100, ExpectedStatusCode: http.StatusOK, @@ -418,18 +434,40 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { Name: "should return only the shared channel remotes homed remotely", Client: th.SystemAdminClient, RemoteId: rc1.RemoteId, - ExcludeHome: true, + Filter: model.SharedChannelRemoteFilterOpts{ExcludeHome: true}, Page: 0, PerPage: 100, ExpectedStatusCode: http.StatusOK, ExpectedError: false, ExpectedIds: []string{sc2.ChannelId}, }, + { + Name: "should return the complete list of shared channel remotes for a remote cluster including unconfirmed", + Client: th.SystemAdminClient, + RemoteId: rc1.RemoteId, + Filter: model.SharedChannelRemoteFilterOpts{IncludeUnconfirmed: true}, + Page: 0, + PerPage: 100, + ExpectedStatusCode: http.StatusOK, + ExpectedError: false, + ExpectedIds: []string{sc1.ChannelId, sc2.ChannelId, sc5.ChannelId}, + }, + { + Name: "should return only the unconfirmed shared channel remotes for a remote cluster", + Client: th.SystemAdminClient, + RemoteId: rc1.RemoteId, + Filter: model.SharedChannelRemoteFilterOpts{ExcludeConfirmed: true}, + Page: 0, + PerPage: 100, + ExpectedStatusCode: http.StatusOK, + ExpectedError: false, + ExpectedIds: []string{sc5.ChannelId}, + }, { Name: "should correctly paginate the results", Client: th.SystemAdminClient, RemoteId: rc1.RemoteId, - IncludeDeleted: true, + Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true, IncludeUnconfirmed: true}, Page: 1, PerPage: 1, ExpectedStatusCode: http.StatusOK, @@ -440,7 +478,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - scrs, resp, err := tc.Client.GetSharedChannelRemotesByRemoteCluster(context.Background(), tc.RemoteId, tc.ExcludeHome, tc.ExcludeRemote, tc.IncludeDeleted, tc.Page, tc.PerPage) + scrs, resp, err := tc.Client.GetSharedChannelRemotesByRemoteCluster(context.Background(), tc.RemoteId, tc.Filter, tc.Page, tc.PerPage) checkHTTPStatus(t, resp, tc.ExpectedStatusCode) if tc.ExpectedError { require.Error(t, err) diff --git a/server/channels/web/params.go b/server/channels/web/params.go index 314223ad49..e92054e8f9 100644 --- a/server/channels/web/params.go +++ b/server/channels/web/params.go @@ -99,6 +99,8 @@ type Params struct { CreatorId string OnlyConfirmed bool OnlyPlugins bool + IncludeUnconfirmed bool + ExcludeConfirmed bool ExcludePlugins bool ExcludeHome bool ExcludeRemote bool @@ -170,6 +172,8 @@ func ParamsFromRequest(r *http.Request) *Params { params.CreatorId = query.Get("creator_id") params.OnlyConfirmed, _ = strconv.ParseBool(query.Get("only_confirmed")) params.OnlyPlugins, _ = strconv.ParseBool(query.Get("only_plugins")) + params.IncludeUnconfirmed, _ = strconv.ParseBool(query.Get("include_unconfirmed")) + params.ExcludeConfirmed, _ = strconv.ParseBool(query.Get("exclude_confirmed")) params.ExcludePlugins, _ = strconv.ParseBool(query.Get("exclude_plugins")) params.ExcludeHome, _ = strconv.ParseBool(query.Get("exclude_home")) params.ExcludeRemote, _ = strconv.ParseBool(query.Get("exclude_remote")) diff --git a/server/public/model/client4.go b/server/public/model/client4.go index 76cbb4cbfc..37b1240792 100644 --- a/server/public/model/client4.go +++ b/server/public/model/client4.go @@ -8900,15 +8900,21 @@ func (c *Client4) DeleteRemoteCluster(ctx context.Context, remoteClusterId strin return BuildResponse(r), nil } -func (c *Client4) GetSharedChannelRemotesByRemoteCluster(ctx context.Context, remoteId string, excludeHome, excludeRemote, includeDeleted bool, page, perPage int) ([]*SharedChannelRemote, *Response, error) { +func (c *Client4) GetSharedChannelRemotesByRemoteCluster(ctx context.Context, remoteId string, filter SharedChannelRemoteFilterOpts, page, perPage int) ([]*SharedChannelRemote, *Response, error) { v := url.Values{} - if excludeHome { + if filter.IncludeUnconfirmed { + v.Set("include_unconfirmed", "true") + } + if filter.ExcludeConfirmed { + v.Set("exclude_confirmed", "true") + } + if filter.ExcludeHome { v.Set("exclude_home", "true") } - if excludeRemote { + if filter.ExcludeRemote { v.Set("exclude_remote", "true") } - if includeDeleted { + if filter.IncludeDeleted { v.Set("include_deleted", "true") } if page != 0 {