Skip to content

Commit daa4ec2

Browse files
authored
Serve system projects to translate endpoints (#4408)
The History, Comments, Locales and Sibling strings endpoints looked the entity up in `Project.objects.visible()`, which is `available().filter(system_project=False)`. The tutorial is a system project, so all four returned 404 for every user, and the panels showed nothing rather than reporting a failure. What these endpoints need to know is whether the user can reach the project, not whether it is listed on the dashboards. `available()` still excludes disabled and resource-less projects, and `visible_for` still hides private ones from non-superusers.
1 parent 09a2f91 commit daa4ec2

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎pontoon/base/tests/views/test_ajax.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,32 @@ def test_get_team_comments_authentication(rf, user_a, admin):
302302
response = get_team_comments(request_b)
303303

304304
assert response.status_code == 200
305+
306+
307+
@pytest.mark.django_db
308+
@pytest.mark.parametrize(
309+
"view",
310+
[
311+
get_translations_from_other_locales,
312+
get_sibling_entities,
313+
get_translation_history,
314+
get_team_comments,
315+
],
316+
)
317+
def test_translate_view_endpoints_reach_system_projects(rf, user_a, view):
318+
"""The tutorial is a system project: kept off the dashboards, but translated
319+
in the same UI as any other project, so these endpoints have to serve it."""
320+
project = ProjectFactory(
321+
name="System Project", slug="system-project", system_project=True
322+
)
323+
resource = ResourceFactory(project=project)
324+
entity = EntityFactory(string="Entity", resource=resource)
325+
locale = LocaleFactory(code="gs", name="Geonosian")
326+
327+
request = rf.get(
328+
f"/?entity={entity.id}&locale={locale.code}",
329+
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
330+
)
331+
request.user = user_a
332+
333+
assert view(request).status_code == 200

‎pontoon/base/views.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def get_translations_from_other_locales(request):
442442
status=400,
443443
)
444444

445-
visible_projects = Project.objects.visible().visible_for(request.user)
445+
visible_projects = Project.objects.available().visible_for(request.user)
446446
entities = Entity.objects.filter(resource__project__in=visible_projects)
447447

448448
entity = get_object_or_404(entities, pk=entity)
@@ -487,7 +487,7 @@ def get_sibling_entities(request):
487487
status=400,
488488
)
489489

490-
visible_projects = Project.objects.visible().visible_for(request.user)
490+
visible_projects = Project.objects.available().visible_for(request.user)
491491
entities = Entity.objects.filter(resource__project__in=visible_projects)
492492

493493
entity = get_object_or_404(entities, pk=entity)
@@ -533,7 +533,7 @@ def get_translation_history(request):
533533
status=400,
534534
)
535535

536-
visible_projects = Project.objects.visible().visible_for(request.user)
536+
visible_projects = Project.objects.available().visible_for(request.user)
537537
entities = Entity.objects.filter(resource__project__in=visible_projects)
538538

539539
entity = get_object_or_404(entities, pk=entity)
@@ -615,7 +615,7 @@ def get_team_comments(request):
615615
status=400,
616616
)
617617

618-
visible_projects = Project.objects.visible().visible_for(request.user)
618+
visible_projects = Project.objects.available().visible_for(request.user)
619619
entities = Entity.objects.filter(resource__project__in=visible_projects)
620620

621621
entity = get_object_or_404(entities, pk=entity)

0 commit comments

Comments
 (0)