From 26e4184c8dc5db0b93c81859873da07d396d90ce Mon Sep 17 00:00:00 2001 From: Idan Date: Wed, 2 Jan 2019 15:38:57 +0000 Subject: [PATCH] Add patch info to pre_upload_hook. We got a specific case in which this change is needed: An aritifact type that only one instance is allowed to be in 'active' status. To enforce that we want to use pre_update_hook, and check if there is any other artifact in 'active' status. To do so we need json_patch info (we need to know if the json_patch change status to "active" or "deactivated". This change aim to suuport this case and also support backward compatibility. With this background, if the a user update 'active' artifact to be with status "deactivated", we must know the patch info. Change-Id: I6e85ff89144ca6d3a69c7a240de3f41bd1d999e7 --- glare/engine.py | 2 +- glare/objects/base.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/glare/engine.py b/glare/engine.py index ec7eb00..159c943 100644 --- a/glare/engine.py +++ b/glare/engine.py @@ -151,7 +151,7 @@ class Engine(object): action_names = ['update'] af_dict = af.to_dict() policy.authorize('artifact:update', af_dict, context) - af.pre_update_hook(context, af) + af.pre_update_hook_with_patch(context, af, patch) try: for operation in patch._ops: # apply the change to make sure that it's correct diff --git a/glare/objects/base.py b/glare/objects/base.py index 73aa7fd..4e7acd7 100644 --- a/glare/objects/base.py +++ b/glare/objects/base.py @@ -549,6 +549,10 @@ Possible values: def pre_update_hook(cls, context, af): pass + @classmethod + def pre_update_hook_with_patch(cls, context, af, json_patch): + cls.pre_update_hook(context, af) + @classmethod def post_update_hook(cls, context, af): pass