Skip to content

Commit 55836d8

Browse files
authored
Adds filter endpoints (#376)
* Adds filter endpoints * Org revision * Light user config * User extention for light user config * Submodule merge
1 parent 3bad75b commit 55836d8

File tree

6 files changed

+103
-12
lines changed

6 files changed

+103
-12
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""light user changes
2+
3+
Revision ID: 60a3d04181f7
4+
Revises: e3e108cd4b22
5+
Create Date: 2026-01-27 08:15:25.521072
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '60a3d04181f7'
14+
down_revision = 'e3e108cd4b22'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('organization', sa.Column('light_user_config', sa.JSON(), nullable=True))
22+
op.add_column('user', sa.Column('messages_created_today', sa.Integer(), nullable=True))
23+
op.add_column('user', sa.Column('is_light_user', sa.Boolean(), nullable=True))
24+
# ### end Alembic commands ###
25+
26+
27+
def downgrade():
28+
# ### commands auto generated by Alembic - please adjust! ###
29+
op.drop_column('user', 'is_light_user')
30+
op.drop_column('user', 'messages_created_today')
31+
op.drop_column('organization', 'light_user_config')
32+
# ### end Alembic commands ###

controller/inbox_mail/manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def create_inbox_mail_by_thread(
2020
meta_data: Optional[Dict[str, Any]] = None,
2121
thread_id: Optional[str] = None,
2222
) -> Dict[str, Any]:
23-
2423
return inbox_mail.create_by_thread(
2524
org_id=org_id,
2625
sender_id=sender_id,
@@ -84,13 +83,15 @@ def get_inbox_mail_threads_overview(
8483
page: int = 1,
8584
limit: int = 10,
8685
user_is_admin: bool = False,
86+
filters: Optional[List[str]] = None,
8787
) -> Dict[str, Any]:
8888
overview_by_threads = inbox_mail.get_overview_by_threads(
8989
org_id=org_id,
9090
user_id=user_id,
9191
page=page,
9292
limit=limit,
9393
user_is_admin=user_is_admin,
94+
filters=filters,
9495
)
9596

9697
admin_user_ids = [str(u.id) for u in user.get_admin_users()]
@@ -121,7 +122,6 @@ def create_auto_generated_inbox_mail_thread_for_error(
121122
is_important: bool = False,
122123
meta_data: Optional[Dict[str, Any]] = None,
123124
) -> Dict[str, Any]:
124-
125125
inbox_mail.create_by_thread(
126126
org_id=org_id,
127127
sender_id=None,
@@ -152,7 +152,6 @@ def extend_inbox_mail_sender_receiver_names(
152152
is_admin_support_thread: bool = False,
153153
is_auto_generated: bool = False,
154154
) -> None:
155-
156155
recipient_ids = [
157156
rid for rid in participant_ids if str(rid) != str(mail_dict.get("sender_id"))
158157
]

controller/organization/manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def change_organization(org_id: str, changes: Dict[str, Any]) -> None:
2121
raise ValueError(f"Organization with id {org_id} does not exist")
2222

2323
for k in changes:
24-
2524
if hasattr(org, k):
2625
setattr(org, k, changes[k])
2726
else:
@@ -49,7 +48,7 @@ def get_user_info(user) -> User:
4948
return user_expanded
5049

5150

52-
def get_user_count(organization_id: str) -> int:
51+
def get_user_count(organization_id: str) -> Dict[str, int]:
5352
return organization.get_user_count(organization_id)
5453

5554

@@ -63,7 +62,7 @@ def get_all_users(
6362
parsed = None
6463
if user_role:
6564
try:
66-
parsed = enums.UserRoles[user_role.upper()]
65+
parsed = enums.UserRoles[user_role.upper()] # noqa: F841
6766
except KeyError:
6867
raise ValueError(f"Invalid UserRoles: {user_role}")
6968
all_users = []

fast_api/routes/inbox_mail.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import List, Dict, Any
1+
from typing import List, Dict, Any, Optional
22
from controller.auth import kratos, manager as auth_manager
33
from fast_api.models import (
44
InboxMailCreateRequest,
55
UpdateInboxMailThreadProgressRequest,
66
)
77
from controller.inbox_mail import manager as inbox_mail_manager
88
from submodules.model.global_objects import inbox_mail as inbox_mail_go
9-
from fastapi import APIRouter, HTTPException, Request
9+
from fastapi import APIRouter, HTTPException, Request, Query
1010
from fast_api.routes.client_response import (
1111
get_silent_success,
1212
pack_json_result,
@@ -67,17 +67,20 @@ def get_inbox_mails_by_thread(request: Request, thread_id: str) -> List[Dict[str
6767

6868
@router.get("/overview")
6969
def get_inbox_mail_thread_overview_paginated(
70-
request: Request, page: int = 1, limit: int = 10
70+
request: Request,
71+
page: int = 1,
72+
limit: int = 10,
73+
filters: Optional[List[str]] = Query(default=None),
7174
):
7275
user_is_admin = auth_manager.check_is_admin(request)
7376
user = auth_manager.get_user_by_info(request.state.info)
74-
7577
mail = inbox_mail_manager.get_inbox_mail_threads_overview(
7678
org_id=user.organization_id,
7779
user_id=str(user.id),
7880
page=page,
7981
limit=limit,
8082
user_is_admin=user_is_admin,
83+
filters=filters,
8184
)
8285
return pack_json_result(mail)
8386

@@ -173,3 +176,37 @@ def update_inbox_mail_threads_unread_by_content(request: Request, thread_id: str
173176
thread_id=thread_id
174177
)
175178
return get_silent_success()
179+
180+
181+
@router.put("/thread/{thread_id}/unread-last")
182+
def mark_inbox_mail_thread_as_unread(request: Request, thread_id: str):
183+
user_is_admin = auth_manager.check_is_admin(request)
184+
if not user_is_admin:
185+
raise HTTPException(status_code=403, detail="Not authorized")
186+
inbox_mail_thread = inbox_mail_go.get_inbox_mail_thread_by_id(thread_id=thread_id)
187+
if not inbox_mail_thread:
188+
raise HTTPException(status_code=404, detail="Thread not found")
189+
190+
inbox_mail_go.mark_thread_as_unread(thread_id=thread_id)
191+
return get_silent_success()
192+
193+
194+
@router.delete("/thread/{thread_id}/similar")
195+
def delete_similar_system_threads(request: Request, thread_id: str):
196+
user_is_admin = auth_manager.check_is_admin(request)
197+
if not user_is_admin:
198+
raise HTTPException(status_code=403, detail="Not authorized")
199+
200+
inbox_mail_thread = inbox_mail_go.get_inbox_mail_thread_by_id(thread_id=thread_id)
201+
if not inbox_mail_thread:
202+
raise HTTPException(status_code=404, detail="Thread not found")
203+
204+
# only allowed for autoGenerated system threads
205+
meta_data = inbox_mail_thread.meta_data or {}
206+
if not meta_data.get("autoGenerated"):
207+
raise HTTPException(
208+
status_code=400, detail="Only allowed for auto-generated system threads"
209+
)
210+
211+
deleted_count = inbox_mail_go.delete_system_threads_by_content(thread_id=thread_id)
212+
return pack_json_result({"deletedCount": deleted_count})

fast_api/routes/organization.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"use_new_cognition_ui",
5353
"auto_logout_minutes",
5454
"one_drive_path",
55+
"is_light_user",
5556
}
5657
USER_INFO_RENAME_MAP = {"email": "mail"}
5758
ALL_ORGANIZATIONS_WHITELIST = {
@@ -67,6 +68,7 @@
6768
"conversation_lifespan_days",
6869
"file_lifespan_days",
6970
"token_limit",
71+
"light_user_config",
7072
}
7173
RELEASE_NOTIFICATIONS_WHITELIST = {"id", "link", "config"}
7274

@@ -108,8 +110,18 @@ def get_user_info_extended(request: Request):
108110
),
109111
"first_name": name.get("first") if name else None,
110112
"last_name": name.get("last") if name else None,
113+
"light_user_config": None,
114+
"messages_created_today": None,
115+
"messages_created_this_month": None,
111116
}
112117

118+
if user.is_light_user:
119+
org = organization.get(user.organization_id)
120+
if org and org.light_user_config and org.light_user_config.get("is_active"):
121+
user_dict["light_user_config"] = org.light_user_config
122+
user_dict["messages_created_today"] = user.messages_created_today
123+
user_dict["messages_created_this_month"] = user.messages_created_this_month
124+
113125
return pack_json_result(user_dict)
114126

115127

@@ -160,7 +172,6 @@ def get_all_user(
160172
# in use cognition-ui & refinery-ui & admin-dashboard (08.01.25)
161173
@router.get("/all-active-admin-messages")
162174
def all_active_admin_messages(request: Request, limit: int = 100) -> str:
163-
164175
data = admin_message_manager.get_messages(limit, active_only=True)
165176
data_dict = sql_alchemy_to_dict(
166177
data, column_whitelist=ACTIVE_ADMIN_MESSAGES_WHITELIST
@@ -319,6 +330,8 @@ def get_mapped_sorted_paginated_users(
319330
"metadata_public": user.metadata_public,
320331
"sso_provider": user.sso_provider,
321332
"messages_created_this_month": user.messages_created_this_month,
333+
"messages_created_today": user.messages_created_today,
334+
"is_light_user": user.is_light_user,
322335
}
323336
for user in active_users
324337
]
@@ -409,3 +422,14 @@ def delete_release_notification(request: Request, notification_id: str):
409422
auth_manager.check_admin_access(request.state.info)
410423
release_notification.delete(notification_id, with_commit=True)
411424
return get_silent_success()
425+
426+
427+
# in use admin-dashboard (27.01.26)
428+
@router.put("/toggle-light-user-status/{user_id}")
429+
def toggle_light_user_status(request: Request, user_id: str):
430+
auth_manager.check_admin_access(request.state.info)
431+
u = user_manager.get_or_create_user(user_id)
432+
if not u:
433+
raise HTTPException(status_code=404, detail="User not found")
434+
user_manager.update_user_field(user_id, "is_light_user", not u.is_light_user)
435+
return get_silent_success()

0 commit comments

Comments
 (0)