Skip to content

Commit

Permalink
More work on external assignee functionality, along with config switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Feb 27, 2015
1 parent 7435ed3 commit 8747822
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 29 deletions.
6 changes: 4 additions & 2 deletions nag/app/controllers/SaveTask.php
Expand Up @@ -3,7 +3,7 @@ class Nag_SaveTask_Controller extends Horde_Controller_Base
{
public function processRequest(Horde_Controller_Request $request, Horde_Controller_Response $response)
{
global $nag_shares, $prefs;
global $nag_shares, $prefs, $conf;

$vars = Horde_Variables::getDefaultVariables();
$registry = $this->getInjector()->getInstance('Horde_Registry');
Expand Down Expand Up @@ -91,7 +91,9 @@ public function processRequest(Horde_Controller_Request $request, Horde_Controll
$notification->push(sprintf(_("There was a problem saving the task: %s."), $e->getMessage()), 'horde.error');
Horde::url('list.php', true)->redirect();
}
Nag::sendITipNotifications($storage->get($newid[0]), $notification, Nag::ITIP_REQUEST);
if ($conf['assignees']['allow_external']) {
Nag::sendITipNotifications($storage->get($newid[0]), $notification, Nag::ITIP_REQUEST);
}
}

$notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success');
Expand Down
8 changes: 8 additions & 0 deletions nag/config/conf.xml
Expand Up @@ -21,6 +21,14 @@
</configswitch>
</configsection>

<configsection name="assignees">
<configheader>Assignee Handling</configheader>
<configboolean name="allow_external" desc="Should we allow assingment of tasks
to external users? This enables sending vTodo/iTip messages for task
assignments. Turning this off will restrict assignees to Horde users that have
read access to the parent tasklist.">true</configboolean>
</configsection>

<configsection name="menu">
<configheader>Menu settings</configheader>
<configboolean name="import_export" desc="Should we display an Import/Export
Expand Down
8 changes: 7 additions & 1 deletion nag/config/prefs.php
Expand Up @@ -183,13 +183,19 @@
'read' => _("On all task lists I have read access to")
),
'desc' => _("Choose if you want to be notified of new, edited, and deleted tasks by email:"),
'locked' => function() {
return $GLOBALS['conf']['assignees']['allow_external'];
}
);

$_prefs['task_notification_exclude_self'] = array(
'value' => 0,
'locked' => false,
'type' => 'checkbox',
'desc' => _("Don't send me a notification if I've added, changed or deleted the task?")
'desc' => _("Don't send me a notification if I've added, changed or deleted the task?"),
'locked' => function() {
return $GLOBALS['conf']['assignees']['allow_external'];
}
);

// alarm methods
Expand Down
20 changes: 12 additions & 8 deletions nag/lib/Form/Task.php
Expand Up @@ -113,16 +113,20 @@ public function __construct($vars, $title = '')
$horde_group->listUsers($group));
}
}
$users = array_flip($users);
if (count($users)) {
foreach (array_keys($users) as $user) {
$identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($user);
$fullname = $identity->getValue('fullname');
$users[$user] = strlen($fullname) ? $fullname : $user;
if (empty($GLOBALS['conf']['assignees']['allow_external'])) {
$users = array_flip($users);
if (count($users)) {
foreach (array_keys($users) as $user) {
$identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($user);
$fullname = $identity->getValue('fullname');
$users[$user] = strlen($fullname) ? $fullname : $user;
}
}
$this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
null, array($users, _("None")));
} else {
$this->addVariable(_("Assignee"), 'assignee', 'Nag:NagContact', false);
}
$this->addVariable(_("Assignee"), 'assignee', 'enum', false, false,
null, array($users, _("None")));
}

$this->addVariable(_("Private?"), 'private', 'boolean', false);
Expand Down
35 changes: 26 additions & 9 deletions nag/lib/Nag.php
Expand Up @@ -955,12 +955,19 @@ public static function formatAssignee($assignee, $link = false)
return '';
}

$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($assignee);
$fullname = $identity->getValue('fullname');
if (!strlen($fullname)) {
$fullname = $assignee;
if ($GLOBALS['conf']['assignees']['allow_external']) {
$email = new Horde_Mail_Rfc822_Address($assignee);
$fullname = $email->personal;
$email = $email->bare_address;
} else {
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($assignee);
$fullname = $identity->getValue('fullname');
if (!strlen($fullname)) {
$fullname = $assignee;
}
$email = $identity->getValue('from_addr');
}
$email = $identity->getValue('from_addr');

if ($link && !empty($email) &&
$GLOBALS['registry']->hasMethod('mail/compose')) {
return Horde::link($GLOBALS['registry']->call(
Expand Down Expand Up @@ -1741,6 +1748,15 @@ public static function getSyncLists()
return array();
}

public static function getUserEmail($user)
{
if (strpos($user, '@')) {
return $user;
}
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user);
return $identity->getValue('from_addr');
}

/**
* Maps an iCalendar attendee response string to the corresponding
* Nag value.
Expand Down Expand Up @@ -1786,7 +1802,6 @@ public static function sendITipNotifications(
{
global $injector, $registry, $nag_shares;

Horde::debug($task);
if (!$task->assignee) {
return;
}
Expand All @@ -1807,8 +1822,7 @@ public static function sendITipNotifications(
$view->task = $task;
$view->imageId = $image->getContentId();

$ident_assignee = $injector->getInstance('Horde_Core_Factory_Identity')->create($task->assignee);
$email = $ident_assignee->getValue('from_addr');
$email = Nag::getUserEmail($task->assignee);
if (strpos($email, '@') === false) {
continue;
}
Expand Down Expand Up @@ -1844,7 +1858,10 @@ public static function sendITipNotifications(
break;
}
$view->attendees = $email;
$view->organizer = $registry->convertUserName($task->creator, false);
$view->organizer = empty($task->organizer)
? $registry->convertUserName($task->creator, false)
: $task->organizer;

if ($action == self::ITIP_REQUEST) {
// @todo
// $attend_link = Horde::url('attend.php', true, -1)
Expand Down
17 changes: 14 additions & 3 deletions nag/lib/Task.php
Expand Up @@ -1201,9 +1201,11 @@ public function toiCalendar(Horde_Icalendar $calendar)
$vTodo->setAttribute('UID', $this->uid);

if (!empty($this->assignee)) {
$vTodo->setAttribute('ORGANIZER', $this->assignee);
$vTodo->setAttribute('ATTENDEE', Nag::getUserEmail($this->assignee), array('ROLE' => 'REQ-PARTICIPANT'));
}

$vTodo->setAttribute('ORGANIZER', !empty($this->organizer) ? Nag::getUserEmail($this->organizer) : Nag::getUserEmail($this->owner));

if (!empty($this->name)) {
$vTodo->setAttribute('SUMMARY', $this->name);
}
Expand Down Expand Up @@ -1436,7 +1438,9 @@ public function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)

try {
$organizer = $vTodo->getAttribute('ORGANIZER');
if (!is_array($organizer)) { $this->organizer = $organizer; }
if (!is_array($organizer)) {
$this->organizer = $organizer;
}
} catch (Horde_Icalendar_Exception $e) {}

// If an attendee matches our from_addr, add current user as assignee.
Expand Down Expand Up @@ -1468,12 +1472,19 @@ public function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
$name = isset($atparms[$index]['CN']) ? $atparms[$index]['CN'] : null;
}
if (in_array($attendee, $all_addrs) !== false) {
$this->assignee = $GLOBALS['registry']->getAuth();
$this->assignee = $GLOBALS['conf']['assignees']['allow_external'] ? $attendee : $GLOBALS['registry']->getAuth();
$this->status = Nag::RESPONSE_ACCEPTED;
break;
} elseif ($GLOBALS['conf']['assignees']['allow_external']) {
$this->assignee = $attendee;
}
}

// Default to current user as organizer
if (empty($this->organizer) && !empty($this->assignee)) {
$this->organizer = $identity->getValue('from_addr');
}

try {
$uid = $vTodo->getAttribute('UID');
if (!is_array($uid)) { $this->uid = $uid; }
Expand Down
18 changes: 18 additions & 0 deletions nag/lib/Ui/VarRenderer/Nag.php
Expand Up @@ -440,4 +440,22 @@ protected function _renderVarInput_NagTags($form, $var, $vars)
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('Nag_Ajax_Imple_TagAutoCompleter', array('id' => $varname));
return $html;
}

protected function _renderVarInput_NagContact($form, $var, $vars)
{
$name = $var->getVarName();
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')
->create(
'Nag_Ajax_Imple_ContactAutoCompleter',
array('id' => $name)
);
return sprintf('<input type="text" name="%s" id="%s" value="%s" autocomplete="off"%s />',
$name,
$name,
@htmlspecialchars($var->getValue($vars)),
$this->_getActionScripts($form, $var))
. '<span id="' . $name . '_loading_img" style="display:none;">'
. Horde::img('loading.gif', _("Loading..."))
. '</span>';
}
}
18 changes: 12 additions & 6 deletions nag/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>false</active>
</lead>
<date>2015-02-24</date>
<date>2015-02-27</date>
<version>
<release>4.3.0</release>
<api>4.2.0</api>
Expand Down Expand Up @@ -100,6 +100,7 @@
</dir> <!-- /lib/Ajax/Application/Handler -->
</dir> <!-- /lib/Ajax/Application -->
<dir name="Imple">
<file name="ContactAutoCompleter.php" role="horde" />
<file name="TagAutoCompleter.php" role="horde" />
</dir> <!-- /lib/Ajax/Imple -->
<file name="Application.php" role="horde" />
Expand All @@ -120,6 +121,7 @@
<dir name="Form">
<dir name="Type">
<file name="NagAlarm.php" role="horde" />
<file name="NagContact.php" role="horde" />
<file name="NagDue.php" role="horde" />
<file name="NagMethod.php" role="horde" />
<file name="NagRecurrence.php" role="horde" />
Expand Down Expand Up @@ -441,6 +443,10 @@
<file name="export.inc" role="horde" />
<file name="import.inc" role="horde" />
</dir> <!-- /templates/data -->
<dir name="itip">
<file name="notification.html.php" role="horde" />
<file name="notification.plain.php" role="horde" />
</dir> <!-- /templates/itip -->
<dir name="list">
<file name="header.html.php" role="horde" />
<file name="task_headers.html.php" role="horde" />
Expand All @@ -456,8 +462,6 @@
</dir> <!-- /templates/view -->
<file name="javascript_defs.php" role="horde" />
<file name="list.html.php" role="horde" />
<file name="notification.html.php" role="horde" />
<file name="notification.plain.php" role="horde" />
<file name="quick.inc" role="horde" />
</dir> <!-- /templates -->
<dir name="test">
Expand Down Expand Up @@ -824,6 +828,7 @@
<install as="nag/lib/Tasklist.php" name="lib/Tasklist.php" />
<install as="nag/lib/Ajax/Application.php" name="lib/Ajax/Application.php" />
<install as="nag/lib/Ajax/Application/Handler/Smartmobile.php" name="lib/Ajax/Application/Handler/Smartmobile.php" />
<install as="nag/lib/Ajax/Imple/ContactAutoCompleter.php" name="lib/Ajax/Imple/ContactAutoCompleter.php" />
<install as="nag/lib/Ajax/Imple/TagAutoCompleter.php" name="lib/Ajax/Imple/TagAutoCompleter.php" />
<install as="nag/lib/Block/Summary.php" name="lib/Block/Summary.php" />
<install as="nag/lib/Driver/Kolab.php" name="lib/Driver/Kolab.php" />
Expand All @@ -838,6 +843,7 @@
<install as="nag/lib/Form/Search.php" name="lib/Form/Search.php" />
<install as="nag/lib/Form/Task.php" name="lib/Form/Task.php" />
<install as="nag/lib/Form/Type/NagAlarm.php" name="lib/Form/Type/NagAlarm.php" />
<install as="nag/lib/Form/Type/NagContact.php" name="lib/Form/Type/NagContact.php" />
<install as="nag/lib/Form/Type/NagDue.php" name="lib/Form/Type/NagDue.php" />
<install as="nag/lib/Form/Type/NagMethod.php" name="lib/Form/Type/NagMethod.php" />
<install as="nag/lib/Form/Type/NagRecurrence.php" name="lib/Form/Type/NagRecurrence.php" />
Expand Down Expand Up @@ -960,13 +966,13 @@
<install as="nag/tasks/index.php" name="tasks/index.php" />
<install as="nag/templates/javascript_defs.php" name="templates/javascript_defs.php" />
<install as="nag/templates/list.html.php" name="templates/list.html.php" />
<install as="nag/templates/notification.html.php" name="templates/notification.html.php" />
<install as="nag/templates/notification.plain.php" name="templates/notification.plain.php" />
<install as="nag/templates/quick.inc" name="templates/quick.inc" />
<install as="nag/templates/alarm/mail.html.php" name="templates/alarm/mail.html.php" />
<install as="nag/templates/alarm/mail.plain.php" name="templates/alarm/mail.plain.php" />
<install as="nag/templates/data/export.inc" name="templates/data/export.inc" />
<install as="nag/templates/data/import.inc" name="templates/data/import.inc" />
<install as="nag/templates/itip/notification.html.php" name="templates/itip/notification.html.php" />
<install as="nag/templates/itip/notification.plain.php" name="templates/itip/notification.plain.php" />
<install as="nag/templates/list/header.html.php" name="templates/list/header.html.php" />
<install as="nag/templates/list/task_headers.html.php" name="templates/list/task_headers.html.php" />
<install as="nag/templates/list/_task.html.php" name="templates/list/_task.html.php" />
Expand Down Expand Up @@ -1638,7 +1644,7 @@
<stability>
<release>beta</release>
<api>alpha</api></stability>
<date>2015-02-24</date>
<date>2015-02-27</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Fall back to sort by name if sort criteria are equal.
Expand Down

0 comments on commit 8747822

Please sign in to comment.