Skip to content

[PLTFRM-475] Add module notify-privileged-activity#19

Merged
kat3samsin merged 11 commits intoproductionfrom
PLTFRM-475/notify-wp-admin-privileged-user
May 22, 2025
Merged

[PLTFRM-475] Add module notify-privileged-activity#19
kat3samsin merged 11 commits intoproductionfrom
PLTFRM-475/notify-wp-admin-privileged-user

Conversation

@kat3samsin
Copy link
Copy Markdown
Contributor

@kat3samsin kat3samsin commented May 15, 2025

Description

Added ability to send a notification to the Administration Email Address set in wp-admin when a new administrator user is created.

image

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally or in Codespaces (or has an appropriate fallback).
  • This change has relevant unit tests (if applicable).
  • This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

Requires https://github.com/Automattic/vip-go-api/pull/6269

  1. Check out PR.
  2. Enable notify-privileged-activity module
  3. vip dev-env create && vip dev-env start
  4. Add admin user
    vip dev-env exec --slug=vip-security-boost -- wp user generate --count=1 --role=administrator
  5. Verify you received the email here

@kat3samsin kat3samsin requested a review from a team May 19, 2025 19:28
@kat3samsin kat3samsin marked this pull request as ready for review May 19, 2025 19:38
Copilot AI review requested due to automatic review settings May 19, 2025 19:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new module, notify-privileged-activity, that sends an email notification to the administration email when a new administrator user is created. Key changes include:

  • Loading a new email component and initializing the notify-privileged-activity module.
  • Adding MJML-based email templates and a build script to compile them.
  • Enabling the Mailpit service in the development environment for testing email delivery.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vip-security-boost.php Loads the new email/email.php dependency.
utils/dev-env.php Temporarily comments out WP_CLI check to facilitate testing.
scripts/build-mjml.sh Adds a script to compile MJML templates using Node.js and PHP.
modules/notify-privileged-activity/class-notify-privileged-activity.php Implements the email notification on administrator creation.
email/templates/.html, email/mjml/.mjml, email/mjml/common/* Add and update email template files and MJML partials.
email/mjml/build-mjml.php New script to generate HTML emails from MJML templates.
email/email.php Introduces the email sending functionality with template parsing.
composer.json Updates autoload-dev configuration and adds build-mjml script.
.wpvip/vip-dev-env.yml.ejs Enables Mailpit for local email testing.

Comment thread email/email.php Outdated
kat3samsin and others added 3 commits May 19, 2025 15:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@kat3samsin kat3samsin requested a review from Copilot May 19, 2025 20:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new module to send privileged activity notifications (an email when an administrator is created) and supports MJML email template compilation. Key changes include:

  • Adding the notify-privileged-activity module and its associated class.
  • Introducing email handling in email/email.php and related MJML templates.
  • Updating the development environment configuration and build scripts.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vip-security-boost.php Added email module inclusion to integrate the new notification functionality
utils/dev-env.php Comments adjusted to allow user creation testing without WP_CLI restrictions
scripts/build-mjml.sh New build script for compiling MJML templates using Node.js and PHP
modules/notify-privileged-activity/class-notify-privileged-activity.php New module to send notification emails on new admin user creation
email/templates & email/mjml/* Added email templates and MJML files to support the new notification email design
email/email.php Introduced Email class for sending emails and parsing MJML-based templates
composer.json Updated autoload-dev and added a new build-mjml script
.wpvip/vip-dev-env.yml.ejs Enabled Mailpit for testing emails

Comment thread utils/dev-env.php Outdated
Comment thread composer.json Outdated
$admin_email = get_option( 'admin_email' );

if ( empty( $admin_email ) || ! is_email( $admin_email ) ) {
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably good to log2logstash here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll add log2logstash in another PR.

$user->user_email
);

Email::send( $user_id, $admin_email, $subject, 'privileged-user-created', [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably good to also log2logstash here?

@brunobasto
Copy link
Copy Markdown
Contributor

@kat3samsin

I got

[22-May-2025 16:40:29 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function Automattic\VIP\Security\PrivilegedActivityNotifier\_s() in /wp/wp-content/plugins/vip-security-boost/modules/notify-privileged-activity/class-notify-privileged-activity.php:29

when trying to add an admin role. Changing _s( to __( seems to fix the issue

@kat3samsin
Copy link
Copy Markdown
Contributor Author

I got

[22-May-2025 16:40:29 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function Automattic\VIP\Security\PrivilegedActivityNotifier\_s() in /wp/wp-content/plugins/vip-security-boost/modules/notify-privileged-activity/class-notify-privileged-activity.php:29

when trying to add an admin role. Changing _s( to __( seems to fix the issue

@brunobasto I think you got the old code, can you try pulling again?

@brunobasto
Copy link
Copy Markdown
Contributor

@brunobasto I think you got the old code, can you try pulling again?

Ah, yeah. Sorry about that. Works now!

Copy link
Copy Markdown
Contributor

@brunobasto brunobasto left a comment

Choose a reason for hiding this comment

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

Works great!

@kat3samsin kat3samsin added this pull request to the merge queue May 22, 2025
Merged via the queue into production with commit 133d411 May 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants