Skip to content

Commit 5c50982

Browse files
authored
Merge pull request #428 from creativecommons/retention-period
New rejection policy & data retention period
2 parents 1e0881c + abcc509 commit 5c50982

7 files changed

+193
-24
lines changed

plugins/cc-global-network/admin/user-application-page.php

+50
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,55 @@ function ccgn_application_mc_review_form ( $applicant_id ) {
215215
);
216216
}
217217
}
218+
function ccgn_application_institutional_agreement_form ( $applicant_id, $state ) {
219+
if ( ccgn_current_user_is_legal_team() && ($state == CCGN_APPLICATION_STATE_LEGAL ) ) {
220+
echo '<h2>Institutional Agreement</h2>';
221+
$institutional_agreement_meta = get_user_meta($applicant_id, 'ccgn-institutional-agreement', true);
222+
if (!empty($institutional_agreement_meta) && ($institutional_agreement_meta['status'] == 'sent-agreement')) {
223+
$now = new DateTime('now');
224+
$agreement_date = new DateTime($institutional_agreement_meta['date']);
225+
echo '<p>Agreement sent: '.date('Y-m-d',strtotime($institutional_agreement_meta['date'])).' ('.$agreement_date->diff($now)->days.' days ago)';
226+
}
227+
$existing_entry = ccgn_entries_referring_to_user (
228+
$applicant_id,
229+
CCGN_GF_INSTITUTIONAL_AGREEMENT,
230+
CCGN_GF_INSTITUTIONAL_AGREEMENT_ID
231+
)[0];
232+
gravity_form(
233+
CCGN_GF_INSTITUTIONAL_AGREEMENT,
234+
false,
235+
false,
236+
false,
237+
array(
238+
CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX_PARAMETER
239+
=> $existing_entry[
240+
CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX
241+
],
242+
CCGN_GF_INSTITUTIONAL_AGREEMENT_ID_PARAMETER
243+
=> $applicant_id
244+
)
245+
);
246+
}
247+
}
248+
function ccgn_application_institutional_agreement_submit_handler( $entry, $form ) {
249+
if ( $form[ 'title' ] == CCGN_GF_INSTITUTIONAL_AGREEMENT ) {
250+
$applicant_id = $entry[ CCGN_GF_INSTITUTIONAL_AGREEMENT_ID ];
251+
if ($entry[ CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX ] == 'yes') {
252+
//The institutional agreement has been sent
253+
$institutional_agreement_meta = array(
254+
'status' => 'sent-agreement',
255+
'date' => date('Y-m-d H:i:s', strtotime('now')),
256+
);
257+
update_user_meta($applicant_id, 'ccgn-institutional-agreement', $institutional_agreement_meta);
258+
} else {
259+
$institutional_agreement_meta = array(
260+
'status' => 'agreement-not-sent',
261+
'date' => date('Y-m-d H:i:s', strtotime('now')),
262+
);
263+
update_user_meta($applicant_id, 'ccgn-institutional-agreement', $institutional_agreement_meta);
264+
}
265+
}
266+
}
218267
function ccgn_application_mc_review_submit_handler( $entry, $form ) {
219268
if ( $form[ 'title' ] == CCGN_GF_MC_REVIEW ) {
220269
$applicant_id = $entry[ CCGN_GF_MC_REVIEW_APPLICANT_ID ];
@@ -811,6 +860,7 @@ function ccgn_application_users_page () {
811860
ccgn_application_users_page_render_details( $applicant_id, $state );
812861
ccgn_application_users_page_render_state( $applicant_id, $state );
813862
if ( ccgn_user_is_institutional_applicant( $applicant_id ) ) {
863+
ccgn_application_institutional_agreement_form( $applicant_id, $state );
814864
ccgn_application_format_legal_approval( $applicant_id, $state );
815865
}
816866
}

plugins/cc-global-network/cc-global-network.php

+21
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
require_once CCGN_PATH . 'cron/email-vouch-request-reminders.php';
7474
require_once CCGN_PATH . 'cron/email-update-vouchers-reminders.php';
7575
require_once CCGN_PATH . 'cron/email-update-details-reminders.php';
76+
require_once CCGN_PATH . 'cron/remove-marked-users.php';
7677

7778

7879
// Testing support
@@ -254,6 +255,13 @@ function ccgn_sanitize_user_not_strict($user, $raw_user, $strict)
254255
2
255256
);
256257

258+
add_action(
259+
'gform_after_submission',
260+
'ccgn_application_institutional_agreement_submit_handler',
261+
10,
262+
2
263+
);
264+
257265
////////////////////////////////////////////////////////////////////////////////
258266
// Forms for existing members
259267
////////////////////////////////////////////////////////////////////////////////
@@ -381,6 +389,19 @@ function ccgn_sanitize_user_not_strict($user, $raw_user, $strict)
381389
'ccgn_schedule_remove_email_update_details_reminders'
382390
);
383391

392+
add_action(
393+
'ccgn_check_accounts_to_be_removed',
394+
'ccgn_check_accounts_to_be_removed'
395+
);
396+
register_activation_hook(
397+
__FILE__,
398+
'ccgn_schedule_add_retention_data'
399+
);
400+
register_deactivation_hook(
401+
__FILE__,
402+
'ccgn_schedule_remove_retention_data'
403+
);
404+
384405
////////////////////////////////////////////////////////////////////////////////
385406
// Admin script && styles
386407
////////////////////////////////////////////////////////////////////////////////

plugins/cc-global-network/cron/email-update-details-reminders.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
// Be careful changing this value, you may send a reminder sooner than expected
2020
// Also beware any knock-on effect on CCGN_CLOSE_UPDATE_VOUCHERS_AFTER_DAYS
2121
define('CCGN_FIRST_REMINDER_UPDATE_DETAILS_AFTER_DAYS', 7);
22-
define('CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS', CCGN_FIRST_REMINDER_UPDATE_DETAILS_AFTER_DAYS + 7);
23-
//define('CCGN_SEND_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS', CCGN_SEND_REMINDER_UPDATE_DETAILS_AFTER_DAYS + 3 );
24-
define( 'CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS', CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS + 10 );
22+
define('CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS', 7);
23+
define( 'CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS', 10 );
2524

2625
////////////////////////////////////////////////////////////////////////////////
2726
// Checking and sending
@@ -61,7 +60,7 @@ function ccgn_update_details_set_second_reminder( $applicant_id ) {
6160
update_user_meta($applicant_id, 'ccgn_applicant_update_details_state', $update_details_meta);
6261
}
6362

64-
// Send reminders to those that need them
63+
// Send reminders to those who need them
6564

6665
function ccgn_email_update_details_reminders()
6766
{
@@ -70,34 +69,36 @@ function ccgn_email_update_details_reminders()
7069
CCGN_APPLICATION_STATE_UPDATE_DETAILS
7170
);
7271
foreach ($applicants as $applicant_id) {
72+
$now = new DateTime( 'now' );
7373
$status = get_user_meta($applicant_id, 'ccgn_applicant_update_details_state', true);
74-
$state_date = new DateTime($status['date']);
74+
if (!empty($status)) {
75+
$state_date = new DateTime($status['date']);
76+
} else {
77+
$state_date = get_user_meta($applicant_id, CCGN_APPLICATION_STATE_DATE, true);
78+
}
7579
$days_in_state = $state_date->diff($now)->days;
76-
if ($days_in_state > CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS) {
77-
if ( ($status['state'] == 'second-reminder') && ($status['done']) ) {
80+
$current_state = $status['state'];
81+
if ( ( ($current_state == 'none') || (empty($current_state))) && ($days_in_state < CCGN_FIRST_REMINDER_UPDATE_DETAILS_AFTER_DAYS) ) {
82+
ccgn_update_details_set_first_reminder($applicant_id);
83+
} elseif ( ( ($current_state == 'first-reminder') ) && ($days_in_state < CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS) ) {
84+
ccgn_update_details_set_second_reminder($applicant_id);
85+
} elseif ( $days_in_state > CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS ) {
86+
if ( ($current_state == 'second-reminder') && ($status['done']) ) {
7887
ccgn_close_update_details_applicant($applicant_id);
79-
} elseif ( $status['state'] == 'none' ) {
88+
}
89+
elseif ( $status['state'] == 'none' ) {
8090
ccgn_update_details_set_first_reminder($applicant_id);
8191
} elseif ( $status['state'] == 'first-reminder' ) {
8292
ccgn_update_details_set_second_reminder($applicant_id);
8393
} else {
8494
//update user status date
95+
ccgn_update_details_set_first_reminder($applicant_id);
8596
update_user_meta(
8697
$applicant_id,
8798
CCGN_APPLICATION_STATE_DATE,
8899
date('Y-m-d H:i:s', strtotime('now'))
89100
);
90101
}
91-
} elseif ( ($days_in_state > CCGN_FIRST_REMINDER_UPDATE_DETAILS_AFTER_DAYS) && ($days_in_state <= CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS) ) {
92-
// Send first reminder
93-
if (empty($status['state'])) {
94-
ccgn_update_details_set_first_reminder($applicant_id);
95-
}
96-
} elseif ( ($days_in_state > CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS) && ($days_in_state <= CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS) ) {
97-
// Send second reminder
98-
if (($status['state'] == 'first-reminer') && ($status['done'])) {
99-
ccgn_update_details_set_second_reminder($applicant_id);
100-
}
101102
}
102103
}
103104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
defined('ABSPATH') or die('No script kiddies please!');
4+
5+
/*
6+
This script checks for accounts who needs to be removed according to the new rejection policy
7+
- Applications which were not completed/submitted
8+
- Applications which failed to update their vouchers
9+
- Applications which were rejected by the Membership Committee (30 days after the rejection was sent)
10+
11+
This code may close an application!
12+
*/
13+
14+
////////////////////////////////////////////////////////////////////////////////
15+
// Defines
16+
////////////////////////////////////////////////////////////////////////////////
17+
18+
// Be careful changing this value, you may send a reminder sooner than expected
19+
define('CCGN_REMOVE_APPLICATION_AFTER_DAYS', 30);
20+
21+
22+
////////////////////////////////////////////////////////////////////////////////
23+
// Checking and sending
24+
////////////////////////////////////////////////////////////////////////////////
25+
26+
// remove accounts after retention period
27+
28+
function ccgn_close_and_remove_retention_data_applicant($applicant_id)
29+
{
30+
_ccgn_application_delete_entries_created_by($applicant_id);
31+
delete_user_meta($applicant_id, CCGN_APPLICATION_TYPE);
32+
delete_user_meta($applicant_id, CCGN_APPLICATION_STATE);
33+
delete_user_meta($applicant_id, CCGN_USER_IS_AUTOVOUCHED);
34+
35+
$delete = wp_delete_user($applicant_id);
36+
}
37+
38+
39+
function ccgn_check_accounts_to_be_removed()
40+
{
41+
$states_to_delete = array(
42+
CCGN_APPLICATION_STATE_DELETE,
43+
CCGN_APPLICATION_STATE_DIDNT_UPDATE_VOUCHERS,
44+
CCGN_APPLICATION_STATE_CHARTER,
45+
CCGN_APPLICATION_STATE_DETAILS,
46+
CCGN_APPLICATION_STATE_LEGAL
47+
);
48+
$now = new DateTime('now');
49+
foreach ($states_to_delete as $state) {
50+
$applicants = ccgn_applicant_ids_with_state( $state );
51+
foreach ($applicants as $applicant_id) {
52+
if ( $state == CCGN_APPLICATION_STATE_LEGAL) {
53+
$stage = get_user_meta($applicant_id, 'ccgn-institutional-agreement', true);
54+
if (!empty($stage) && ($stage['status'] == 'sent-agreement')) {
55+
$agreement_date = new DateTime($stage['date']);
56+
$days_in_state = $agreement_date->diff($now)->days;
57+
if ($days_in_state > CCGN_REMOVE_APPLICATION_AFTER_DAYS) {
58+
ccgn_close_and_remove_retention_data_applicant($applicant_id);
59+
}
60+
}
61+
} else {
62+
$status_date = get_user_meta($applicant_id, 'ccgn-application-state-date', true);
63+
$state_date = new DateTime($status_date);
64+
$days_in_state = $state_date->diff($now)->days;
65+
if ($days_in_state > CCGN_REMOVE_APPLICATION_AFTER_DAYS) {
66+
ccgn_close_and_remove_retention_data_applicant($applicant_id);
67+
}
68+
}
69+
}
70+
}
71+
}
72+
73+
function ccgn_schedule_add_retention_data()
74+
{
75+
if (!wp_next_scheduled('ccgn_check_accounts_to_be_removed')) {
76+
wp_schedule_event(
77+
time(),
78+
'daily',
79+
'ccgn_check_accounts_to_be_removed'
80+
);
81+
}
82+
}
83+
84+
function ccgn_schedule_remove_retention_data()
85+
{
86+
wp_clear_scheduled_hook('ccgn_check_accounts_to_be_removed');
87+
}

plugins/cc-global-network/includes/application-state.php

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function ccgn_applicant_type_desc ( $user_id ) {
106106
);
107107
// This application state happens when a member reject the applicant who asked for vouch, voting 'NO'
108108
define( 'CCGN_APPLICATION_STATE_REVIEW', 'to-be-reviewed' );
109+
// This state applies to the new data retention policy, which should retain the data for no more than 30 days
110+
define('CCGN_APPLICATION_STATE_DELETE', 'to-be-deleted' );
111+
//legal is waiting for institutional agreement 30 days countdown to be deleted
112+
define('CCGN_APPLICATION_STATE_INSTITUTIONAL_AGREEMENT', 'waiting-institutional-agreement' );
113+
109114
define(
110115
'CCGN_APPLICATION_STATE_CAN_BE_PRE_APPROVED',
111116
[

plugins/cc-global-network/includes/buddypress-integration.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,11 @@ function _ccgn_user_level_set_autouvouched_interim_membership_council (
772772
/* Rejected account should be deleted. There's no need to keep this data on the website **/
773773
function ccgn_user_level_set_rejected ( $user_id ) {
774774

775-
_ccgn_application_delete_entries_created_by($user_id);
776-
delete_user_meta($user_id, CCGN_APPLICATION_TYPE);
777-
delete_user_meta($user_id, CCGN_APPLICATION_STATE);
778-
delete_user_meta($user_id, CCGN_USER_IS_AUTOVOUCHED);
779-
780-
$delete = wp_delete_user($user_id);
775+
//regarding to the new rejection policy and the data retencion period this is changed to this state which should be deleted after 30 days
776+
ccgn_registration_user_set_stage(
777+
$user_id,
778+
CCGN_APPLICATION_STATE_DELETE
779+
);
781780
}
782781

783782
function ccgn_user_level_set_didnt_update_vouchers ( $user_id ) {

plugins/cc-global-network/includes/gravityforms-interaction.php

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
define('CCGN_GF_VOUCH', 'Vouch For Applicant');
3333
define('CCGN_GF_MC_REVIEW', 'MC user review');
34+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT', 'Institutional Agreement');
3435

3536
// Admin approval of applicant
3637

@@ -208,6 +209,11 @@
208209
define('CCGN_GF_MC_REVIEW_NOTE_PARAMETER', 'mc-review-note');
209210
define('CCGN_GF_MC_REVIEW_APPLICANT_ID_PARAMETER', 'applicant_id');
210211

212+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX', '1.1');
213+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX_PARAMETER', 'institutional_agreement_sent');
214+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_ID', '2');
215+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_ID_PARAMETER', 'applicant_id');
216+
211217
// Field values that we need to check
212218

213219
define('CCGN_GF_VOUCH_DO_YOU_VOUCH_YES', 'Yes');

0 commit comments

Comments
 (0)