core-framework 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- core_framework/__init__.py +0 -0
- core_framework/alembic/comment/alembic/README +1 -0
- core_framework/alembic/comment/alembic/env.py +72 -0
- core_framework/alembic/comment/alembic/script.py.mako +28 -0
- core_framework/alembic/comment/alembic/versions/30334fd1347b_init.py +59 -0
- core_framework/alembic/comment/alembic/versions/a2b3c4d5e6f7_improve_comment_indexes.py +54 -0
- core_framework/alembic/comment/alembic/versions/bcc8e00cfc8b_add_extra_tables.py +64 -0
- core_framework/alembic/comment/alembic/versions/d1e2f3a4b5c6_add_comment_stats_dirty_table.py +29 -0
- core_framework/alembic/comment/alembic/versions/e3f4a5b6c7d8_cascade_delete_comment_descendants.py +49 -0
- core_framework/alembic/comment/alembic/versions/f7e6d5c4b3a2_comments_path_to_ltree.py +60 -0
- core_framework/alembic/comment/alembic.ini +52 -0
- core_framework/alembic/extension/alembic/README +1 -0
- core_framework/alembic/extension/alembic/env.py +98 -0
- core_framework/alembic/extension/alembic/script.py.mako +28 -0
- core_framework/alembic/extension/alembic/versions/0389226049cb_add_pg_trgm_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/5dc58b016cf5_add_citext_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/b0ba0d8a284e_add_pg_stat_statements_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/c9d0e1f2a3b4_add_ltree_extension.py +25 -0
- core_framework/alembic/extension/alembic.ini +147 -0
- core_framework/alembic/moderation/alembic/README +1 -0
- core_framework/alembic/moderation/alembic/env.py +98 -0
- core_framework/alembic/moderation/alembic/script.py.mako +28 -0
- core_framework/alembic/moderation/alembic/versions/085ba9021850_add_category_to_user_restrictions.py +93 -0
- core_framework/alembic/moderation/alembic/versions/5f9e4fc14a41_create_moderation_appeals_table.py +69 -0
- core_framework/alembic/moderation/alembic/versions/63e37381e73b_add_user_reports_table.py +33 -0
- core_framework/alembic/moderation/alembic/versions/6a2ae31b7ac6_add_moderation_actions_table.py +34 -0
- core_framework/alembic/moderation/alembic/versions/716aa1735c03_improve_indexes.py +36 -0
- core_framework/alembic/moderation/alembic/versions/7d243ddbfde1_add_post_reports_table.py +35 -0
- core_framework/alembic/moderation/alembic/versions/8fba1f72dd46_add_indexes.py +64 -0
- core_framework/alembic/moderation/alembic/versions/95cc35a51984_update_restriction_history.py +91 -0
- core_framework/alembic/moderation/alembic/versions/9ad79d0af730_add_unique_constraint_user_reports_.py +28 -0
- core_framework/alembic/moderation/alembic/versions/a5e569f5df1a_create_user_restrictions_table.py +38 -0
- core_framework/alembic/moderation/alembic/versions/b2c3d4e5f6a7_add_indexes.py +42 -0
- core_framework/alembic/moderation/alembic/versions/c3d4e5f6a7b8_improve_report_indexes.py +48 -0
- core_framework/alembic/moderation/alembic/versions/d4af74643ff5_add_internal_notes_table.py +38 -0
- core_framework/alembic/moderation/alembic/versions/db20f2fb7390_add_comment_reports_table.py +35 -0
- core_framework/alembic/moderation/alembic/versions/e66226952ea6_add_report_category_to_user_reports_.py +54 -0
- core_framework/alembic/moderation/alembic/versions/f5e8cb275c30_enforce_1_pending_appeal.py +29 -0
- core_framework/alembic/moderation/alembic/versions/fe1faad2832d_create_restriction_history_table.py +69 -0
- core_framework/alembic/moderation/alembic.ini +147 -0
- core_framework/alembic/post/alembic/README +1 -0
- core_framework/alembic/post/alembic/env.py +97 -0
- core_framework/alembic/post/alembic/script.py.mako +28 -0
- core_framework/alembic/post/alembic/versions/51542673f5c8_add_tables_for_muted_banned_users.py +41 -0
- core_framework/alembic/post/alembic/versions/5beeeae40a4a_add_post_views_table.py +45 -0
- core_framework/alembic/post/alembic/versions/620971509a8b_init.py +55 -0
- core_framework/alembic/post/alembic/versions/a1b2c3d4e5f6_add_indexes.py +44 -0
- core_framework/alembic/post/alembic/versions/c1d2e3f4a5b6_add_post_hashtags_table.py +36 -0
- core_framework/alembic/post/alembic/versions/e56723f2afff_add_post_stats_table.py +39 -0
- core_framework/alembic/post/alembic/versions/fbc723ac58cc_add_post_likes_table.py +32 -0
- core_framework/alembic/post/alembic.ini +149 -0
- core_framework/alembic/user/alembic/README +1 -0
- core_framework/alembic/user/alembic/env.py +98 -0
- core_framework/alembic/user/alembic/script.py.mako +28 -0
- core_framework/alembic/user/alembic/versions/1a8bb99726ed_remove_avatar_id_from_users.py +81 -0
- core_framework/alembic/user/alembic/versions/2ccacf455941_improve_indexes.py +34 -0
- core_framework/alembic/user/alembic/versions/47f47ce2110e_create_user_deletions_table.py +31 -0
- core_framework/alembic/user/alembic/versions/5976db3f0175_drop_user_states.py +26 -0
- core_framework/alembic/user/alembic/versions/62417002cf32_add_indexes.py +46 -0
- core_framework/alembic/user/alembic/versions/6f7ccf3c226b_refactor_user_login_events.py +66 -0
- core_framework/alembic/user/alembic/versions/73432817015b_add_user_preferences_table.py +33 -0
- core_framework/alembic/user/alembic/versions/765bc01a7a59_create_user_blocks_table.py +33 -0
- core_framework/alembic/user/alembic/versions/7a56631f9927_create_user_login_events_table.py +49 -0
- core_framework/alembic/user/alembic/versions/831611e589bc_create_user_state.py +31 -0
- core_framework/alembic/user/alembic/versions/83c98ab2a779_add_user_profiles_table.py +88 -0
- core_framework/alembic/user/alembic/versions/8a94362cad6d_create_user_role.py +31 -0
- core_framework/alembic/user/alembic/versions/94b973923895_add_user_change_history_table.py +97 -0
- core_framework/alembic/user/alembic/versions/cbc0f4efe84f_add_avatar_id_column_to_users_table.py +31 -0
- core_framework/alembic/user/alembic/versions/d8b98ac6b073_add_index_for_get_admin_user_ids_query.py +29 -0
- core_framework/alembic/user/alembic/versions/ddb70cc09d16_create_user_states_table.py +34 -0
- core_framework/alembic/user/alembic/versions/f9ba10815ecd_add_users_table.py +33 -0
- core_framework/alembic/user/alembic.ini +147 -0
- core_framework/api/__init__.py +0 -0
- core_framework/api/admin/__init__.py +0 -0
- core_framework/api/admin/comments/router.py +69 -0
- core_framework/api/admin/comments/schemas.py +53 -0
- core_framework/api/admin/moderation/__init__.py +0 -0
- core_framework/api/admin/moderation/router.py +205 -0
- core_framework/api/admin/moderation/schemas.py +110 -0
- core_framework/api/admin/posts/router.py +62 -0
- core_framework/api/admin/posts/schemas.py +29 -0
- core_framework/api/admin/router.py +17 -0
- core_framework/api/admin/users/__init__.py +0 -0
- core_framework/api/admin/users/router.py +181 -0
- core_framework/api/admin/users/schemas.py +137 -0
- core_framework/api/auth/__init__.py +0 -0
- core_framework/api/auth/router.py +21 -0
- core_framework/api/auth/schemas.py +28 -0
- core_framework/api/comments/authenticated/router.py +126 -0
- core_framework/api/comments/authenticated/schemas.py +27 -0
- core_framework/api/comments/public/router.py +103 -0
- core_framework/api/comments/public/schemas.py +36 -0
- core_framework/api/comments/router.py +9 -0
- core_framework/api/comments/schemas.py +17 -0
- core_framework/api/dependencies.py +168 -0
- core_framework/api/events/router.py +39 -0
- core_framework/api/events/schemas.py +20 -0
- core_framework/api/posts/authenticated/router.py +83 -0
- core_framework/api/posts/authenticated/schemas.py +37 -0
- core_framework/api/posts/public/router.py +100 -0
- core_framework/api/posts/public/schemas.py +39 -0
- core_framework/api/posts/router.py +9 -0
- core_framework/api/posts/schemas.py +39 -0
- core_framework/api/router.py +19 -0
- core_framework/api/schemas.py +9 -0
- core_framework/api/system/__init__.py +0 -0
- core_framework/api/system/router.py +108 -0
- core_framework/api/users/__init__.py +0 -0
- core_framework/api/users/authenticated/__init__.py +0 -0
- core_framework/api/users/authenticated/router.py +244 -0
- core_framework/api/users/authenticated/schemas.py +81 -0
- core_framework/api/users/public/__init__.py +0 -0
- core_framework/api/users/public/router.py +25 -0
- core_framework/api/users/public/schemas.py +7 -0
- core_framework/api/users/router.py +9 -0
- core_framework/api/users/shared/schemas.py +174 -0
- core_framework/application/__init__.py +0 -0
- core_framework/application/auth/__init__.py +0 -0
- core_framework/application/auth/access_service.py +26 -0
- core_framework/application/auth/auth_service.py +10 -0
- core_framework/application/auth/models.py +10 -0
- core_framework/application/bootstrap.py +19 -0
- core_framework/application/comments/admin_service.py +236 -0
- core_framework/application/comments/aggregation_service.py +28 -0
- core_framework/application/comments/authenticated_service.py +89 -0
- core_framework/application/comments/public_service.py +218 -0
- core_framework/application/events/README.md +26 -0
- core_framework/application/events/event_service.py +51 -0
- core_framework/application/events/event_token.py +46 -0
- core_framework/application/events/models.py +9 -0
- core_framework/application/moderation/__init__.py +0 -0
- core_framework/application/moderation/appeal_service.py +98 -0
- core_framework/application/moderation/moderator_service.py +46 -0
- core_framework/application/moderation/report_service.py +180 -0
- core_framework/application/moderation/scheduled_service.py +5 -0
- core_framework/application/moderation/user_service.py +180 -0
- core_framework/application/posts/admin_service.py +104 -0
- core_framework/application/posts/aggregation_service.py +28 -0
- core_framework/application/posts/authenticated_service.py +72 -0
- core_framework/application/posts/public_service.py +197 -0
- core_framework/application/shared/__init__.py +0 -0
- core_framework/application/shared/enums.py +16 -0
- core_framework/application/shared/exceptions.py +16 -0
- core_framework/application/shared/user_agent.py +24 -0
- core_framework/application/users/__init__.py +0 -0
- core_framework/application/users/admin_service.py +298 -0
- core_framework/application/users/authenticated_service.py +179 -0
- core_framework/application/users/public_service.py +7 -0
- core_framework/application/users/scheduled_service.py +5 -0
- core_framework/bundled_alembic.py +57 -0
- core_framework/core/__init__.py +37 -0
- core_framework/core/cache.py +234 -0
- core_framework/core/context.py +14 -0
- core_framework/core/database.py +111 -0
- core_framework/core/exception_handlers/__init__.py +3 -0
- core_framework/core/exception_handlers/comment.py +99 -0
- core_framework/core/exception_handlers/common.py +5 -0
- core_framework/core/exception_handlers/moderation.py +104 -0
- core_framework/core/exception_handlers/post.py +54 -0
- core_framework/core/exception_handlers/setup.py +80 -0
- core_framework/core/exception_handlers/user.py +72 -0
- core_framework/core/http_client.py +64 -0
- core_framework/core/logging.py +99 -0
- core_framework/core/middleware.py +64 -0
- core_framework/core/observability.py +36 -0
- core_framework/core/pagination.py +203 -0
- core_framework/core/redis.py +135 -0
- core_framework/core/runtime.py +66 -0
- core_framework/core/settings.py +189 -0
- core_framework/domains/__init__.py +0 -0
- core_framework/domains/comment/README.md +243 -0
- core_framework/domains/comment/__init__.py +25 -0
- core_framework/domains/comment/constants.py +3 -0
- core_framework/domains/comment/dependencies.py +29 -0
- core_framework/domains/comment/enums.py +11 -0
- core_framework/domains/comment/exceptions.py +31 -0
- core_framework/domains/comment/models.py +54 -0
- core_framework/domains/comment/repository.py +947 -0
- core_framework/domains/comment/service.py +259 -0
- core_framework/domains/moderation/README.md +138 -0
- core_framework/domains/moderation/__init__.py +47 -0
- core_framework/domains/moderation/dependencies.py +29 -0
- core_framework/domains/moderation/enums.py +62 -0
- core_framework/domains/moderation/exceptions.py +31 -0
- core_framework/domains/moderation/models.py +94 -0
- core_framework/domains/moderation/repository.py +828 -0
- core_framework/domains/moderation/service.py +334 -0
- core_framework/domains/post/README.md +182 -0
- core_framework/domains/post/__init__.py +22 -0
- core_framework/domains/post/constants.py +3 -0
- core_framework/domains/post/dependencies.py +29 -0
- core_framework/domains/post/enums.py +18 -0
- core_framework/domains/post/exceptions.py +21 -0
- core_framework/domains/post/models.py +53 -0
- core_framework/domains/post/repository.py +791 -0
- core_framework/domains/post/service.py +204 -0
- core_framework/domains/user/README.md +74 -0
- core_framework/domains/user/__init__.py +39 -0
- core_framework/domains/user/constants.py +8 -0
- core_framework/domains/user/dependencies.py +29 -0
- core_framework/domains/user/enums.py +19 -0
- core_framework/domains/user/exceptions.py +31 -0
- core_framework/domains/user/models.py +124 -0
- core_framework/domains/user/repository.py +612 -0
- core_framework/domains/user/service.py +257 -0
- core_framework/domains/user/utils.py +182 -0
- core_framework/main.py +104 -0
- core_framework/worker/__init__.py +0 -0
- core_framework/worker/main.py +56 -0
- core_framework/worker/schedules/__init__.py +35 -0
- core_framework/worker/schedules/schedule_aggregate_comment_stats.py +32 -0
- core_framework/worker/schedules/schedule_aggregate_post_view_counts.py +28 -0
- core_framework/worker/schedules/schedule_expired_account_deletions.py +24 -0
- core_framework/worker/schedules/schedule_expired_mute_lifts.py +24 -0
- core_framework/worker/tasks/__init__.py +11 -0
- core_framework/worker/tasks/process_account_deletion.py +13 -0
- core_framework/worker/tasks/process_aggregate_comment_stats.py +19 -0
- core_framework/worker/tasks/process_aggregate_post_stats.py +12 -0
- core_framework/worker/tasks/process_mute_lift.py +13 -0
- core_framework-0.3.0.dist-info/METADATA +22 -0
- core_framework-0.3.0.dist-info/RECORD +222 -0
- core_framework-0.3.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""add user_change_history table
|
|
2
|
+
|
|
3
|
+
Revision ID: 94b973923895
|
|
4
|
+
Revises: 62417002cf32
|
|
5
|
+
Create Date: 2026-02-08 08:28:43.812819
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
|
|
13
|
+
# revision identifiers, used by Alembic.
|
|
14
|
+
revision: str = "94b973923895"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "62417002cf32"
|
|
16
|
+
branch_labels: str | Sequence[str] | None = None
|
|
17
|
+
depends_on: str | Sequence[str] | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
"""Upgrade schema."""
|
|
22
|
+
op.execute("""
|
|
23
|
+
create table user_change_history (
|
|
24
|
+
id bigint generated always as identity primary key,
|
|
25
|
+
user_id varchar(128) not null references users(user_id) on delete cascade,
|
|
26
|
+
actor_id varchar(128),
|
|
27
|
+
entity_type varchar(50) not null,
|
|
28
|
+
field varchar(100) not null,
|
|
29
|
+
old_value text,
|
|
30
|
+
new_value text,
|
|
31
|
+
created_at timestamptz not null default now()
|
|
32
|
+
);
|
|
33
|
+
""")
|
|
34
|
+
op.execute("""
|
|
35
|
+
create index idx_user_change_history_user_created
|
|
36
|
+
on user_change_history (user_id, created_at desc);
|
|
37
|
+
""")
|
|
38
|
+
op.execute("""
|
|
39
|
+
create or replace function log_user_update_change()
|
|
40
|
+
returns trigger as $$
|
|
41
|
+
begin
|
|
42
|
+
if tg_op = 'UPDATE' then
|
|
43
|
+
if new.username is distinct from old.username then
|
|
44
|
+
insert into "user".user_change_history (user_id, actor_id, entity_type, field, old_value, new_value)
|
|
45
|
+
values (new.user_id, current_setting('app.actor_id', true), 'users', 'username', old.username, new.username);
|
|
46
|
+
end if;
|
|
47
|
+
if new.role is distinct from old.role then
|
|
48
|
+
insert into "user".user_change_history (user_id, actor_id, entity_type, field, old_value, new_value)
|
|
49
|
+
values (new.user_id, current_setting('app.actor_id', true), 'users', 'role', old.role::text, new.role::text);
|
|
50
|
+
end if;
|
|
51
|
+
if new.avatar_id is distinct from old.avatar_id then
|
|
52
|
+
insert into "user".user_change_history (user_id, actor_id, entity_type, field, old_value, new_value)
|
|
53
|
+
values (new.user_id, current_setting('app.actor_id', true), 'users', 'avatar_id', old.avatar_id, new.avatar_id);
|
|
54
|
+
end if;
|
|
55
|
+
end if;
|
|
56
|
+
return new;
|
|
57
|
+
end;
|
|
58
|
+
$$ language plpgsql;
|
|
59
|
+
""")
|
|
60
|
+
op.execute("""
|
|
61
|
+
create trigger user_change_history_users_trigger
|
|
62
|
+
after update on users
|
|
63
|
+
for each row
|
|
64
|
+
execute function log_user_update_change();
|
|
65
|
+
""")
|
|
66
|
+
op.execute("""
|
|
67
|
+
create or replace function log_user_deletion_change()
|
|
68
|
+
returns trigger as $$
|
|
69
|
+
begin
|
|
70
|
+
if tg_op = 'INSERT' then
|
|
71
|
+
insert into "user".user_change_history (user_id, actor_id, entity_type, field, old_value, new_value)
|
|
72
|
+
values (new.user_id, current_setting('app.actor_id', true), 'user_deletions', 'scheduled_for', null, new.scheduled_for::text);
|
|
73
|
+
return new;
|
|
74
|
+
elsif tg_op = 'DELETE' then
|
|
75
|
+
insert into "user".user_change_history (user_id, actor_id, entity_type, field, old_value, new_value)
|
|
76
|
+
values (old.user_id, current_setting('app.actor_id', true), 'user_deletions', 'scheduled_for', old.scheduled_for::text, null);
|
|
77
|
+
return old;
|
|
78
|
+
end if;
|
|
79
|
+
return null;
|
|
80
|
+
end;
|
|
81
|
+
$$ language plpgsql;
|
|
82
|
+
""")
|
|
83
|
+
op.execute("""
|
|
84
|
+
create trigger user_change_history_deletions_trigger
|
|
85
|
+
after insert or delete on user_deletions
|
|
86
|
+
for each row
|
|
87
|
+
execute function log_user_deletion_change();
|
|
88
|
+
""")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def downgrade() -> None:
|
|
92
|
+
op.execute("drop trigger if exists user_change_history_deletions_trigger on user_deletions;")
|
|
93
|
+
op.execute("drop trigger if exists user_change_history_users_trigger on users;")
|
|
94
|
+
op.execute("drop function if exists log_user_deletion_change();")
|
|
95
|
+
op.execute("drop function if exists log_user_update_change();")
|
|
96
|
+
op.execute("drop index if exists idx_user_change_history_user_created;")
|
|
97
|
+
op.execute("drop table if exists user_change_history;")
|
core_framework/alembic/user/alembic/versions/cbc0f4efe84f_add_avatar_id_column_to_users_table.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""add avatar_id column to users table
|
|
2
|
+
|
|
3
|
+
Revision ID: cbc0f4efe84f
|
|
4
|
+
Revises: 47f47ce2110e
|
|
5
|
+
Create Date: 2026-01-17 08:10:44.617640
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
|
|
13
|
+
# revision identifiers, used by Alembic.
|
|
14
|
+
revision: str = "cbc0f4efe84f"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "47f47ce2110e"
|
|
16
|
+
branch_labels: str | Sequence[str] | None = None
|
|
17
|
+
depends_on: str | Sequence[str] | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.execute("""
|
|
22
|
+
alter table users
|
|
23
|
+
add column avatar_id varchar(36) null;
|
|
24
|
+
""")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def downgrade() -> None:
|
|
28
|
+
op.execute("""
|
|
29
|
+
alter table users
|
|
30
|
+
drop column avatar_id;
|
|
31
|
+
""")
|
core_framework/alembic/user/alembic/versions/d8b98ac6b073_add_index_for_get_admin_user_ids_query.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""add index for retrieve_admin_user_ids query
|
|
2
|
+
|
|
3
|
+
Revision ID: d8b98ac6b073
|
|
4
|
+
Revises: 7a56631f9927
|
|
5
|
+
Create Date: 2026-01-06 06:43:07.084368
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
|
|
13
|
+
# revision identifiers, used by Alembic.
|
|
14
|
+
revision: str = "d8b98ac6b073"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "7a56631f9927"
|
|
16
|
+
branch_labels: str | Sequence[str] | None = None
|
|
17
|
+
depends_on: str | Sequence[str] | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.execute("""
|
|
22
|
+
create index idx_users_role_admin
|
|
23
|
+
on users (user_id)
|
|
24
|
+
where role = 'admin'
|
|
25
|
+
""")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def downgrade() -> None:
|
|
29
|
+
op.execute("drop index if exists idx_users_role_admin")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""create user_states table
|
|
2
|
+
|
|
3
|
+
Revision ID: ddb70cc09d16
|
|
4
|
+
Revises: 831611e589bc
|
|
5
|
+
Create Date: 2025-12-27 11:56:49.222617
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
|
|
13
|
+
# revision identifiers, used by Alembic.
|
|
14
|
+
revision: str = "ddb70cc09d16"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "831611e589bc"
|
|
16
|
+
branch_labels: str | Sequence[str] | None = None
|
|
17
|
+
depends_on: str | Sequence[str] | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.execute("""
|
|
22
|
+
create table user_states (
|
|
23
|
+
user_id varchar(128) primary key references users(user_id) on delete cascade,
|
|
24
|
+
state user_state not null default 'active',
|
|
25
|
+
reason text,
|
|
26
|
+
expires_at timestamptz,
|
|
27
|
+
created_at timestamptz not null default now(),
|
|
28
|
+
updated_at timestamptz not null default now()
|
|
29
|
+
);
|
|
30
|
+
""")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def downgrade() -> None:
|
|
34
|
+
op.execute("drop table if exists user_states;")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""add users table
|
|
2
|
+
|
|
3
|
+
Revision ID: f9ba10815ecd
|
|
4
|
+
Revises: 8a94362cad6d
|
|
5
|
+
Create Date: 2025-12-26 12:26:41.852985
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
|
|
11
|
+
from alembic import op
|
|
12
|
+
|
|
13
|
+
# revision identifiers, used by Alembic.
|
|
14
|
+
revision: str = "f9ba10815ecd"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "8a94362cad6d"
|
|
16
|
+
branch_labels: str | Sequence[str] | None = None
|
|
17
|
+
depends_on: str | Sequence[str] | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.execute("""
|
|
22
|
+
create table users (
|
|
23
|
+
user_id varchar(128) primary key,
|
|
24
|
+
username varchar(50) unique not null,
|
|
25
|
+
role user_role not null default 'member',
|
|
26
|
+
created_at timestamptz not null default now(),
|
|
27
|
+
updated_at timestamptz not null default now()
|
|
28
|
+
);
|
|
29
|
+
""")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def downgrade() -> None:
|
|
33
|
+
op.execute("drop table if exists users;")
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# A generic, single database configuration.
|
|
2
|
+
|
|
3
|
+
[alembic]
|
|
4
|
+
# path to migration scripts.
|
|
5
|
+
# this is typically a path given in POSIX (e.g. forward slashes)
|
|
6
|
+
# format, relative to the token %(here)s which refers to the location of this
|
|
7
|
+
# ini file
|
|
8
|
+
script_location = %(here)s/alembic
|
|
9
|
+
|
|
10
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
11
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
|
12
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
13
|
+
# for all available tokens
|
|
14
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
15
|
+
|
|
16
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
17
|
+
# defaults to the current working directory. for multiple paths, the path separator
|
|
18
|
+
# is defined by "path_separator" below.
|
|
19
|
+
prepend_sys_path = .
|
|
20
|
+
|
|
21
|
+
# timezone to use when rendering the date within the migration file
|
|
22
|
+
# as well as the filename.
|
|
23
|
+
# If specified, requires the tzdata library which can be installed by adding
|
|
24
|
+
# `alembic[tz]` to the pip requirements.
|
|
25
|
+
# string value is passed to ZoneInfo()
|
|
26
|
+
# leave blank for localtime
|
|
27
|
+
# timezone =
|
|
28
|
+
|
|
29
|
+
# max length of characters to apply to the "slug" field
|
|
30
|
+
# truncate_slug_length = 40
|
|
31
|
+
|
|
32
|
+
# set to 'true' to run the environment during
|
|
33
|
+
# the 'revision' command, regardless of autogenerate
|
|
34
|
+
# revision_environment = false
|
|
35
|
+
|
|
36
|
+
# set to 'true' to allow .pyc and .pyo files without
|
|
37
|
+
# a source .py file to be detected as revisions in the
|
|
38
|
+
# versions/ directory
|
|
39
|
+
# sourceless = false
|
|
40
|
+
|
|
41
|
+
# version location specification; This defaults
|
|
42
|
+
# to <script_location>/versions. When using multiple version
|
|
43
|
+
# directories, initial revisions must be specified with --version-path.
|
|
44
|
+
# The path separator used here should be the separator specified by "path_separator"
|
|
45
|
+
# below.
|
|
46
|
+
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
|
|
47
|
+
|
|
48
|
+
# path_separator; This indicates what character is used to split lists of file
|
|
49
|
+
# paths, including version_locations and prepend_sys_path within configparser
|
|
50
|
+
# files such as alembic.ini.
|
|
51
|
+
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
|
|
52
|
+
# to provide os-dependent path splitting.
|
|
53
|
+
#
|
|
54
|
+
# Note that in order to support legacy alembic.ini files, this default does NOT
|
|
55
|
+
# take place if path_separator is not present in alembic.ini. If this
|
|
56
|
+
# option is omitted entirely, fallback logic is as follows:
|
|
57
|
+
#
|
|
58
|
+
# 1. Parsing of the version_locations option falls back to using the legacy
|
|
59
|
+
# "version_path_separator" key, which if absent then falls back to the legacy
|
|
60
|
+
# behavior of splitting on spaces and/or commas.
|
|
61
|
+
# 2. Parsing of the prepend_sys_path option falls back to the legacy
|
|
62
|
+
# behavior of splitting on spaces, commas, or colons.
|
|
63
|
+
#
|
|
64
|
+
# Valid values for path_separator are:
|
|
65
|
+
#
|
|
66
|
+
# path_separator = :
|
|
67
|
+
# path_separator = ;
|
|
68
|
+
# path_separator = space
|
|
69
|
+
# path_separator = newline
|
|
70
|
+
#
|
|
71
|
+
# Use os.pathsep. Default configuration used for new projects.
|
|
72
|
+
path_separator = os
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# set to 'true' to search source files recursively
|
|
76
|
+
# in each "version_locations" directory
|
|
77
|
+
# new in Alembic version 1.10
|
|
78
|
+
# recursive_version_locations = false
|
|
79
|
+
|
|
80
|
+
# the output encoding used when revision files
|
|
81
|
+
# are written from script.py.mako
|
|
82
|
+
# output_encoding = utf-8
|
|
83
|
+
|
|
84
|
+
# database URL. This is consumed by the user-maintained env.py script only.
|
|
85
|
+
# other means of configuring database URLs may be customized within the env.py
|
|
86
|
+
# file.
|
|
87
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
[post_write_hooks]
|
|
91
|
+
# post_write_hooks defines scripts or Python functions that are run
|
|
92
|
+
# on newly generated revision scripts. See the documentation for further
|
|
93
|
+
# detail and examples
|
|
94
|
+
|
|
95
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
96
|
+
# hooks = black
|
|
97
|
+
# black.type = console_scripts
|
|
98
|
+
# black.entrypoint = black
|
|
99
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
100
|
+
|
|
101
|
+
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
|
|
102
|
+
# hooks = ruff
|
|
103
|
+
# ruff.type = module
|
|
104
|
+
# ruff.module = ruff
|
|
105
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
106
|
+
|
|
107
|
+
# Alternatively, use the exec runner to execute a binary found on your PATH
|
|
108
|
+
# hooks = ruff
|
|
109
|
+
# ruff.type = exec
|
|
110
|
+
# ruff.executable = ruff
|
|
111
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
112
|
+
|
|
113
|
+
# Logging configuration. This is also consumed by the user-maintained
|
|
114
|
+
# env.py script only.
|
|
115
|
+
[loggers]
|
|
116
|
+
keys = root,sqlalchemy,alembic
|
|
117
|
+
|
|
118
|
+
[handlers]
|
|
119
|
+
keys = console
|
|
120
|
+
|
|
121
|
+
[formatters]
|
|
122
|
+
keys = generic
|
|
123
|
+
|
|
124
|
+
[logger_root]
|
|
125
|
+
level = WARNING
|
|
126
|
+
handlers = console
|
|
127
|
+
qualname =
|
|
128
|
+
|
|
129
|
+
[logger_sqlalchemy]
|
|
130
|
+
level = WARNING
|
|
131
|
+
handlers =
|
|
132
|
+
qualname = sqlalchemy.engine
|
|
133
|
+
|
|
134
|
+
[logger_alembic]
|
|
135
|
+
level = INFO
|
|
136
|
+
handlers =
|
|
137
|
+
qualname = alembic
|
|
138
|
+
|
|
139
|
+
[handler_console]
|
|
140
|
+
class = StreamHandler
|
|
141
|
+
args = (sys.stderr,)
|
|
142
|
+
level = NOTSET
|
|
143
|
+
formatter = generic
|
|
144
|
+
|
|
145
|
+
[formatter_generic]
|
|
146
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
147
|
+
datefmt = %H:%M:%S
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Annotated, Any
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, BackgroundTasks, Depends, Request, status
|
|
4
|
+
from ulid import ULID
|
|
5
|
+
|
|
6
|
+
from core_framework.api.admin.comments.schemas import AdminCommentResponse
|
|
7
|
+
from core_framework.application.comments.admin_service import (
|
|
8
|
+
remove_comment,
|
|
9
|
+
restore_comment,
|
|
10
|
+
retrieve_admin_comment_by_id,
|
|
11
|
+
retrieve_admin_comments,
|
|
12
|
+
set_comment_inactive,
|
|
13
|
+
)
|
|
14
|
+
from core_framework.application.comments.authenticated_service import mark_comment_stats_dirty
|
|
15
|
+
from core_framework.core.pagination import (
|
|
16
|
+
PaginationCursorType,
|
|
17
|
+
PaginationResponse,
|
|
18
|
+
TokenCursorQueryParams,
|
|
19
|
+
paginate_cursor,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
router = APIRouter(
|
|
23
|
+
prefix="/comments",
|
|
24
|
+
tags=["comments - admin"],
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@router.get("", response_model=PaginationResponse[AdminCommentResponse])
|
|
29
|
+
async def get_comments(
|
|
30
|
+
request: Request,
|
|
31
|
+
pagination_params: Annotated[TokenCursorQueryParams, Depends()],
|
|
32
|
+
) -> Any:
|
|
33
|
+
comments = await retrieve_admin_comments(
|
|
34
|
+
cursor=pagination_params.cursor,
|
|
35
|
+
limit=pagination_params.limit,
|
|
36
|
+
)
|
|
37
|
+
return paginate_cursor(
|
|
38
|
+
request=request,
|
|
39
|
+
items=comments,
|
|
40
|
+
limit=pagination_params.limit,
|
|
41
|
+
cursor_field=PaginationCursorType.CREATED_AT,
|
|
42
|
+
retrieved=pagination_params.retrieved,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@router.get("/{comment_id}", response_model=AdminCommentResponse)
|
|
47
|
+
async def get_comment(comment_id: ULID) -> Any:
|
|
48
|
+
return await retrieve_admin_comment_by_id(comment_id=str(comment_id))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@router.put("/{comment_id}/inactive", status_code=status.HTTP_204_NO_CONTENT)
|
|
52
|
+
async def put_comment_inactive(comment_id: ULID, background_tasks: BackgroundTasks) -> None:
|
|
53
|
+
parent_comment_id = await set_comment_inactive(comment_id=str(comment_id))
|
|
54
|
+
if parent_comment_id is not None:
|
|
55
|
+
background_tasks.add_task(mark_comment_stats_dirty, comment_id=parent_comment_id)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@router.delete("/{comment_id}/inactive", status_code=status.HTTP_204_NO_CONTENT)
|
|
59
|
+
async def delete_comment_inactive(comment_id: ULID, background_tasks: BackgroundTasks) -> None:
|
|
60
|
+
parent_comment_id = await restore_comment(comment_id=str(comment_id))
|
|
61
|
+
if parent_comment_id is not None:
|
|
62
|
+
background_tasks.add_task(mark_comment_stats_dirty, comment_id=parent_comment_id)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@router.delete("/{comment_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
66
|
+
async def delete_comment(comment_id: ULID, background_tasks: BackgroundTasks) -> None:
|
|
67
|
+
parent_comment_id = await remove_comment(comment_id=str(comment_id))
|
|
68
|
+
if parent_comment_id is not None:
|
|
69
|
+
background_tasks.add_task(mark_comment_stats_dirty, comment_id=parent_comment_id)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Annotated, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
from ulid import ULID
|
|
6
|
+
|
|
7
|
+
from core_framework.api.comments.schemas import CommentContent
|
|
8
|
+
from core_framework.api.users.shared.schemas import UserReference
|
|
9
|
+
from core_framework.domains.comment import CommentStatus, CommentSubjectType
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AdminCommentStatsResponse(BaseModel):
|
|
13
|
+
like_count: Annotated[int, Field(ge=0)] = 0
|
|
14
|
+
reply_count: Annotated[int, Field(ge=0)] = 0
|
|
15
|
+
report_count: Annotated[int, Field(ge=0)] = 0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PostSubjectPreview(BaseModel):
|
|
19
|
+
subject_type: Literal[CommentSubjectType.POST]
|
|
20
|
+
post_id: ULID
|
|
21
|
+
author: UserReference
|
|
22
|
+
content_preview: Annotated[str, Field(min_length=1)]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class UserWallSubjectPreview(BaseModel):
|
|
26
|
+
subject_type: Literal[CommentSubjectType.USER_WALL]
|
|
27
|
+
user: UserReference
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
type AdminCommentSubjectPreview = Annotated[
|
|
31
|
+
PostSubjectPreview | UserWallSubjectPreview,
|
|
32
|
+
Field(discriminator="subject_type"),
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ParentCommentPreview(BaseModel):
|
|
37
|
+
comment_id: ULID
|
|
38
|
+
author: UserReference
|
|
39
|
+
content_preview: Annotated[str, Field(min_length=1)]
|
|
40
|
+
status: CommentStatus
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AdminCommentResponse(BaseModel):
|
|
44
|
+
id: ULID
|
|
45
|
+
author: UserReference
|
|
46
|
+
content: CommentContent
|
|
47
|
+
subject: AdminCommentSubjectPreview
|
|
48
|
+
parent_comment: ParentCommentPreview | None
|
|
49
|
+
status: CommentStatus
|
|
50
|
+
edited_count: Annotated[int, Field(ge=0)] = 0
|
|
51
|
+
stats: AdminCommentStatsResponse
|
|
52
|
+
edited_at: datetime | None
|
|
53
|
+
created_at: datetime
|
|
File without changes
|