Enable message email notification

Enable email notification of private messages, add a new
user/%user/message-settings form to override default
email settings for authorized users.

Change-Id: I13c629f4fbf2790d5a6fc8a1333e607a42beca3f
This commit is contained in:
Marton Kiss 2015-09-01 17:04:42 +02:00
parent 49f3f19d11
commit 079b22f2b3
10 changed files with 264 additions and 0 deletions

View File

@ -378,6 +378,10 @@ projects[privatemsg][patch][] = "http://drupal.org/files/privatemsg-1573000-64.p
; https://drupal.org/node/2070719
projects[privatemsg][patch][] = "http://drupal.org/files/2077223-privatemsg-realname-enabled-1.patch"
projects[privatemsg_notify_sender][type] = "module"
projects[privatemsg_notify_sender][subdir] = "contrib"
projects[privatemsg_notify_sender][version] = "1.1"
projects[quicktabs][type] = "module"
projects[quicktabs][subdir] = "contrib"
projects[quicktabs][version] = "3.6"

View File

@ -69,6 +69,7 @@ dependencies[] = paranoia
dependencies[] = pathauto
dependencies[] = privatemsg
dependencies[] = privatemsg_realname
dependencies[] = privatemsg_notify_sender
dependencies[] = quicktabs
dependencies[] = r4032login
dependencies[] = radioactivity

View File

@ -356,6 +356,18 @@ function groups_update_7119() {
drupal_flush_all_caches();
}
/**
* Enable groups messages and privatemsg_notify_sender contrib module.
*/
function groups_update_7120() {
if (!module_exists('groups_messages')) {
module_enable(array('groups_messages'));
}
if (!module_exists('privatemsg_notify_sender')) {
module_enable(array('privatemsg_notify_sender'));
}
drupal_flush_all_caches();
}
/**
* Set language negotiation to URL based.

View File

@ -308,6 +308,7 @@ function groups_install_additional_modules() {
'groups_reports',
'groups_wikis',
'groups_ambassador_pages',
'groups_messages',
);
// Resolve the dependencies now, so that module_enable() doesn't need
// to do it later for each individual module (which kills performance).

View File

@ -0,0 +1,14 @@
<?php
/**
* @file
* groups_messages.features.inc
*/
/**
* Implements hook_ctools_plugin_api().
*/
function groups_messages_ctools_plugin_api($module = NULL, $api = NULL) {
if ($module == "strongarm" && $api == "strongarm") {
return array("version" => "1");
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* @file
* groups_messages.features.user_permission.inc
*/
/**
* Implements hook_user_default_permissions().
*/
function groups_messages_user_default_permissions() {
$permissions = array();
// Exported permission: 'administer privatemsg settings'.
$permissions['administer privatemsg settings'] = array(
'name' => 'administer privatemsg settings',
'roles' => array(
'administrator' => 'administrator',
),
'module' => 'privatemsg',
);
// Exported permission: 'allow disabling privatemsg'.
$permissions['allow disabling privatemsg'] = array(
'name' => 'allow disabling privatemsg',
'roles' => array(
'community_manager' => 'community_manager',
),
'module' => 'privatemsg',
);
// Exported permission: 'delete privatemsg'.
$permissions['delete privatemsg'] = array(
'name' => 'delete privatemsg',
'roles' => array(
'authenticated user' => 'authenticated user',
),
'module' => 'privatemsg',
);
// Exported permission: 'read all private messages'.
$permissions['read all private messages'] = array(
'name' => 'read all private messages',
'roles' => array(
'administrator' => 'administrator',
),
'module' => 'privatemsg',
);
// Exported permission: 'read privatemsg'.
$permissions['read privatemsg'] = array(
'name' => 'read privatemsg',
'roles' => array(
'authenticated user' => 'authenticated user',
),
'module' => 'privatemsg',
);
// Exported permission: 'reply only privatemsg'.
$permissions['reply only privatemsg'] = array(
'name' => 'reply only privatemsg',
'roles' => array(
'community_manager' => 'community_manager',
),
'module' => 'privatemsg',
);
// Exported permission: 'select text format for privatemsg'.
$permissions['select text format for privatemsg'] = array(
'name' => 'select text format for privatemsg',
'roles' => array(
'community_manager' => 'community_manager',
),
'module' => 'privatemsg',
);
// Exported permission: 'use tokens in privatemsg'.
$permissions['use tokens in privatemsg'] = array(
'name' => 'use tokens in privatemsg',
'roles' => array(
'community_manager' => 'community_manager',
),
'module' => 'privatemsg',
);
// Exported permission: 'write privatemsg'.
$permissions['write privatemsg'] = array(
'name' => 'write privatemsg',
'roles' => array(
'authenticated user' => 'authenticated user',
),
'module' => 'privatemsg',
);
return $permissions;
}

View File

@ -0,0 +1,25 @@
name = Groups Messages
description = Groups messaging features privatemsg and notification addons
core = 7.x
package = Groups - Building Blocks
version = 7.x-1.0
project = groups_messages
dependencies[] = ctools
dependencies[] = features
dependencies[] = privatemsg
dependencies[] = strongarm
features[ctools][] = strongarm:strongarm:1
features[features_api][] = api:2
features[user_permission][] = administer privatemsg settings
features[user_permission][] = allow disabling privatemsg
features[user_permission][] = delete privatemsg
features[user_permission][] = read all private messages
features[user_permission][] = read privatemsg
features[user_permission][] = reply only privatemsg
features[user_permission][] = select text format for privatemsg
features[user_permission][] = use tokens in privatemsg
features[user_permission][] = write privatemsg
features[variable][] = pm_email_notify_body
features[variable][] = pm_email_notify_default
features[variable][] = pm_email_notify_from
features[variable][] = pm_email_notify_subject

View File

@ -0,0 +1,24 @@
<?php
/**
* @file
* Code for the Groups Messages feature.
*/
include_once 'groups_messages.features.inc';
/**
* Implements hook_menu().
*/
function groups_messages_menu() {
$items['user/%user/message-settings'] = array(
'title' => 'Message settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('groups_messages_message_settings_form', 1),
'access callback' => 'user_access',
'access arguments' => array('read privatemsg'),
'file' => 'includes/message_settings.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @file
* groups_messages.strongarm.inc
*/
/**
* Implements hook_strongarm().
*/
function groups_messages_strongarm() {
$export = array();
$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'pm_email_notify_body';
$strongarm->value = 'Hi [privatemsg_message:recipient],
This is an automatic reminder from the site [site:name]. You have received a new message from [privatemsg_message:author].
To read your message, follow this link:
[privatemsg_message:url]
If you don\'t want to receive these emails again, change your preferences here:
[privatemsg_message:recipient:edit-url]';
$export['pm_email_notify_body'] = $strongarm;
$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'pm_email_notify_default';
$strongarm->value = 1;
$export['pm_email_notify_default'] = $strongarm;
$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'pm_email_notify_from';
$strongarm->value = '';
$export['pm_email_notify_from'] = $strongarm;
$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'pm_email_notify_subject';
$strongarm->value = 'New message in [privatemsg_message:subject]';
$export['pm_email_notify_subject'] = $strongarm;
return $export;
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Build message settings form
*/
function groups_messages_message_settings_form($form, &$form_state, $account) {
$form['uid'] = array(
'#type' => 'value',
'#value' => $account->uid,
);
$form['privatemsg']['pm_send_notifications'] = array(
'#type' => 'checkbox',
'#title' => t('Receive email notification for incoming private messages'),
'#default_value' => _pm_email_notify_is_enabled($account->uid),
'#states' => array(
'visible' => array(
':input[name="pm_enable"]' => array('checked' => TRUE),
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save message settings'),
);
return $form;
}
/**
* Implements hook_form_submit()
*/
function groups_messages_message_settings_form_submit($form, &$form_state) {
$values = $form_state['values'];
db_merge('pm_email_notify')
->fields(array('email_notify_is_enabled' => $values['pm_send_notifications']))
->key(array('user_id' => $values['uid']))
->execute();
}