permission.py 1006 B

123456789101112131415161718192021222324252627
  1. from fate_flow.controller.permission_controller import PermissionCheck
  2. from fate_flow.entity import RetCode
  3. from fate_flow.hook import HookManager
  4. from fate_flow.hook.common.parameters import PermissionCheckParameters, PermissionReturn
  5. from fate_flow.settings import COMPONENT_PERMISSION, DATASET_PERMISSION
  6. @HookManager.register_permission_check_hook
  7. def permission(parm: PermissionCheckParameters) -> PermissionReturn:
  8. if parm.role == "local" or str(parm.party_id) == "0":
  9. return PermissionReturn()
  10. if parm.src_party_id == parm.party_id:
  11. return PermissionReturn()
  12. checker = PermissionCheck(**parm.to_dict())
  13. if COMPONENT_PERMISSION:
  14. component_result = checker.check_component()
  15. if component_result.code != RetCode.SUCCESS:
  16. return component_result
  17. if DATASET_PERMISSION:
  18. dataset_result = checker.check_dataset()
  19. if dataset_result.code != RetCode.SUCCESS:
  20. return dataset_result
  21. return PermissionReturn()