Filemanager - allow to delete own notification props
authorPaul Mehrer <p.mehrer@metaways.de>
Tue, 6 Jun 2017 09:51:40 +0000 (11:51 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Tue, 6 Jun 2017 11:21:40 +0000 (13:21 +0200)
and added test for this

Change-Id: I73b3c5920cffee3b390c78ea8613eff47e6fdf52
Reviewed-on: http://gerrit.tine20.com/customers/4828
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Filemanager/ControllerTests.php
tine20/Filemanager/Controller/Node.php

index be0c189..b46d31a 100644 (file)
@@ -120,6 +120,10 @@ class Filemanager_ControllerTests extends TestCase
                 isset($node->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)[0]) &&
                 $scleverNotificationProps == $node->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)[0]
             );
+
+            $node->{Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION} = array();
+            $node = $fileManager->update($node);
+            static::assertEquals(0, count($node->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)));
         } finally {
             Tinebase_Core::set(Tinebase_Core::USER, $oldUser);
         }
index 30e98b2..c716083 100644 (file)
@@ -124,25 +124,28 @@ class Filemanager_Controller_Node extends Tinebase_Controller_Record_Abstract
                 }
             }
 
-            if (null !== $usersNotificationSettings) {
-                // we reset all input and then just apply the notification settings for the current user
-                $_record = $this->get($_record->getId());
-                $found = false;
-                foreach ($_record->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION) as &$xpNotification) {
-                    if (isset($xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_ID]) &&
-                            isset($xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_TYPE]) &&
-                            Tinebase_Acl_Rights::ACCOUNT_TYPE_USER === $xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_TYPE] &&
-                            $currentUserId ===  $xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_ID]) {
+            // we reset all input and then just apply the notification settings for the current user
+            $_record = $this->get($_record->getId());
+            $found = false;
+            foreach ($_record->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION) as $key => &$xpNotification) {
+                if (isset($xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_ID]) &&
+                        isset($xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_TYPE]) &&
+                        Tinebase_Acl_Rights::ACCOUNT_TYPE_USER === $xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_TYPE] &&
+                        $currentUserId ===  $xpNotification[Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION_ACCOUNT_ID]) {
+                    if (null !== $usersNotificationSettings) {
                         $xpNotification = $usersNotificationSettings;
-                        $found = true;
-                        break;
+                    } else {
+                        unset($_record->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)[$key]);
                     }
+                    $found = true;
+                    break;
                 }
-                if (false === $found) {
-                    $_record->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)[] = $usersNotificationSettings;
-                }
-                // now continue to do the update
-            } else {
+            }
+            if (false === $found && null !== $usersNotificationSettings) {
+                $_record->xprops(Tinebase_Model_Tree_Node::XPROPS_NOTIFICATION)[] = $usersNotificationSettings;
+            }
+
+            if (false === $found && null === $usersNotificationSettings){
                 throw new Tinebase_Exception_AccessDenied('No permission to update nodes.');
             }
         }