Skip to content

Commit 4ed1d9f

Browse files
Inbox mail table (#202)
* Inbox mail table * Create and get requests for inbox mail * new model * mail collection by threads * enums inboxmail reference * restructure return inbox mails * is admin notificaiton * create admin notification * kratos * inbox mail threads * fix warning subquery * is in progress inbox mail thread * update progress * unread mail count * unread mails * remove kratos * remove org filter * inbox mail support progress state * clear prints * extend * remove org filter fix, get engineers * add org name to inbox threads * fix import * update kratos import * pr comments * clean up comments * PR comments --------- Co-authored-by: LennartSchmidtKern <lennart.schmidt@kern.ai>
1 parent d055b09 commit 4ed1d9f

File tree

4 files changed

+518
-0
lines changed

4 files changed

+518
-0
lines changed

business_objects/user.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@ def get_user_cached_if_not_admin(user_id: str) -> Optional[User]:
2626
return user
2727

2828

29+
def get_admin_users() -> List[User]:
30+
kernai_admins = (
31+
session.query(User)
32+
.filter(User.email.ilike("%@kern.ai"), User.verified == True)
33+
.all()
34+
)
35+
36+
query = """
37+
SELECT email FROM global.full_admin_access
38+
"""
39+
40+
result = general.execute_all(query)
41+
full_admin_emails = [row[0].lower() for row in result] if result else []
42+
43+
if full_admin_emails:
44+
full_admins = (
45+
session.query(User).filter(User.email.in_(full_admin_emails)).all()
46+
)
47+
else:
48+
full_admins = []
49+
50+
admin_users = {user.id: user for user in kernai_admins + full_admins}
51+
return list(admin_users.values())
52+
53+
54+
def get_engineer_users(org_id: str) -> List[User]:
55+
engineers = (
56+
session.query(User)
57+
.filter(User.role == enums.UserRoles.ENGINEER.value)
58+
.filter(User.organization_id == org_id)
59+
.all()
60+
)
61+
return engineers
62+
63+
2964
@TTLCacheDecorator(CacheEnum.USER, 5, "user_id")
3065
def get_user_cached(user_id: str) -> User:
3166
user = get(user_id)
@@ -52,6 +87,23 @@ def get_all(
5287
return query.all()
5388

5489

90+
def get_all_users_by_users_team(user_id: str) -> List[User]:
91+
if not user_id:
92+
return []
93+
teams_subquery = (
94+
session.query(TeamMember.team_id)
95+
.filter(TeamMember.user_id == user_id)
96+
.subquery()
97+
)
98+
query = (
99+
session.query(User)
100+
.join(TeamMember, TeamMember.user_id == User.id)
101+
.filter(TeamMember.team_id.in_(sql.select(teams_subquery)))
102+
.distinct(User.id)
103+
)
104+
return query.all()
105+
106+
55107
def get_all_team_members_by_project(project_id: str) -> List[User]:
56108
query = (
57109
session.query(TeamMember)

enums.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ class Tablenames(Enum):
180180
TIMED_EXECUTIONS = "timed_executions"
181181
CONVERSATION_SHARE = "conversation_share"
182182
CONVERSATION_GLOBAL_SHARE = "conversation_global_share"
183+
INBOX_MAIL = "inbox_mail"
184+
INBOX_MAIL_THREAD = "inbox_mail_thread"
185+
INBOX_MAIL_THREAD_ASSOCIATION = "inbox_mail_thread_association"
183186

184187
def snake_case_to_pascal_case(self):
185188
# the type name (written in PascalCase) of a table is needed to create backrefs
@@ -1026,3 +1029,10 @@ class MessageType(Enum):
10261029

10271030
class TimedExecutionKey(Enum):
10281031
LAST_RESET_USER_MESSAGE_COUNT = "LAST_RESET_USER_MESSAGE_COUNT"
1032+
1033+
1034+
class InboxMailThreadSupportProgressState(Enum):
1035+
PENDING = "PENDING"
1036+
IN_PROGRESS = "IN_PROGRESS"
1037+
RESOLVED = "RESOLVED"
1038+
FAILED = "FAILED"

0 commit comments

Comments
 (0)