MM-12488: Accepts parameters to search and filter LDAP groups. (#10418)

This commit is contained in:
Martin Kraft
2019-03-14 15:43:52 -04:00
committed by GitHub
parent e94faea383
commit 5dbf8aec7d
5 changed files with 33 additions and 4 deletions

View File

@@ -68,7 +68,17 @@ func getLdapGroups(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
groups, total, err := c.App.GetAllLdapGroupsPage(c.Params.Page, c.Params.PerPage)
opts := model.GroupSearchOpts{
Q: c.Params.Q,
}
if c.Params.IsLinked != nil {
opts.IsLinked = c.Params.IsLinked
}
if c.Params.IsConfigured != nil {
opts.IsConfigured = c.Params.IsConfigured
}
groups, total, err := c.App.GetAllLdapGroupsPage(c.Params.Page, c.Params.PerPage, opts)
if err != nil {
c.Err = err
return

View File

@@ -61,13 +61,13 @@ func (a *App) GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) {
// GetAllLdapGroupsPage retrieves all LDAP groups under the configured base DN using the default or configured group
// filter.
func (a *App) GetAllLdapGroupsPage(page int, perPage int) ([]*model.Group, int, *model.AppError) {
func (a *App) GetAllLdapGroupsPage(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, int, *model.AppError) {
var groups []*model.Group
var total int
if a.Ldap != nil {
var err *model.AppError
groups, total, err = a.Ldap.GetAllGroupsPage(page, perPage)
groups, total, err = a.Ldap.GetAllGroupsPage(page, perPage, opts)
if err != nil {
return nil, 0, err
}

View File

@@ -19,6 +19,6 @@ type LdapInterface interface {
GetAllLdapUsers() ([]*model.User, *model.AppError)
MigrateIDAttribute(toAttribute string) error
GetGroup(groupUID string) (*model.Group, *model.AppError)
GetAllGroupsPage(page int, perPage int) ([]*model.Group, int, *model.AppError)
GetAllGroupsPage(page int, perPage int, opts model.GroupSearchOpts) ([]*model.Group, int, *model.AppError)
FirstLoginSync(userID, userAuthService, userAuthData string) *model.AppError
}

View File

@@ -48,6 +48,12 @@ type GroupPatch struct {
Description *string `json:"description"`
}
type GroupSearchOpts struct {
Q string
IsLinked *bool
IsConfigured *bool
}
func (group *Group) Patch(patch *GroupPatch) {
if patch.Name != nil {
group.Name = *patch.Name

View File

@@ -59,6 +59,9 @@ type Params struct {
SyncableId string
SyncableType model.GroupSyncableType
BotUserId string
Q string
IsLinked *bool
IsConfigured *bool
}
func ParamsFromRequest(r *http.Request) *Params {
@@ -232,5 +235,15 @@ func ParamsFromRequest(r *http.Request) *Params {
params.BotUserId = val
}
params.Q = query.Get("q")
if val, err := strconv.ParseBool(query.Get("is_linked")); err == nil {
params.IsLinked = &val
}
if val, err := strconv.ParseBool(query.Get("is_configured")); err == nil {
params.IsConfigured = &val
}
return params
}