MM-33180: Extend Group APIs for plugins. (#17232)

Add `GetGroupMemberUsers` (mapping to `GetGroupMemberUsersPage`) and `GetGroupsBySource`.

Fixes: https://mattermost.atlassian.net/browse/MM-33180

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Jesse Hallam 2021-04-12 14:01:28 -03:00 committed by GitHub
parent f145ac202d
commit 2de65cfb11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 146 additions and 0 deletions

View file

@ -537,6 +537,16 @@ func (api *PluginAPI) GetGroupByName(name string) (*model.Group, *model.AppError
return api.app.GetGroupByName(name, model.GroupSearchOpts{})
}
func (api *PluginAPI) GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError) {
users, _, err := api.app.GetGroupMemberUsersPage(groupID, page, perPage)
return users, err
}
func (api *PluginAPI) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
return api.app.GetGroupsBySource(groupSource)
}
func (api *PluginAPI) GetGroupsForUser(userID string) ([]*model.Group, *model.AppError) {
return api.app.GetGroupsByUserId(userID)
}

View file

@ -533,6 +533,18 @@ type API interface {
// Minimum server version: 5.18
GetGroupByName(name string) (*model.Group, *model.AppError)
// GetGroupMemberUsers gets a page of users belonging to the given group.
//
// @tag Group
// Minimum server version: 5.35
GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError)
// GetGroupsBySource gets a list of all groups for the given source.
//
// @tag Group
// Minimum server version: 5.35
GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
// GetGroupsForUser gets the groups a user is in.
//
// @tag Group

View file

@ -581,6 +581,20 @@ func (api *apiTimerLayer) GetGroupByName(name string) (*model.Group, *model.AppE
return _returnsA, _returnsB
}
func (api *apiTimerLayer) GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.GetGroupMemberUsers(groupID, page, perPage)
api.recordTime(startTime, "GetGroupMemberUsers", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.GetGroupsBySource(groupSource)
api.recordTime(startTime, "GetGroupsBySource", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) GetGroupsForUser(userId string) ([]*model.Group, *model.AppError) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.GetGroupsForUser(userId)

View file

@ -2821,6 +2821,66 @@ func (s *apiRPCServer) GetGroupByName(args *Z_GetGroupByNameArgs, returns *Z_Get
return nil
}
type Z_GetGroupMemberUsersArgs struct {
A string
B int
C int
}
type Z_GetGroupMemberUsersReturns struct {
A []*model.User
B *model.AppError
}
func (g *apiRPCClient) GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError) {
_args := &Z_GetGroupMemberUsersArgs{groupID, page, perPage}
_returns := &Z_GetGroupMemberUsersReturns{}
if err := g.client.Call("Plugin.GetGroupMemberUsers", _args, _returns); err != nil {
log.Printf("RPC call to GetGroupMemberUsers API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetGroupMemberUsers(args *Z_GetGroupMemberUsersArgs, returns *Z_GetGroupMemberUsersReturns) error {
if hook, ok := s.impl.(interface {
GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetGroupMemberUsers(args.A, args.B, args.C)
} else {
return encodableError(fmt.Errorf("API GetGroupMemberUsers called but not implemented."))
}
return nil
}
type Z_GetGroupsBySourceArgs struct {
A model.GroupSource
}
type Z_GetGroupsBySourceReturns struct {
A []*model.Group
B *model.AppError
}
func (g *apiRPCClient) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
_args := &Z_GetGroupsBySourceArgs{groupSource}
_returns := &Z_GetGroupsBySourceReturns{}
if err := g.client.Call("Plugin.GetGroupsBySource", _args, _returns); err != nil {
log.Printf("RPC call to GetGroupsBySource API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetGroupsBySource(args *Z_GetGroupsBySourceArgs, returns *Z_GetGroupsBySourceReturns) error {
if hook, ok := s.impl.(interface {
GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetGroupsBySource(args.A)
} else {
return encodableError(fmt.Errorf("API GetGroupsBySource called but not implemented."))
}
return nil
}
type Z_GetGroupsForUserArgs struct {
A string
}

View file

@ -1222,6 +1222,56 @@ func (_m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppErro
return r0, r1
}
// GetGroupMemberUsers provides a mock function with given fields: groupID, page, perPage
func (_m *API) GetGroupMemberUsers(groupID string, page int, perPage int) ([]*model.User, *model.AppError) {
ret := _m.Called(groupID, page, perPage)
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
r0 = rf(groupID, page, perPage)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.User)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
r1 = rf(groupID, page, perPage)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetGroupsBySource provides a mock function with given fields: groupSource
func (_m *API) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
ret := _m.Called(groupSource)
var r0 []*model.Group
if rf, ok := ret.Get(0).(func(model.GroupSource) []*model.Group); ok {
r0 = rf(groupSource)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Group)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(model.GroupSource) *model.AppError); ok {
r1 = rf(groupSource)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetGroupsForUser provides a mock function with given fields: userId
func (_m *API) GetGroupsForUser(userId string) ([]*model.Group, *model.AppError) {
ret := _m.Called(userId)