Skip to content

Commit

Permalink
Sync last_active_at field
Browse files Browse the repository at this point in the history
  • Loading branch information
lloesche committed Oct 9, 2024
1 parent 8e99b08 commit 3a5d54a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fixattiosync/attioresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class AttioUser(AttioResource):
demo_workspace_viewed: Optional[bool]
email: Optional[str]
registered_at: Optional[datetime]
last_active_at: Optional[datetime]
status: Optional[str]
user_id: Optional[UUID]
person_id: Optional[UUID]
Expand All @@ -183,13 +184,20 @@ def __eq__(self: Self, other: Any) -> bool:
or not isinstance(other.registered_at, datetime)
or not hasattr(other, "workspaces")
or not isinstance(other.workspaces, list)
or not hasattr(other, "last_active_at")
or not hasattr(other, "user_email_notifications_disabled")
or not hasattr(other, "at_least_one_cloud_account_connected")
or not hasattr(other, "is_main_user_in_at_least_one_workspace")
or not hasattr(other, "cloud_account_connected_workspace_name")
or not hasattr(other, "workspace_has_subscription")
):
return False
self_last_active_at = None
other_last_active_at = None
if self.last_active_at is not None:
self_last_active_at = self.last_active_at.astimezone(timezone.utc)
if other.last_active_at is not None:
other_last_active_at = other.last_active_at.astimezone(timezone.utc)
return bool(
self.id == other.id
and str(self.email).lower() == str(other.email).lower()
Expand All @@ -200,6 +208,7 @@ def __eq__(self: Self, other: Any) -> bool:
and self.is_main_user_in_at_least_one_workspace == other.is_main_user_in_at_least_one_workspace
and self.cloud_account_connected_workspace_name == other.cloud_account_connected_workspace_name
and self.workspace_has_subscription == other.workspace_has_subscription
and self_last_active_at == other_last_active_at
)

@classmethod
Expand All @@ -215,6 +224,10 @@ def make(cls: Type[Self], data: dict[str, Any]) -> Self:
if registered_at:
registered_at = datetime.fromisoformat(registered_at).replace(microsecond=0)

last_active_at = get_nested_field(values, "last_active_at", ["value"])
if last_active_at:
last_active_at = datetime.fromisoformat(last_active_at).replace(microsecond=0)

primary_email_address = get_nested_field(values, "primary_email_address", ["email_address"])
status = get_nested_field(values, "status", ["status", "title"])
user_id = optional_uuid(str(get_nested_field(values, "user_id", ["value"])))
Expand Down Expand Up @@ -251,6 +264,7 @@ def make(cls: Type[Self], data: dict[str, Any]) -> Self:
"demo_workspace_viewed": None,
"email": primary_email_address,
"registered_at": registered_at,
"last_active_at": last_active_at,
"status": status,
"user_id": user_id,
"person_id": person_id,
Expand Down
12 changes: 12 additions & 0 deletions fixattiosync/fixresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class FixUser:
cloud_account_connected_workspace_name: Optional[str] = None
workspace_has_subscription: Optional[bool] = None
registered_at: Optional[datetime] = None
last_active_at: Optional[datetime] = None

def __post_init__(self) -> None:
self.registered_at = self.created_at.replace(microsecond=0)
self.last_active_at = self.last_active.replace(microsecond=0)

def __eq__(self: Self, other: Any) -> bool:
if (
Expand All @@ -43,13 +45,20 @@ def __eq__(self: Self, other: Any) -> bool:
or not isinstance(other.registered_at, datetime)
or not hasattr(other, "workspaces")
or not isinstance(other.workspaces, list)
or not hasattr(other, "last_active_at")
or not hasattr(other, "user_email_notifications_disabled")
or not hasattr(other, "at_least_one_cloud_account_connected")
or not hasattr(other, "is_main_user_in_at_least_one_workspace")
or not hasattr(other, "cloud_account_connected_workspace_name")
or not hasattr(other, "workspace_has_subscription")
):
return False
self_last_active_at = None
other_last_active_at = None
if self.last_active_at is not None:
self_last_active_at = self.last_active_at.astimezone(timezone.utc)
if other.last_active_at is not None:
other_last_active_at = other.last_active_at.astimezone(timezone.utc)
return bool(
self.id == other.id
and str(self.email).lower() == str(other.email).lower()
Expand All @@ -60,6 +69,7 @@ def __eq__(self: Self, other: Any) -> bool:
and self.is_main_user_in_at_least_one_workspace == other.is_main_user_in_at_least_one_workspace
and self.cloud_account_connected_workspace_name == other.cloud_account_connected_workspace_name
and self.workspace_has_subscription == other.workspace_has_subscription
and self_last_active_at == other_last_active_at
)

def attio_data(
Expand Down Expand Up @@ -93,6 +103,8 @@ def attio_data(
"target_record_id": str(workspace.record_id),
}
)
if self.last_active_at is not None:
data["data"]["values"]["last_active_at"] = self.last_active_at.isoformat()
if self.user_email_notifications_disabled is not None:
data["data"]["values"]["email_notifications_disabled"] = self.user_email_notifications_disabled
if self.at_least_one_cloud_account_connected is not None:
Expand Down

0 comments on commit 3a5d54a

Please sign in to comment.