MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / getUsers

Method getUsers

rest/admin_api.go:2033–2081  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2031}
2032
2033func (h *handler) getUsers() error {
2034
2035 limit := h.getIntQuery(paramLimit, 0)
2036 nameOnly, _ := h.getOptBoolQuery(paramNameOnly, true)
2037
2038 if limit > 0 && nameOnly {
2039 return base.HTTPErrorf(http.StatusBadRequest, "Use of %s only supported when %s=false", paramLimit, paramNameOnly)
2040 }
2041
2042 var bytes []byte
2043 var marshalErr error
2044 if nameOnly {
2045 var users []string
2046 var err error
2047 if h.db.Options.UseViews {
2048 users, _, err = h.db.AllPrincipalIDs(h.ctx())
2049 } else {
2050 users, err = h.db.GetUserNames(h.ctx())
2051 }
2052 if err != nil {
2053 return err
2054 }
2055 bytes, marshalErr = base.JSONMarshal(users)
2056 } else {
2057 if h.db.Options.UseViews {
2058 return base.HTTPErrorf(http.StatusBadRequest, "Use of %s=false not supported when database has use_views=true", paramNameOnly)
2059 }
2060 users, err := h.db.GetUsers(h.ctx(), int(limit))
2061 if err != nil {
2062 return err
2063 }
2064 bytes, marshalErr = base.JSONMarshal(users)
2065 }
2066
2067 if marshalErr != nil {
2068 return marshalErr
2069 }
2070
2071 auditFields := base.AuditFields{
2072 base.AuditFieldNameOnly: nameOnly,
2073 }
2074 if limit > 0 {
2075 auditFields[base.AuditFieldLimit] = limit
2076 }
2077 base.Audit(h.ctx(), base.AuditIDUsersAll, auditFields)
2078
2079 h.writeRawJSON(bytes)
2080 return nil
2081}
2082
2083func (h *handler) getRoles() error {
2084 includeDeleted, _ := h.getOptBoolQuery(paramDeleted, false)

Callers

nothing calls this directly

Calls 10

getIntQueryMethod · 0.95
getOptBoolQueryMethod · 0.95
ctxMethod · 0.95
writeRawJSONMethod · 0.95
HTTPErrorfFunction · 0.92
JSONMarshalFunction · 0.92
AuditFunction · 0.92
AllPrincipalIDsMethod · 0.80
GetUserNamesMethod · 0.80
GetUsersMethod · 0.80

Tested by

no test coverage detected