Skip to content

Commit

Permalink
GP Profiles: Add notifier for suggesting strings and approval.
Browse files Browse the repository at this point in the history
See WordPress/five-for-the-future#196


git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11929 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
iandunn committed Jul 1, 2022
1 parent 58668f1 commit 2caef2e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Plugin name: GlotPress Profiles Activity Notifier
* Description: Adds activity to profiles.wordpress.org when contributors do noteworthy things.
* Author: WordPress.org
* License: GPLv2 or later
*/

namespace WordPressdotorg\GlotPress\Profiles;

use WordPressdotorg\Profiles as Profiles_API;
use GP_Translation;

defined( 'WPINC' ) || die();

/*
* Requests will always fail when in local environments, unless the dev is proxied. Proxied devs could test
* locally if they're careful (especially with user IDs), but it's better to test on w.org sandboxes with
* test accounts. That prevents real profiles from having test data accidentally added to them.
*/
if ( 'local' === wp_get_environment_type() ) {
return;
}

add_action( 'gp_translation_created', __NAMESPACE__ . '\add_translation_activity' );
add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_translation_activity' );

/**
* Add a activity when strings are suggested and approved.
*/
function add_translation_activity( GP_Translation $translation ) : void {
if ( 'waiting' === $translation->status ) {
$type = 'glotpress_translation_suggested';
} elseif ( 'current' === $translation->status ) {
$type = 'glotpress_translation_approved';
} else {
return;
}

$request_body = array(
'action' => 'wporg_handle_activity',
'component' => 'glotpress',
'type' => $type,
'user_id' => $translation->user_id,
);

Profiles_API\api( $request_body );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* ⚠️ These tests run against the production database and object cache on w.org and profiles.w.org.
* Make sure that any modifications are hardcoded to only affect test sites and test user accounts.
*
* usage: wp eval-file e2e.php test_name
*/

namespace WordPressdotorg\GlotPress\Profiles\Tests;

use WordPressdotorg\GlotPress\Profiles as GlotPress_Profiles;
use Exception, WP_User, GP_Translation;

ini_set( 'display_errors', 'On' ); // won't do anything if fatal errors

if ( 'staging' !== wp_get_environment_type() || 'cli' !== php_sapi_name() ) {
die( 'Error: Wrong environment.' );
}

if ( 700 !== get_current_blog_id() ) {
die( 'Must be run on translate-test.wordpress.org.' );
}

const TEST_USERNAME = 'iandunn-test';

/** @var array $args */
main( $args[0] );

function main( $case ) {
$user = get_user_by( 'slug', TEST_USERNAME );

try {
call_user_func( __NAMESPACE__ . "\\test_$case", $user );

} catch ( Exception $exception ) {
echo $exception->getMessage();

}
}

function test_add( WP_User $user ) {
$translation = new GP_Translation( array(
'user_id' => $user->ID,
'status' => 'waiting',
) );
GlotPress_Profiles\add_translation_activity( $translation );

$translation = new GP_Translation( array(
'user_id' => $user->ID,
'status' => 'current',
) );
GlotPress_Profiles\add_translation_activity( $translation );

echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n";
}

0 comments on commit 2caef2e

Please sign in to comment.