Add tool: set ORIGINAL bundle resource policies by handle#266
Open
milanmajchrak wants to merge 2 commits into
Open
Add tool: set ORIGINAL bundle resource policies by handle#266milanmajchrak wants to merge 2 commits into
milanmajchrak wants to merge 2 commits into
Conversation
tools/set_original_policies: standalone script that resolves item handles to UUIDs and replaces resource policies on each item's ORIGINAL bundle (and optionally its bitstreams) with a single policy for a configurable group and action. Generalises the replace_resource_policies tool (PR #264): configurable --group (name or UUID) and --action instead of Administrator/READ only, --apply-to bundle|bitstreams|both, Bearer-JWT auth via login OR a pre-obtained --bearer-token, CSV/repeated/file handle input, dry-run, and bounded retry/backoff. No dependency on src/settings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The common case is to update the ORIGINAL bundle policy without touching every bitstream, so make 'bundle' the default; pass --apply-to both (or bitstreams) to include them. Docs updated to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem description
We need to (re)set resource policies on the ORIGINAL bundle of specific items, addressed by handle — e.g. to embargo original files (admin-only) or to make them anonymously readable with no start date. The existing
tools/policy_and_auth/policy.pyworks per community (by UUID), not per handle.What this adds
A new self-contained tool
tools/set_original_policies/:/api/pid/find, falling back to the discovery search API.READ): deletes the existing policies for that action and creates a single policy granting it to a configurable group (name or UUID, defaultAdministrator).Configurable (vs. Administrator/READ-only)
--group— group name or UUID (defaultAdministrator).--action—READ(default) / WRITE / ADD / REMOVE / DELETE / ADMIN.--apply-to—bundle,bitstreams, orboth(defaultbundle).Authentication (DSpace 7/8 Bearer-JWT)
Same flow as PR #264 —
GET /api/security/csrf→POST /api/authn/login→Authorization: Bearer <jwt>+X-XSRF-TOKENon every request. Two modes:--email, password via--password/DSPACE_PASSWORD/ prompt), or--bearer-token(orDSPACE_BEARER_TOKEN) — login is skipped and logout is not called so the supplied token stays valid.Other
--handles(CSV), repeated--handle, or--handles-file(one per line,#comments); de-duplicated.--dry-run, explicit--timeout-sec,--retry-count,--retry-backoff-secwith exponential backoff,--continue-on-bitstream-error,--log-file.Relationship to #264
This generalises the
replace_resource_policiestool from #264 (which is Administrator/READ-only): configurable group + action, bundle-only option, file handle input, and direct Bearer-token auth. It is fully standalone (depends only onrequests, imports nothing fromsrc/).Testing
python -m py_compileclean;--helprenders.#comments), de-duplication, and group UUID-vs-name detection.--bearer-tokenbranch verified locally (skips login, goes straight to CSRF).--dry-runfirst.🤖 Generated with Claude Code