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 required: true
schema: schema:
type: string 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 - name: exclude_home
in: query in: query
description: Show only those Shared channel remotes that were shared with this server description: Show only those Shared channel remotes that were shared with this server

View File

@ -116,10 +116,12 @@ func getSharedChannelRemotesByRemoteCluster(c *Context, w http.ResponseWriter, r
} }
filter := model.SharedChannelRemoteFilterOpts{ filter := model.SharedChannelRemoteFilterOpts{
RemoteId: c.Params.RemoteId, RemoteId: c.Params.RemoteId,
ExcludeHome: c.Params.ExcludeHome, IncludeUnconfirmed: c.Params.IncludeUnconfirmed,
ExcludeRemote: c.Params.ExcludeRemote, ExcludeConfirmed: c.Params.ExcludeConfirmed,
IncludeDeleted: c.Params.IncludeDeleted, ExcludeHome: c.Params.ExcludeHome,
ExcludeRemote: c.Params.ExcludeRemote,
IncludeDeleted: c.Params.IncludeDeleted,
} }
sharedChannelRemotes, err := c.App.GetSharedChannelRemotes(c.Params.Page, c.Params.PerPage, filter) sharedChannelRemotes, err := c.App.GetSharedChannelRemotes(c.Params.Page, c.Params.PerPage, filter)
if err != nil { if err != nil {

View File

@ -313,6 +313,20 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
_, err = th.App.ShareChannel(th.Context, sc4) _, err = th.App.ShareChannel(th.Context, sc4)
require.NoError(t, err) 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 // for the pagination test, we need to get the channelId of the
// second SharedChannelRemote that belongs to RC1, sorted by ID, // second SharedChannelRemote that belongs to RC1, sorted by ID,
// so we accumulate those SharedChannelRemotes on creation and // so we accumulate those SharedChannelRemotes on creation and
@ -321,7 +335,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
sharedChannelRemotesFromRC1 := []*model.SharedChannelRemote{} sharedChannelRemotesFromRC1 := []*model.SharedChannelRemote{}
// create the shared channel remotes // 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{ scr := &model.SharedChannelRemote{
Id: model.NewId(), Id: model.NewId(),
ChannelId: sc.ChannelId, ChannelId: sc.ChannelId,
@ -330,6 +344,10 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
IsInviteConfirmed: true, IsInviteConfirmed: true,
RemoteId: sc.RemoteId, RemoteId: sc.RemoteId,
} }
// scr for c5 is not confirmed yet
if sc.ChannelId == sc5.ChannelId {
scr.IsInviteConfirmed = false
}
_, err = th.App.SaveSharedChannelRemote(scr) _, err = th.App.SaveSharedChannelRemote(scr)
require.NoError(t, err) require.NoError(t, err)
@ -355,9 +373,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name string Name string
Client *model.Client4 Client *model.Client4
RemoteId string RemoteId string
ExcludeHome bool Filter model.SharedChannelRemoteFilterOpts
ExcludeRemote bool
IncludeDeleted bool
Page int Page int
PerPage int PerPage int
ExpectedStatusCode 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", Name: "should return the complete list of shared channel remotes for a remote cluster, including deleted",
Client: th.SystemAdminClient, Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId, RemoteId: rc1.RemoteId,
IncludeDeleted: true, Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true},
Page: 0, Page: 0,
PerPage: 100, PerPage: 100,
ExpectedStatusCode: http.StatusOK, ExpectedStatusCode: http.StatusOK,
@ -407,7 +423,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name: "should return only the shared channel remotes homed localy", Name: "should return only the shared channel remotes homed localy",
Client: th.SystemAdminClient, Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId, RemoteId: rc1.RemoteId,
ExcludeRemote: true, Filter: model.SharedChannelRemoteFilterOpts{ExcludeRemote: true},
Page: 0, Page: 0,
PerPage: 100, PerPage: 100,
ExpectedStatusCode: http.StatusOK, ExpectedStatusCode: http.StatusOK,
@ -418,18 +434,40 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name: "should return only the shared channel remotes homed remotely", Name: "should return only the shared channel remotes homed remotely",
Client: th.SystemAdminClient, Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId, RemoteId: rc1.RemoteId,
ExcludeHome: true, Filter: model.SharedChannelRemoteFilterOpts{ExcludeHome: true},
Page: 0, Page: 0,
PerPage: 100, PerPage: 100,
ExpectedStatusCode: http.StatusOK, ExpectedStatusCode: http.StatusOK,
ExpectedError: false, ExpectedError: false,
ExpectedIds: []string{sc2.ChannelId}, 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", Name: "should correctly paginate the results",
Client: th.SystemAdminClient, Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId, RemoteId: rc1.RemoteId,
IncludeDeleted: true, Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true, IncludeUnconfirmed: true},
Page: 1, Page: 1,
PerPage: 1, PerPage: 1,
ExpectedStatusCode: http.StatusOK, ExpectedStatusCode: http.StatusOK,
@ -440,7 +478,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) { 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) checkHTTPStatus(t, resp, tc.ExpectedStatusCode)
if tc.ExpectedError { if tc.ExpectedError {
require.Error(t, err) require.Error(t, err)

View File

@ -99,6 +99,8 @@ type Params struct {
CreatorId string CreatorId string
OnlyConfirmed bool OnlyConfirmed bool
OnlyPlugins bool OnlyPlugins bool
IncludeUnconfirmed bool
ExcludeConfirmed bool
ExcludePlugins bool ExcludePlugins bool
ExcludeHome bool ExcludeHome bool
ExcludeRemote bool ExcludeRemote bool
@ -170,6 +172,8 @@ func ParamsFromRequest(r *http.Request) *Params {
params.CreatorId = query.Get("creator_id") params.CreatorId = query.Get("creator_id")
params.OnlyConfirmed, _ = strconv.ParseBool(query.Get("only_confirmed")) params.OnlyConfirmed, _ = strconv.ParseBool(query.Get("only_confirmed"))
params.OnlyPlugins, _ = strconv.ParseBool(query.Get("only_plugins")) 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.ExcludePlugins, _ = strconv.ParseBool(query.Get("exclude_plugins"))
params.ExcludeHome, _ = strconv.ParseBool(query.Get("exclude_home")) params.ExcludeHome, _ = strconv.ParseBool(query.Get("exclude_home"))
params.ExcludeRemote, _ = strconv.ParseBool(query.Get("exclude_remote")) 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 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{} 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") v.Set("exclude_home", "true")
} }
if excludeRemote { if filter.ExcludeRemote {
v.Set("exclude_remote", "true") v.Set("exclude_remote", "true")
} }
if includeDeleted { if filter.IncludeDeleted {
v.Set("include_deleted", "true") v.Set("include_deleted", "true")
} }
if page != 0 { if page != 0 {