Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 32 additions & 0 deletions alembic/versions/60a3d04181f7_light_user_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""light user changes

Revision ID: 60a3d04181f7
Revises: e3e108cd4b22
Create Date: 2026-01-27 08:15:25.521072

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '60a3d04181f7'
down_revision = 'e3e108cd4b22'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('organization', sa.Column('light_user_config', sa.JSON(), nullable=True))
op.add_column('user', sa.Column('messages_created_today', sa.Integer(), nullable=True))
op.add_column('user', sa.Column('is_light_user', sa.Boolean(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'is_light_user')
op.drop_column('user', 'messages_created_today')
op.drop_column('organization', 'light_user_config')
# ### end Alembic commands ###
5 changes: 2 additions & 3 deletions controller/inbox_mail/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def create_inbox_mail_by_thread(
meta_data: Optional[Dict[str, Any]] = None,
thread_id: Optional[str] = None,
) -> Dict[str, Any]:

return inbox_mail.create_by_thread(
org_id=org_id,
sender_id=sender_id,
Expand Down Expand Up @@ -84,13 +83,15 @@ def get_inbox_mail_threads_overview(
page: int = 1,
limit: int = 10,
user_is_admin: bool = False,
filters: Optional[List[str]] = None,
) -> Dict[str, Any]:
overview_by_threads = inbox_mail.get_overview_by_threads(
org_id=org_id,
user_id=user_id,
page=page,
limit=limit,
user_is_admin=user_is_admin,
filters=filters,
)

admin_user_ids = [str(u.id) for u in user.get_admin_users()]
Expand Down Expand Up @@ -121,7 +122,6 @@ def create_auto_generated_inbox_mail_thread_for_error(
is_important: bool = False,
meta_data: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:

inbox_mail.create_by_thread(
org_id=org_id,
sender_id=None,
Expand Down Expand Up @@ -152,7 +152,6 @@ def extend_inbox_mail_sender_receiver_names(
is_admin_support_thread: bool = False,
is_auto_generated: bool = False,
) -> None:

recipient_ids = [
rid for rid in participant_ids if str(rid) != str(mail_dict.get("sender_id"))
]
Expand Down
5 changes: 2 additions & 3 deletions controller/organization/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def change_organization(org_id: str, changes: Dict[str, Any]) -> None:
raise ValueError(f"Organization with id {org_id} does not exist")

for k in changes:

if hasattr(org, k):
setattr(org, k, changes[k])
else:
Expand Down Expand Up @@ -49,7 +48,7 @@ def get_user_info(user) -> User:
return user_expanded


def get_user_count(organization_id: str) -> int:
def get_user_count(organization_id: str) -> Dict[str, int]:
return organization.get_user_count(organization_id)


Expand All @@ -63,7 +62,7 @@ def get_all_users(
parsed = None
if user_role:
try:
parsed = enums.UserRoles[user_role.upper()]
parsed = enums.UserRoles[user_role.upper()] # noqa: F841
except KeyError:
raise ValueError(f"Invalid UserRoles: {user_role}")
all_users = []
Expand Down
45 changes: 41 additions & 4 deletions fast_api/routes/inbox_mail.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List, Dict, Any
from typing import List, Dict, Any, Optional
from controller.auth import kratos, manager as auth_manager
from fast_api.models import (
InboxMailCreateRequest,
UpdateInboxMailThreadProgressRequest,
)
from controller.inbox_mail import manager as inbox_mail_manager
from submodules.model.global_objects import inbox_mail as inbox_mail_go
from fastapi import APIRouter, HTTPException, Request
from fastapi import APIRouter, HTTPException, Request, Query
from fast_api.routes.client_response import (
get_silent_success,
pack_json_result,
Expand Down Expand Up @@ -67,17 +67,20 @@ def get_inbox_mails_by_thread(request: Request, thread_id: str) -> List[Dict[str

@router.get("/overview")
def get_inbox_mail_thread_overview_paginated(
request: Request, page: int = 1, limit: int = 10
request: Request,
page: int = 1,
limit: int = 10,
filters: Optional[List[str]] = Query(default=None),
):
user_is_admin = auth_manager.check_is_admin(request)
user = auth_manager.get_user_by_info(request.state.info)

mail = inbox_mail_manager.get_inbox_mail_threads_overview(
org_id=user.organization_id,
user_id=str(user.id),
page=page,
limit=limit,
user_is_admin=user_is_admin,
filters=filters,
)
return pack_json_result(mail)

Expand Down Expand Up @@ -173,3 +176,37 @@ def update_inbox_mail_threads_unread_by_content(request: Request, thread_id: str
thread_id=thread_id
)
return get_silent_success()


@router.put("/thread/{thread_id}/unread-last")
def mark_inbox_mail_thread_as_unread(request: Request, thread_id: str):
user_is_admin = auth_manager.check_is_admin(request)
if not user_is_admin:
raise HTTPException(status_code=403, detail="Not authorized")
inbox_mail_thread = inbox_mail_go.get_inbox_mail_thread_by_id(thread_id=thread_id)
if not inbox_mail_thread:
raise HTTPException(status_code=404, detail="Thread not found")

inbox_mail_go.mark_thread_as_unread(thread_id=thread_id)
return get_silent_success()


@router.delete("/thread/{thread_id}/similar")
def delete_similar_system_threads(request: Request, thread_id: str):
user_is_admin = auth_manager.check_is_admin(request)
if not user_is_admin:
raise HTTPException(status_code=403, detail="Not authorized")

inbox_mail_thread = inbox_mail_go.get_inbox_mail_thread_by_id(thread_id=thread_id)
if not inbox_mail_thread:
raise HTTPException(status_code=404, detail="Thread not found")

# only allowed for autoGenerated system threads
meta_data = inbox_mail_thread.meta_data or {}
if not meta_data.get("autoGenerated"):
raise HTTPException(
status_code=400, detail="Only allowed for auto-generated system threads"
)

deleted_count = inbox_mail_go.delete_system_threads_by_content(thread_id=thread_id)
return pack_json_result({"deletedCount": deleted_count})
26 changes: 25 additions & 1 deletion fast_api/routes/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"use_new_cognition_ui",
"auto_logout_minutes",
"one_drive_path",
"is_light_user",
}
USER_INFO_RENAME_MAP = {"email": "mail"}
ALL_ORGANIZATIONS_WHITELIST = {
Expand All @@ -67,6 +68,7 @@
"conversation_lifespan_days",
"file_lifespan_days",
"token_limit",
"light_user_config",
}
RELEASE_NOTIFICATIONS_WHITELIST = {"id", "link", "config"}

Expand Down Expand Up @@ -108,8 +110,18 @@ def get_user_info_extended(request: Request):
),
"first_name": name.get("first") if name else None,
"last_name": name.get("last") if name else None,
"light_user_config": None,
"messages_created_today": None,
"messages_created_this_month": None,
}

if user.is_light_user:
org = organization.get(user.organization_id)
if org and org.light_user_config and org.light_user_config.get("is_active"):
user_dict["light_user_config"] = org.light_user_config
user_dict["messages_created_today"] = user.messages_created_today
user_dict["messages_created_this_month"] = user.messages_created_this_month

return pack_json_result(user_dict)


Expand Down Expand Up @@ -160,7 +172,6 @@ def get_all_user(
# in use cognition-ui & refinery-ui & admin-dashboard (08.01.25)
@router.get("/all-active-admin-messages")
def all_active_admin_messages(request: Request, limit: int = 100) -> str:

data = admin_message_manager.get_messages(limit, active_only=True)
data_dict = sql_alchemy_to_dict(
data, column_whitelist=ACTIVE_ADMIN_MESSAGES_WHITELIST
Expand Down Expand Up @@ -319,6 +330,8 @@ def get_mapped_sorted_paginated_users(
"metadata_public": user.metadata_public,
"sso_provider": user.sso_provider,
"messages_created_this_month": user.messages_created_this_month,
"messages_created_today": user.messages_created_today,
"is_light_user": user.is_light_user,
}
for user in active_users
]
Expand Down Expand Up @@ -409,3 +422,14 @@ def delete_release_notification(request: Request, notification_id: str):
auth_manager.check_admin_access(request.state.info)
release_notification.delete(notification_id, with_commit=True)
return get_silent_success()


# in use admin-dashboard (27.01.26)
@router.put("/toggle-light-user-status/{user_id}")
def toggle_light_user_status(request: Request, user_id: str):
auth_manager.check_admin_access(request.state.info)
u = user_manager.get_or_create_user(user_id)
if not u:
raise HTTPException(status_code=404, detail="User not found")
user_manager.update_user_field(user_id, "is_light_user", not u.is_light_user)
return get_silent_success()