UNLOCK_ALL_PHONES: tester accounts see every island unlocked (map and server rule)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -263,6 +263,18 @@ def answers_missing_response(answered: int, required: int) -> Response:
|
||||
)
|
||||
|
||||
|
||||
def user_has_all_nodes_unlocked(user_id) -> bool:
|
||||
"""
|
||||
کاربرِ آزمونگر (`settings.UNLOCK_ALL_PHONES`): قفلِ ترتیبِ جزیرهها برایش برداشته میشود.
|
||||
وقتی فهرست خالی است (حالتِ عادی) هیچ کوئریای زده نمیشود.
|
||||
"""
|
||||
from django.conf import settings
|
||||
if user_id is None or not settings.UNLOCK_ALL_PHONES:
|
||||
return False
|
||||
from accounts.models import User
|
||||
return User.objects.filter(pk=user_id, phone__in=settings.UNLOCK_ALL_PHONES).exists()
|
||||
|
||||
|
||||
def node_is_unlocked(user_id, node) -> bool:
|
||||
"""
|
||||
آیا این جزیره برای این کاربر روی نقشه قفل نیست؟ همان قاعدهی `HomeView` است
|
||||
@@ -273,6 +285,8 @@ def node_is_unlocked(user_id, node) -> bool:
|
||||
اگر جزیره در درختِ کششده نبود (مثلاً تازه ساخته شده و کش کهنه است) «قفل» حساب میشود
|
||||
و در لاگ WARNING میماند؛ همانطور که نقشه هم آن را نشان نمیدهد.
|
||||
"""
|
||||
if user_has_all_nodes_unlocked(user_id):
|
||||
return True
|
||||
tree = _grade_tree(node.unit.grade_id) or []
|
||||
unit = next((u for u in tree if u['id'] == str(node.unit_id)), None)
|
||||
if unit is not None:
|
||||
@@ -455,6 +469,7 @@ class HomeView(APIView):
|
||||
|
||||
from subscription.services import has_active_subscription
|
||||
subscribed = user_id is not None and has_active_subscription(user_id)
|
||||
unlock_all = user_has_all_nodes_unlocked(user_id)
|
||||
units_payload = []
|
||||
for index, unit in enumerate(tree):
|
||||
node_payload = []
|
||||
@@ -471,6 +486,8 @@ class HomeView(APIView):
|
||||
)
|
||||
if node_status != 'completed':
|
||||
unlock_next = False
|
||||
if unlock_all and node_status == 'locked':
|
||||
node_status = 'unlocked'
|
||||
node_payload.append({
|
||||
'id': node['id'],
|
||||
'title': node['title'],
|
||||
|
||||
Reference in New Issue
Block a user