Skip to content

Commit cbad993

Browse files
Custom cleanup conversations and files by org (#275)
* conv file lifespan * gdpr compliant clean up, unify alembic * model * alembic * user count * camel case * model
1 parent f2f0c1e commit cbad993

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""add conversation and file lifespan
2+
3+
Revision ID: eb5ecbee5090
4+
Revises: 89a5f2211130
5+
Create Date: 2024-11-26 11:03:23.883173
6+
7+
"""
8+
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "eb5ecbee5090"
15+
down_revision = "89a5f2211130"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.add_column(
23+
"organization",
24+
sa.Column("conversation_lifespan_days", sa.Integer(), nullable=True),
25+
)
26+
op.add_column(
27+
"organization",
28+
sa.Column(
29+
"file_lifespan_days", sa.Integer(), nullable=True, server_default="14"
30+
),
31+
)
32+
op.drop_column("organization", "gdpr_compliant")
33+
# ### end Alembic commands ###
34+
35+
36+
def downgrade():
37+
# ### commands auto generated by Alembic - please adjust! ###
38+
op.add_column(
39+
"organization",
40+
sa.Column("gdpr_compliant", sa.BOOLEAN(), autoincrement=False, nullable=True),
41+
)
42+
op.drop_column("organization", "file_lifespan_days")
43+
op.drop_column("organization", "conversation_lifespan_days")
44+
# ### end Alembic commands ###

controller/organization/manager.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@
44
from submodules.model.business_objects import organization, general, user
55
from submodules.model.exceptions import EntityAlreadyExistsException
66
from submodules.model.models import Organization, User
7-
from util import notification
87
from controller.auth import kratos
98
from submodules.model.util import sql_alchemy_to_dict
109
from submodules.s3 import controller as s3
1110

1211
USER_INFO_WHITELIST = {"id", "role"}
13-
ORGANIZATION_WHITELIST = {
14-
"id",
15-
"name",
16-
"max_rows",
17-
"max_cols",
18-
"max_char_count",
19-
"gdpr_compliant",
20-
}
12+
ORGANIZATION_WHITELIST = {"id", "name", "max_rows", "max_cols", "max_char_count"}
2113

2214

2315
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:
2820
for k in changes:
2921

3022
if hasattr(org, k):
31-
__check_notification(org_id, k, changes[k])
3223
setattr(org, k, changes[k])
3324
else:
3425
raise ValueError(f"Organization has no attribute {k}")
@@ -55,6 +46,10 @@ def get_user_info(user) -> User:
5546
return user_expanded
5647

5748

49+
def get_user_count(organization_id: str) -> int:
50+
return organization.get_user_count(organization_id)
51+
52+
5853
def get_all_users(
5954
organization_id: str, user_role: Optional[str] = None, as_dict: bool = True
6055
) -> List[User]:
@@ -98,10 +93,3 @@ def get_overview_stats(org_id: str) -> List[Dict[str, Union[str, int]]]:
9893
if org_id is None:
9994
return []
10095
return organization.get_organization_overview_stats(org_id)
101-
102-
103-
def __check_notification(org_id: str, key: str, value: Any):
104-
if key in ["gdpr_compliant"]:
105-
notification.send_organization_update(
106-
None, f"gdpr_compliant:{value}", True, org_id
107-
)

fast_api/routes/organization.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
)
1717
from controller.auth import manager as auth_manager
1818
from controller.auth.kratos import (
19-
resolve_user_mail_by_id,
2019
resolve_user_name_and_email_by_id,
2120
)
2221
from controller.organization import manager
@@ -25,7 +24,6 @@
2524
from controller.user import manager as user_manager
2625

2726
from fast_api.routes.client_response import get_silent_success, pack_json_result
28-
from submodules.model import events
2927
from submodules.model.business_objects import organization, user
3028
from submodules.model.util import sql_alchemy_to_dict
3129
from util import notification
@@ -206,23 +204,13 @@ def get_all_organizations(request: Request):
206204
else None
207205
),
208206
"isPaying": org.is_paying,
209-
"users": {
210-
"edges": [
211-
{
212-
"node": {
213-
"id": str(user.id),
214-
"mail": resolve_user_mail_by_id(user.id),
215-
}
216-
}
217-
for user in org.users
218-
if resolve_user_mail_by_id(user.id) is not None
219-
]
220-
},
207+
"userCount": manager.get_user_count(org.id),
221208
"maxRows": org.max_rows,
222209
"maxCols": org.max_cols,
223210
"maxCharCount": org.max_char_count,
224-
"gdprCompliant": org.gdpr_compliant,
225211
"logAdminRequests": org.log_admin_requests,
212+
"conversationLifespanDays": org.conversation_lifespan_days,
213+
"fileLifespanDays": org.file_lifespan_days,
226214
}
227215
}
228216
)

0 commit comments

Comments
 (0)