Skip to content

Reduce User monkeypatching#4197

Merged
mathjazz merged 3 commits into
mozilla:mainfrom
eemeli:user-utils
Jun 9, 2026
Merged

Reduce User monkeypatching#4197
mathjazz merged 3 commits into
mozilla:mainfrom
eemeli:user-utils

Conversation

@eemeli

@eemeli eemeli commented Jun 8, 2026

Copy link
Copy Markdown
Member

Built on top of #4196, actual diff here is here -- so will probably need a rebase before merging. Edit: Done.


Over time, we've ended up monkeypatching a plethora of functionality onto the base User object, via its add_to_class() method. While this does make the methods and properties available everywhere, they're also hard to discover and get no editor support.

This PR moves most of these utility functions into pontoon.base.badge_utils, pontoon/base/notification_utils, pontoon.base.user_utils. A few are left in to keep them available in templates, which would otherwise need to have their contexts include the utility-provied values. For the methods and properties left on User, a type-hinting-only subclass is provided for better editor support -- this also provides a place to define the model's foreign-key relationships.

@eemeli eemeli requested a review from mathjazz June 8, 2026 05:21
@codecov-commenter

codecov-commenter commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.12798% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.72%. Comparing base (b0906cc) to head (cb91796).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mathjazz mathjazz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good.

Could we document which helpers intentionally remain monkeypatched on User, and why? The split is reasonable, but without a short comment, it’s hard to tell later whether a remaining add_to_class() method is intentional or just not migrated yet.

@eemeli eemeli requested a review from mathjazz June 9, 2026 11:09
@mathjazz mathjazz merged commit b75897a into mozilla:main Jun 9, 2026
5 checks passed
@eemeli eemeli deleted the user-utils branch June 9, 2026 11:24
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.

3 participants