MCPcopy Create free account
hub / github.com/documentdb/documentdb / GetAllUsersInfo

Function GetAllUsersInfo

pg_documentdb/src/commands/users.c:1599–1626  ·  view source on GitHub ↗

* GetAllUsersInfo queries and returns all users information, including their id, name, and roles. * We need to exclude system pg login roles. * Returns the user info datum containing the query result. */

Source from the content-addressed store, hash-verified

1597 * Returns the user info datum containing the query result.
1598 */
1599static Datum
1600GetAllUsersInfo(void)
1601{
1602 const char *cmdStr = FormatSqlQuery(
1603 "WITH r AS ("
1604 " SELECT child.rolname::text AS child_role, "
1605 " CASE WHEN parent.rolname = '%s' "
1606 " THEN '%s' "
1607 " ELSE parent.rolname::text "
1608 " END AS parent_role "
1609 " FROM pg_roles parent "
1610 " JOIN pg_auth_members am ON parent.oid = am.roleid "
1611 " JOIN pg_roles child ON am.member = child.oid "
1612 " WHERE child.rolcanlogin = true "
1613 " AND child.rolname NOT IN ('%s', '%s', '%s', '%s', '%s') "
1614 ") "
1615 "SELECT ARRAY_AGG(%s.row_get_bson(r) ORDER BY r.child_role, r.parent_role) "
1616 "FROM r;",
1617 ApiRootInternalRole, ApiRootRole,
1618 ApiAdminRole, ApiAdminRoleV2, ApiBgWorkerRole, ApiReplicationRole,
1619 ApiSettingsManagerRole,
1620 CoreSchemaName);
1621
1622 bool readOnly = true;
1623 bool isNull = false;
1624 return ExtensionExecuteQueryViaSPI(cmdStr, readOnly, SPI_OK_SELECT,
1625 &isNull);
1626}
1627
1628
1629/*

Callers 1

Calls 2

FormatSqlQueryFunction · 0.85

Tested by

no test coverage detected