Skip to content

Commit

Permalink
Update groups API
Browse files Browse the repository at this point in the history
  • Loading branch information
jfreda committed Apr 12, 2024
1 parent f8c1c75 commit cee9681
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/api/v2/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
Expand Down

0 comments on commit cee9681

Please sign in to comment.