From 9368dc6eedfbb043aa3b213cf5039416cf79c36b Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 27 May 2010 14:25:33 +0200 Subject: [PATCH] Add option to notify users about calendar permission changes. I'm not sure about which text, information and links to include with the message by default, any ideas are welcome. --- kronolith/config/conf.xml | 28 ++++++++------ kronolith/config/hooks.php.dist | 37 +++++++++++++++++- kronolith/docs/CHANGES | 1 + kronolith/lib/Kronolith.php | 85 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 12 deletions(-) diff --git a/kronolith/config/conf.xml b/kronolith/config/conf.xml index 3cf477a12..46e766163 100644 --- a/kronolith/config/conf.xml +++ b/kronolith/config/conf.xml @@ -60,17 +60,23 @@ - Calendar Auto-Sharing - - - none - read - edit - full - - + Share Settings + + + none + read + edit + full + + + + + + false diff --git a/kronolith/config/hooks.php.dist b/kronolith/config/hooks.php.dist index a121df0ee..a6e89eed1 100644 --- a/kronolith/config/hooks.php.dist +++ b/kronolith/config/hooks.php.dist @@ -14,7 +14,7 @@ class Kronolith_Hooks { /** - * AJAX HOOK: Add user-defined AJAX action handlers. + * Adds user-defined AJAX action handlers. * * @param string $action The AJAX action. * @param Horde_Variables $vars The URL parameters. @@ -32,4 +32,39 @@ class Kronolith_Hooks // throw new Horde_Ajax_Exception('Unknown action'); // } + /** + * Generates the e-mail notification message when the share owner changes. + * + * @param string $user The new owner. + * @param Horde_Share $share A calendar or tasklist. + */ +// public function shareOwnerNotification($user, Horde_Share $share) +// { +// return 'Some fancy text including the ' . $user . ' and the ' . $share->get('name'); +// } + + /** + * Generates the e-mail notification message when the share permissions + * change. + * + * @param string $user A user who has been added to the permissions. + * @param Horde_Share $share A calendar or tasklist. + */ +// public function shareUserNotification($user, Horde_Share $share) +// { +// return 'Some fancy text including the ' . $user . ' and the ' . $share->get('name'); +// } + + /** + * Generates the e-mail notification message when the share permissions + * change. + * + * @param mixed $group The id of a group that has been added to the + * permissions. + * @param Horde_Share $share A calendar or tasklist. + */ +// public function shareGroupNotification($group, Horde_Share $share) +// { +// return 'Some fancy text including the ' . $group . ' and the ' . $share->get('name'); +// } } diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index 19d21fe66..c83431e32 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Add option to notify users about calendar permission changes. [mjr] listTimeObject calendars are now viewable independently in the calendar portal blocks (Request #8530). [mjr] Recurring event exceptions are now indicated as such in the UI. diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 4064091b0..99bca3216 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1593,6 +1593,18 @@ class Kronolith $perm = $share->getPermission(); $errors = array(); + if ($GLOBALS['conf']['share']['notify']) { + $identity = $GLOBALS['injector'] + ->getInstance('Horde_Prefs_Identity') + ->getIdentity(); + $userName = $identity->getName(); + $mail = new Horde_Mime_Mail( + array('from' => $identity->getDefaultFromAddress(true), + 'charset' => Horde_Nls::getCharset()) + ); + $mail->addHeader('User-Agent', 'Kronolith ' . $GLOBALS['registry']->getVersion()); + } + // Process owner and owner permissions. $old_owner = $share->get('owner'); $new_owner_backend = Horde_Util::getFormData('owner_select', Horde_Util::getFormData('owner_input', $old_owner)); @@ -1605,6 +1617,23 @@ class Kronolith } else { $share->set('owner', $new_owner); $share->save(); + if ($GLOBALS['conf']['share']['notify']) { + $to = $GLOBALS['injector'] + ->getInstance('Horde_Prefs_Identity') + ->getIdentity($new_owner) + ->getDefaultFromAddress(true); + try { + $message = Horde::callHook('shareOwnerNotification', array($new_owner, $share)); + } catch (Horde_Exception_HookNotSet $e) { + $message = sprintf(_("%s has assigned the ownership of \"%s\" to you"), + $userName, + $share->get('name')); + } + $mail->addHeader('Subject', _("Ownership assignment")); + $mail->addHeader('To', $to); + $mail->setBody($message, Horde_Nls::getCharset()); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); + } } } @@ -1700,6 +1729,11 @@ class Kronolith $u_delete = Horde_Util::getFormData('u_delete'); $u_delegate = Horde_Util::getFormData('u_delegate'); + $current = $perm->getUserPermissions(); + if ($GLOBALS['conf']['share']['notify']) { + $mail->addHeader('Subject', _("Access permissions")); + } + $perm->removeUserPermission(null, null, false); foreach ($u_names as $key => $user_backend) { // Apply backend hooks @@ -1714,20 +1748,45 @@ class Kronolith continue; } + $has_perms = false; if (!empty($u_show[$key])) { $perm->addUserPermission($user, Horde_Perms::SHOW, false); + $has_perms = true; } if (!empty($u_read[$key])) { $perm->addUserPermission($user, Horde_Perms::READ, false); + $has_perms = true; } if (!empty($u_edit[$key])) { $perm->addUserPermission($user, Horde_Perms::EDIT, false); + $has_perms = true; } if (!empty($u_delete[$key])) { $perm->addUserPermission($user, Horde_Perms::DELETE, false); + $has_perms = true; } if (!empty($u_delegate[$key])) { $perm->addUserPermission($user, Kronolith::PERMS_DELEGATE, false); + $has_perms = true; + } + + // Notify users that have been added. + if ($GLOBALS['conf']['share']['notify'] && + !isset($current[$user]) && $has_perms) { + $to = $GLOBALS['injector'] + ->getInstance('Horde_Prefs_Identity') + ->getIdentity($user) + ->getDefaultFromAddress(true); + try { + $message = Horde::callHook('shareUserNotification', array($user, $share)); + } catch (Horde_Exception_HookNotSet $e) { + $message = sprintf(_("%s has given you access to \"%s\"."), + $userName, + $share->get('name')); + } + $mail->addHeader('To', $to); + $mail->setBody($message, Horde_Nls::getCharset()); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } @@ -1739,26 +1798,52 @@ class Kronolith $g_delete = Horde_Util::getFormData('g_delete'); $g_delegate = Horde_Util::getFormData('g_delegate'); + $current = $perm->getGroupPermissions(); $perm->removeGroupPermission(null, null, false); foreach ($g_names as $key => $group) { if (empty($group)) { continue; } + $has_perms = false; if (!empty($g_show[$key])) { $perm->addGroupPermission($group, Horde_Perms::SHOW, false); + $has_perms = true; } if (!empty($g_read[$key])) { $perm->addGroupPermission($group, Horde_Perms::READ, false); + $has_perms = true; } if (!empty($g_edit[$key])) { $perm->addGroupPermission($group, Horde_Perms::EDIT, false); + $has_perms = true; } if (!empty($g_delete[$key])) { $perm->addGroupPermission($group, Horde_Perms::DELETE, false); + $has_perms = true; } if (!empty($g_delegate[$key])) { $perm->addGroupPermission($group, Kronolith::PERMS_DELEGATE, false); + $has_perms = true; + } + + // Notify users that have been added. + if ($GLOBALS['conf']['share']['notify'] && + !isset($current[$group]) && $has_perms) { + $groupOb = Group::singleton()->getGroupById($group); + if (!empty($groupOb->data['email'])) { + try { + $message = Horde::callHook('shareGroupNotification', array($group, $share)); + } catch (Horde_Exception_HookNotSet $e) { + $message = sprintf(_("%s has given your group \"%s\" access to \"%s\"."), + $userName, + $groupOb->getName(), + $share->get('name')); + } + $mail->addHeader('To', $groupOb->getName() . ' <' . $groupOb->data['email'] . '>'); + $mail->setBody($message, Horde_Nls::getCharset()); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); + } } } try { -- 2.11.0