Skip to content

fix(graph): keep the permissions list query options with $top=0 - #4035

Merged
asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/4018-permissions-top-query-option
Nov 17, 2026
Merged

asaah262 merged 1 commit into
opencloud-eu:mainfrom
asaah262:fix/4018-permissions-top-query-option

Conversation

@asaah262

Copy link
Copy Markdown
Contributor

Description

The permissions list endpoints (GET …/items/{itemId}/permissions and GET …/root/permissions) dropped all query options when the request contained $top, except for $count=true&$top=0. getListPermissionsQueryOptions returned empty options together with a nil error in that case, so $select, $filter and $count were silently ignored and the full listing was returned with status 200.

With this change:

Request Before After
$top=0 with $count=true only the number of permissions unchanged
$top=0 without $count=true all other query options dropped $top=0 is ignored, the other query options are kept
$top other than 0 all query options dropped, full listing 400 invalidRequest: only $top=0 is supported

Related Issue

Motivation and Context

The web client sends $top=0 with every permissions request. Because of this bug:

  • the allowed actions of each space, requested with [email protected], were computed together with the full share listing of the space;
  • the roles for external shares (OCM enabled), requested with the federated roles $filter, were the roles for internal users, e.g. "Can upload".

Why $top=0 without $count=true is ignored

$top exists on this endpoint for one purpose: $count=true&$top=0 returns only the number of permissions, e.g. for the member count of a space. Returning only the first n permissions is not supported, as the permissions have no stable order and there is no paging.

Strictly, $top=0 means "zero entries". But the web client also sends $top=0 when it lists the shares of a resource in the sharing panel and needs all of them. Returning zero entries, or rejecting $top=0, would break the sharing panel. Ignoring $top=0 without $count=true keeps the sharing panel working as before and makes $select and $filter take effect. No web change is needed.

Why other values of $top are rejected

The server cannot return only the first n permissions. Answering $top=5 with all permissions misleads the client, so it is rejected with 400, like an unsupported $filter. None of the opencloud-eu clients (web, desktop, android, ios) sends such a value.

Impact

  • Web client: the sharing panel and the member count of a space behave as before. The allowed actions of a space are computed without listing the shares, and with OCM enabled, the external share roles are the roles for federated users.
  • Other clients: desktop, android and ios don't use the permissions list endpoints.
  • API: requests with a $top other than 0 now fail with 400 instead of returning all permissions.

How Has This Been Tested?

  • Test environment: Local Go development environment (Ginkgo/Gomega, testify mocks), and a local OpenCloud instance built from this branch.
  • New Go specs (12) for the list handlers:
    • $top=0 without $count=true keeps $select, the federated roles filter and the filter without link permissions, also with $count=false and on the space root endpoint (failing before the change);
    • $top other than 0, also negative, with $count=true or with $select, is rejected with 400 without calling the service (failing before the change);
    • $top=0 alone still lists all permissions, and a $top that is not a number is still rejected.
  • New acceptance scenarios in apiSharingNg1/listPermissions.feature: $top=0 alone and together with $select and the federated roles filter on a folder, $select with $top=0 on a project space, and 400 for $top=5, $top=5&$count=true and $top=-1.
  • Manual check against the local instance, before and after the change: the requests above, plus $count=true&$top=0, which still returns only the number.
  • go test ./services/graph/... passes in all 11 packages; go test -race ./services/graph/pkg/service/v0/ passes.
  • gofmt and git diff --check are clean. go vet reports no new findings.
  • Not run locally: the acceptance tests and golangci-lint. CI will be the first to run them.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added

AI assistance: Claude Code (claude-opus-5-5) wrote the first draft of the code, the tests and this description; I reviewed and adjusted them.

@codacy-production

codacy-production Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2032e85) 94240 28200 29.92%
Head commit (ccba4a5) 94238 (-2) 28208 (+8) 29.93% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4035) 4 4 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@asaah262
asaah262 requested a review from pbleser-oc November 17, 2026 12:17
@asaah262
asaah262 marked this pull request as ready for review November 17, 2026 12:17
@pbleser-oc

Copy link
Copy Markdown
Member

I checked which of our clients could be affected by the new 400 for a $top other than 0, since such a request returned the full listing with 200 before. None of them is:

Client Uses the permissions list endpoints Sends $top
web yes always 0
desktop no no
Android no no
iOS no no
  • web (main at 765b8e98ad): packages/web-client/src/graph/permissions/permissions.ts passes options?.top || 0 to both endpoints, and none of its callers sets top. The callers send $count=true with the grantedToV2 ne '' filter for the member count of a space (SpaceHeader.vue), $select of the allowed actions (piniaStores/spaces.ts), the federated roles filter with $select of the roles (useLoadShares.ts), or no options at all.
  • desktop (main at fc2a86e11): only calls graph/v1.0/me, graph/v1.0/me/photo/$value and graph/v1.0/me/drives.
  • Android (main at 78101755b): only calls the Graph endpoints for the list of spaces and the avatar. Sharing goes through the OCS shares API.
  • iOS (ios at 53fdb7f9, ios-sdk at 01708b0): the SDK only calls graph/v1.0/me/drives and graph/v1.0/drives, with $select and $filter at most. Sharing goes through the OCS shares API.

So rejecting any other $top is safe today. If a client starts paging the permissions with $top, this check will need to change, or the endpoints will need real paging.

@asaah262

Copy link
Copy Markdown
Contributor Author

@pbleser-oc Thanks for checking the clients. Agreed.

@pbleser-oc pbleser-oc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the fix looks good to me, and the tests cover the requests of the web client well. None of our clients is affected by the new 400 for a $top other than 0, see my comment above for the details.

@asaah262
asaah262 merged commit 1668aa8 into opencloud-eu:main Nov 17, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graph: $top makes the permissions list ignore $select and $filter

2 participants