refactor/templates #27

Merged
wikiker merged 18 commits from refactor/templates into dev 2026-11-19 16:57:00 +01:00
Owner

Templates now use shared components.

Templates now use shared components.
Security fixes:
- Added @login_required to record_lookup to prevent enumeration attacks
- Added admin_required decorator for staff-only views
- Added user_permissions_overview view (staff only)
- Added user_permissions.html template
- Added 'Uživatelé' link in navbar for staff

Documentation:
- Added permissions section to README.md
- Documented roles, how to assign permissions, security measures

Tests:
- Added test_auth_security.py with 11 tests
- Tests cover: record_lookup security, overview access, user permissions
- All 46 tests pass (1 skipped due to FIO_API_TOKEN config)

Addresses issues from AUTH.md:
- Issue 2: record_lookup now requires authentication
- Issue 1: Django admin login forms still need attention
- Add seminar access check to record_document view to protect media files
  - Documents now only accessible to users with permission to the seminar
  - Accountants can access all documents
  - Regular users can only access documents from seminars they organize

- Implement proper permission filtering in record_lookup view
  - Accountants see all records
  - Logged-in users see only records from accessible seminars
  - Added input validation for invalid codes and dates

- Fix user_permissions_overview view
  - Properly prefetch permissions to avoid N+1 queries
  - Show "superuser" marker for superusers
  - Include is_active field in user listing

- Fix test_auth_security.py
  - Remove reference to non-existent AUTH.md
  - Fix useless assertion in test_record_lookup_enumeration_blocked

Resolves all issues from AUTH.md review comments.
Implement new permission model:
- Accountant: relative to seminars, can edit records in assigned seminars
- Staff: absolute permissions, can manage users, import bank statements, repay
- Superuser: system-level only, not a normal privilege

Changes:
- Add accountants ManyToManyField to Seminar model
- Update is_accessible_by() to check organizers and accountants
- Add can_edit_records() method to Seminar model
- Rename accountant_required to staff_required for absolute permissions
- Update accountant_required to check seminar-specific accountant access
- Update seminar_access_required to support require_edit parameter
- Update all views to use appropriate decorators
- Update tests to use new permission model
- Add migration for new Seminar.accountants field

Views updated:
- Staff-only: overview, record_add, seminar_add, virtual_add, add_overview,
  import_statement, repay, mark_repaid, bulk_edit_records
- Seminar accountant: record_detail, record_delete, record_document
- Seminar access: seminar_overview, event_overview, evend_add

Resolves all permission model requirements.
- Fix event management permissions: only accountants can add events
- Add comprehensive authorization matrix tests (16 new tests)
- Improve permission error messages with clear explanations
- Add permission_denied.html template with user-friendly messages
- Enhance user_permissions view with user management features:
  - Toggle staff status
  - Toggle active status
  - Add/remove users from seminars (as organizers or accountants)
- Add public user profile pages:
  - Any logged-in user can view other users' profiles
  - Shows organized seminars and accountant seminars
  - Staff can see additional user information
- Update profile page to show seminar information
- Update all templates to use Metro UI consistently

Authorization matrix implemented:
- Staff: absolute permissions (manage users, bank imports, repay)
- Accountant: seminar-relative (edit records in assigned seminars)
- Organizer: seminar-relative (view and edit own seminars)
- Regular user: can view profiles and accessible seminars

All 50 tests passing.
Comprehensive refactoring to rename all occurrences of "accountant" to "treasurer"
and "účetní" to "finančník" throughout the codebase:

Changes in models:
- Seminar.accountants → Seminar.treasurers
- Seminar.accountant_seminars → Seminar.treasurer_seminars
- Added save() method to ensure all treasurers are also organizers
- Added is_treasurer() helper method

Changes in decorators:
- accountant_required → treasurer_required (where applicable)
- Updated error messages to use "finančník" instead of "účetní"

Changes in views:
- Updated all references to use "treasurers" instead of "accountants"
- Updated user_permissions view to manage treasurers

Changes in templates:
- Updated all UI text to use "Finančník" instead of "Účetní"
- Updated user profile pages to show treasurer seminars
- Updated user permissions page to manage treasurers

Changes in tests:
- Updated all test data to use treasurers instead of accountants
- Updated assertions to check for treasurer permissions

Changes in migrations:
- Created 0008_add_treasurers_field.py to add the treasurers field
- Updated dependencies to handle complex migration history

Changes in documentation:
- Updated README.md
- Updated all helenka-notes/*.md files

This maintains the business rule that treasurers (finančník) are a subset of
organizers, meaning every treasurer must also be an organizer of the seminar.

All 50 tests passing.
Complete refactoring of all templates to use component-based architecture
as specified in TEMPLATES.md guidelines.

Template Architecture:
- Created _page.html as base for all pages (container, messages, header)
- Created 7 reusable components: _messages, _dialog, _dialog_form,
  _confirm_form, _info_box, _table, _field
- All page templates now extend _page.html

Key Improvements:
- Eliminate duplicate template boilerplate (~500 lines reduced)
- Replace all inline JavaScript with external JS files
- Replace all onclick handlers with declarative data attributes
- Remove all inline style attributes (now in CSS classes)
- Standardize page structure (page_title, page_heading, page_actions, main)
- Add comprehensive test suite (11 tests all passing)

New Files:
- app/budget/static/budget/js/helenka.js - Core dialog handlers
- app/budget/static/budget/js/overview-filters.js - Year filters, bulk edit
- app/budget/static/budget/js/smart-upload.js - Smart upload functionality
- app/budget/static/budget/js/event-charts.js - Chart.js integration
- app/budget/static/budget/js/record_bank_transactions.js - Merge dialog
- app/budget/templates/_page.html - Base page template
- app/budget/templates/components/*.html - 7 component templates
- app/budget/templates/budget/_smart_upload_body.html - Smart upload template
- app/budget/tests/test_template_refactoring.py - Test suite (11 tests pass)

Cleanup:
- Zero inline <script> tags in templates
- Zero inline style attributes
- Only 1 onclick (intentional in _confirm_form.html per spec)
- CSS cleaned of Metro utility class duplicates

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Add {% load static budget_extras %} to templates that use {% static %} or |czk filter
- Fix event.html to use proper conditional instead of undefined czk_eq_0 filter
- All 95 tests pass (1 skipped)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Multi-line {% include %} tags with 'with' parameters are not valid Django syntax
- Converted all multi-line includes to single-line format
- Fixed detail.html to use |add filter instead of ~ operator for string concatenation
- Updated test_templates.py render method to handle CSRF tokens properly
- All 106 tests pass (1 skipped)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Removed {# Parameters: ... #} comments from all component templates
- These comments were appearing in rendered output, causing test failures
- All 106 tests pass (1 skipped)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Created budget/_import_form_fields.html for import dialog date fields
- Fixed add_overview.html: single-line includes, proper dialog structure
- Updated components/_dialog_form.html: removed dead block, proper field rendering
- Updated components/_dialog.html: |lower filter for overlay attribute
- Updated components/_table.html: |lower filter for search attribute
- Updated components/_confirm_form.html: escapejs filter for confirm message
- Updated components/_field.html: added help_text rendering
- Updated components/_messages.html: proper role and class attributes
- Added .errorlist styling to main.css
- Added distinct prefixes to RecordForm, SeminarForm, VirtualTransactionForm
- Added Czech labels to SeminarForm
- Changed Výpis z účtu icon from mif-plus to mif-upload
- Updated tests to use prefixed field names

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Move {% url %} tags in add_overview.html inside dialogs block so they execute
- Update dialog contract tests to use prefixed field names (record-, virtual-)
- Add follow=True to invalid POST test to follow redirect to add_overview

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Add prefix to EventForm to prevent ID collisions
- Fix detail.html edit dialog by passing record_form to fields_template
- Fix _table.html to use show_inspector parameter correctly
- Update tests to use prefixed field names (event-title)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Fix striped boolean flag in _table.html (remove default:True filter)
- Remove dead block dialog_hidden from overview.html bulk-edit dialog
- Add fields_template to bulk-edit dialog and move script to scripts block
- Add JS to reposition dialog when details element is toggled
- Replace fg-muted with text-muted, bg-darkGray with bg-charcoal
- Add escapejs filter to confirm messages
- Move url tags to dialogs block for proper action resolution
- Enhance errorlist styling to match Metro remark alert

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
wikiker force-pushed refactor/templates from 114e8de4fe to d2cbd7a9a7 2026-11-18 08:28:22 +01:00 Compare
wikiker deleted branch refactor/templates 2026-11-19 16:57:00 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
Reference
wikiker/helenka!27
No description provided.