⚠️ not suited to first time contributors (PRs will be closed without explanation!).
Is your feature request related to a problem? Please describe.
Organization-owned models currently have no shared, public lifecycle hook for reacting to an organization change. Integrations must implement their own save-time checks and cannot consistently receive both the previous and new organization in the same transaction.
Describe the solution you'd like
Add an organization_changed signal to openwisp_users.signals, emitted by OrgMixin and inherited by ShareableOrgMixin.
The signal should emit only for existing objects whose persisted organization_id actually changed. It should use the concrete model as sender and provide instance, old_organization_id, and organization_id. It must respect update_fields, including relation names and attnames, and support deferred fields and swappable models.
The signal must run synchronously inside the transaction that saves the organization change, so receivers can make related changes atomically.
Describe alternatives you've considered
Application-specific pre-save and post-save receivers duplicate organization-change detection and cannot provide a consistent public integration point. Deferring the signal to transaction.on_commit() is unsuitable for receivers which must reconcile related tenant-owned data atomically.
Additional context
openwisp-controller needs this signal to reconcile templates and provisioned credentials when a device moves organization. A controller follow-up will depend on this issue.
Is your feature request related to a problem? Please describe.
Organization-owned models currently have no shared, public lifecycle hook for reacting to an organization change. Integrations must implement their own save-time checks and cannot consistently receive both the previous and new organization in the same transaction.
Describe the solution you'd like
Add an
organization_changedsignal toopenwisp_users.signals, emitted byOrgMixinand inherited byShareableOrgMixin.The signal should emit only for existing objects whose persisted
organization_idactually changed. It should use the concrete model as sender and provideinstance,old_organization_id, andorganization_id. It must respectupdate_fields, including relation names and attnames, and support deferred fields and swappable models.The signal must run synchronously inside the transaction that saves the organization change, so receivers can make related changes atomically.
Describe alternatives you've considered
Application-specific pre-save and post-save receivers duplicate organization-change detection and cannot provide a consistent public integration point. Deferring the signal to
transaction.on_commit()is unsuitable for receivers which must reconcile related tenant-owned data atomically.Additional context
openwisp-controllerneeds this signal to reconcile templates and provisioned credentials when a device moves organization. A controller follow-up will depend on this issue.