From 4f98f044d50e643e1524b4a6e2c81acb0fac2d25 Mon Sep 17 00:00:00 2001 From: Matthew Li Date: Wed, 2 Aug 2023 13:35:22 -0700 Subject: [PATCH] Determine whether object was transferred vs. deleted on case-by-case basis --- .../user/utils_/merge_users/class_handlers.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/coldfront/core/user/utils_/merge_users/class_handlers.py b/coldfront/core/user/utils_/merge_users/class_handlers.py index 294465768..6e3e36a0a 100644 --- a/coldfront/core/user/utils_/merge_users/class_handlers.py +++ b/coldfront/core/user/utils_/merge_users/class_handlers.py @@ -74,14 +74,12 @@ def _get_settable_if_falsy_attrs(self): attribute in the source object.""" return [] - def _handle_associated_object(self): + def _handle_associated_object(self, transferred=False): """An object B may be associated with a User through a different object A. When A is deleted, B may be deleted with it. When A is transferred, B is transferred with it. Record that this has occurred.""" - try: - self._src_obj.refresh_from_db() - except ObjectDoesNotExist: + if not transferred: # The object was deleted. message = ( f'{self._class_name}({self._src_obj.pk}): indirectly deleted') @@ -233,7 +231,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _run_special_handling(self): - self._handle_associated_object() + transferred = self._src_obj.allocation_user.user == self._dst_user + self._handle_associated_object(transferred=transferred) class AllocationUserAttributeUsageHandler(ClassHandler): @@ -242,7 +241,10 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _run_special_handling(self): - self._handle_associated_object() + transferred = ( + self._src_obj.allocation_user_attribute.allocation_user.user == + self._dst_user) + self._handle_associated_object(transferred=transferred) class ClusterAccessRequestHandler(ClassHandler): @@ -251,7 +253,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _run_special_handling(self): - self._handle_associated_object() + transferred = self._src_obj.allocation_user.user == self._dst_user + self._handle_associated_object(transferred=transferred) class ProjectUserHandler(ClassHandler): @@ -310,7 +313,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _run_special_handling(self): - self._handle_associated_object() + transferred = self._src_obj.project_user.user == self._dst_user + self._handle_associated_object(transferred=transferred) class SavioProjectAllocationRequestHandler(ClassHandler):