Skip to content

Commit

Permalink
Sync user notification settings (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
lloesche authored Oct 11, 2024
1 parent 1aa7945 commit a1765af
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fixattiosync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
__author__ = "Some Engineering Inc."
__license__ = "AGPL-3.0"
__copyright__ = "Copyright © 2024 Some Engineering Inc."
__version__ = "0.0.17"
__version__ = "0.0.18"
11 changes: 10 additions & 1 deletion fixattiosync/fixdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from uuid import UUID
from argparse import ArgumentParser
from .logger import log
from .fixresources import FixUser, FixWorkspace, FixCloudAccount, FixRoles
from .fixresources import FixUser, FixWorkspace, FixCloudAccount, FixRoles, FixUserNotificationSettings
from typing import Optional


Expand Down Expand Up @@ -83,6 +83,15 @@ def hydrate(self) -> None:
rows = cursor.fetchall()
for row in rows:
self.__workspaces[row["organization_id"]].owner = self.__users[row["user_id"]]
with self.conn.cursor(row_factory=dict_row) as cursor:
cursor.execute('SELECT * FROM public."user_notification_settings";')
rows = cursor.fetchall()
for row in rows:
if row["user_id"] in self.__users:
user = self.__users[row["user_id"]]
user.notification_settings = FixUserNotificationSettings(**row)
else:
log.error(f"Data error: notification settings for user {row['user_id']} not found")
with self.conn.cursor(row_factory=dict_row) as cursor:
cursor.execute('SELECT * FROM public."cloud_account";')
rows = cursor.fetchall()
Expand Down
14 changes: 14 additions & 0 deletions fixattiosync/fixresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FixUser:
workspace_has_subscription: Optional[bool] = None
registered_at: Optional[datetime] = None
last_active_at: Optional[datetime] = None
notification_settings: Optional[FixUserNotificationSettings] = None

def __post_init__(self) -> None:
self.registered_at = self.created_at.replace(microsecond=0)
Expand Down Expand Up @@ -138,6 +139,8 @@ def attio_person(self) -> dict[str, Any]:
}

def update_info(self) -> None:
if self.notification_settings is not None:
self.user_email_notifications_disabled = not self.notification_settings.marketing
best_workspace = None
for workspace in self.workspaces:
if self.workspace_roles[workspace.id] & (
Expand Down Expand Up @@ -299,3 +302,14 @@ class FixCloudAccount:
azure_credential_id: Optional[UUID]
last_scan_resources_errors: int
last_degraded_scan_started_at: Optional[datetime]


@dataclass
class FixUserNotificationSettings:
user_id: UUID
weekly_report: bool
inactivity_reminder: bool
tutorial: bool
marketing: bool
created_at: datetime
updated_at: datetime
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "fixattiosync"
version = "0.0.17"
version = "0.0.18"
authors = [{name="Some Engineering Inc."}]
description = "Fix Attio Sync"
license = {file="LICENSE"}
Expand Down

0 comments on commit a1765af

Please sign in to comment.