-
Notifications
You must be signed in to change notification settings - Fork 0
Add region restriction handling for various services and views #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
46c6266
Add region restriction handling for various services and views
tenkus47 49a65ff
Add user total count retrieval by parent ID
tenkus47 9736696
Remove deprecated Buddhist traditions taxonomy and refactor related code
tenkus47 22c2109
Refactor recitations service to streamline data retrieval
tenkus47 d08b3aa
Enhance daily log services with timezone support
tenkus47 bbc44ef
Refactor daily log service to simplify cache checks
tenkus47 4ec57c1
Add delete author group functionality and corresponding view
tenkus47 e2ce778
Refactor region restriction services and enhance error handling
tenkus47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
migrations/versions/g2h3i4j5k6l7_add_china_restricted_items_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| """add china_restricted_items table for China timezone content exclusions | ||
|
|
||
| Revision ID: g2h3i4j5k6l7 | ||
| Revises: f1a2b3c4d5e7 | ||
| Create Date: 2026-07-05 12:00:00.000000 | ||
|
|
||
| Items listed in this table are hidden from clients whose X-Timezone header | ||
| matches a Chinese IANA timezone (see pecha_api/assets/chinese_timezone.json). | ||
| """ | ||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| from migrations.idempotency import index_exists, table_exists | ||
|
|
||
| revision: str = "g2h3i4j5k6l7" | ||
| down_revision: Union[str, None] = "f1a2b3c4d5e7" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
| china_restricted_item_type = postgresql.ENUM( | ||
| "MANTRA", | ||
| "ACCUMULATOR", | ||
| "GROUP_ACCUMULATOR", | ||
| "PLAN", | ||
| "SERIES", | ||
| "GROUP", | ||
| "RECITATION", | ||
| "RECITATION_COLLECTION", | ||
| name="china_restricted_item_type", | ||
| create_type=False, | ||
| ) | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.execute( | ||
| """ | ||
| DO $$ BEGIN | ||
| CREATE TYPE china_restricted_item_type AS ENUM ( | ||
| 'MANTRA', | ||
| 'ACCUMULATOR', | ||
| 'GROUP_ACCUMULATOR', | ||
| 'PLAN', | ||
| 'SERIES', | ||
| 'GROUP', | ||
| 'RECITATION', | ||
| 'RECITATION_COLLECTION' | ||
| ); | ||
| EXCEPTION | ||
| WHEN duplicate_object THEN NULL; | ||
| END $$; | ||
| """ | ||
| ) | ||
|
|
||
| if not table_exists("china_restricted_items"): | ||
| op.create_table( | ||
| "china_restricted_items", | ||
| sa.Column( | ||
| "id", | ||
| sa.UUID(), | ||
| nullable=False, | ||
| server_default=sa.text("gen_random_uuid()"), | ||
| ), | ||
| sa.Column("item_type", china_restricted_item_type, nullable=False), | ||
| sa.Column("item_id", sa.UUID(), nullable=False), | ||
| sa.Column( | ||
| "created_at", | ||
| sa.DateTime(timezone=True), | ||
| nullable=False, | ||
| server_default=sa.text("CURRENT_TIMESTAMP"), | ||
| ), | ||
| sa.Column( | ||
| "updated_at", | ||
| sa.DateTime(timezone=True), | ||
| nullable=True, | ||
| server_default=sa.text("CURRENT_TIMESTAMP"), | ||
| ), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| sa.UniqueConstraint( | ||
| "item_type", | ||
| "item_id", | ||
| name="uq_china_restricted_items_type_id", | ||
| ), | ||
| ) | ||
|
|
||
| if not index_exists("china_restricted_items", "idx_china_restricted_items_item_type"): | ||
| op.create_index( | ||
| "idx_china_restricted_items_item_type", | ||
| "china_restricted_items", | ||
| ["item_type"], | ||
| unique=False, | ||
| ) | ||
| if not index_exists("china_restricted_items", "idx_china_restricted_items_item_id"): | ||
| op.create_index( | ||
| "idx_china_restricted_items_item_id", | ||
| "china_restricted_items", | ||
| ["item_id"], | ||
| unique=False, | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| if index_exists("china_restricted_items", "idx_china_restricted_items_item_id"): | ||
| op.drop_index("idx_china_restricted_items_item_id", table_name="china_restricted_items") | ||
| if index_exists("china_restricted_items", "idx_china_restricted_items_item_type"): | ||
| op.drop_index("idx_china_restricted_items_item_type", table_name="china_restricted_items") | ||
| if table_exists("china_restricted_items"): | ||
| op.drop_table("china_restricted_items") | ||
| op.execute("DROP TYPE IF EXISTS china_restricted_item_type") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timezone_namepassed to a function that doesn't accept itis_user_logged_today_in_cacheaccepts onlyuser_idandlog_date, butrecord_daily_log_if_neededindaily_log_service.py(lines 59-63) calls it withtimezone_name=timezone_name. Python raisesTypeError: is_user_logged_today_in_cache() got an unexpected keyword argument 'timezone_name'at call time regardless of the value — so every request to/daily-log/streakand/daily-log/statsintroduced in this PR will 500. The function signature needs atimezone_name: Optional[str] = Noneparameter (even if not used for the cache key) to match how all callers now invoke it.