Skip to content

Commit

Permalink
change tl_event.TL_STATUS_* to custom helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Apr 29, 2024
1 parent 1998c31 commit 21ca8ca
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions projectroles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,14 @@ def _get_project_update_data(old_data, project, project_settings):
upd_fields.append(k)
return extra_data, upd_fields

@staticmethod
def _get_timeline_ok_status():
timeline = get_backend_api('timeline_backend')
if not timeline:
raise ImproperlyConfigured('Timeline backend not found')
else:
return timeline.TL_STATUS_OK

@classmethod
def _create_timeline_event(
cls, project, action, owner, old_data, project_settings, request
Expand Down Expand Up @@ -1289,7 +1297,7 @@ def modify_project(self, data, request, instance=None):

# Once all is done, update timeline event, create alerts and emails
if tl_event:
tl_event.set_status(tl_event.TL_STATUS_OK)
tl_event.set_status(self._get_timeline_ok_status())
self._notify_users(project, action, owner, old_parent, request)
return project

Expand Down Expand Up @@ -1853,7 +1861,7 @@ def delete_assignment(self, request, instance):

inh_as = project.get_role(user, inherited_only=True)
if tl_event:
tl_event.set_status(tl_event.TL_STATUS_OK)
tl_event.set_status(timeline.TL_STATUS_OK)
if app_alerts:
self._update_app_alerts(app_alerts, project, user, inh_as)
if SEND_EMAIL and app_settings.get(
Expand Down Expand Up @@ -2028,6 +2036,20 @@ class RoleAssignmentOwnerTransferMixin(ProjectModifyPluginViewMixin):
#: Owner role object
role_owner = None

def _get_timeline_ok_status(self):
timeline = get_backend_api('timeline_backend')
if not timeline:
return None
else:
return timeline.TL_STATUS_OK

def _get_timeline_failed_status(self):
timeline = get_backend_api('timeline_backend')
if not timeline:
return None
else:
return timeline.TL_STATUS_FAILED

def _create_timeline_event(self, old_owner, new_owner, project):
timeline = get_backend_api('timeline_backend')
# Init Timeline event
Expand Down Expand Up @@ -2133,11 +2155,11 @@ def transfer_owner(self, project, new_owner, old_owner_as, old_owner_role):
)
except Exception as ex:
if tl_event:
tl_event.set_status(tl_event.TL_STATUS_FAILED, str(ex))
tl_event.set_status(self._get_timeline_failed_status(), str(ex))
raise ex

if tl_event:
tl_event.set_status(tl_event.TL_STATUS_OK)
tl_event.set_status(self._get_timeline_ok_status())
if not old_inh_owner and self.request.user != old_owner:
if app_alerts:
app_alerts.add_alert(
Expand Down Expand Up @@ -2547,7 +2569,7 @@ def create_assignment(self, invite, user, timeline=None):
)
role_as.save()
if tl_event:
tl_event.set_status(tl_event.TL_STATUS_OK)
tl_event.set_status(timeline.TL_STATUS_OK)

# Notify the issuer by alert and email
if app_alerts:
Expand Down

0 comments on commit 21ca8ca

Please sign in to comment.