diff --git a/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py b/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py new file mode 100644 index 00000000..39a353df --- /dev/null +++ b/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py @@ -0,0 +1,44 @@ +"""add conversation and file lifespan + +Revision ID: eb5ecbee5090 +Revises: 89a5f2211130 +Create Date: 2024-11-26 11:03:23.883173 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "eb5ecbee5090" +down_revision = "89a5f2211130" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "organization", + sa.Column("conversation_lifespan_days", sa.Integer(), nullable=True), + ) + op.add_column( + "organization", + sa.Column( + "file_lifespan_days", sa.Integer(), nullable=True, server_default="14" + ), + ) + op.drop_column("organization", "gdpr_compliant") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "organization", + sa.Column("gdpr_compliant", sa.BOOLEAN(), autoincrement=False, nullable=True), + ) + op.drop_column("organization", "file_lifespan_days") + op.drop_column("organization", "conversation_lifespan_days") + # ### end Alembic commands ### diff --git a/controller/organization/manager.py b/controller/organization/manager.py index 5bb805e0..318ba0fb 100644 --- a/controller/organization/manager.py +++ b/controller/organization/manager.py @@ -4,20 +4,12 @@ from submodules.model.business_objects import organization, general, user from submodules.model.exceptions import EntityAlreadyExistsException from submodules.model.models import Organization, User -from util import notification from controller.auth import kratos from submodules.model.util import sql_alchemy_to_dict from submodules.s3 import controller as s3 USER_INFO_WHITELIST = {"id", "role"} -ORGANIZATION_WHITELIST = { - "id", - "name", - "max_rows", - "max_cols", - "max_char_count", - "gdpr_compliant", -} +ORGANIZATION_WHITELIST = {"id", "name", "max_rows", "max_cols", "max_char_count"} def change_organization(org_id: str, changes: Dict[str, Any]) -> None: @@ -28,7 +20,6 @@ def change_organization(org_id: str, changes: Dict[str, Any]) -> None: for k in changes: if hasattr(org, k): - __check_notification(org_id, k, changes[k]) setattr(org, k, changes[k]) else: raise ValueError(f"Organization has no attribute {k}") @@ -55,6 +46,10 @@ def get_user_info(user) -> User: return user_expanded +def get_user_count(organization_id: str) -> int: + return organization.get_user_count(organization_id) + + def get_all_users( organization_id: str, user_role: Optional[str] = None, as_dict: bool = True ) -> List[User]: @@ -98,10 +93,3 @@ def get_overview_stats(org_id: str) -> List[Dict[str, Union[str, int]]]: if org_id is None: return [] return organization.get_organization_overview_stats(org_id) - - -def __check_notification(org_id: str, key: str, value: Any): - if key in ["gdpr_compliant"]: - notification.send_organization_update( - None, f"gdpr_compliant:{value}", True, org_id - ) diff --git a/fast_api/routes/organization.py b/fast_api/routes/organization.py index 322117cd..be27a4b1 100644 --- a/fast_api/routes/organization.py +++ b/fast_api/routes/organization.py @@ -16,7 +16,6 @@ ) from controller.auth import manager as auth_manager from controller.auth.kratos import ( - resolve_user_mail_by_id, resolve_user_name_and_email_by_id, ) from controller.organization import manager @@ -25,7 +24,6 @@ from controller.user import manager as user_manager from fast_api.routes.client_response import get_silent_success, pack_json_result -from submodules.model import events from submodules.model.business_objects import organization, user from submodules.model.util import sql_alchemy_to_dict from util import notification @@ -206,23 +204,13 @@ def get_all_organizations(request: Request): else None ), "isPaying": org.is_paying, - "users": { - "edges": [ - { - "node": { - "id": str(user.id), - "mail": resolve_user_mail_by_id(user.id), - } - } - for user in org.users - if resolve_user_mail_by_id(user.id) is not None - ] - }, + "userCount": manager.get_user_count(org.id), "maxRows": org.max_rows, "maxCols": org.max_cols, "maxCharCount": org.max_char_count, - "gdprCompliant": org.gdpr_compliant, "logAdminRequests": org.log_admin_requests, + "conversationLifespanDays": org.conversation_lifespan_days, + "fileLifespanDays": org.file_lifespan_days, } } ) diff --git a/submodules/model b/submodules/model index 348c4586..ce7e748f 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 348c4586a64f68a4873aabe8126a3f8ee9fcba06 +Subproject commit ce7e748fc9b50787be180f635d441ad7eb11204d