Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency Report email automation #1290

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 79 additions & 56 deletions public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ public static function meta_keys( $meta_group = '' ) {
'Global Sponsorship Grant' => 'text',
'Running money through WPCS PBC' => 'checkbox',
);

/*
* The "Transparency Report Received" checkbox can only be checked or unchecked when the current user is admin or super admin.
* See https://github.com/WordPress/wordcamp.org/issues/1280#issuecomment-2058571557.
*/
if ( current_user_can( 'manage_options' ) ) {
Copy link
Contributor

@pkevan pkevan Apr 23, 2024

Choose a reason for hiding this comment

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

Not sure if you've tested this scenario but I've come across several times in the past where a user who isn't shown or displayed a field in this way can overwrite the field with a default value. Unsure if this is the case here, but wanted to mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for bringing that up! I hadn't thought of that case.
Just checked off the field and then updated the post using another user unable to see the checkbox, and it didn't overwrite.

$retval['Transparency Report Received'] = 'checkbox';
}

break;

case 'all':
Expand All @@ -442,65 +451,79 @@ public static function meta_keys( $meta_group = '' ) {
'Global Sponsorship Grant Amount' => 'number',
'Global Sponsorship Grant' => 'text',
'Running money through WPCS PBC' => 'checkbox',
);

'Organizer Name' => 'text',
'WordPress.org Username' => 'text',
'Email Address' => 'text', // Lead organizer.
'Telephone' => 'text',
'Mailing Address' => 'textarea',
'Sponsor Wrangler Name' => 'text',
'Sponsor Wrangler E-mail Address' => 'text',
'Budget Wrangler Name' => 'text',
'Budget Wrangler E-mail Address' => 'text',
'Venue Wrangler Name' => 'text',
'Venue Wrangler E-mail Address' => 'text',
'Speaker Wrangler Name' => 'text',
'Speaker Wrangler E-mail Address' => 'text',
'Food/Beverage Wrangler Name' => 'text',
'Food/Beverage Wrangler E-mail Address' => 'text',
'Swag Wrangler Name' => 'text',
'Swag Wrangler E-mail Address' => 'text',
'Volunteer Wrangler Name' => 'text',
'Volunteer Wrangler E-mail Address' => 'text',
'Printing Wrangler Name' => 'text',
'Printing Wrangler E-mail Address' => 'text',
'Design Wrangler Name' => 'text',
'Design Wrangler E-mail Address' => 'text',
'Website Wrangler Name' => 'text',
'Website Wrangler E-mail Address' => 'text',
'Social Media/Publicity Wrangler Name' => 'text',
'Social Media/Publicity Wrangler E-mail Address' => 'text',
'A/V Wrangler Name' => 'text',
'A/V Wrangler E-mail Address' => 'text',
'Party Wrangler Name' => 'text',
'Party Wrangler E-mail Address' => 'text',
'Travel Wrangler Name' => 'text',
'Travel Wrangler E-mail Address' => 'text',
'Safety Wrangler Name' => 'text',
'Safety Wrangler E-mail Address' => 'text',
'Mentor WordPress.org User Name' => 'text',
'Mentor Name' => 'text',
'Mentor E-mail Address' => 'text',
/*
* The "Transparency Report Received" checkbox can only be checked or unchecked when the current user is admin or super admin.
* See https://github.com/WordPress/wordcamp.org/issues/1280#issuecomment-2058571557.
*/
if ( current_user_can( 'manage_options' ) ) {
$retval['Transparency Report Received'] = 'checkbox';
}

'Virtual event only' => 'checkbox',
'Streaming account to use' => 'select-streaming',
'Host region' => 'textarea',
'Venue Name' => 'text',
'Physical Address' => 'textarea',
'Maximum Capacity' => 'text',
'Available Rooms' => 'text',
'Website URL' => 'text',
'Contact Information' => 'textarea',
'Exhibition Space Available' => 'checkbox',

'Contributor Day' => 'checkbox',
'Contributor Day Date (YYYY-mm-dd)' => 'date',
'Contributor Venue Name' => 'text',
'Contributor Venue Address' => 'textarea',
'Contributor Venue Capacity' => 'text',
'Contributor Venue Website URL' => 'text',
'Contributor Venue Contact Info' => 'textarea',
$retval = array_merge(
$retval,
array(
'Organizer Name' => 'text',
'WordPress.org Username' => 'text',
'Email Address' => 'text', // Lead organizer.
'Telephone' => 'text',
'Mailing Address' => 'textarea',
'Sponsor Wrangler Name' => 'text',
'Sponsor Wrangler E-mail Address' => 'text',
'Budget Wrangler Name' => 'text',
'Budget Wrangler E-mail Address' => 'text',
'Venue Wrangler Name' => 'text',
'Venue Wrangler E-mail Address' => 'text',
'Speaker Wrangler Name' => 'text',
'Speaker Wrangler E-mail Address' => 'text',
'Food/Beverage Wrangler Name' => 'text',
'Food/Beverage Wrangler E-mail Address' => 'text',
'Swag Wrangler Name' => 'text',
'Swag Wrangler E-mail Address' => 'text',
'Volunteer Wrangler Name' => 'text',
'Volunteer Wrangler E-mail Address' => 'text',
'Printing Wrangler Name' => 'text',
'Printing Wrangler E-mail Address' => 'text',
'Design Wrangler Name' => 'text',
'Design Wrangler E-mail Address' => 'text',
'Website Wrangler Name' => 'text',
'Website Wrangler E-mail Address' => 'text',
'Social Media/Publicity Wrangler Name' => 'text',
'Social Media/Publicity Wrangler E-mail Address' => 'text',
'A/V Wrangler Name' => 'text',
'A/V Wrangler E-mail Address' => 'text',
'Party Wrangler Name' => 'text',
'Party Wrangler E-mail Address' => 'text',
'Travel Wrangler Name' => 'text',
'Travel Wrangler E-mail Address' => 'text',
'Safety Wrangler Name' => 'text',
'Safety Wrangler E-mail Address' => 'text',
'Mentor WordPress.org User Name' => 'text',
'Mentor Name' => 'text',
'Mentor E-mail Address' => 'text',

'Virtual event only' => 'checkbox',
'Streaming account to use' => 'select-streaming',
'Host region' => 'textarea',
'Venue Name' => 'text',
'Physical Address' => 'textarea',
'Maximum Capacity' => 'text',
'Available Rooms' => 'text',
'Website URL' => 'text',
'Contact Information' => 'textarea',
'Exhibition Space Available' => 'checkbox',

'Contributor Day' => 'checkbox',
'Contributor Day Date (YYYY-mm-dd)' => 'date',
'Contributor Venue Name' => 'text',
'Contributor Venue Address' => 'textarea',
'Contributor Venue Capacity' => 'text',
'Contributor Venue Website URL' => 'text',
'Contributor Venue Contact Info' => 'textarea',
)
);

break;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function test_timed_messages_sent( $send_when, $send_when_period, $send_w
update_post_meta( self::$timed_reminder_post_id, 'wcor_send_when', $send_when );
update_post_meta( self::$timed_reminder_post_id, $send_when_period, $send_when_days );

if ( in_array( $send_when, array( 'wcor_send_before', 'wcor_send_after' ) ) ) {
if ( in_array( $send_when, array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_and_no_report' ) ) ) {
update_post_meta( self::$wordcamp_dayton_post_id, 'Start Date (YYYY-mm-dd)', $compare_date );
} elseif ( 'wcor_send_after_pending' === $send_when ) {
update_post_meta( self::$wordcamp_dayton_post_id, '_timestamp_added_to_planning_schedule', $compare_date );
Expand Down Expand Up @@ -191,28 +191,36 @@ public function test_timed_messages_sent( $send_when, $send_when_period, $send_w
*/
public function data_timed_messages_sent() {
return array(
// Before the camp starts
// Before the camp starts.
array(
'wcor_send_before',
'wcor_send_days_before',
3,
strtotime( 'now + 3 days' ),
),

// After the camp ends
// After the camp ends.
array(
'wcor_send_after',
'wcor_send_days_after',
3,
strtotime( 'now - 3 days' )
strtotime( 'now - 3 days' ),
),

// After added to the pending schedule
// After added to the pending schedule.
array(
'wcor_send_after_pending',
'wcor_send_days_after_pending',
3,
strtotime( 'now - 3 days' )
strtotime( 'now - 3 days' ),
),

// After the camp ends and no transparency report is received.
array(
'wcor_send_after_and_no_report',
'wcor_send_days_after_and_no_report',
3,
strtotime( 'now - 3 days' ),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@
</td>
</tr>

<tr>
<th><input id="wcor_send_after_and_no_report" name="wcor_send_when" type="radio" value="wcor_send_after_and_no_report" <?php checked( $post->wcor_send_when, 'wcor_send_after_and_no_report' ); ?>></th>
<td><label for="wcor_send_after_and_no_report">after the camp ends and no transparency report is received: </label></td>
<td>
<input id="wcor_send_days_after_and_no_report" name="wcor_send_days_after_and_no_report" type="text" class="small-text" value="<?php echo esc_attr( $post->wcor_send_days_after_and_no_report ); ?>" />
<label for="wcor_send_days_after_and_no_report">days</label>
</td>
</tr>

<tr>
<th><input id="wcor_send_trigger" name="wcor_send_when" type="radio" value="wcor_send_trigger" <?php checked( $post->wcor_send_when, 'wcor_send_trigger' ); ?>></th>
<td><label for="wcor_send_trigger">on a trigger: </label></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public function send_timed_emails() {
'meta_query' => array(
array(
'key' => 'wcor_send_when',
'value' => array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending' ),
'value' => array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_after_and_no_report' ),
'compare' => 'IN'
),
),
Expand Down Expand Up @@ -623,6 +623,17 @@ protected function timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_
if ( $days_after_pending && $timestamp_added_to_pending_schedule ) {
$execution_timestamp = $timestamp_added_to_pending_schedule + ( $days_after_pending * DAY_IN_SECONDS );

if ( $execution_timestamp <= current_time( 'timestamp' ) ) {
$ready = true;
}
}
} elseif ( 'wcor_send_after_and_no_report' == $send_when ) {
$days_after_and_no_report = absint( get_post_meta( $email->ID, 'wcor_send_days_after_and_no_report', true ) );
$report_received = get_post_meta( $wordcamp->ID, 'Transparency Report Received', true );

if ( $end_date && $days_after_and_no_report && ! $report_received ) {
$execution_timestamp = $end_date + ( $days_after_and_no_report * DAY_IN_SECONDS );

if ( $execution_timestamp <= current_time( 'timestamp' ) ) {
$ready = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function save_post_meta( $post, $new_meta ) {
}

if ( isset( $new_meta['wcor_send_when'] ) ) {
if ( in_array( $new_meta['wcor_send_when'], array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_trigger' ) ) ) {
if ( in_array( $new_meta['wcor_send_when'], array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_after_and_no_report', 'wcor_send_trigger' ) ) ) {
update_post_meta( $post->ID, 'wcor_send_when', $new_meta['wcor_send_when'] );
}
}
Expand All @@ -211,6 +211,10 @@ protected function save_post_meta( $post, $new_meta ) {
update_post_meta( $post->ID, 'wcor_send_days_after_pending', absint( $new_meta['wcor_send_days_after_pending'] ) );
}

if ( isset( $new_meta['wcor_send_days_after_and_no_report'] ) ) {
update_post_meta( $post->ID, 'wcor_send_days_after_and_no_report', absint( $new_meta['wcor_send_days_after_and_no_report'] ) );
}

if ( isset( $new_meta['wcor_which_trigger'] ) ) {
if ( in_array( $new_meta['wcor_which_trigger'], array_merge( array( 'null' ), array_keys( $GLOBALS['WCOR_Mailer']->triggers ) ) ) ) {
update_post_meta( $post->ID, 'wcor_which_trigger', $new_meta['wcor_which_trigger'] );
Expand Down
Loading