User Permissions should be obtained in fewer REST requests
Describe the bug
In 7.x and 8.x, user permissions are obtained one-by-one in several calls to the /server/api/authz/authorizations/search/object endpoint. These requests are most easily seen after login, as you'll see ~10 of these requests in a row for the Site object:
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=isCollectionAdmin&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=isCommunityAdmin&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=administratorOf&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canSubmit&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canEditItem&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canSeeQA&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=coarNotifyEnabled&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canManageGroups&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canSendFeedback&embed=feature
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]&feature=canViewUsageStatistics&embed=feature
These requests are all identical except for the feature= parameter, where they request permissions specific to that feature.
In the REST API, we already have a way to request permissions in bulk, by just removing the optional feature parameter:
# This will return all permissions the current authenticated user has on the Site object.
GET /server/api/authz/authorizations/search/object?uri=https://sandbox.dspace.org/server/api/core/sites/[site-uuid]
Ideally, we should avoid one-by-one requests of this sort, and request all the authorizations at once and cache them for the remainder of the user's session. If additional endpoints or options are necessary in the REST API, then we should add them to better support this request for bulk permissions.
To Reproduce
Steps to reproduce the behavior:
- Visit demo.dspace.org or sandbox.dspace.org
- Open Chrome DevTools
- Login as an Admin, and look at the number of requests made to the
/server/api/authz/authorizations/search/objectendpoint
Expected behavior
Ideally, we should request user permissions in one request (or fewer requests) and cache them for the remainder of the user's session.
Hi @tdonohue, we'd like to have this issue assigned to 4Science, @atarix83 can be the Assignee. Thanks!
Thanks @GraziaQuercia ! I'll assign this to @atarix83 then.
@atarix83 and @GraziaQuercia did you have time to work on this issue in the meantime? Would love to see some improvement on this, but I also understand if you are busy with the CRIS merger at the moment.
Opened #6256 with a complementary approach for the unauthenticated case. Instead of batching the checks, it skips the ones that can never succeed for an anonymous visitor — the admin, edit and login-only features, which are always false for someone who is not logged in. The two approaches compose: fewer checks asked (skip), and the remainder batched (this issue).
Measured on a local DSpace 11 stack with OpenTelemetry tracing, one anonymous item render dropped from 42 to 31 backend calls (15 → 5 authorization checks), and single-core SSR render throughput rose ~45% (~3.3 → ~4.8 renders/s). It waits for isAuthenticationLoaded() before deciding, so logged-in admins are never affected. The feature classification and the open design question (static list vs. having each feature declare whether it requires authentication) are in #6256.
Investigated and drafted with Claude Fable 5.1 (Anthropic) via Claude Code.