fix(lifecycle): authorize and validate setLifecycleStage

Merged
MA
1mo ago
+1322-430

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: setLifecycleStage now 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 of policies.json), and it is listed in the policies guide.
  • Validation: returns BAD_REQUEST when the stage does not exist, does not apply to the entity type, is not user-assignable, or the destination stage's allowedPreviousStages excludes the current stage. Before, a disallowed move succeeded and LifecycleStageTransitionHook silently kept the old stage. The hook still guards every other writer of Status.
  • LifecycleStageSettings.userAssignable (default true) 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 LIFECYCLE change category (LifecycleStageChangeEventGenerator).
  • Status.lifecycleStage resolves through a batch-loading LifecycleStageGraphType instead of one fetch per Status (replaces StatusLifecycleStageResolver).
  • 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:

  1. #20630 Authorize and validate setLifecycleStage šŸ‘ˆ this PR
  2. #20631 Glossary term versioning and default glossary stages
  3. #20632 UI: change stage, new version, badges
  4. #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-core test suite passes.
  • Smoke: test_lifecycle_state checks that setLifecycleStage refuses a disallowed move with BAD_REQUEST and 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

šŸ¤– Generated with Claude Code