Skip to content
New issue

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

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

Already on GitHub? # to your account

Drupal feature to add tag to subject line of admin notifications #3096

Merged
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
200 changes: 105 additions & 95 deletions drupal/sites/all/features/boinc_standard/boinc_standard.features.inc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ features[role_export][] = "administrator"
features[role_export][] = "community_member"
features[role_export][] = "content_editor"
features[role_export][] = "verified_contributor"
features[rules_categories][] = "moderator notification"
features[rules_categories][] = "admin notification"
features[rules_categories][] = "moderator notification"
features[user_permission][] = "Use PHP input for field settings (dangerous - grant with care)"
features[user_permission][] = "access administration pages"
features[user_permission][] = "access all views"
Expand Down
10 changes: 6 additions & 4 deletions drupal/sites/all/features/teams/teams.features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ function teams_rules_defaults() {
'#type' => 'action',
'#settings' => array(
'from' => '',
'subject' => '[drupal-error] Error creating new team',
'subject' => '[subject_tag:string] Error creating new team',
'message' => '[user:display-name] attempted to create team [team_name:string], but an error was returned. See function \'boincteam_create_form_submit\'. BOINC function \'make_team\' did not return a valid boinc_team object.',
'#eval input' => array(
'token_rules_input_evaluator' => array(
'subject' => array(
'0' => ':global',
'0' => 'subject_tag',
'1' => ':global',
),
'message' => array(
'0' => 'team_name',
Expand Down Expand Up @@ -106,12 +107,13 @@ function teams_rules_defaults() {
'#type' => 'action',
'#settings' => array(
'from' => '',
'subject' => '[drupal-error] Error creating BOINC team - no pathauo module',
'subject' => '[subject_tag:string] Error creating BOINC team - no pathauo module',
'message' => '[user:display-name] attempted to create team [team_name:string], but no pathauto module detected. See function \'boincteam_create_form_submit\'.',
'#eval input' => array(
'token_rules_input_evaluator' => array(
'subject' => array(
'0' => ':global',
'0' => 'subject_tag',
'1' => ':global',
),
'message' => array(
'0' => 'team_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function boinccore_admin_community(&$form_state) {
'min_credit_to_post' => variable_get('boinc_comment_min_credit', 0),
'penalty_period' => variable_get('boinc_penalty_period', 7*24*60*60),
'moderator_mailing_list' => variable_get('boinc_moderator_mailing_list', ''),
'admin_mailing_list' => variable_get('boinc_admin_mailing_list', ''),
'moderator_force_individual_notifications' => variable_get('boinc_moderator_force_individual_notifications', 0),
);

Expand Down Expand Up @@ -51,13 +50,6 @@ function boinccore_admin_community(&$form_state) {
emails even when a mailing list is provided.'),
);

$form['boinc_admin_mailing_list'] = array(
'#type' => 'textfield',
'#title' => t('Admin mailing list'),
'#default_value' => $default['admin_mailing_list'],
'#description' => t('Enter an email-address which will be used to contact admisistrators. If empty, the site email configured in Settings -> Site Information will be used.'),
);

$form['tools'] = array(
'#title' => t('Tools'),
'#type' => 'fieldset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function boincteam_create_form_submit($form, &$form_state) {
}
else {
drupal_set_message(t('Teams cannot be created at this time. The @project administrators have been notified.', array('@project' => PROJECT)));
rules_invoke_event('boincteam_create_team_error', $values['name']);
rules_invoke_event('boincteam_create_team_error', $values['name'], variable_get('boinc_admin_mailing_list_subject_tag', ''));
watchdog('BOINC team', 'BOINC teams cannot be created for an unknown
reason.', 'error');
return FALSE;
Expand Down Expand Up @@ -215,7 +215,7 @@ function boincteam_create_form_submit($form, &$form_state) {
}
else {
drupal_set_message(t('Teams cannot be created at this time. The @project administrators have been notified.', array('@project' => PROJECT)));
rules_invoke_event('boincteam_create_team_nopathauto_error', $values['name']);
rules_invoke_event('boincteam_create_team_nopathauto_error', $values['name'], variable_get('boinc_admin_mailing_list_subject_tag', ''));
watchdog('BOINC team', 'BOINC teams require the Pathauto module. Teams
cannot be created.', 'error');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,15 @@ function rules_events_hook_boincteam_arguments() {
'label' => 'team name',
'required' => TRUE,
),
) + rules_events_global_user_argument();
) + rules_events_hook_boincteam_adminnotify_argument();
}

function rules_events_hook_boincteam_adminnotify_argument() {
return array(
'subject_tag' => array(
'type' => 'string',
'label' => 'Subject tag for email filtering',
'required' => TRUE,
),
) + rules_events_global_user_argument();
}
14 changes: 14 additions & 0 deletions drupal/sites/default/boinc/modules/boincuser/boincuser.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function boincuser_admin_environment(&$form_state) {
'boinc_host_sched_logs_dir' => variable_get('boinc_host_sched_logs_dir', ''),
'boinc_server_status_url' => variable_get('boinc_server_status_url', ''),
'boinc_app_list_url' => variable_get('boinc_app_list_url', ''),
'boinc_admin_mailing_list' => variable_get('boinc_admin_mailing_list', ''),
'boinc_admin_mailing_list_subject_tag' => variable_get('boinc_admin_mailing_list_subject_tag', ''),
'boinc_debug_mode' => variable_get('boinc_debug_mode', 0),
'boinc_project_config_keywords' => variable_get('boinc_project_config_keywords', ''),
);
Expand Down Expand Up @@ -142,6 +144,18 @@ function boincuser_admin_environment(&$form_state) {
'#default_value' => $default['boinc_host_sched_logs_dir'],
'#description' => t('The filesystem directory that contains host scheduler logs'),
);
$form['boinc_admin_mailing_list'] = array(
'#type' => 'textfield',
'#title' => t('Admin mailing list'),
'#default_value' => $default['boinc_admin_mailing_list'],
'#description' => t('Enter an email-address which will be used to contact admisistrators. If empty, the site email configured in Settings -> Site Information will be used.'),
);
$form['boinc_admin_mailing_list_subject_tag'] = array(
'#type' => 'textfield',
'#title' => t('Admin mailing list - subject tag'),
'#default_value' => $default['boinc_admin_mailing_list_subject_tag'],
'#description' => t('Text which will appear at the beginning of the subject for any admin notification emails. If empty, no tag will be included. Examples: [drupal-error].'),
);
$form['boinc_debug_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Show debug messages in system log'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function boincuser_delete_validate($form, &$form_state) {
$account = $form_state['values']['_account'];
$boinc_user = boincuser_load($account->uid, TRUE);
if (!$boinc_user) {
rules_invoke_event('boincuser_delete_general_error');
rules_invoke_event('boincuser_delete_general_error', variable_get('boinc_admin_mailing_list_subject_tag', ''));
return form_set_error('current_pass',
bts('There was a problem deleting your account. The @project administrators have been contacted.',
array(
Expand Down Expand Up @@ -314,7 +314,7 @@ function boincuser_delete_submit($form, &$form_state) {
$account = user_load(array('uid' => $uid));

if (!$account) {
rules_invoke_event('boincuser_delete_uid_invalid_error');
rules_invoke_event('boincuser_delete_uid_invalid_error', variable_get('boinc_admin_mailing_list_subject_tag', ''));
drupal_set_message(
bts('ERROR: The user account @uid does not exist. The @project administrators have been notified.',
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ function boincuser_delete_rules_event_info() {
'boincuser_delete_general_error' => array(
'label' => bts('Error from user deleting own account.', array(), NULL, 'boinc:rule-event'),
'module' => 'Boincuser_Delete',
'arguments' => rules_events_global_user_argument(),
'arguments' => rules_events_hook_boincuser_adminnotify_argument(),
),
'boincuser_delete_uid_invalid_error' => array(
'label' => bts('Error from user deleting own account. User ID is invalid', array(), NULL, 'boinc:rule-event'),
'module' => 'Boincuser_Delete',
'arguments' => rules_events_global_user_argument(),
'arguments' => rules_events_hook_boincuser_adminnotify_argument(),
),
);
}

// function rules_events_hook_boincuser_adminnotify_argument is located in boincuser_rules.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function boincuser_register_validate($form, &$form_state) {
$tmp_user = BoincUser::lookup_prev_email_addr($lower_email_addr);
if ($tmp_user) {
// User already exists
rules_invoke_event('boincuser_change_email_error', $lower_email_addr);
rules_invoke_event('boincuser_change_email_error', $lower_email_addr, variable_get('boinc_admin_mailing_list_subject_tag', ''));
form_set_error('mail',
bts('An account already exists for @email. The @project administrators have been notified.',
array(
Expand Down Expand Up @@ -868,7 +868,7 @@ function boincuser_revertemail_validate($form, &$form_state) {
$boinc_user = BoincUser::lookup_id_nocache($account->boincuser_id);

if (BoincUser::lookup_email_addr($boinc_user->previous_email_addr)) {
rules_invoke_event('boincuser_revert_email_error', $boinc_user->previous_email_addr);
rules_invoke_event('boincuser_revert_email_error', $boinc_user->previous_email_addr, variable_get('boinc_admin_mailing_list_subject_tag', ''));
form_set_error('mail',
bts('An account already exists for @email. Previous email address cannot be used because another account is using it as their email address. The @project administrators have been notified.',
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function boincuser_consentto_termsofuse($user) {
),
'NULL', 'boinc:consent-termsofuse'),
'error');
rules_invoke_event('boincuser_general_consent_error');
rules_invoke_event('boincuser_general_consent_error', variable_get('boinc_admin_mailing_list_subject_tag', ''));
}
return $rc1;
}
Expand All @@ -363,7 +363,7 @@ function boincuser_consentto_termsofuse($user) {
bts('ERROR: Consent type for enrollment not found. The @project administrators have been nofitifed.',
array('@project' => variable_get('site_name', 'Drupal-BOINC')), NULL, 'boinc:consent-termsofuse'),
'error');
rules_invoke_event('boincuser_general_consent_type_error', CONSENT_TYPE_ENROLL);
rules_invoke_event('boincuser_general_consent_type_error', CONSENT_TYPE_ENROLL, variable_get('boinc_admin_mailing_list_subject_tag', ''));
}
return FALSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function boincuser_rules_event_info() {
'boincuser_general_consent_error' => array(
'label' => bts('Error from user consenting to terms-of-use.', array(), NULL, 'boinc:rule-event'),
'module' => 'Boincuser',
'arguments' => rules_events_global_user_argument(),
'arguments' => rules_events_hook_boincuser_adminnotify_argument(),
),
'boincuser_general_consent_type_error' => array(
'label' => bts('Error dealing with missing consent type.', array(), NULL, 'boinc:rule-event'),
Expand All @@ -50,7 +50,7 @@ function rules_events_hook_boincuser_chemail_arguments() {
'label' => 'New email address',
'required' => TRUE,
),
) + rules_events_global_user_argument();
) + rules_events_hook_boincuser_adminnotify_argument();
}

function rules_events_hook_boincuser_consenttype_argument() {
Expand All @@ -60,5 +60,15 @@ function rules_events_hook_boincuser_consenttype_argument() {
'label' => 'Consent type id that caused the error',
'required' => TRUE,
),
) + rules_events_hook_boincuser_adminnotify_argument();
}

function rules_events_hook_boincuser_adminnotify_argument() {
return array(
'subject_tag' => array(
'type' => 'string',
'label' => 'Subject tag for email filtering',
'required' => TRUE,
),
) + rules_events_global_user_argument();
}
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ function boincwork_host_merge($old_host, $new_host, &$message = NULL) {
$recent_credit = $old_host->expavg_credit + $new_host->expavg_credit;

if ($new_host->rpc_seqno == $old_host->id) {
rules_invoke_event('boincwork_circular_merge_error', $old_host->id, $new_host->id);
rules_invoke_event('boincwork_circular_merge_error', $old_host->id, $new_host->id, variable_get('boinc_admin_mailing_list_subject_tag', ''));
watchdog('boincwork',
'Circular merge attempted, target host rpc_seqno is equal to old host\'s id: old host id=%old_host, target host id=%new_host',
array(
Expand All @@ -785,7 +785,7 @@ function boincwork_host_merge($old_host, $new_host, &$message = NULL) {
}

if ($new_host->userid==0) {
rules_invoke_event('boincwork_zombie_merge_error', $old_host->id, $new_host->id);
rules_invoke_event('boincwork_zombie_merge_error', $old_host->id, $new_host->id, variable_get('boinc_admin_mailing_list_subject_tag', ''));
watchdog('boincwork',
'Zombie merge attempted, target host has userid=0: old host id=%old_host, target host id=%new_host',
array(
Expand Down Expand Up @@ -1727,7 +1727,7 @@ function communityprefs_form_submit($form, &$form_state) {
user_save($user, $settings);

drupal_set_message(bts('Your community preferences have been updated.', array(), NULL, 'boinc:account-preferences-community'));

// Form will not redirect if storage is set; not good if language changes
unset($form_state['storage']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ function rules_events_hook_boincwork_arguments() {
'label' => 'target host id',
'required' => TRUE,
),
) + rules_events_global_user_argument();
) + rules_events_hook_boincwork_adminnotify_argument();
}

function rules_events_hook_boincwork_adminnotify_argument() {
return array(
'subject_tag' => array(
'type' => 'string',
'label' => 'Subject tag for email filtering',
'required' => TRUE,
),
) + rules_events_global_user_argument();
}