Skip to content

feat(access-control): page and filter role lists - #681

Merged
uniqueg merged 5 commits into
devfrom
feat/609-page-role-lists
Nov 4, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/609-page-role-lists

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #609.

ownership_server.getResourceRoles takes optional q, limit and offset, for apps declaring them in their specification.

  • Response stays a list. Without limit and offset, it's unchanged and has all roles.
  • q: case-insensitive substring of the subject (users, groups, service clients).
  • limit (default 100, at most 1000) and offset: a page, sorted by subject type, subject and role, so pages are stable. Header Link if the app has a public URL. Uses foca.utils.pagination of feat: add IdConfig, locked fields, pagination #623.
  • Docs: 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_size and page. cloud-registry and trs-filer still need to adopt this.

Verification

  • ruff, mypy foca tests, strict docs build, full pytest with MongoDB: 3645 passed, 1 skipped, 100% coverage; after the last review fixes, tests/security/access_control/test_ownership_server.py again.
  • Reviewers probed the real Connexion stack: path parameters named as options, non-string q, large values, CRLF in q, links with other parameters.

Declined review findings

  • q doesn't normalize Unicode (low): matching is by code point after case folding; such identifiers are rare.
  • Return type is a list or a tuple (medium, partly): always returning a tuple would break wrappers relying on a list without paging, so wrappers are told in the docs what they get for a page.
  • limit declared type: number gives 400 (low): it fails closed; docs say to declare integer or string.
  • No total in responses: dropped on purpose, so as not to add a header that other FOCA lists don't have.

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:

  • Add optional case-insensitive filtering and stable offset-based pagination to resource role listings, including pagination links when a public URL is configured.

Enhancements:

  • Preserve the existing unpaged list response while documenting query parameter declarations, response behavior, validation, and wrapper compatibility.

Documentation:

  • Document filtering, pagination, validation, links, and specification requirements for getResourceRoles.

Tests:

  • Add coverage for filtering users, groups, and service clients; pagination boundaries and ordering; invalid values; path parameter handling; and pagination links.

uniqueg and others added 3 commits November 4, 2026 07:43
`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]>
@uniqueg uniqueg added this to the v0.21.0 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Enhances getResourceRoles with opt-in, case-insensitive filtering and stable offset pagination, while retaining the legacy unpaged response and documenting the API and wrapper compatibility requirements.

Sequence diagram for filtered and paginated resource role listing

sequenceDiagram
    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
Loading

Flow diagram for resource role filtering and pagination

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Adds optional case-insensitive subject filtering and stable offset-based pagination while preserving the existing unpaged list response.
  • Accepts q, limit, and offset, ignoring matching path parameters.
  • Validates and normalizes pagination through shared pagination utilities, including defaults and maximum limits.
  • Filters roles before sorting and slicing pages by subject type, subject, and role.
  • Returns pagination metadata and Link headers when a public URL is configured.
  • Preserves the original list return shape when no pagination parameter is requested.
foca/security/access_control/ownership_server.py
Documents how applications expose and integrate searchable, paginated resource-role listings.
  • Describes query parameter behavior, validation, ordering, links, and the absence of totals.
  • Documents compatibility considerations for existing specifications and wrappers.
  • Adds an OpenAPI example declaring the supported query parameters.
docs/access-control.md
Expands ownership-server coverage for filtering, pagination, validation, compatibility, and link generation.
  • Tests default unpaged behavior and searches across users, groups, and service clients.
  • Covers page boundaries, defaults, maximum limits, invalid values, and filtering-before-pagination.
  • Verifies path-parameter handling and public-URL pagination links.
tests/security/access_control/test_ownership_server.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cd2dc70) to head (bfeb598).

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     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 4, 2026 07:16

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit fbc0961 into dev Nov 4, 2026
56 checks passed
@uniqueg
uniqueg deleted the feat/609-page-role-lists branch November 4, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(access-control): page and filter role lists

1 participant