fix(lifecycle): authorize and validate setLifecycleStage
Merged
MA
1mo ago+1322+1322+0123456789012345678901234567890123456789-430-430-012345678901234567890123456789
Summary
setLifecycleStage had no privilege check, so any authenticated user could set or clear the lifecycle stage on any entity. This PR adds the check and validates the request before writing.
- Authorization:
setLifecycleStagenow requires the new Edit Lifecycle Stage privilege (EDIT_ENTITY_LIFECYCLE_STAGE) or Edit Entity. The default Admin, Editor, and asset-owner policies grant it (in both the GMS and system-update copies ofpolicies.json), and it is listed in the policies guide. - Validation: returns
BAD_REQUESTwhen the stage does not exist, does not apply to the entity type, is not user-assignable, or the destination stage'sallowedPreviousStagesexcludes the current stage. Before, a disallowed move succeeded andLifecycleStageTransitionHooksilently kept the old stage. The hook still guards every other writer ofStatus. LifecycleStageSettings.userAssignable(defaulttrue) marks system-managed stages.listLifecycleStages(entityType:)reports it for the given type.EntityPrivileges.canEditLifecycleStage, for the UI in a later PR of this stack.- Change history: lifecycle stage changes on documents and glossary terms appear in the timeline under a new
LIFECYCLEchange category (LifecycleStageChangeEventGenerator). Status.lifecycleStageresolves through a batch-loadingLifecycleStageGraphTypeinstead of one fetch perStatus(replacesStatusLifecycleStageResolver).- The transition rule lives in
LifecycleStages.isTransitionAllowed, shared by the resolver and the hook.
Stack
Part of a stack that brings glossary lifecycle stages and versioning to OSS. Review and merge in order:
- #20630 Authorize and validate
setLifecycleStageš this PR - #20631 Glossary term versioning and default glossary stages
- #20632 UI: change stage, new version, badges
- #20633 Business Glossary guide
Origin
Ported from DataHub Cloud: acryldata/datahub-fork#9192 (privilege), acryldata/datahub-fork#13480 (validation, canEditLifecycleStage, timeline registration), acryldata/datahub-fork#9443 (lifecycle change events), and the userAssignable assignment guards. The files match the Cloud versions except for Cloud-only parts (proposals, document draft handling), which are left out.
Testing
SetLifecycleStageResolverTest(including an unauthorized caller, which wrote the stage before this change),LifecycleStageAssignmentUtilsTest,ListLifecycleStagesResolverTest,LifecycleStageTypeMapperTest,EntityPrivilegesResolverTest,LifecycleStagesTest,LifecycleStageChangeEventGeneratorTest,TimelineServiceLifecycleRegistrationTest.- Full
datahub-graphql-coretest suite passes. - Smoke:
test_lifecycle_statechecks thatsetLifecycleStagerefuses a disallowed move withBAD_REQUESTand that the change shows in the term's history. Tests that need the well-known PUBLISHED and DRAFT stages now add their entity types instead of overwriting the stages, and no longer delete them in teardown.
Checklist
- The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
- Tests for the changes have been added/updated
- For any breaking change an entry has been made in Updating DataHub
š¤ Generated with Claude Code