MM-16258: Adds new API endpoint + (App & Client & Store) to retrieve … (#11176)

* MM-16258: Adds new API endpoint + (App & Client & Store) to retrieve Users who would be removed from a list of hypothetical group IDs representing the synced groups.

* MM-16258: Adds roles to JSON response.

* MM-16258: Updates GetByIDs to use Squirrel.

* MM-16258: Puts as much as possible into Squirrel.

* MM-16258: Changes names of methods, functions, and route.

* MM-16258: Updates some comments.

* MM-16258: Extra validation of group_ids parameter.

* MM-16258: Changes validation of group_ids query param.

* MM-16258: Rename a variable and a constant.

* MM-16258: Fix test.
Этот коммит содержится в:
Martin Kraft
2019-06-17 09:51:56 -04:00
коммит произвёл GitHub
родитель 5ee1f6e2e0
Коммит 9d41c7a583
10 изменённых файлов: 615 добавлений и 0 удалений

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

@@ -4412,3 +4412,15 @@ func (c *Client4) PatchGroupSyncable(groupID, syncableID string, syncableType Gr
defer closeBody(r)
return GroupSyncableFromJson(r.Body), BuildResponse(r)
}
func (c *Client4) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int, etag string) ([]*UserWithGroups, int64, *Response) {
groupIDStr := strings.Join(groupIDs, ",")
query := fmt.Sprintf("?group_ids=%s&page=%d&per_page=%d", groupIDStr, page, perPage)
r, err := c.DoApiGet(c.GetTeamRoute(teamID)+"/members_minus_group_members"+query, etag)
if err != nil {
return nil, 0, BuildErrorResponse(r, err)
}
defer closeBody(r)
ugc := UsersWithGroupsAndCountFromJson(r.Body)
return ugc.Users, ugc.Count, BuildResponse(r)
}

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

@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"regexp"
"sort"
@@ -768,3 +769,24 @@ func IsValidLocale(locale string) bool {
return true
}
type UserWithGroups struct {
User
GroupIDs string `json:"-"`
Groups []*Group `json:"groups"`
SchemeGuest bool `json:"scheme_guest"`
SchemeUser bool `json:"scheme_user"`
SchemeAdmin bool `json:"scheme_admin"`
}
type UsersWithGroupsAndCount struct {
Users []*UserWithGroups `json:"users"`
Count int64 `json:"total_count"`
}
func UsersWithGroupsAndCountFromJson(data io.Reader) *UsersWithGroupsAndCount {
uwg := &UsersWithGroupsAndCount{}
bodyBytes, _ := ioutil.ReadAll(data)
json.Unmarshal(bodyBytes, uwg)
return uwg
}