Skip to content

Commit

Permalink
Custom cleanup conversations and files by org (#275)
Browse files Browse the repository at this point in the history
* conv file lifespan

* gdpr compliant clean up, unify alembic

* model

* alembic

* user count

* camel case

* model
  • Loading branch information
LennartSchmidtKern authored Nov 28, 2024
1 parent f2f0c1e commit cbad993
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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 ###
22 changes: 5 additions & 17 deletions controller/organization/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}")
Expand All @@ -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]:
Expand Down Expand Up @@ -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
)
18 changes: 3 additions & 15 deletions fast_api/routes/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
}
)
Expand Down

0 comments on commit cbad993

Please sign in to comment.