Skip to content

Commit 1695728

Browse files
committed
feat(ledger): list_report_shares — where a report went, with revocation state
The sender's read behind share_report and revoke_report_share: each recipient graph, when, by whom, how many facts, and whether the share was revoked. report_id narrows to one report; omitted, the list is the graph's distribution log. Revoked rows stay out unless include_revoked is set. Schema snapshot refreshed for the reportShares field (robosystems #1913).
1 parent bfa6f26 commit 1695728

8 files changed

Lines changed: 287 additions & 0 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@
412412
from ..graphql.generated.list_ledger_blocked_source_graphs import (
413413
ListLedgerBlockedSourceGraphsBlockedSourceGraphs as BlockedSourceGraphsPage,
414414
)
415+
from ..graphql.generated.list_ledger_report_shares import (
416+
ListLedgerReportShares,
417+
)
418+
from ..graphql.generated.list_ledger_report_shares import (
419+
ListLedgerReportSharesReportShares as ReportSharesPage,
420+
)
415421
from ..graphql.generated.list_ledger_agents import (
416422
ListLedgerAgents,
417423
ListLedgerAgentsAgents,
@@ -528,6 +534,7 @@
528534
LIST_INFORMATION_BLOCKS_GQL,
529535
LIST_LEDGER_ACCOUNTS_GQL,
530536
LIST_LEDGER_BLOCKED_SOURCE_GRAPHS_GQL,
537+
LIST_LEDGER_REPORT_SHARES_GQL,
531538
LIST_LEDGER_AGENTS_GQL,
532539
LIST_LEDGER_DIMENSIONS_GQL,
533540
LIST_LEDGER_ELEMENTS_GQL,
@@ -3535,6 +3542,34 @@ def revoke_report_share(
35353542
"Revoke report share", envelope, RevokeReportShareResponse
35363543
)
35373544

3545+
def list_report_shares(
3546+
self,
3547+
graph_id: str,
3548+
report_id: str | None = None,
3549+
include_revoked: bool = False,
3550+
limit: int = 100,
3551+
offset: int = 0,
3552+
) -> ReportSharesPage | None:
3553+
"""Where this graph's reports have been shared — the sender's record
3554+
behind `share_report` and `revoke_report_share`.
3555+
3556+
`report_id` narrows to one report; omitted, the list is the graph's whole
3557+
distribution log. Revoked shares stay out unless `include_revoked` is set:
3558+
a recipient shared to, revoked, and shared to again has one revoked row
3559+
and one live.
3560+
"""
3561+
data = self._query(
3562+
graph_id,
3563+
LIST_LEDGER_REPORT_SHARES_GQL,
3564+
{
3565+
"reportId": report_id,
3566+
"includeRevoked": include_revoked,
3567+
"limit": limit,
3568+
"offset": offset,
3569+
},
3570+
)
3571+
return ListLedgerReportShares.model_validate(data).report_shares
3572+
35383573
# ── Blocked source graphs ────────────────────────────────────────────
35393574
#
35403575
# Sharing is authorized capability-style: whoever holds this graph's id

‎robosystems_client/graphql/generated/__init__.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@
352352
ListLedgerReconciliationsReconciliationsReconciliationsDifferencesRollForward,
353353
ListLedgerReconciliationsReconciliationsReconciliationsRollForward,
354354
)
355+
from .list_ledger_report_shares import (
356+
ListLedgerReportShares,
357+
ListLedgerReportSharesReportShares,
358+
ListLedgerReportSharesReportSharesPagination,
359+
ListLedgerReportSharesReportSharesReportShares,
360+
)
355361
from .list_ledger_reports import (
356362
ListLedgerReports,
357363
ListLedgerReportsReports,
@@ -456,6 +462,7 @@
456462
LIST_LEDGER_MAPPINGS_GQL,
457463
LIST_LEDGER_PUBLISH_LISTS_GQL,
458464
LIST_LEDGER_RECONCILIATIONS_GQL,
465+
LIST_LEDGER_REPORT_SHARES_GQL,
459466
LIST_LEDGER_REPORTS_GQL,
460467
LIST_LEDGER_STRUCTURES_GQL,
461468
LIST_LEDGER_TAXONOMIES_GQL,
@@ -716,6 +723,7 @@
716723
"LIST_LEDGER_PUBLISH_LISTS_GQL",
717724
"LIST_LEDGER_RECONCILIATIONS_GQL",
718725
"LIST_LEDGER_REPORTS_GQL",
726+
"LIST_LEDGER_REPORT_SHARES_GQL",
719727
"LIST_LEDGER_STRUCTURES_GQL",
720728
"LIST_LEDGER_TAXONOMIES_GQL",
721729
"LIST_LEDGER_TRANSACTIONS_GQL",
@@ -806,6 +814,10 @@
806814
"ListLedgerReconciliationsReconciliationsReconciliationsDifferencesComponents",
807815
"ListLedgerReconciliationsReconciliationsReconciliationsDifferencesRollForward",
808816
"ListLedgerReconciliationsReconciliationsReconciliationsRollForward",
817+
"ListLedgerReportShares",
818+
"ListLedgerReportSharesReportShares",
819+
"ListLedgerReportSharesReportSharesPagination",
820+
"ListLedgerReportSharesReportSharesReportShares",
809821
"ListLedgerReports",
810822
"ListLedgerReportsReports",
811823
"ListLedgerReportsReportsReports",

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from .list_ledger_mappings import ListLedgerMappings
5959
from .list_ledger_publish_lists import ListLedgerPublishLists
6060
from .list_ledger_reconciliations import ListLedgerReconciliations
61+
from .list_ledger_report_shares import ListLedgerReportShares
6162
from .list_ledger_reports import ListLedgerReports
6263
from .list_ledger_structures import ListLedgerStructures
6364
from .list_ledger_taxonomies import ListLedgerTaxonomies
@@ -125,6 +126,7 @@
125126
LIST_LEDGER_MAPPINGS_GQL,
126127
LIST_LEDGER_PUBLISH_LISTS_GQL,
127128
LIST_LEDGER_RECONCILIATIONS_GQL,
129+
LIST_LEDGER_REPORT_SHARES_GQL,
128130
LIST_LEDGER_REPORTS_GQL,
129131
LIST_LEDGER_STRUCTURES_GQL,
130132
LIST_LEDGER_TAXONOMIES_GQL,
@@ -1016,6 +1018,29 @@ def list_ledger_reconciliations(
10161018
data = self.get_data(response)
10171019
return ListLedgerReconciliations.model_validate(data)
10181020

1021+
def list_ledger_report_shares(
1022+
self,
1023+
include_revoked: bool,
1024+
limit: int,
1025+
offset: int,
1026+
report_id: Union[Optional[str], UnsetType] = UNSET,
1027+
**kwargs: Any,
1028+
) -> ListLedgerReportShares:
1029+
variables: dict[str, object] = {
1030+
"reportId": report_id,
1031+
"includeRevoked": include_revoked,
1032+
"limit": limit,
1033+
"offset": offset,
1034+
}
1035+
response = self.execute(
1036+
query=LIST_LEDGER_REPORT_SHARES_GQL,
1037+
operation_name="ListLedgerReportShares",
1038+
variables=variables,
1039+
**kwargs,
1040+
)
1041+
data = self.get_data(response)
1042+
return ListLedgerReportShares.model_validate(data)
1043+
10191044
def list_ledger_reports(
10201045
self,
10211046
lifecycle: Union[Optional[ReportLifecycle], UnsetType] = UNSET,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Optional
2+
3+
from pydantic import Field
4+
5+
from .base_model import BaseModel
6+
7+
8+
class ListLedgerReportShares(BaseModel):
9+
report_shares: Optional["ListLedgerReportSharesReportShares"] = Field(
10+
alias="reportShares"
11+
)
12+
13+
14+
class ListLedgerReportSharesReportShares(BaseModel):
15+
report_shares: list["ListLedgerReportSharesReportSharesReportShares"] = Field(
16+
alias="reportShares"
17+
)
18+
pagination: "ListLedgerReportSharesReportSharesPagination"
19+
20+
21+
class ListLedgerReportSharesReportSharesReportShares(BaseModel):
22+
id: str
23+
report_id: str = Field(alias="reportId")
24+
target_graph_id: str = Field(alias="targetGraphId")
25+
target_graph_name: Optional[str] = Field(alias="targetGraphName")
26+
shared_by: str = Field(alias="sharedBy")
27+
shared_at: str = Field(alias="sharedAt")
28+
revoked_at: Optional[str] = Field(alias="revokedAt")
29+
fact_count: int = Field(alias="factCount")
30+
31+
32+
class ListLedgerReportSharesReportSharesPagination(BaseModel):
33+
total: int
34+
limit: int
35+
offset: int
36+
has_more: bool = Field(alias="hasMore")
37+
38+
39+
ListLedgerReportShares.model_rebuild()
40+
ListLedgerReportSharesReportShares.model_rebuild()

‎robosystems_client/graphql/generated/operations.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"LIST_LEDGER_PUBLISH_LISTS_GQL",
5656
"LIST_LEDGER_RECONCILIATIONS_GQL",
5757
"LIST_LEDGER_REPORTS_GQL",
58+
"LIST_LEDGER_REPORT_SHARES_GQL",
5859
"LIST_LEDGER_STRUCTURES_GQL",
5960
"LIST_LEDGER_TAXONOMIES_GQL",
6061
"LIST_LEDGER_TRANSACTIONS_GQL",
@@ -2199,6 +2200,34 @@
21992200
}
22002201
"""
22012202

2203+
LIST_LEDGER_REPORT_SHARES_GQL = """
2204+
query ListLedgerReportShares($reportId: String, $includeRevoked: Boolean! = false, $limit: Int! = 100, $offset: Int! = 0) {
2205+
reportShares(
2206+
reportId: $reportId
2207+
includeRevoked: $includeRevoked
2208+
limit: $limit
2209+
offset: $offset
2210+
) {
2211+
reportShares {
2212+
id
2213+
reportId
2214+
targetGraphId
2215+
targetGraphName
2216+
sharedBy
2217+
sharedAt
2218+
revokedAt
2219+
factCount
2220+
}
2221+
pagination {
2222+
total
2223+
limit
2224+
offset
2225+
hasMore
2226+
}
2227+
}
2228+
}
2229+
"""
2230+
22022231
LIST_LEDGER_REPORTS_GQL = """
22032232
query ListLedgerReports($lifecycle: ReportLifecycle, $entityId: String) {
22042233
reports(lifecycle: $lifecycle, entityId: $entityId) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
query ListLedgerReportShares(
2+
$reportId: String
3+
$includeRevoked: Boolean! = false
4+
$limit: Int! = 100
5+
$offset: Int! = 0
6+
) {
7+
reportShares(
8+
reportId: $reportId
9+
includeRevoked: $includeRevoked
10+
limit: $limit
11+
offset: $offset
12+
) {
13+
reportShares {
14+
id reportId targetGraphId targetGraphName
15+
sharedBy sharedAt revokedAt factCount
16+
}
17+
pagination { total limit offset hasMore }
18+
}
19+
}

‎robosystems_client/graphql/schema.graphql‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,34 @@ type Query {
814814
listId: String!
815815
): PublishListDetail
816816

817+
"""
818+
Where this graph's reports have been shared: each recipient graph, when,
819+
by whom, how many facts it received, and whether the share was revoked.
820+
821+
The sender's record behind `share-report` and `revoke-report-share`.
822+
Revoked shares are history: a recipient shared to, revoked, and shared to
823+
again has two rows, one revoked and one live.
824+
"""
825+
reportShares(
826+
"""One report's shares. Omit for the graph's whole distribution log."""
827+
reportId: String = null
828+
829+
"""
830+
Also list revoked shares. Off by default, so the list is the copies recipients still hold.
831+
"""
832+
includeRevoked: Boolean! = false
833+
834+
"""
835+
Maximum rows to return, 1-1000. Omit to use this field's own default; out of range raises `INVALID_PAGINATION`.
836+
"""
837+
limit: Int = null
838+
839+
"""
840+
Rows to skip before returning, 0 or greater. Out of range raises `INVALID_PAGINATION`.
841+
"""
842+
offset: Int = null
843+
): ReportShareList
844+
817845
"""
818846
Source graphs barred from sharing reports into this graph.
819847
@@ -4626,6 +4654,44 @@ type PublishListMember {
46264654
addedAt: DateTime!
46274655
}
46284656

4657+
"""Paginated list of a report's shares, newest first."""
4658+
type ReportShareList {
4659+
"""Shares, newest first."""
4660+
reportShares: [ReportShare!]!
4661+
4662+
"""Pagination metadata."""
4663+
pagination: PaginationInfo!
4664+
}
4665+
4666+
"""One delivery of a report to a recipient graph."""
4667+
type ReportShare {
4668+
"""Share row identifier (ULID)."""
4669+
id: String!
4670+
4671+
"""The shared report's ID in this graph."""
4672+
reportId: String!
4673+
4674+
"""The recipient's graph ID."""
4675+
targetGraphId: String!
4676+
4677+
"""Display name of the recipient graph (if known)."""
4678+
targetGraphName: String
4679+
4680+
"""User ID that shared the report."""
4681+
sharedBy: String!
4682+
4683+
"""When the report was shared, or last re-shared."""
4684+
sharedAt: DateTime!
4685+
4686+
"""
4687+
When the share was revoked. Null while the recipient holds the copy; a re-share after a revoke is a new row, so a revoked row stays revoked.
4688+
"""
4689+
revokedAt: DateTime
4690+
4691+
"""Number of facts delivered to the recipient on this share."""
4692+
factCount: Int!
4693+
}
4694+
46294695
"""Paginated list of blocked source graphs."""
46304696
type BlockedSourceGraphList {
46314697
"""Blocked source graphs."""

‎tests/test_ledger_client.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,67 @@ def test_list_blocked_source_graphs(self, mock_query, mock_config, graph_id):
35993599
assert page.blocked_source_graphs[0].source_graph_id == "kg_sender"
36003600
assert page.pagination.total == 1
36013601

3602+
@patch("robosystems_client.clients.ledger_client.LedgerClient._query")
3603+
def test_list_report_shares(self, mock_query, mock_config, graph_id):
3604+
mock_query.return_value = {
3605+
"reportShares": {
3606+
"reportShares": [
3607+
{
3608+
"id": "share_2",
3609+
"reportId": "rpt_1",
3610+
"targetGraphId": "kg_recipient",
3611+
"targetGraphName": "Harbor Fund",
3612+
"sharedBy": "usr_1",
3613+
"sharedAt": "2026-10-01T12:00:00Z",
3614+
"revokedAt": None,
3615+
"factCount": 47,
3616+
},
3617+
{
3618+
"id": "share_1",
3619+
"reportId": "rpt_1",
3620+
"targetGraphId": "kg_recipient",
3621+
"targetGraphName": "Harbor Fund",
3622+
"sharedBy": "usr_1",
3623+
"sharedAt": "2026-09-01T12:00:00Z",
3624+
"revokedAt": "2026-09-15T12:00:00Z",
3625+
"factCount": 40,
3626+
},
3627+
],
3628+
"pagination": {"total": 2, "limit": 100, "offset": 0, "hasMore": False},
3629+
}
3630+
}
3631+
client = LedgerClient(mock_config)
3632+
page = client.list_report_shares(graph_id, report_id="rpt_1", include_revoked=True)
3633+
assert page is not None
3634+
assert [s.id for s in page.report_shares] == ["share_2", "share_1"]
3635+
assert page.report_shares[0].revoked_at is None
3636+
assert page.report_shares[1].revoked_at is not None
3637+
assert page.report_shares[0].fact_count == 47
3638+
assert page.pagination.total == 2
3639+
assert mock_query.call_args.args[2] == {
3640+
"reportId": "rpt_1",
3641+
"includeRevoked": True,
3642+
"limit": 100,
3643+
"offset": 0,
3644+
}
3645+
3646+
@patch("robosystems_client.clients.ledger_client.LedgerClient._query")
3647+
def test_list_report_shares_defaults_to_live_shares_of_every_report(
3648+
self, mock_query, mock_config, graph_id
3649+
):
3650+
mock_query.return_value = {
3651+
"reportShares": {
3652+
"reportShares": [],
3653+
"pagination": {"total": 0, "limit": 100, "offset": 0, "hasMore": False},
3654+
}
3655+
}
3656+
client = LedgerClient(mock_config)
3657+
page = client.list_report_shares(graph_id)
3658+
assert page is not None
3659+
assert page.report_shares == []
3660+
assert mock_query.call_args.args[2]["reportId"] is None
3661+
assert mock_query.call_args.args[2]["includeRevoked"] is False
3662+
36023663

36033664
# ── Chart of accounts ─────────────────────────────────────────────────
36043665

0 commit comments

Comments
 (0)