Skip to content

Commit

Permalink
Determine whether object was transferred vs. deleted on case-by-case …
Browse files Browse the repository at this point in the history
…basis
  • Loading branch information
matthew-li committed Aug 2, 2023
1 parent d2e28a5 commit 4f98f04
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions coldfront/core/user/utils_/merge_users/class_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4f98f04

Please sign in to comment.