From cee9681c3d9dbbfab3b7e098e0359f35137c5272 Mon Sep 17 00:00:00 2001 From: Josh Freda Date: Fri, 12 Apr 2024 11:24:39 -0500 Subject: [PATCH] Update groups API --- internal/api/v2/groups.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/api/v2/groups.go b/internal/api/v2/groups.go index b40b22940..ce0bd2988 100644 --- a/internal/api/v2/groups.go +++ b/internal/api/v2/groups.go @@ -47,6 +47,14 @@ func GroupsHandler(srv server.Server) http.Handler { return } + // Respond with error if group approvals are not enabled. + if srv.Config.GoogleWorkspace.GroupApprovals == nil || + !srv.Config.GoogleWorkspace.GroupApprovals.Enabled { + http.Error(w, + "Group approvals have not been enabled", http.StatusUnprocessableEntity) + return + } + switch r.Method { case "POST": // Decode request. @@ -73,11 +81,16 @@ func GroupsHandler(srv server.Server) http.Handler { ) // Retrieve groups with prefix, if configured. - if srv.Config.GoogleWorkspace.GroupApprovals.SearchPrefix != "" { + searchPrefix := "" + if srv.Config.GoogleWorkspace.GroupApprovals != nil && + srv.Config.GoogleWorkspace.GroupApprovals.SearchPrefix != "" { + searchPrefix = srv.Config.GoogleWorkspace.GroupApprovals.SearchPrefix + } + if searchPrefix != "" { maxNonPrefixGroups = maxGroupResults - maxPrefixGroupResults prefixQuery := fmt.Sprintf( - "%s%s", srv.Config.GoogleWorkspace.GroupApprovals.SearchPrefix, query) + "%s%s", searchPrefix, query) prefixGroups, err = srv.GWService.AdminDirectory.Groups.List(). Domain(srv.Config.GoogleWorkspace.Domain). MaxResults(maxPrefixGroupResults).