Last active
June 12, 2020 07:34
-
-
Save har07/c2bf836553182c1410cea90f0fb5e4be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (h *PolicyHandler) listUsersGrid(c echo.Context) error { | |
tenant := c.Param("tenant") | |
id := c.Param("id") | |
gridParams := c.Get("gridParams").(*query.GridParams) | |
policy, err := h.PolicyStorage.GetPolicy(tenant, id) | |
if err != nil { | |
return response.JSONError(c, http.StatusBadRequest, err) | |
} | |
// because groups can contain users, we list users in groups too | |
groupMembers, _ := h.GroupStorage.GetGroupsMembers(tenant, policy.GroupIDs) | |
groupMembers, _ = array.AddElementStringArray(groupMembers, policy.UserIDs) | |
// gridParams.HasFilter = true | |
// gridParams.Filter.Logic = "or" | |
// filter | |
if len(groupMembers) > 0 { | |
gridParams.HasFilter = true | |
parent := &query.GridFilter{} | |
parent.Logic = "or" | |
parent.Field = "id" | |
parent.Operator = "eq" | |
parent.Value = groupMembers[0] | |
if len(groupMembers) > 1 { | |
parent.HasSubFilter = true | |
for _, v := range groupMembers[1:] { | |
gf := &query.GridFilter{} | |
gf.Field = "id" | |
gf.Operator = "eq" | |
gf.Value = v | |
parent.Filters = append(parent.Filters, *gf) | |
} | |
} | |
gridParams.Filter.Filters = append(gridParams.Filter.Filters, *parent) | |
} | |
data, count, err := h.ProfileStorage.GridProfiles(tenant, gridParams) | |
if err != nil { | |
return response.JSONError(c, http.StatusBadRequest, err) | |
} | |
return response.JSONGrid(c, http.StatusOK, data, len(data), count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment