[MM-47378] Respond with bad requests for wrong query parameters 'roles' in getUsers (#21569)

* Respond with bad requests for wrong query parameters in roles

* Revert "Respond with bad requests for wrong query parameters in roles"

This reverts commit d8374d94e0b1f61ad445127010f9780475c48d1a.

* Add GetUser client function to query with channel_id and roles

* Return bad parameters error on invalid roles

* Make client function generic, lint fixes

* i18n strings addition

* Validate 'role', add stricter check for comma separated roles
Этот коммит содержится в:
Shivashis Padhi
2022-12-09 11:43:13 +05:30
коммит произвёл GitHub
родитель fc31b1713e
Коммит 0193bfd7de
5 изменённых файлов: 149 добавлений и 0 удалений

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

@@ -1060,6 +1060,24 @@ func (c *Client4) GetUsers(page int, perPage int, etag string) ([]*User, *Respon
return list, BuildResponse(r), nil
}
// GetUsersWithChannelRoles returns a page of users on the system. Page counting starts at 0.
func (c *Client4) GetUsersWithCustomQueryParameters(page int, perPage int, queryParameters, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?page=%v&per_page=%v&%v", page, perPage, queryParameters)
r, err := c.DoAPIGet(c.usersRoute()+query, etag)
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var list []*User
if r.StatusCode == http.StatusNotModified {
return list, BuildResponse(r), nil
}
if err := json.NewDecoder(r.Body).Decode(&list); err != nil {
return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return list, BuildResponse(r), nil
}
// GetUsersInTeam returns a page of users on a team. Page counting starts at 0.
func (c *Client4) GetUsersInTeam(teamId string, page int, perPage int, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?in_team=%v&page=%v&per_page=%v", teamId, page, perPage)