From a2abbd464e091a865a7154b1cf867126075031d5 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Mon, 25 Nov 2024 18:14:35 +0100 Subject: [PATCH 1/7] conv file lifespan --- ...54b3_add_conversation_and_file_lifespan.py | 30 +++++++++++++++++++ fast_api/routes/organization.py | 2 ++ submodules/model | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py diff --git a/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py b/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py new file mode 100644 index 00000000..2015f9a4 --- /dev/null +++ b/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py @@ -0,0 +1,30 @@ +"""add conversation and file lifespan + +Revision ID: 9a224ef654b3 +Revises: 7aa933ec5de9 +Create Date: 2024-11-25 13:09:16.448641 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '9a224ef654b3' +down_revision = '7aa933ec5de9' +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)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('organization', 'file_lifespan_days') + op.drop_column('organization', 'conversation_lifespan_days') + # ### end Alembic commands ### diff --git a/fast_api/routes/organization.py b/fast_api/routes/organization.py index 322117cd..8e26379c 100644 --- a/fast_api/routes/organization.py +++ b/fast_api/routes/organization.py @@ -223,6 +223,8 @@ def get_all_organizations(request: Request): "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 d324f249..1481b2f1 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit d324f249baf21e439071e445aeea6b161cf2644c +Subproject commit 1481b2f1ce0acad6e02969b5e06017accf1deba2 From 913aac8bb47fa90c6647022d003c526288bd7e24 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Tue, 26 Nov 2024 12:15:09 +0100 Subject: [PATCH 2/7] gdpr compliant clean up, unify alembic --- ...54b3_add_conversation_and_file_lifespan.py | 30 ------------- ...5090_add_conversation_and_file_lifespan.py | 44 +++++++++++++++++++ controller/organization/manager.py | 18 +------- fast_api/routes/organization.py | 2 - submodules/model | 2 +- 5 files changed, 46 insertions(+), 50 deletions(-) delete mode 100644 alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py create mode 100644 alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py diff --git a/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py b/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py deleted file mode 100644 index 2015f9a4..00000000 --- a/alembic/versions/9a224ef654b3_add_conversation_and_file_lifespan.py +++ /dev/null @@ -1,30 +0,0 @@ -"""add conversation and file lifespan - -Revision ID: 9a224ef654b3 -Revises: 7aa933ec5de9 -Create Date: 2024-11-25 13:09:16.448641 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9a224ef654b3' -down_revision = '7aa933ec5de9' -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)) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('organization', 'file_lifespan_days') - op.drop_column('organization', 'conversation_lifespan_days') - # ### end Alembic commands ### 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..de43b4fa --- /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: 7aa933ec5de9 +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 = "7aa933ec5de9" +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..a3cec7d4 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}") @@ -98,10 +89,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 8e26379c..536d0c76 100644 --- a/fast_api/routes/organization.py +++ b/fast_api/routes/organization.py @@ -25,7 +25,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 @@ -221,7 +220,6 @@ def get_all_organizations(request: Request): "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 1481b2f1..f129a633 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 1481b2f1ce0acad6e02969b5e06017accf1deba2 +Subproject commit f129a633fd520974b5dc0ec4ab8de01121b71985 From 90ca696bdcb62dff30db3a5baaf21c8b5c26c2c2 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Tue, 26 Nov 2024 13:50:34 +0100 Subject: [PATCH 3/7] model --- submodules/model | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/model b/submodules/model index f129a633..7b042bd3 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit f129a633fd520974b5dc0ec4ab8de01121b71985 +Subproject commit 7b042bd319ed1ec3992c5b32bd1efd47c172f658 From 30456f5d4b084754f4cd8c4b237d0c1dff46b540 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Wed, 27 Nov 2024 13:34:41 +0100 Subject: [PATCH 4/7] alembic --- .../eb5ecbee5090_add_conversation_and_file_lifespan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py b/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py index de43b4fa..b23d4d37 100644 --- a/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py +++ b/alembic/versions/eb5ecbee5090_add_conversation_and_file_lifespan.py @@ -1,7 +1,7 @@ """add conversation and file lifespan Revision ID: eb5ecbee5090 -Revises: 7aa933ec5de9 +Revises: 2c0029684bd7 Create Date: 2024-11-26 11:03:23.883173 """ @@ -12,7 +12,7 @@ # revision identifiers, used by Alembic. revision = "eb5ecbee5090" -down_revision = "7aa933ec5de9" +down_revision = "2c0029684bd7" branch_labels = None depends_on = None From b35a43d0acdd21c4a8c9fd684c1a99e998b9eb68 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Wed, 27 Nov 2024 15:47:46 +0100 Subject: [PATCH 5/7] user count --- controller/organization/manager.py | 4 ++++ fast_api/routes/organization.py | 14 +------------- submodules/model | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/controller/organization/manager.py b/controller/organization/manager.py index a3cec7d4..318ba0fb 100644 --- a/controller/organization/manager.py +++ b/controller/organization/manager.py @@ -46,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]: diff --git a/fast_api/routes/organization.py b/fast_api/routes/organization.py index 536d0c76..a54a987a 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 @@ -205,18 +204,7 @@ 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 - ] - }, + "user_count": manager.get_user_count(org.id), "maxRows": org.max_rows, "maxCols": org.max_cols, "maxCharCount": org.max_char_count, diff --git a/submodules/model b/submodules/model index b69feddb..99791571 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit b69feddb238fae263674b6963931e3f1441448d8 +Subproject commit 99791571c22594bfc550ec4ad8c63fecbf769d3c From df58d9096ba5de4a97cb5f3e397c49088d131294 Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Wed, 27 Nov 2024 15:49:22 +0100 Subject: [PATCH 6/7] camel case --- fast_api/routes/organization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_api/routes/organization.py b/fast_api/routes/organization.py index a54a987a..be27a4b1 100644 --- a/fast_api/routes/organization.py +++ b/fast_api/routes/organization.py @@ -204,7 +204,7 @@ def get_all_organizations(request: Request): else None ), "isPaying": org.is_paying, - "user_count": manager.get_user_count(org.id), + "userCount": manager.get_user_count(org.id), "maxRows": org.max_rows, "maxCols": org.max_cols, "maxCharCount": org.max_char_count, From f93ad1df9c074502788b21958798b1ee8bf08eec Mon Sep 17 00:00:00 2001 From: LennartSchmidtKern Date: Thu, 28 Nov 2024 11:59:54 +0100 Subject: [PATCH 7/7] model --- submodules/model | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/model b/submodules/model index 99791571..ce7e748f 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 99791571c22594bfc550ec4ad8c63fecbf769d3c +Subproject commit ce7e748fc9b50787be180f635d441ad7eb11204d