From 5dbf8aec7d8abcd548b2e7a6847bc0def3f4b4ed Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Thu, 14 Mar 2019 15:43:52 -0400 Subject: [PATCH] MM-12488: Accepts parameters to search and filter LDAP groups. (#10418) --- api4/ldap.go | 12 +++++++++++- app/ldap.go | 4 ++-- einterfaces/ldap.go | 2 +- model/group.go | 6 ++++++ web/params.go | 13 +++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/api4/ldap.go b/api4/ldap.go index 69766a4add..0c42800adf 100644 --- a/api4/ldap.go +++ b/api4/ldap.go @@ -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 diff --git a/app/ldap.go b/app/ldap.go index ffe73c1456..b892255cec 100644 --- a/app/ldap.go +++ b/app/ldap.go @@ -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 } diff --git a/einterfaces/ldap.go b/einterfaces/ldap.go index b7dc18a9b8..ddc72f752b 100644 --- a/einterfaces/ldap.go +++ b/einterfaces/ldap.go @@ -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 } diff --git a/model/group.go b/model/group.go index f0754848c8..0761afa5ac 100644 --- a/model/group.go +++ b/model/group.go @@ -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 diff --git a/web/params.go b/web/params.go index 5f39edce8e..6f915352ce 100644 --- a/web/params.go +++ b/web/params.go @@ -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 }