feat: parse aggregate commercial use values, see #708

Add support for parsing comma-separated and JSON-style commercial use permission values in both Python backend and JavaScript frontend. Implement helper functions to split aggregated values into individual permissions while preserving original values when no aggregation is detected.

Added comprehensive test coverage for the new parsing functionality to ensure correct handling of various input formats including strings, arrays, and iterable objects with aggregated commercial use values.
This commit is contained in:
Will Miao
2025-11-30 17:10:21 +08:00
parent f09224152a
commit 22ee37b817
4 changed files with 223 additions and 4 deletions

View File

@@ -46,3 +46,35 @@ def test_build_license_flags_respects_commercial_hierarchy():
assert build_license_flags({**base, "allowCommercialUse": ["Image"]}) == 2
# Sell forces all commercial bits regardless of image listing.
assert build_license_flags({**base, "allowCommercialUse": ["Sell"]}) == 30
def test_build_license_flags_parses_aggregate_string():
source = {
"allowNoCredit": True,
"allowCommercialUse": "{Image,RentCivit,Rent}",
"allowDerivatives": True,
"allowDifferentLicense": False,
}
payload = resolve_license_payload(source)
assert set(payload["allowCommercialUse"]) == {"Image", "RentCivit", "Rent"}
flags = build_license_flags(source)
expected_flags = (1 << 0) | (7 << 1) | (1 << 5)
assert flags == expected_flags
def test_build_license_flags_parses_aggregate_inside_list():
source = {
"allowNoCredit": True,
"allowCommercialUse": ["{Image,RentCivit,Rent}"],
"allowDerivatives": True,
"allowDifferentLicense": False,
}
payload = resolve_license_payload(source)
assert set(payload["allowCommercialUse"]) == {"Image", "RentCivit", "Rent"}
flags = build_license_flags(source)
expected_flags = (1 << 0) | (7 << 1) | (1 << 5)
assert flags == expected_flags