mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
GH-9636 plugins api GetUsersInChannelByStatus (#9645)
* adds GetUsersInChannelByStatus to plugin api with generated rpc code. * fixed typo in comment with actual func name * replaced Response model with AppError in output of GetUsersInChannelByStatus * removed etag param from GetUsersInChannelByStatus since it is not used * plugin api for GetUsersInChannelByStatus updated to take the limit, conforming to the app api. * fixed an issue in my own logic on app/plugin integration. * adds GetUsersInChannelByStatus to plugin api with generated rpc code. * fixed typo in comment with actual func name * replaced Response model with AppError in output of GetUsersInChannelByStatus * removed etag param from GetUsersInChannelByStatus since it is not used * plugin api for GetUsersInChannelByStatus updated to take the limit, conforming to the app api. * fixed an issue in my own logic on app/plugin integration. * GetUsersInChannelByStatus changed to more generic GetUsersInChannel which takes a sortBy parameter, allowing for more granular/extensible sorting functionality in the future * GetUsersInChannel accepts sort parameter of 'username' and 'status'. Both values are consts in model pkg. * Documents minimum server version for GetUsersInChannel. * adds GetUsersInChannelByStatus to plugin api with generated rpc code. * fixed typo in comment with actual func name * replaced Response model with AppError in output of GetUsersInChannelByStatus * removed etag param from GetUsersInChannelByStatus since it is not used * plugin api for GetUsersInChannelByStatus updated to take the limit, conforming to the app api. * fixed an issue in my own logic on app/plugin integration. * adds GetUsersInChannelByStatus to plugin api with generated rpc code. * Resolved conflict on rebase * replaced Response model with AppError in output of GetUsersInChannelByStatus * removed etag param from GetUsersInChannelByStatus since it is not used * plugin api for GetUsersInChannelByStatus updated to take the limit, conforming to the app api. * fixed an issue in my own logic on app/plugin integration. * GetUsersInChannelByStatus changed to more generic GetUsersInChannel which takes a sortBy parameter, allowing for more granular/extensible sorting functionality in the future * GetUsersInChannel accepts sort parameter of 'username' and 'status'. Both values are consts in model pkg. * Documents minimum server version for GetUsersInChannel. * replaces GetUsersInChannel from #9608 / #9643 with sortBy functionality
This commit is contained in:
committed by
Joram Wilander
parent
6c6638f05e
commit
1ee872578c
@@ -200,6 +200,18 @@ func (api *PluginAPI) UpdateUserStatus(userId, status string) (*model.Status, *m
|
|||||||
|
|
||||||
return api.app.GetStatus(userId)
|
return api.app.GetStatus(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *PluginAPI) GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
||||||
|
switch sortBy {
|
||||||
|
case model.CHANNEL_SORT_BY_USERNAME:
|
||||||
|
return api.app.GetUsersInChannel(channelId, page*perPage, perPage)
|
||||||
|
case model.CHANNEL_SORT_BY_STATUS:
|
||||||
|
return api.app.GetUsersInChannelByStatus(channelId, page*perPage, perPage)
|
||||||
|
default:
|
||||||
|
return nil, model.NewAppError("GetUsersInChannel", "plugin.api.get_users_in_channel", nil, "invalid sort option", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) {
|
func (api *PluginAPI) GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) {
|
||||||
if api.app.Ldap == nil {
|
if api.app.Ldap == nil {
|
||||||
return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
@@ -298,10 +310,6 @@ func (api *PluginAPI) DeleteChannelMember(channelId, userId string) *model.AppEr
|
|||||||
return api.app.LeaveChannel(channelId, userId)
|
return api.app.LeaveChannel(channelId, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
|
||||||
return api.app.GetUsersInChannel(channelId, page*perPage, perPage)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
return api.app.CreatePostMissingChannel(post, true)
|
return api.app.CreatePostMissingChannel(post, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ const (
|
|||||||
CHANNEL_HEADER_MAX_RUNES = 1024
|
CHANNEL_HEADER_MAX_RUNES = 1024
|
||||||
CHANNEL_PURPOSE_MAX_RUNES = 250
|
CHANNEL_PURPOSE_MAX_RUNES = 250
|
||||||
CHANNEL_CACHE_SIZE = 25000
|
CHANNEL_CACHE_SIZE = 25000
|
||||||
|
|
||||||
|
CHANNEL_SORT_BY_USERNAME = "username"
|
||||||
|
CHANNEL_SORT_BY_STATUS = "status"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
|
|||||||
@@ -832,7 +832,7 @@ func (c *Client4) GetUsersInChannel(channelId string, page int, perPage int, eta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsersInChannelStatus returns a page of users in a channel. Page counting starts at 0. Sorted by Status
|
// GetUsersInChannelByStatus returns a page of users in a channel. Page counting starts at 0. Sorted by Status
|
||||||
func (c *Client4) GetUsersInChannelByStatus(channelId string, page int, perPage int, etag string) ([]*User, *Response) {
|
func (c *Client4) GetUsersInChannelByStatus(channelId string, page int, perPage int, etag string) ([]*User, *Response) {
|
||||||
query := fmt.Sprintf("?in_channel=%v&page=%v&per_page=%v&sort=status", channelId, page, perPage)
|
query := fmt.Sprintf("?in_channel=%v&page=%v&per_page=%v&sort=status", channelId, page, perPage)
|
||||||
if r, err := c.DoApiGet(c.GetUsersRoute()+query, etag); err != nil {
|
if r, err := c.DoApiGet(c.GetUsersRoute()+query, etag); err != nil {
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ type API interface {
|
|||||||
// The status parameter can be: "online", "away", "dnd", or "offline".
|
// The status parameter can be: "online", "away", "dnd", or "offline".
|
||||||
UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
|
UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
|
||||||
|
|
||||||
|
// GetUsersInChannel returns a page of users in a channel. Page counting starts at 0.
|
||||||
|
// The sortBy parameter can be: "username" or "status".
|
||||||
|
//
|
||||||
|
// Minimum server version: 5.6
|
||||||
|
GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError)
|
||||||
|
|
||||||
// GetLDAPUserAttributes will return LDAP attributes for a user.
|
// GetLDAPUserAttributes will return LDAP attributes for a user.
|
||||||
// The attributes parameter should be a list of attributes to pull.
|
// The attributes parameter should be a list of attributes to pull.
|
||||||
// Returns a map with attribute names as keys and the user's attributes as values.
|
// Returns a map with attribute names as keys and the user's attributes as values.
|
||||||
@@ -183,11 +189,6 @@ type API interface {
|
|||||||
// DeleteChannelMember deletes a channel membership for a user.
|
// DeleteChannelMember deletes a channel membership for a user.
|
||||||
DeleteChannelMember(channelId, userId string) *model.AppError
|
DeleteChannelMember(channelId, userId string) *model.AppError
|
||||||
|
|
||||||
// GetUsersInChannel gets users in given channel.
|
|
||||||
//
|
|
||||||
// Minimum server version: 5.6
|
|
||||||
GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError)
|
|
||||||
|
|
||||||
// CreatePost creates a post.
|
// CreatePost creates a post.
|
||||||
CreatePost(post *model.Post) (*model.Post, *model.AppError)
|
CreatePost(post *model.Post) (*model.Post, *model.AppError)
|
||||||
|
|
||||||
|
|||||||
@@ -1004,6 +1004,38 @@ func (s *apiRPCServer) UpdateUserStatus(args *Z_UpdateUserStatusArgs, returns *Z
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Z_GetUsersInChannelArgs struct {
|
||||||
|
A string
|
||||||
|
B string
|
||||||
|
C int
|
||||||
|
D int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Z_GetUsersInChannelReturns struct {
|
||||||
|
A []*model.User
|
||||||
|
B *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *apiRPCClient) GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
||||||
|
_args := &Z_GetUsersInChannelArgs{channelId, sortBy, page, perPage}
|
||||||
|
_returns := &Z_GetUsersInChannelReturns{}
|
||||||
|
if err := g.client.Call("Plugin.GetUsersInChannel", _args, _returns); err != nil {
|
||||||
|
log.Printf("RPC call to GetUsersInChannel API failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
return _returns.A, _returns.B
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *apiRPCServer) GetUsersInChannel(args *Z_GetUsersInChannelArgs, returns *Z_GetUsersInChannelReturns) error {
|
||||||
|
if hook, ok := s.impl.(interface {
|
||||||
|
GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError)
|
||||||
|
}); ok {
|
||||||
|
returns.A, returns.B = hook.GetUsersInChannel(args.A, args.B, args.C, args.D)
|
||||||
|
} else {
|
||||||
|
return encodableError(fmt.Errorf("API GetUsersInChannel called but not implemented."))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Z_GetLDAPUserAttributesArgs struct {
|
type Z_GetLDAPUserAttributesArgs struct {
|
||||||
A string
|
A string
|
||||||
B []string
|
B []string
|
||||||
@@ -1928,37 +1960,6 @@ func (s *apiRPCServer) DeleteChannelMember(args *Z_DeleteChannelMemberArgs, retu
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Z_GetUsersInChannelArgs struct {
|
|
||||||
A string
|
|
||||||
B int
|
|
||||||
C int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Z_GetUsersInChannelReturns struct {
|
|
||||||
A []*model.User
|
|
||||||
B *model.AppError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *apiRPCClient) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
|
||||||
_args := &Z_GetUsersInChannelArgs{channelId, page, perPage}
|
|
||||||
_returns := &Z_GetUsersInChannelReturns{}
|
|
||||||
if err := g.client.Call("Plugin.GetUsersInChannel", _args, _returns); err != nil {
|
|
||||||
log.Printf("RPC call to GetUsersInChannel API failed: %s", err.Error())
|
|
||||||
}
|
|
||||||
return _returns.A, _returns.B
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *apiRPCServer) GetUsersInChannel(args *Z_GetUsersInChannelArgs, returns *Z_GetUsersInChannelReturns) error {
|
|
||||||
if hook, ok := s.impl.(interface {
|
|
||||||
GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError)
|
|
||||||
}); ok {
|
|
||||||
returns.A, returns.B = hook.GetUsersInChannel(args.A, args.B, args.C)
|
|
||||||
} else {
|
|
||||||
return encodableError(fmt.Errorf("API GetUsersInChannel called but not implemented."))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Z_CreatePostArgs struct {
|
type Z_CreatePostArgs struct {
|
||||||
A *model.Post
|
A *model.Post
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1243,6 +1243,32 @@ func (_m *API) GetUsersByUsernames(usernames []string) ([]*model.User, *model.Ap
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsersInChannel provides a mock function with given fields: channelId, sortBy, page, perPage
|
||||||
|
func (_m *API) GetUsersInChannel(channelId string, sortBy string, page int, perPage int) ([]*model.User, *model.AppError) {
|
||||||
|
ret := _m.Called(channelId, sortBy, page, perPage)
|
||||||
|
|
||||||
|
var r0 []*model.User
|
||||||
|
if rf, ok := ret.Get(0).(func(string, string, int, int) []*model.User); ok {
|
||||||
|
r0 = rf(channelId, sortBy, 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, string, int, int) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId, sortBy, page, perPage)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersInTeam provides a mock function with given fields: teamId, page, perPage
|
// GetUsersInTeam provides a mock function with given fields: teamId, page, perPage
|
||||||
func (_m *API) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
func (_m *API) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
||||||
ret := _m.Called(teamId, page, perPage)
|
ret := _m.Called(teamId, page, perPage)
|
||||||
@@ -1268,31 +1294,6 @@ func (_m *API) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.Us
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsersInChannel provides a mock function with given fields: channelId, page, perPage
|
|
||||||
func (_m *API) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
|
||||||
ret := _m.Called(channelId, page, perPage)
|
|
||||||
|
|
||||||
var r0 []*model.User
|
|
||||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
|
|
||||||
r0 = rf(channelId, 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(channelId, page, perPage)
|
|
||||||
} else {
|
|
||||||
if ret.Get(1) != nil {
|
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasPermissionTo provides a mock function with given fields: userId, permission
|
// HasPermissionTo provides a mock function with given fields: userId, permission
|
||||||
func (_m *API) HasPermissionTo(userId string, permission *model.Permission) bool {
|
func (_m *API) HasPermissionTo(userId string, permission *model.Permission) bool {
|
||||||
ret := _m.Called(userId, permission)
|
ret := _m.Called(userId, permission)
|
||||||
|
|||||||
Reference in New Issue
Block a user