MM-64330 - filter abac users in channel invite (#31219)

* MM-64330 - filter abac users in channel invite

* implement cursor functionality for abac user filtering

* remove unnecessary comments

* refactor the backend implementation simplifying the functions

* refactor api to use opts as parameters, rename function

* add missing translation

* remove unnecesary test code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Pablo Vélez
2025-06-20 10:53:14 +02:00
коммит произвёл GitHub
родитель 968550d275
Коммит 5fc74cd401
11 изменённых файлов: 346 добавлений и 21 удалений

Просмотреть файл

@@ -1396,8 +1396,23 @@ func (c *Client4) GetUsersInChannelByStatus(ctx context.Context, channelId strin
// GetUsersNotInChannel returns a page of users not in a channel. Page counting starts at 0.
func (c *Client4) GetUsersNotInChannel(ctx context.Context, teamId, channelId string, page int, perPage int, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?in_team=%v&not_in_channel=%v&page=%v&per_page=%v", teamId, channelId, page, perPage)
r, err := c.DoAPIGet(ctx, c.usersRoute()+query, etag)
options := &GetUsersNotInChannelOptions{
TeamID: teamId,
Page: page,
Limit: perPage,
Etag: etag,
CursorID: "",
}
return c.GetUsersNotInChannelWithOptions(ctx, channelId, options)
}
// GetUsersNotInChannelWithOptionsStruct returns a page of users not in a channel using the options struct.
func (c *Client4) GetUsersNotInChannelWithOptions(ctx context.Context, channelId string, options *GetUsersNotInChannelOptions) ([]*User, *Response, error) {
query := fmt.Sprintf("?in_team=%v&not_in_channel=%v&page=%v&per_page=%v", options.TeamID, channelId, options.Page, options.Limit)
if options.CursorID != "" {
query += fmt.Sprintf("&cursor_id=%v", options.CursorID)
}
r, err := c.DoAPIGet(ctx, c.usersRoute()+query, options.Etag)
if err != nil {
return nil, BuildResponse(r), err
}
@@ -1407,7 +1422,7 @@ func (c *Client4) GetUsersNotInChannel(ctx context.Context, teamId, channelId st
return list, BuildResponse(r), nil
}
if err := json.NewDecoder(r.Body).Decode(&list); err != nil {
return nil, nil, NewAppError("GetUsersNotInChannel", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return nil, nil, NewAppError("GetUsersNotInChannelWithOptionsStruct", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return list, BuildResponse(r), nil
}

Просмотреть файл

@@ -243,6 +243,19 @@ type ViewUsersRestrictions struct {
Channels []string
}
//msgp:ignore GetUsersNotInChannelOptions
type GetUsersNotInChannelOptions struct {
TeamID string `json:"team_id"`
// Page-based pagination (used for non-ABAC channels)
// This will be discarded if the channel has an ABAC policy and CursorID will be used.
Page int `json:"page"`
Limit int `json:"limit"`
// Cursor-based pagination (used for ABAC channels)
// If CursorID is empty for ABAC channels, it will start from the beginning
CursorID string `json:"cursor_id"`
Etag string `json:"etag"`
}
func (r *ViewUsersRestrictions) Hash() string {
if r == nil {
return ""