From 6b772b7704f7dbd56bf7c633b862ace2a5d6e66b Mon Sep 17 00:00:00 2001 From: prabinoid Date: Mon, 4 Nov 2024 17:13:45 +0545 Subject: [PATCH] Task dto last updated attribute made timezone aware and add teams by organisation manager fixed --- backend/models/postgis/task.py | 8 ++++++-- backend/models/postgis/utils.py | 3 ++- backend/services/team_service.py | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/models/postgis/task.py b/backend/models/postgis/task.py index 0c2abde81c..788cf4e72b 100644 --- a/backend/models/postgis/task.py +++ b/backend/models/postgis/task.py @@ -26,6 +26,7 @@ ) from sqlalchemy.orm import relationship from sqlalchemy.orm.exc import MultipleResultsFound +from datetime import timezone from backend.db import Base, get_session from backend.exceptions import NotFound @@ -1357,7 +1358,6 @@ async def reset_lock( comment=comment, db=db, ) - # Update task lock history with duration await TaskHistory.update_task_locked_with_duration( task_id=task_id, @@ -1737,7 +1737,11 @@ async def as_dto_with_instructions( task_history.append(history) - last_updated = task_history[0].action_date if task_history else None + last_updated = ( + task_history[0].action_date.replace(tzinfo=timezone.utc).isoformat() + if task_history + else None + ) task_dto = await Task.as_dto(task_id, project_id, db, last_updated) per_task_instructions = await Task.get_per_task_instructions( task_id, project_id, preferred_locale, db diff --git a/backend/models/postgis/utils.py b/backend/models/postgis/utils.py index c0a12b180d..abd2aaf71b 100644 --- a/backend/models/postgis/utils.py +++ b/backend/models/postgis/utils.py @@ -134,7 +134,8 @@ class ST_Y(GenericFunction): def timestamp(): """Used in SQL Alchemy models to ensure we refresh timestamp when new models initialised""" - return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) + # return datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) + return datetime.datetime.utcnow() # Based on https://stackoverflow.com/a/51916936 diff --git a/backend/services/team_service.py b/backend/services/team_service.py index 8c0a1a562e..18a1d02497 100644 --- a/backend/services/team_service.py +++ b/backend/services/team_service.py @@ -735,7 +735,8 @@ async def is_user_team_manager(team_id: int, user_id: int, db: Database) -> bool # Org admin manages teams attached to their org user_managed_orgs = [ - org.id for org in await OrganisationService.get_organisations(user_id, db) + org.organisation_id + for org in await OrganisationService.get_organisations(user_id, db) ] if team.organisation_id in user_managed_orgs: return True