Allow shared channel remotes endpoint to be filtered by confirmation status (#28213)

* Allow shared channel remotes endpoint to be filtered by confirmation status

* Adds tests
This commit is contained in:
Miguel de la Cruz 2024-09-18 13:36:43 +02:00 committed by GitHub
parent 70cb1934e9
commit 7a0019b63a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 77 additions and 17 deletions

View File

@ -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

View File

@ -117,6 +117,8 @@ func getSharedChannelRemotesByRemoteCluster(c *Context, w http.ResponseWriter, r
filter := model.SharedChannelRemoteFilterOpts{
RemoteId: c.Params.RemoteId,
IncludeUnconfirmed: c.Params.IncludeUnconfirmed,
ExcludeConfirmed: c.Params.ExcludeConfirmed,
ExcludeHome: c.Params.ExcludeHome,
ExcludeRemote: c.Params.ExcludeRemote,
IncludeDeleted: c.Params.IncludeDeleted,

View File

@ -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)

View File

@ -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"))

View File

@ -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 {