Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Tablenames(Enum):
ADMIN_QUERY_MESSAGE_SUMMARY = "admin_query_message_summary"
RELEASE_NOTIFICATION = "release_notification"
TIMED_EXECUTIONS = "timed_executions"
INBOX_MAIL = "inbox_mail"

def snake_case_to_pascal_case(self):
# the type name (written in PascalCase) of a table is needed to create backrefs
Expand Down
47 changes: 47 additions & 0 deletions global_objects/inbox_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Dict, List

from ..session import session
from sqlalchemy import cast, String

from submodules.model.business_objects import general
from submodules.model.models import InboxMail


def get_inbox_mail(
org_id: str,
user_email: str,
) -> List[InboxMail]:
return (
session.query(InboxMail)
.filter(InboxMail.organization_id == org_id)
.filter(cast(InboxMail.send_to, String).like(f"%{user_email}%"))
.all()
)


def create(
org_id: str,
send_from: str,
send_to: Dict,
subject: str,
content: str,
mark_as_important: bool,
meta_data: Dict,
parent_id: str = None,
child_id: str = None,
with_commit: bool = True,
) -> InboxMail:
obj = InboxMail(
organization_id=org_id,
send_from=send_from,
send_to=send_to,
subject=subject,
content=content,
mark_as_important=mark_as_important,
meta_data=meta_data,
parent_id=parent_id,
child_id=child_id,
)
general.add(obj, with_commit)

return obj
32 changes: 32 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,3 +2512,35 @@ class TimedExecutions(Base):
__table_args__ = {"schema": "global"}
time_key = Column(String, unique=True, primary_key=True) # enums.TimedExecutionKey
last_executed_at = Column(DateTime)


class InboxMail(Base):
__tablename__ = Tablenames.INBOX_MAIL.value
__table_args__ = {"schema": "global"}
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
organization_id = Column(
UUID(as_uuid=True),
ForeignKey(f"{Tablenames.ORGANIZATION.value}.id", ondelete="CASCADE"),
index=True,
)
created_at = Column(DateTime, default=sql.func.now())
send_from = Column(String)
send_to = Column(JSON)
subject = Column(String)
content = Column(String)
mark_as_important = Column(Boolean, default=False)
meta_data = Column(JSON)
is_seen = Column(Boolean, default=False)
being_worked_on = Column(Boolean, default=False)
parent_id = Column(
UUID(as_uuid=True),
ForeignKey(f"global.{Tablenames.INBOX_MAIL.value}.id", ondelete="SET NULL"),
index=True,
nullable=True,
)
child_id = Column(
UUID(as_uuid=True),
ForeignKey(f"global.{Tablenames.INBOX_MAIL.value}.id", ondelete="SET NULL"),
index=True,
nullable=True,
)