Problem/Motivation

When the user who owns a proc entity is deleted, Proc::getOwner() throws:

TypeError: Drupal\proc\Entity\Proc::getOwner(): Return value must be of type Drupal\user\UserInterface, null returned

The method is declared : UserInterface, but $this->get('user_id')->entity is NULL once the account is gone. EntityOwnerInterface doesn't declare a return type, and ProcListBuilder already expects NULL (getOwner() ? … : 'Anonymous'), but that check can never run.

Ciphers from deleted users are still referenced by content (e.g. attachments other users received), so deleting them is not an option.

Steps to reproduce

  1. As user A, generate keys and encrypt something (e.g. a file for user B).
  2. Delete user A.
  3. Visit /admin/content/procs: fatal error.

The same call is used in ProcMetadataMessageTrait ("Encrypted by %author") and StandardProcRelabelling::relabel(), so viewing or relabelling those ciphers is likely affected too (not yet confirmed).

Proposed resolution

  • Change the return type to ?UserInterface.
  • Fall back to "Anonymous" in ProcMetadataMessageTrait and StandardProcRelabelling, as ProcListBuilder already does.
  • Add a kernel test: delete the owner, assert getOwner() returns NULL and the metadata message renders.

Follow-up (separate issue): decide what proc should do with a user's keyrings and ciphers on account deletion/cancellation.

Remaining tasks

  • MR + test
  • Review

User interface changes

Ciphers of deleted users show "Encrypted by Anonymous" instead of a fatal error.

API changes

Proc::getOwner() may now return NULL. Callers that chain on it (->label(), etc.) must handle NULL.

Data model changes

None.

Comments

duartebriz created an issue. See original summary.

duartebriz’s picture

Issue summary: View changes
rodrigo panchiniak fernandes’s picture

Version: 10.0.x-dev » 10.1.134
Assigned: Unassigned » rodrigo panchiniak fernandes