Allow mailing list for moderator notification:

* Added general moderator notification rule
* Added moderator mailing list and individual notification preference to Community admin configuration form
* Updated node, comment, and user abuse flag actions to use the new moderator notification method
* Fixed bugs in comment abuse link that prevented the link from working or even appearing on the page

(DBOINCP-86)
This commit is contained in:
Tristan Olive 2015-05-05 01:10:33 -04:00
parent eb10d63ecc
commit dbfcdbb06e
5 changed files with 129 additions and 65 deletions

View File

@ -199,58 +199,59 @@ function boinc_standard_rules_defaults() {
return array(
'rules' => array(
'rules_offensive_comment_reported' => array(
'#type' => 'rule',
'#set' => 'event_flag_flagged_abuse_comment',
'#label' => 'Offensive comment reported',
'#active' => 1,
'#weight' => '0',
'#categories' => array(
'0' => 'moderator notification',
'1' => 'boinc_standard',
),
'#status' => 'default',
'#conditions' => array(),
'#actions' => array(
'0' => array(
'1' => array(
'#info' => array(
'label' => 'Notify moderators via email',
'module' => 'BOINC core',
'eval input' => array(
'0' => 'from',
'0' => 'subject',
'1' => 'message',
'2' => 'subject',
'2' => 'from',
),
'label' => 'Send a mail to all users of a role',
'module' => 'System',
),
'#name' => 'rules_action_mail_to_users_of_role',
'#name' => 'boinccore_rules_action_mail_to_moderators',
'#settings' => array(
'from' => '',
'subject' => 'Report of offensive [node:type] comment at [:global:site-name]',
'message' => '[flagging_user:display-name] has reported the following comment on [node:type] content as being offensive or inappropriate for the [:global:site-name] site:
[:global:site-url]goto/comment/[comment:comment-cid]
Total reports of this comment: [comment:flag-abuse-comment-count]',
'#eval input' => array(
'token_rules_input_evaluator' => array(
'from' => array(
'0' => ':global',
'subject' => array(
'0' => 'node',
'1' => ':global',
),
'message' => array(
'0' => ':global',
'0' => 'flagging_user',
'1' => 'comment',
'2' => 'flagging_user',
'3' => 'node',
'2' => 'node',
'3' => ':global',
),
'subject' => array(
'from' => array(
'0' => ':global',
'1' => 'node',
),
),
),
'message' => '[flagging_user:display-name] has reported the following comment on [node:type] content as being offensive or inappropriate for the [:global:site-name] site:
[:global:site-url]goto/comment/[comment:comment-cid]
Total reports of this comment: [comment:flag-abuse-comment-count]',
'recipients' => array(
'0' => 1271379760,
),
'subject' => 'Report of offensive [node:type] comment at [:global:site-name]',
),
'#type' => 'action',
),
),
'#active' => 1,
'#categories' => array(
'0' => 'boinc_standard',
'1' => 'moderator notification',
),
'#label' => 'Offensive comment reported',
'#set' => 'event_flag_flagged_abuse_comment',
'#status' => 'default',
'#type' => 'rule',
),
'#type' => 'action',
'#weight' => 0,
),
),
'#version' => 6003,
),
'rules_offensive_content_reported' => array(
@ -266,22 +267,9 @@ Total reports of this comment: [comment:flag-abuse-comment-count]',
'#status' => 'default',
'#conditions' => array(),
'#actions' => array(
'0' => array(
'#weight' => 0,
'#info' => array(
'label' => 'Send a mail to all users of a role',
'module' => 'System',
'eval input' => array(
'0' => 'subject',
'1' => 'message',
'2' => 'from',
),
),
'#name' => 'rules_action_mail_to_users_of_role',
'1' => array(
'#type' => 'action',
'#settings' => array(
'recipients' => array(
'0' => 1271379760,
),
'from' => '',
'subject' => 'Report of offensive [node:type] content at [:global:site-name]',
'message' => '[flagging_user:display-name] has reported the following [node:type] content as being offensive or inappropriate for the [:global:site-name] site:
@ -306,7 +294,17 @@ Total reports of this content: [node:flag-abuse-node-count]',
),
),
),
'#type' => 'action',
'#name' => 'boinccore_rules_action_mail_to_moderators',
'#info' => array(
'label' => 'Notify moderators via email',
'module' => 'BOINC core',
'eval input' => array(
'0' => 'subject',
'1' => 'message',
'2' => 'from',
),
),
'#weight' => 0,
),
),
'#version' => 6003,
@ -324,13 +322,9 @@ Total reports of this content: [node:flag-abuse-node-count]',
'#status' => 'default',
'#conditions' => array(),
'#actions' => array(
'0' => array(
'#weight' => 0,
'1' => array(
'#type' => 'action',
'#settings' => array(
'recipients' => array(
'0' => 1271379760,
),
'from' => '',
'subject' => 'Report of offensive user at [:global:site-name]',
'message' => '[flagging_user:display-name] has reported [account:display-name] for inappropriate behavior:
@ -354,16 +348,17 @@ Total current reports of this user: [account:flag-abuse-user-count]',
),
),
),
'#name' => 'rules_action_mail_to_users_of_role',
'#name' => 'boinccore_rules_action_mail_to_moderators',
'#info' => array(
'label' => 'Send a mail to all users of a role',
'module' => 'System',
'label' => 'Notify moderators via email',
'module' => 'BOINC core',
'eval input' => array(
'0' => 'subject',
'1' => 'message',
'2' => 'from',
),
),
'#weight' => 0,
),
),
'#version' => 6003,

View File

@ -39,7 +39,6 @@ dependencies[] = "rules"
dependencies[] = "rules_admin"
dependencies[] = "smtp"
dependencies[] = "strongarm"
dependencies[] = "system"
dependencies[] = "tableofcontents"
dependencies[] = "tabtamer"
dependencies[] = "taxonomy"

View File

@ -15,6 +15,8 @@ function boinccore_admin_community(&$form_state) {
$default = array(
'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', ''),
'moderator_force_individual_notifications' => variable_get('boinc_moderator_force_individual_notifications', 0),
);
// Define the form
@ -32,6 +34,21 @@ function boinccore_admin_community(&$form_state) {
'#description' => t('The amount of time (in seconds) that user privileges
are revoked when a user is banned from community participation.'),
);
$form['boinc_moderator_mailing_list'] = array(
'#type' => 'textfield',
'#title' => t('Moderator mailing list'),
'#default_value' => $default['moderator_mailing_list'],
'#description' => t('As an alternative to sending moderator notifications
to individual users with the moderator role, enter a mailing list address
here to be the only target of the notification emails.'),
);
$form['boinc_moderator_force_individual_notifications'] = array(
'#type' => 'checkbox',
'#title' => t('Always send individual notifications'),
'#default_value' => $default['moderator_force_individual_notifications'],
'#description' => t('Continue to send individual moderator notification
emails even when a mailing list is provided.'),
);
return system_settings_form($form);
}

View File

@ -94,6 +94,19 @@ function boinccore_enable() {
boinccore_admin_default_content_generate();
}
/**
* Implementation of hook_rules_action_info().
*/
function boinccore_rules_action_info() {
return array(
'boinccore_rules_action_mail_to_moderators' => array(
'label' => t('Notify moderators via email'),
'module' => 'BOINC core',
'eval input' => array('subject', 'message', 'from'),
),
);
}
/**
* Implementation of hook_form_alter()
*/
@ -683,6 +696,43 @@ function boinccore_get_country_list() {
);
}
/**
* Action: Send mail to moderators.
*/
function boinccore_rules_action_mail_to_moderators($settings) {
$mailing_list = variable_get('boinc_moderator_mailing_list', '');
$force_individual_notifications = variable_get('boinc_moderator_force_individual_notifications', 0);
if (!$mailing_list OR $force_individual_notifications) {
// Send individual emails to all moderators
$roles = user_roles();
$moderator_rid = array_search('moderator', $roles);
if ($moderator_rid !== FALSE) {
$settings['recipients'] = array($moderator_rid);
rules_action_mail_to_users_of_role($settings);
}
else {
watchdog(
'boinccore',
'Unable to identify members of the moderator role to send moderator notifications!',
array(),
WATCHDOG_ERROR
);
}
}
if ($mailing_list) {
$settings['to'] = $mailing_list;
rules_action_mail($settings);
}
}
/**
* Action "Send mail to moderators" configuration form
*/
function boinccore_rules_action_mail_to_moderators_form($settings = array(), &$form) {
// Select only non-anonymous user roles because anonymous users won't have emails.
rules_action_mail_to_user_form($settings, $form);
}
/*
* BOINC wrapper for string translation
*/

View File

@ -408,11 +408,14 @@ function boinc_preprocess_comment(&$vars, $hook) {
$vars['links'] = theme_links($links);
if ($user->uid) {
$report_comment_link = '' .
'<ul class="links">';
'<li class="first">' . flag_create_link('abuse_comment', $comment->cid) . '</li>' .
'</ul>';
$vars['links'] = $report_comment_link . $vars['links'];
$abuse_link = flag_create_link('abuse_comment', $cid);
if ($abuse_link) {
$report_comment_link = '' .
'<ul class="links">' .
'<li class="first">' . $abuse_link . '</li>' .
'</ul>';
$vars['links'] = $report_comment_link . $vars['links'];
}
}
// Show signatures based on user preference