Commit graph

18 commits

Author SHA1 Message Date
Timo Tijhof
949c9c932e mail: Improve docs, fix file headers, widen @covers
* Add missing `ingroup` to class blocks (and remove from any file blocks)
  as otherwise the file is indexed twice (e.g. in Doxygen) which makes
  navigation on doc.wikimedia.org rather messy.

  Remove duplicate descriptions from file blocks in favour of class
  doc blocks. This reduces needless duplication and was often
  incorrect or outdated, and helps make file headers more consistently
  (visually) ignorable.

  Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged

* Widen `@covers` tags in phpunit tests

  Given all called methods are de-facto and liberally claimed, and
  that we keep the coverage limited to the subject class, it maintains
  the spirit and intent by listing the class explicitly instead.

  PHPUnit offers a more precise tool when you need it (i.e. when testing
  legacy monster/god classes), but for well-written code, the
  class-wide tag is exactly what you want.

  We lose useful coverage and waste valuable time on keeping tags
  accurate through refactors (or worse, forget to do so).
  Tracking tiny per-method details wastes time in realizing (and
  fixing) when people inevitably don't keep them in sync, and time
  lost in finding uncovered code to write tests to realize it was
  already covered but "not yet claimed".

  Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:

- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
  later moved to a separate file in bf8810d6bc (Ic435bbdbb6).

- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.

- UserMailer converted to class with ::send in r26357 (1.12.0),
  git 353f203ce2.

Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 19:48:43 +01:00
thiemowmde
de374b9c8a Use native willReturnSelf in tests where possible
Change-Id: I38a1858a5190c9fc5c80ac8f846a18af163a18e6
2024-04-10 14:13:05 +02:00
Dringsim
30edaf6e46
EmailUserTest: check user in getOption() in mutelist test
Change-Id: Ieb51d0bc391c7d768e7dc5f2c411dfbeb1ef4dae
2023-12-30 00:46:40 +08:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
Daimona Eaytoy
8af16b7945 Make EmailUser stable, deprecate old methods
Bug: T265541
Change-Id: I09276e2bc12d474e1a5defe6a23fff4e633aeaaf
2023-09-26 23:27:29 +00:00
daniel
710867ebc3 EmailUser: use authorizeAction()
EmailUser should distinguish between pre-checking permission, and
authorizing the sending of emails, so we can call authorizeAction()
at the appropriate time. This way, rate limits get enforced
implicitly.

This change demonstrates the motivation behind Iebd62b0487a
and I0c2ce8bdf07.

Change-Id: Ic30c36f82ab142130b5f4167c13284aeed899231
2023-09-26 21:20:32 +02:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Daimona Eaytoy
1e27f61cc5 mail: Final round of EmailUser refactoring
- Replace MessageLocalizer with message formatters. This is still not
  very pretty, but at least now callers don't need to obtain monster
  classes like RequestContext to use this service.
- Update the documentation and add a couple notes about potential future
  improvements.

A subsequent patch will make the service stable for use, deprecate the
old stuff, and update the release notes.

Bug: T265541
Change-Id: Ic9b0ef7b3b410d48375836f4db565ffd46936319
2023-06-20 11:02:51 +00:00
Daimona Eaytoy
c7eb0db5d1 mail: Round 6 of EmailUser refactoring
- Rename methods to follow the more standard convention used for
  commands.
- Update doc comments.
- Add new hooks with final method names and parameter types, to replace
  the old messy hooks.
- Deprecate the remaining old hooks.

Bug: T265541
Change-Id: I609709a70fb58ce00b9f179ee4de2f6ac5e0a1cf
2023-06-20 11:00:07 +00:00
Daimona Eaytoy
b469b342d0 Introduce EmailUserFactory
This is necessary so that EmailUser can behave as a command. EmailUser
now takes the performer as a constructor parameter; this, in combination
with the statelessness of the service, allows it to be reused for
multiple sends. Some BC code was also moved to the factory.

Bug: T265541
Change-Id: I2568359f00f429ef3ab3bfbfb803dc8e51cd8add
2023-06-01 11:17:44 +00:00
Daimona Eaytoy
ead6d3135b mail: Round 5 of EmailUser refactoring
- Use UserEmailContact for the sender; internally, we still fall back to
  User.
- Try to use Authority and UserIdentity instead of User where possible
- Replace PermissionManager with Authority
- Fix handling of block message in BC code for Special:EmailUser
  (currently throwing a fatal because of return type mismatch, as the BC
  code is not intercepting the Message object)
- Move the ratelimit check around the beginning of the method, instead
  of running it after having pointlessly built half of the email body
- Stop using User::isBlockedFromEmailuser and add a TODO about
  deprecating that method.

Bug: T265541
Change-Id: Icc06b816a553028d816e6ab1b43ad93605fd5b3f
2023-06-01 11:17:31 +00:00
James D. Forrester
0c52191100 Make EmailUserPermissionsErrorsHook emit deprecation errors
Bug: T265541
Depends-On: I59aaaa360d0d6e9776a0049f57cff298a8caa8a5
Follows-Up: I2492b261505886d845260e2b63c5e71966a637ce
Change-Id: Ica0d8becd56c1e31e75c636b0286a91d7fb653ab
2023-05-24 10:06:48 -04:00
Daimona Eaytoy
4634d4545e mail: Round 4 of EmailUser refactoring
- Remove getTarget(). Converting a username to a user object is not a
  responsibility of this command. This logic generally belongs to
  callers.
- Use Authority for the sender, as we need to perform permission checks
  on them. Internally, we're still converting to User.

Bug: T265541
Change-Id: Ib0cd86d97dbf1cd97dcb316480171e4fbf4a09f4
2023-05-21 07:56:01 +00:00
Daimona Eaytoy
ead444b208 mail: Make EmailUser::getPermissionsError() return StatusValue
This is non-trivial because:
- "blockedemailuser" is not a real message, so it can't be passed to
  StatusValue. For now, use BlockErrorFormatter to obtain a suitable
  message. In the future, we should simply rely on
  Authority/PermissionManager to set a message for us, but that's left
  for another change.
- The hooks used here return an error in the format accepted by
  ErrorPageError. There's no "official" way to do this with StatusValue.
  This patch uses StatusValue::value as a temporary workaround, but
  these hooks should be replaced with a new hook that uses StatusValue
  for errors.

As an aside, note that ApiEmailUser passes the return value of
getPermissionsError to dieWithError(), which doesn't work in the cases
above. This is a pre-existing issue that will be fixed in another patch.

Bug: T265541
Change-Id: I84cc521b24adef6406e0378a293438d5cd7db02a
2023-05-20 13:21:59 +00:00
Daimona Eaytoy
6cd8297039 mail: Round 3 of EmailUser refactoring
- Make getTarget and validateTarget consistently return StatusValue, and
  adjust the return value so that it includes the full error message,
  without having to process the key again in callers.
- Consistently use emailnotarget instead of notargettext. This was
  already the case everywhere but in submit(). I believe this was just a
  mistake.
- Improve confusing reuse of variable in
  SpecialEmailUser::sendEmailForm.

::getPermissionsError() is messier and will be done in another patch.

Bug: T265541
Change-Id: Ifeb081f6c1d49272ca6c67626e5a419a54653471
2023-05-17 09:59:24 +00:00
Daimona Eaytoy
e5f17be06c mail: Round 2 of EmailUser refactoring
- Strengthen types
- Use StatusValue instead of Status
- Extract duplicated code to a new private method
- Add MailAddress::equals to compare addresses, instead of relying on
  the weak '!=' comparison. There might be a question of whether having
  the same address should be enough for two MailAddress objects to be
  equal, but the implementation in this patch preserves the status quo.
- Make the new validateTarget accept a User object directly. This is
  better than passing strings around just to have the "validator" create
  a user for you.
- Avoid returning false if there's a hook error in submit(). Accepting 5
  different error formats in the same hook is simply unreasonable, and
  this should eventually be standardized to use StatusValue. The old
  methods in SpecialEmailUser retain BC.

Bug: T265541
Change-Id: Ia0ba27fe634e328dff1a6c06fb9979cb8ce4f7e7
2023-05-17 09:58:21 +00:00
Daimona Eaytoy
87a0e1d653 mail: Round 1 of EmailUser refactoring
- Make it an actual service
- Make its methods non-static
- Adjust signatures and method calls
- Remove excessively verbose logging
- Use dependency injection
- Add unit tests
- In SpecialEmailUser, add a new non-static method to use for form
  submission, and leave the old one for external callers only.
- Fix parameter type in the EmailUser hook. This was previously not
  spotted by phan because the argument came from an array without
  documented types.

Bug: T265541
Change-Id: I2322e9c3004d76b665d8eb8e0e4029411a01ef5a
2023-05-17 10:34:10 +01:00