refactor: extract CSVImport._decompose_site_role, inverse of _evaluate_site_role#1812
Open
jacalata wants to merge 2 commits into
Open
refactor: extract CSVImport._decompose_site_role, inverse of _evaluate_site_role#1812jacalata wants to merge 2 commits into
jacalata wants to merge 2 commits into
Conversation
…ion check and debug prints
- create_users_csv was producing 7-column CSV, silently dropping
auth_setting; bulk_add roundtrip would lose auth type
- create_from_file extension check used filepath.find("csv") which
evaluates as falsy only when "csv" is at index 0, letting all other
paths through; fixed to "csv" not in filepath
- remove two debug print() calls left in create_from_file
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…th _evaluate_site_role
Moves the ad-hoc site role → (license, admin_level, publish) logic from
create_users_csv into UserItem.CSVImport._decompose_site_role, making it
the explicit inverse of _evaluate_site_role.
Also fixes pre-existing bugs in the decomposition:
- ExplorerCanPublish was emitted as license="ExplorerCanPublish" (not a
valid CSV license value); now correctly "Explorer" with publish=1
- SiteAdministrator (legacy role) was emitting license="" via
str.replace; now maps to ("Explorer", "Site", "1")
- Non-admin roles now emit admin_level="None" (explicit CSV spec value)
rather than "" (empty string); both are accepted by the server but
"None" is consistent with the spec and _evaluate_site_role input
Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
Stacks on #1811.
Moves the ad-hoc site role → CSV columns logic from
create_users_csvintoUserItem.CSVImport._decompose_site_role, making it the explicit inverse of_evaluate_site_role. Both encode/decode functions now live together inCSVImport.What changed
New method:
UserItem.CSVImport._decompose_site_role(site_role) -> (license, admin_level, publish)Replaces the if/elif block in
create_users_csvwith a lookup table.create_users_csvbecomes:Pre-existing bugs fixed in the decomposition:
ExplorerCanPublishwas emitted aslicense="ExplorerCanPublish"— not a valid CSV license value; now("Explorer", "None", "1")SiteAdministrator(legacy role) was emittinglicense=""viastr.replace("SiteAdministrator", ""); now maps to("Explorer", "Site", "1")admin_level="None"(explicit CSV spec value) rather than""— both accepted by the server but"None"is consistent with the spec and what_evaluate_site_roleexpects as inputTest updated:
test_create_users_csvnow asserts"None"for non-admin roles (previously asserted"") and verifies the auth column.Test plan
pytest test/test_user.py test/test_user_model.py— 46 passed🤖 Generated with Claude Code