Skip to content

Commit

Permalink
Merge pull request civicrm#11222 from jitendrapurohit/CRM-21380
Browse files Browse the repository at this point in the history
CRM-21380: Add setting to block activity types from sending assignee …
  • Loading branch information
colemanw authored and sluc23 committed Jan 10, 2018
2 parents 3f3cc31 + e2561e1 commit 8dc3fb6
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 32 deletions.
11 changes: 7 additions & 4 deletions CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,14 @@ public function buildQuickForm() {

$this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);

if (Civi::settings()->get('activity_assignee_notification')) {
$this->assign('activityAssigneeNotification', TRUE);
$doNotNotifyAssigneeFor = Civi::settings()->get('do_not_notify_assignees_for');
if (($this->_activityTypeId && in_array($this->_activityTypeId, $doNotNotifyAssigneeFor)) || !Civi::settings()->get('activity_assignee_notification')) {
$this->assign('activityAssigneeNotification', FALSE);
}
else {
$this->assign('activityAssigneeNotification', FALSE);
$this->assign('activityAssigneeNotification', TRUE);
}
$this->assign('doNotNotifyAssigneeFor', $doNotNotifyAssigneeFor);
}

/**
Expand Down Expand Up @@ -1085,7 +1087,8 @@ protected function processActivity(&$params) {
// send copy to assignee contacts.CRM-4509
$mailStatus = '';

if (Civi::settings()->get('activity_assignee_notification')) {
if (Civi::settings()->get('activity_assignee_notification')
&& !in_array($activity->activity_type_id, Civi::settings()->get('do_not_notify_assignees_for'))) {
$activityIDs = array($activity->id);
if ($followupActivity) {
$activityIDs = array_merge($activityIDs, array($followupActivity->id));
Expand Down
3 changes: 2 additions & 1 deletion CRM/Admin/Form/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public function buildQuickForm() {
$this->addElement('select',
$fieldName,
$fieldValue['title'],
$fieldValue['option_values']
$fieldValue['option_values'],
CRM_Utils_Array::value('attributes', $fieldValue)
);
break;

Expand Down
8 changes: 8 additions & 0 deletions CRM/Admin/Form/Preferences/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
$optionValues = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');

$this->_varNames = array(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
Expand Down Expand Up @@ -104,6 +105,13 @@ public function preProcess() {
'title' => ts('Enable Popup Forms'),
'weight' => 13,
),
'do_not_notify_assignees_for' => array(
'html_type' => 'select',
'option_values' => $optionValues,
'attributes' => array('multiple' => 1, "class" => "huge crm-select2"),
'title' => ts('Do not notify assignees for'),
'weight' => 14,
),
),
);

Expand Down
6 changes: 3 additions & 3 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -1335,10 +1335,10 @@ public static function sendActivityCopy($clientId, $activityId, $contacts, $atta

$activityParams['source_record_id'] = $activityId;
$activityParams['source_contact_id'] = $userID;
$activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name');
$activityParams['activity_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Email');
$activityParams['activity_date_time'] = date('YmdHis');
$activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activityParams['medium_id'] = CRM_Core_OptionGroup::getValue('encounter_medium', 'email', 'name');
$activityParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_status_id', 'Completed');
$activityParams['medium_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'encounter_medium', 'email');
$activityParams['case_id'] = $caseId;
$activityParams['is_auto'] = 0;
$activityParams['target_id'] = $clientId;
Expand Down
6 changes: 3 additions & 3 deletions CRM/Case/XMLProcessor/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function &getActivityInfo($clientID, $activityID, $anyActivity = FALSE, $

if ($dao->fetch()) {
//if activity type is email get info of all activities.
if ($dao->activity_type_id == CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name')) {
if ($dao->activity_type_id == CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Email')) {
$anyActivity = TRUE;
}
$activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, $anyActivity);
Expand Down Expand Up @@ -512,15 +512,15 @@ public function &getActivity($clientID, $activityDAO, &$activityTypeInfo) {
}
$activity['fields'][] = array(
'label' => ts('Status'),
'value' => CRM_Core_OptionGroup::getLabel('activity_status',
'value' => CRM_Core_PseudoConstant::getLabel('CRM_Activity_DAO_Activity', 'activity_status_id',
$activityDAO->status_id
),
'type' => 'String',
);

$activity['fields'][] = array(
'label' => ts('Priority'),
'value' => CRM_Core_OptionGroup::getLabel('priority',
'value' => CRM_Core_PseudoConstant::getLabel('CRM_Activity_DAO_Activity', 'priority',
$activityDAO->priority_id
),
'type' => 'String',
Expand Down
20 changes: 20 additions & 0 deletions settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,24 @@
'description' => 'When enabled, any filter settings a user selects on the contact\'s Activity tab will be remembered as they visit other contacts',
'help_text' => NULL,
),
'do_not_notify_assignees_for' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'do_not_notify_assignees_for',
'type' => 'Array',
'add' => '4.7',
'is_domain' => 1,
'default' => array(),
'title' => 'Do not notify assignees for',
'help_text' => 'These activity types will be excluded from automated email notifications to assignees.',
'html_type' => 'Select',
'html_attributes' => array(
'multiple' => 1,
'class' => 'huge crm-select2',
),
'pseudoconstant' => array(
'optionGroupName' => 'activity_type',
),
'quick_form_type' => 'Select',
),
);
30 changes: 20 additions & 10 deletions templates/CRM/Activity/Form/Activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{/if}
{if $activityAssigneeNotification}
<br />
<span class="description"><i class="crm-i fa-paper-plane"></i> {ts}A copy of this activity will be emailed to each Assignee.{/ts} {help id="sent_copy_email"}</span>
<span id="notify_assignee_msg" class="description"><i class="crm-i fa-paper-plane"></i> {ts}A copy of this activity will be emailed to each Assignee.{/ts} {help id="sent_copy_email"}</span>
{/if}
{/if}
</td>
Expand Down Expand Up @@ -276,18 +276,28 @@


{if $action eq 1 or $action eq 2 or $context eq 'search' or $context eq 'smog'}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
$('#activity_type_id').change(function() {
if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
$('#notify_assignee_msg').hide();
}
else {
$('#notify_assignee_msg').show();
}
});

{/literal}
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
});
</script>
{/literal}
Expand Down
17 changes: 16 additions & 1 deletion templates/CRM/Admin/Form/Preferences/Display.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@
{ts}When enabled, contacts who are assigned activities will automatically receive an email notification with a copy of the activity.{/ts}
</td>
</tr>

<tr class="crm-preferences-display-form-activity_types">
<td class="label">{$form.do_not_notify_assignees_for.label}</td>
<td>{$form.do_not_notify_assignees_for.html}</td>
</tr>
<tr class="crm-preferences-display-form-activity_types">
<td>&nbsp;</td>
<td class="description">
{ts}These activity types will be excluded from automated email notifications to assignees.{/ts}
</td>
</tr>
<tr class="crm-preferences-display-form-block-activity_assignee_notification_ics">
<td class="label"></td>
<td>{$form.activity_assignee_notification_ics.html} {$form.activity_assignee_notification_ics.label}</td>
Expand Down Expand Up @@ -228,6 +237,12 @@
$('#contact_edit_preferences').val(params.toString());
}

// show/hide activity types based on checkbox value
$('.crm-preferences-display-form-activity_types').toggle($('#activity_assignee_notification').is(":checked"));
$('#activity_assignee_notification').click(function() {
$('.crm-preferences-display-form-activity_types').toggle($(this).is(":checked"));
});

var invoicesKey = '{/literal}{$invoicesKey}{literal}';
var invoicing = '{/literal}{$invoicing}{literal}';
if (!invoicing) {
Expand Down
30 changes: 20 additions & 10 deletions templates/CRM/Case/Form/Activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<td>{$form.assignee_contact_id.html}
{if $activityAssigneeNotification}
<br />
<span class="description"><i class="crm-i fa-paper-plane"></i> {ts}A copy of this activity will be emailed to each Assignee.{/ts}</span>
<span id="notify_assignee_msg" class="description"><i class="crm-i fa-paper-plane"></i> {ts}A copy of this activity will be emailed to each Assignee.{/ts}</span>
{/if}
</td>
</tr>
Expand Down Expand Up @@ -271,18 +271,28 @@
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>

{if $action eq 1 or $action eq 2}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
$('#activity_type_id').change(function() {
if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
$('#notify_assignee_msg').hide();
}
else {
$('#notify_assignee_msg').show();
}
});

{/literal}
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
});
</script>
{/literal}
Expand Down
59 changes: 59 additions & 0 deletions tests/phpunit/CRM/Activity/Form/ActivityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Include dataProvider for tests
* @group headless
*/
class CRM_Activity_Form_ActivityTest extends CiviUnitTestCase {

public function setUp() {
parent::setUp();
$this->assignee1 = $this->individualCreate(array(
'first_name' => 'testassignee1',
'last_name' => 'testassignee1',
'email' => 'testassignee1@gmail.com',
));
$this->assignee2 = $this->individualCreate(array(
'first_name' => 'testassignee2',
'last_name' => 'testassignee2',
'email' => 'testassignee2@gmail.com',
));
$this->target = $this->individualCreate();
$this->source = $this->individualCreate();
}

public function testActivityCreate() {
Civi::settings()->set('activity_assignee_notification', TRUE);
//Reset filter to none.
Civi::settings()->set('do_not_notify_assignees_for', array());
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();

$form = new CRM_Activity_Form_Activity();
$activityTypeId = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Meeting');
$params = array(
'source_contact_id' => $this->source,
'assignee_contact_id' => array($this->assignee1),
'target_contact_id' => array($this->target),
'followup_assignee_contact_id' => array(),
'activity_type_id' => $activityTypeId,
);

$activityRef = new ReflectionClass('CRM_Activity_Form_Activity');
$method = $activityRef->getMethod('processActivity');
$method->setAccessible(TRUE);
$method->invokeArgs($form, array(&$params));

$msg = $mut->getMostRecentEmail();
$this->assertNotEmpty($msg);
$mut->clearMessages();

//Block Meeting notification.
Civi::settings()->set('do_not_notify_assignees_for', array($activityTypeId));
$params['assignee_contact_id'] = array($this->assignee2);
$method->invokeArgs($form, array(&$params));
$msg = $mut->getMostRecentEmail();
$this->assertEmpty($msg);
}

}

0 comments on commit 8dc3fb6

Please sign in to comment.