Skip to content

fix: initialize customer DNS management modal#1338

Merged
superdav42 merged 1 commit into
mainfrom
fix/user-manage-dns-records
Jun 3, 2026
Merged

fix: initialize customer DNS management modal#1338
superdav42 merged 1 commit into
mainfrom
fix/user-manage-dns-records

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Jun 3, 2026

Summary

  • Enqueue and localize the customer DNS management script from Domain_Mapping_Element::register_scripts() so user_manage_dns_records has config on front-end shortcode pages.
  • Listen for the actual wubox:load event while preserving the legacy wubox-load event path used by the current minified asset.
  • Normalize read-only DNS fallback records to the table shape expected by the Vue component (id, name, content, ttl).

Verification

  • vendor/bin/phpcs inc/managers/class-dns-record-manager.php tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php inc/ui/class-domain-mapping-element.php tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php
  • vendor/bin/phpunit --no-coverage --filter 'Domain_Mapping_Element_Test|DNS_Record_Manager_Normalization_Test'
  • node_modules/.bin/eslint --resolve-plugins-relative-to /home/dave/Git/ultimate-multisite /home/dave/Git/ultimate-multisite-user-manage-dns/assets/js/dns-management.js --quiet
  • Browser agent on local WordPress: shortcode page loaded dns-management.min.js, opened user_manage_dns_records via wubox, Vue mounted, loadingVisible: false, and the modal displayed read-only DNS records instead of spinning forever.

Summary by CodeRabbit

  • Bug Fixes

    • Improved DNS record normalization to ensure consistent display across different DNS providers
    • Enhanced error handling in DNS management with localized error messages
    • Fixed DNS record edit and delete URL generation to properly handle missing configuration values
    • Improved form validation during bulk DNS operations
  • Tests

    • Added comprehensive test coverage for DNS record normalization and data structure validation
    • Added UI tests for DNS management script registration and event handling

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR improves DNS record management by normalizing backend responses and refactoring the frontend to use secure, localized configuration. A new backend helper normalizes records across all provider paths; the frontend wiring registers and configures the script with AJAX URLs and nonces; and the JavaScript is refactored to use these config-aware helpers throughout record loading, editing, deleting, and bulk operations.

Changes

DNS Record Management Frontend-Backend Integration

Layer / File(s) Summary
Backend DNS Record Normalization
inc/managers/class-dns-record-manager.php, tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php
DNS_Record_Manager::ajax_get_records() normalizes records across all response paths (no provider, provider error, success) via a new normalize_records_for_response() helper. Consistent name, content, ttl, and id fields are mapped from provider or fallback record keys. Unit tests verify normalization of read-only and DNS_Record object inputs.
Frontend Script Registration and Configuration
inc/ui/class-domain-mapping-element.php
Domain_Mapping_Element::register_scripts() registers and enqueues wu-dns-management with AJAX URL, nonce, form URLs, and i18n messages localized to window.wu_dns_config. Inline JS sets window.ajaxurl and forwards wubox:load events to wubox-load for backward compatibility.
Frontend DNS Management Script Refactoring
assets/js/dns-management.js
Script now uses config-aware helpers (getConfig, getAjaxUrl, addQueryArg, showError) instead of direct concatenation. Record loading, edit/delete URLs, and bulk delete operations validate nonce, use localized config and error messages, and properly handle AJAX failures. Event listener changes from wubox-load to wubox:load.
Frontend Integration Tests
tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php
Tests validate that the DNS management script is registered with correct configuration, that script source code listens for wubox:load, and that it uses getAjaxUrl() helper. File reader helper loads plugin source and asserts expected patterns.

Sequence Diagram

sequenceDiagram
  participant UI as Domain_Mapping_Element
  participant JS as dns-management.js
  participant AJAX as WordPress AJAX
  participant Backend as DNS_Record_Manager
  
  UI->>JS: register & localize script with wu_dns_config
  Note over JS: window.wu_dns_config now available
  JS->>JS: loadRecords() via wubox:load listener
  JS->>JS: getConfig() & validate nonce
  JS->>AJAX: POST wu_get_dns_records_for_domain
  AJAX->>Backend: route to ajax_get_records()
  Backend->>Backend: normalize_records_for_response()
  Backend->>AJAX: return normalized records
  AJAX->>JS: success response
  JS->>JS: renderRecords() with normalized data
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • Ultimate-Multisite/ultimate-multisite#308: The main PR's updates to assets/js/dns-management.js (AJAX URL/nonce handling, edit/delete URL construction, bulk-delete confirmation/error handling, and the wubox:load reinit listener) build directly on the DNS record management Vue script introduced in the retrieved PR #308.

Poem

🐰 DNS records now dance to a rhythm so sweet,
With normalization and nonces, the flow is complete,
Config-aware helpers keep chaos at bay,
Localized messages guide users their way,
From backend to frontend, the data flows true. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: initializing the customer DNS management modal by enqueuing/localizing the script and handling event changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/user-manage-dns-records

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php (1)

20-42: 🏗️ Heavy lift

Assert runtime registration state instead of raw source strings.

These assertions only prove that specific substrings exist in the files. They can still pass if register_scripts() stops wiring the handle correctly, localizes the wrong payload, or moves equivalent logic into another helper. Exercising Domain_Mapping_Element::register_scripts() and asserting against the wu-dns-management entry in $wp_scripts would protect the actual contract this PR depends on.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php` around lines 20 - 42,
Replace raw source string assertions with an integration-style test that calls
Domain_Mapping_Element::register_scripts() and asserts the runtime registration
state: invoke Domain_Mapping_Element::register_scripts(), then inspect the
global $wp_scripts (and $wp_styles if needed) to find an entry with handle
'wu-dns-management' and assert its existence, that it is enqueued (or
registered) and that the localized data created via wp_localize_script and
inline script added via wp_add_inline_script were attached to that handle (check
registered script's extra data or localized vars and inline data). Also assert
that admin_url('admin-ajax.php') was included in the localized payload (or in
the localized var key 'ajaxurl') and that the script is ultimately enqueued via
wp_enqueue_script('wu-dns-management') by verifying the enqueue state on the
'wu-dns-management' handle.
tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php (1)

8-17: ⚡ Quick win

Align the test namespace with the source namespace.

This file sits under tests/WP_Ultimo/Managers/ but declares WP_Ultimo\Tests\Managers. The repo convention for this path is to mirror the source namespace, so this should track WP_Ultimo\Managers instead of introducing a separate Tests segment.

As per coding guidelines "test namespace must mirror source structure (e.g., WP_Ultimo\Checkout\Cart_Test tests WP_Ultimo\Checkout\Cart)".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php` around
lines 8 - 17, The test class namespace is incorrect: change the namespace
declaration from "WP_Ultimo\Tests\Managers" to mirror the source namespace
"WP_Ultimo\Managers" so the test tracks the corresponding source code; update
the top of the file where the namespace is declared for the class
DNS_Record_Manager_Normalization_Test to use "WP_Ultimo\Managers" (keep use
statements and class name DNS_Record_Manager_Normalization_Test unchanged).
inc/ui/class-domain-mapping-element.php (1)

830-838: ⚡ Quick win

Reuse the manager sanitizer instead of duplicating the record-shaping rules.

The arrays on Lines 830-838 and 952-959 duplicate DNS_Record_Manager::sanitize_record_data() in inc/managers/class-dns-record-manager.php. That makes the customer modal path drift-prone: a future field/default change can update the AJAX handlers but leave these form handlers behind. Please route both paths through one shared sanitizer.

Also applies to: 952-959

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@inc/ui/class-domain-mapping-element.php` around lines 830 - 838, Replace the
duplicated inline sanitization in inc/ui/class-domain-mapping-element.php with a
call to the centralized sanitizer DNS_Record_Manager::sanitize_record_data() so
both the modal/form path and the AJAX path use the same logic; specifically,
stop building the $record array manually in the blocks around the existing array
(the one creating 'type','name','content','ttl','priority','proxied') and
instead pass the incoming raw record data through
DNS_Record_Manager::sanitize_record_data($record) (ensuring you provide the same
defaults if the sanitizer requires them), and make the identical change for the
other duplicated block noted (around lines 952-959) so both places reuse the
single sanitizer.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@inc/ui/class-domain-mapping-element.php`:
- Around line 830-838: Replace the duplicated inline sanitization in
inc/ui/class-domain-mapping-element.php with a call to the centralized sanitizer
DNS_Record_Manager::sanitize_record_data() so both the modal/form path and the
AJAX path use the same logic; specifically, stop building the $record array
manually in the blocks around the existing array (the one creating
'type','name','content','ttl','priority','proxied') and instead pass the
incoming raw record data through
DNS_Record_Manager::sanitize_record_data($record) (ensuring you provide the same
defaults if the sanitizer requires them), and make the identical change for the
other duplicated block noted (around lines 952-959) so both places reuse the
single sanitizer.

In `@tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php`:
- Around line 8-17: The test class namespace is incorrect: change the namespace
declaration from "WP_Ultimo\Tests\Managers" to mirror the source namespace
"WP_Ultimo\Managers" so the test tracks the corresponding source code; update
the top of the file where the namespace is declared for the class
DNS_Record_Manager_Normalization_Test to use "WP_Ultimo\Managers" (keep use
statements and class name DNS_Record_Manager_Normalization_Test unchanged).

In `@tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php`:
- Around line 20-42: Replace raw source string assertions with an
integration-style test that calls Domain_Mapping_Element::register_scripts() and
asserts the runtime registration state: invoke
Domain_Mapping_Element::register_scripts(), then inspect the global $wp_scripts
(and $wp_styles if needed) to find an entry with handle 'wu-dns-management' and
assert its existence, that it is enqueued (or registered) and that the localized
data created via wp_localize_script and inline script added via
wp_add_inline_script were attached to that handle (check registered script's
extra data or localized vars and inline data). Also assert that
admin_url('admin-ajax.php') was included in the localized payload (or in the
localized var key 'ajaxurl') and that the script is ultimately enqueued via
wp_enqueue_script('wu-dns-management') by verifying the enqueue state on the
'wu-dns-management' handle.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c560774-2a52-427b-b05a-b5febe7f22e5

📥 Commits

Reviewing files that changed from the base of the PR and between a26996d and 570df1e.

📒 Files selected for processing (5)
  • assets/js/dns-management.js
  • inc/managers/class-dns-record-manager.php
  • inc/ui/class-domain-mapping-element.php
  • tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php
  • tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php

@superdav42 superdav42 merged commit 0b7fe4e into main Jun 3, 2026
10 of 11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

  • Enqueue and localize the customer DNS management script from Domain_Mapping_Element::register_scripts() so user_manage_dns_records has config on front-end shortcode pages.
  • Listen for the actual wubox:load event while preserving the legacy wubox-load event path used by the current minified asset.
  • Normalize read-only DNS fallback records to the table shape expected by the Vue component (id, name, content, ttl).

Verification

  • vendor/bin/phpcs inc/managers/class-dns-record-manager.php tests/WP_Ultimo/Managers/DNS_Record_Manager_Normalization_Test.php inc/ui/class-domain-mapping-element.php tests/WP_Ultimo/UI/Domain_Mapping_Element_Test.php
  • vendor/bin/phpunit --no-coverage --filter 'Domain_Mapping_Element_Test|DNS_Record_Manager_Normalization_Test'
  • node_modules/.bin/eslint --resolve-plugins-relative-to /home/dave/Git/ultimate-multisite /home/dave/Git/ultimate-multisite-user-manage-dns/assets/js/dns-management.js --quiet
  • Browser agent on local WordPress: shortcode page loaded dns-management.min.js, opened user_manage_dns_records via wubox, Vue mounted, loadingVisible: false, and the modal displayed read-only DNS records instead of spinning forever.


Merged via PR #1338 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.20.11 spent 13m on this as a headless bash routine.

@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant