[fix] Reassign shared default templates on org change #1334#1427
[fix] Reassign shared default templates on org change #1334#1427omlahore wants to merge 1 commit into
Conversation
Fixes openwisp#1334 Signed-off-by: Om <omlahore47@gmail.com>
📝 WalkthroughWalkthroughThe change updates Estimated code review effort: 1 (Trivial) | ~5 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant DeviceDetailSerializer
participant Config
Client->>DeviceDetailSerializer: PATCH device organization
DeviceDetailSerializer->>Config: clear existing templates
DeviceDetailSerializer->>Config: enforce required templates
DeviceDetailSerializer->>Config: add_default_templates()
Config-->>DeviceDetailSerializer: templates updated for new organization
DeviceDetailSerializer-->>Client: updated device response
Related issues: Suggested labels: bug, backport-needed Suggested reviewers: nemesifier, pandafy Poem: Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (2 errors)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #1334
Problem
When a device's organization is changed via the REST API,
DeviceDetailSerializer.update()clears the config templates and re-adds only the required templates of the new organization. The default templates (shared defaults and the new organization's own defaults) are not re-assigned. This is inconsistent with device registration, whereadd_default_templates()is applied, so a device moved to a new organization ends up missing that organization's default templates.Change
Add
instance.config.add_default_templates()in the organization-change branch, right after the required templates are enforced. The organization is already set on the config before the templates are cleared, so the default queryset resolves against the new organization.add()is idempotent, so there is no duplication with the required templates that were just re-added.Tests
Adds
test_device_change_organization_default_templates, covering a shared default plus per-organization defaults across an organization change, and confirming the previous organization's default is removed. The existingtest_device_change_organization_required_templatesstill passes.Note
Opening this as a draft to confirm the intended behavior: changing a device's organization should re-assign the new organization's default templates, matching what happens on registration. If the current required-only behavior is intentional, I am happy to close this. The change is scoped to the REST API path only; the admin path is left unchanged.