Skip to content

Reorganizar abas do formulário de Journal: separar abas administrativas#1311

Merged
robertatakenaka merged 4 commits intomainfrom
copilot/reorganize-journal-form-tabs
Feb 7, 2026
Merged

Reorganizar abas do formulário de Journal: separar abas administrativas#1311
robertatakenaka merged 4 commits intomainfrom
copilot/reorganize-journal-form-tabs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 7, 2026

O que esse PR faz?

Reestrutura as abas do formulário de Journal, movendo "Legacy Compatibility" e "Notas" para um menu exclusivo de administradores (superusers), mantendo apenas abas essenciais no modelo principal.

Mudanças principais:

  • journal/models.py: Removidas abas Legacy Compatibility e Notes do modelo base Journal
  • journal/proxys.py: Criado JournalProxyAdminOnly com apenas as duas abas administrativas
  • journal/wagtail_hooks.py: Implementado JournalAdminOnlySnippetViewSet com restrição is_superuser no get_queryset()
  • journal/tests.py: Adicionados testes unitários para validar estrutura de abas

Ordem final das abas:

  • Usuários regulares (Journal, JournalProxyEditor): Título | Instituições | Website | Foco e Escopo | Ciência Aberta | Política Editorial | Instruções aos Autores | Corpo Editorial
  • Administradores (JournalProxyAdminOnly): Legacy Compatibility | Notas

Onde a revisão poderia começar?

journal/models.py linha 710 (remoção das abas do edit_handler), seguido por journal/proxys.py linha 350 (novo proxy model) e journal/wagtail_hooks.py linha 331 (viewset com restrição de acesso).

Como este poderia ser testado manualmente?

  1. Executar testes unitários: python manage.py test journal.tests.JournalTabStructureTestCase
  2. No admin do Wagtail:
    • Como usuário regular: verificar que "Journals" exibe apenas 5-8 abas (sem Legacy Compatibility/Notes)
    • Como superuser: verificar menu "Journals (Admin Only)" com acesso às 2 abas administrativas
    • Como não-superuser: verificar que "Journals (Admin Only)" retorna lista vazia

Algum cenário de contexto que queira dar?

A separação de abas administrativas otimiza o carregamento do formulário para editores regulares, reduzindo de 7 para 5 abas no modelo principal. O acesso às configurações legadas permanece disponível para administradores via proxy model dedicado com controle de acesso no nível de queryset.

Screenshots

N/A - Mudanças estruturais no admin backend

Quais são tickets relevantes?

#1244 (parent issue)

Referências

  • Wagtail TabbedInterface documentation
  • Django proxy models para separação de concerns
Original prompt

This section details on the original issue you should resolve

<issue_title>Reorganizar abas do formulário de Journal</issue_title>
<issue_description>### Descrição da tarefa
Reestruturar as abas do formulário de Journal conforme especificado:

  • Alterar os nomes das abas: Títulos → Título; Instituição → Instituições; Foco e sobre → Foco e Escopo
  • Criar um novo menu, acessível somente aos ADMIN, para as abas Compatibilidade e Notas
  • Reordenar as abas: Título | Instituições | Website | Foco e Escopo | Ciência Aberta | Política Editorial | Instruções aos Autores | Corpo Editorial

Subtarefas

  • Refatorar o componente das abas para suportar a nova ordem e nomes
  • Implementar o novo menu exclusivo para ADMIN
  • Testar o novo fluxo de navegação

Considerações e notas

  • Priorizar otimização para melhor carregamento do formulário.
  • Garantir que os campos editáveis permaneçam consistentes com os requisitos do parent issue.

Parent: #1244</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 7, 2026 21:07
…and create separate admin viewset

Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
…on naming

Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
@robertatakenaka robertatakenaka marked this pull request as ready for review February 7, 2026 21:10
Copilot AI review requested due to automatic review settings February 7, 2026 21:10
Copilot AI changed the title [WIP] Refactor Journal form tabs and add admin menu Reorganizar abas do formulário de Journal: separar abas administrativas Feb 7, 2026
Copilot AI requested a review from robertatakenaka February 7, 2026 21:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Wagtail admin editing experience for Journals by reorganizing the main tab layout, splitting “Legacy Compatibility” and “Notes” into a new admin-only section, and adding regression tests for tab structure.

Changes:

  • Removed “Legacy Compatibility” and “Notes” tabs from the main Journal edit handler.
  • Added a new proxy model (JournalProxyAdminOnly) and a corresponding snippet viewset entry to surface admin-only tabs.
  • Added tests to validate tab presence/order across the main model and proxy models.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
journal/models.py Removes admin-only tabs from the primary Journal tabbed interface.
journal/proxys.py Introduces an admin-only proxy model containing Legacy Compatibility + Notes panels.
journal/wagtail_hooks.py Registers a new snippet viewset and permissions hook for the admin-only proxy.
journal/tests.py Adds tests asserting the expected tab structure and ordering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +346 to +353
def get_queryset(self, request):
# Only allow superusers to access this viewset
user = request.user
if not user.is_authenticated or not user.is_superuser:
return models.Journal.objects.none()

# For superusers, return all journals with optimizations
return super().get_queryset(request)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only filters the queryset for non-superusers, but does not actually enforce the "superuser-only" access requirement: non-superusers can still hit the endpoints and get a 200 with an empty list, and the create view may still be reachable if permissions are granted (it doesn't rely on get_queryset). Enforce superuser-only access at the view/permission level (e.g., raising PermissionDenied for any non-superuser request across list/add/edit/inspect and hiding the menu item accordingly), instead of relying on returning an empty queryset.

Copilot uses AI. Check for mistakes.
Comment on lines +357 to +376
panels_legacy_compatibility_fields = [
FieldPanel("alphabet"),
FieldPanel("classification"),
FieldPanel("national_code"),
FieldPanel("type_of_literature"),
FieldPanel("treatment_level"),
FieldPanel("level_of_publication"),
FieldPanel("center_code"),
FieldPanel("identification_number"),
FieldPanel("ftp"),
FieldPanel("user_subscription"),
FieldPanel("subtitle"),
FieldPanel("section"),
FieldPanel("has_supplement"),
FieldPanel("is_supplement"),
FieldPanel("acronym_letters"),
]

panels_notes = [InlinePanel("annotation", label=_("Notes"))]

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panels_legacy_compatibility_fields / panels_notes duplicate panel definitions that already exist on journal.models.Journal. Duplicating these lists increases the chance of the admin-only form drifting from the canonical field set over time; consider reusing the base model’s panel lists (or extracting shared constants) so there is a single source of truth.

Suggested change
panels_legacy_compatibility_fields = [
FieldPanel("alphabet"),
FieldPanel("classification"),
FieldPanel("national_code"),
FieldPanel("type_of_literature"),
FieldPanel("treatment_level"),
FieldPanel("level_of_publication"),
FieldPanel("center_code"),
FieldPanel("identification_number"),
FieldPanel("ftp"),
FieldPanel("user_subscription"),
FieldPanel("subtitle"),
FieldPanel("section"),
FieldPanel("has_supplement"),
FieldPanel("is_supplement"),
FieldPanel("acronym_letters"),
]
panels_notes = [InlinePanel("annotation", label=_("Notes"))]
panels_legacy_compatibility_fields = Journal.panels_legacy_compatibility_fields
panels_notes = Journal.panels_notes

Copilot uses AI. Check for mistakes.
Comment on lines +1198 to +1211
# Get the tabs from edit_handler
tabs = Journal.edit_handler.children
tab_headings = [tab.heading for tab in tabs]

# Verify expected tabs are present
self.assertIn("Title", tab_headings)
self.assertIn("Institutions", tab_headings)
self.assertIn("Website", tab_headings)
self.assertIn("Focus and Scope", tab_headings)
self.assertIn("Open Science", tab_headings)

# Verify admin-only tabs are NOT present
self.assertNotIn("Legacy Compatibility", tab_headings)
self.assertNotIn("Notes", tab_headings)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab.heading values come from gettext_lazy and will be lazy translation objects; with LANGUAGE_CODE = pt-br these assertions against hard-coded English strings are likely to fail (and may also fail due to lazy-object equality semantics). Convert headings to str(...) and build expected values using the same translation mechanism (e.g., str(_("Title")), or run the test under translation.override(...)) so the test is locale- and lazy-safe.

Copilot uses AI. Check for mistakes.
Comment on lines +1217 to +1233
# Get the tabs from edit_handler
tabs = JournalProxyEditor.edit_handler.children
tab_headings = [tab.heading for tab in tabs]

# Verify tab order
expected_order = [
"Title",
"Institutions",
"Website",
"Focus and Scope",
"Open Science",
"Editorial Policy",
"Instructions for Authors",
"Editorial Board",
]

self.assertEqual(tab_headings, expected_order)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: tab_headings will likely be a list of lazy translation objects, so comparing directly to a list of English strings can fail under non-English locales. Consider normalizing with str(tab.heading) (and generating expected_order via str(_(...)) or within a language override) before asserting exact order.

Copilot uses AI. Check for mistakes.
@robertatakenaka robertatakenaka merged commit 17acf89 into main Feb 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reorganizar abas do formulário de Journal

3 participants