Repository navigation
feat(access-control): page and filter role lists - #681
Conversation
`getResourceRoles` takes `q`, `limit` and `offset`, for apps declaring them. Without them, the response stays the same, and it's always a list; links to other pages are in the header `Link`, as of `foca.utils.pagination`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sort roles of pages. Path parameters named as the query parameters only name the resource. Refuse a `q` that isn't a string. Say what apps declaring these parameters need to check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test of path parameters passed with a limit of one, as only one role was granted. Say which types to declare. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideEnhances Sequence diagram for filtered and paginated resource role listingsequenceDiagram
participant Client
participant Connexion
participant OwnershipServer
participant RoleStore
participant Pagination
Client->>Connexion: GET /permissions?q&limit&offset
Connexion->>OwnershipServer: getResourceRoles(q, limit, offset)
OwnershipServer->>OwnershipServer: _get_owned_resource()
OwnershipServer->>RoleStore: list_roles(resource, ptype=RESOURCE_ROLE_PTYPE)
RoleStore-->>OwnershipServer: roles
OwnershipServer->>Pagination: get_page(offset, limit)
OwnershipServer->>Pagination: get_page_links(page, total)
Pagination-->>OwnershipServer: page links
OwnershipServer-->>Connexion: roles, 200, Link
Connexion-->>Client: paged role list
Flow diagram for resource role filtering and paginationflowchart TD
A["getResourceRoles"] --> B{"q, limit, or offset supplied?"}
B -- No --> C["Return all roles"]
B -- Yes --> D["get_page(offset, limit)"]
D --> E["Filter subjects by q.casefold()"]
E --> F["Sort by subject_type, subject, role"]
F --> G["Return page with optional Link header"]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #681 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 60 60
Lines 7828 7847 +19
=========================================
+ Hits 7828 7847 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/security/access_control/test_ownership_server.py" line_range="465" />
<code_context>
+ assert self._subjects(response) == ["bob-team", "Bob"]
+ assert 'rel="next"' in response.headers["Link"]
+ response = self._get(q="carol", limit="2")
+ assert 'rel="next"' not in response.headers["Link"]
+
+
</code_context>
<issue_to_address>
**Filtered page drops later matches**
When the endpoint slices the unfiltered roles before applying `q`, while calculating links from the filtered total, `test_filter_before_page` checks only that the `q="carol"` response has no `next` link; it never checks the response body, so an empty page passes even though the matching role was dropped.
Assert that the `q="carol"` response contains the `carol` role.
</issue_to_address>Linked issues
#609 feat(access-control): page and filter role lists · 5 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Add paging and q search to the role listing for users and groups | ✅ Met | getResourceRoles filters subjects case-insensitively and pages the sorted roles when limit or offset is supplied. |
| 2 | Keep the permissions endpoint layout as the standard | ✅ Met | The change retains the existing getResourceRoles endpoint arrangement and documents it. |
| 3 | Have cloud-registry and trs-filer move to or adopt the standard | ❌ Not addressed | Neither app is changed; the PR description says they still need to adopt this. |
| 4 | Test page limits and links, q matching, and behavior without parameters, with 100% coverage | ✅ Met | The added tests cover no, one, and several q matches; pagination limits, boundaries and links; and the unpaged response. The PR reports 100% coverage. |
| 5 | Update the spec, controllers and docs | ✅ Met | The controller implements the options, and the docs include their behavior and an example specification declaring them. |
| 6 | Keep the default response compatible for clients that do not page | ✅ Met | Without limit or offset, getResourceRoles still returns the full roles list. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/security/access_control/test_ownership_server.py:465
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #609.
ownership_server.getResourceRolestakes optionalq,limitandoffset, for apps declaring them in their specification.limitandoffset, it's unchanged and has all roles.q: case-insensitive substring of the subject (users, groups, service clients).limit(default 100, at most 1000) andoffset: a page, sorted by subject type, subject and role, so pages are stable. HeaderLinkif the app has a public URL. Usesfoca.utils.paginationof feat: add IdConfig, locked fields, pagination #623.docs/access-control.md, including what apps already declaring these parameters need to check.Style note: this follows the offset and limit of #623, whereas the admin permissions list keeps its
page_sizeandpage. cloud-registry and trs-filer still need to adopt this.Verification
ruff,mypy foca tests, strict docs build, fullpytestwith MongoDB: 3645 passed, 1 skipped, 100% coverage; after the last review fixes,tests/security/access_control/test_ownership_server.pyagain.q, large values, CRLF inq, links with other parameters.Declined review findings
qdoesn't normalize Unicode (low): matching is by code point after case folding; such identifiers are rare.limitdeclaredtype: numbergives400(low): it fails closed; docs say to declareintegerorstring.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Enable resource role listings to be searched and paged without changing their default response.
New Features:
Enhancements:
Documentation:
Tests: