From 75c8129185eac1fbff42a38667ec38890cb9f9a0 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 19 Jun 2015 15:02:37 +0200 Subject: [PATCH] add cleanNotifyList() which removes users/groups with read access also adds an optional parameter $noclean to setDefaultAccess and setInheritAccess which keeps the methods from cleaning up the notifier list --- SeedDMS_Core/Core/inc.ClassDocument.php | 73 +++++++++++---------- SeedDMS_Core/Core/inc.ClassFolder.php | 84 ++++++++++++++----------- 2 files changed, 83 insertions(+), 74 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 213eceab2..61de039c0 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -493,8 +493,9 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * will not have read access anymore. * * @param integer $mode access mode + * @param boolean $noclean set to true if notifier list shall not be clean up */ - function setDefaultAccess($mode) { /* {{{ */ + function setDefaultAccess($mode, $noclean="false") { /* {{{ */ $db = $this->_dms->getDB(); $queryStr = "UPDATE tblDocuments set defaultAccess = " . (int) $mode . " WHERE id = " . $this->_id; @@ -503,26 +504,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $this->_defaultAccess = $mode; - // If any of the notification subscribers no longer have read access, - // remove their subscription. - if (empty($this->_notifyList)) - $this->getNotifyList(); - - /* Make a copy of both notifier lists because removeNotify will empty - * $this->_notifyList and the second foreach will not work anymore. - */ - $nusers = $this->_notifyList["users"]; - $ngroups = $this->_notifyList["groups"]; - foreach ($this->_notifyList["users"] as $u) { - if ($this->getAccessMode($u) < M_READ) { - $this->removeNotify($u->getID(), true); - } - } - foreach ($ngroups as $g) { - if ($this->getGroupAccessMode($g) < M_READ) { - $this->removeNotify($g->getID(), false); - } - } + if(!$noclean) + self::cleanNotifyList(); return true; } /* }}} */ @@ -540,9 +523,10 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * * @param boolean $inheritAccess set to true for setting and false for * unsetting inherited access mode + * @param boolean $noclean set to true if notifier list shall not be clean up * @return boolean true if operation was successful otherwise false */ - function setInheritAccess($inheritAccess) { /* {{{ */ + function setInheritAccess($inheritAccess, $noclean=false) { /* {{{ */ $db = $this->_dms->getDB(); $queryStr = "UPDATE tblDocuments SET inheritAccess = " . ($inheritAccess ? "1" : "0") . " WHERE id = " . $this->_id; @@ -551,22 +535,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $this->_inheritAccess = ($inheritAccess ? "1" : "0"); - // If any of the notification subscribers no longer have read access, - // remove their subscription. - if(isset($this->_notifyList["users"])) { - foreach ($this->_notifyList["users"] as $u) { - if ($this->getAccessMode($u) < M_READ) { - $this->removeNotify($u->getID(), true); - } - } - } - if(isset($this->_notifyList["groups"])) { - foreach ($this->_notifyList["groups"] as $g) { - if ($this->getGroupAccessMode($g) < M_READ) { - $this->removeNotify($g->getID(), false); - } - } - } + if(!$noclean) + self::cleanNotifyList(); return true; } /* }}} */ @@ -1252,6 +1222,33 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return $this->_notifyList; } /* }}} */ + /** + * Make sure only users/groups with read access are in the notify list + * + */ + function cleanNotifyList() { /* {{{ */ + // If any of the notification subscribers no longer have read access, + // remove their subscription. + if (empty($this->_notifyList)) + $this->getNotifyList(); + + /* Make a copy of both notifier lists because removeNotify will empty + * $this->_notifyList and the second foreach will not work anymore. + */ + $nusers = $this->_notifyList["users"]; + $ngroups = $this->_notifyList["groups"]; + foreach ($nusers as $u) { + if ($this->getAccessMode($u) < M_READ) { + $this->removeNotify($u->getID(), true); + } + } + foreach ($ngroups as $g) { + if ($this->getGroupAccessMode($g) < M_READ) { + $this->removeNotify($g->getID(), false); + } + } + } /* }}} */ + /** * Add a user/group to the notification list * This function does not check if the currently logged in user diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index e58631c11..70651ca96 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -340,8 +340,9 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * will not have read access anymore. * * @param integer $mode access mode + * @param boolean $noclean set to true if notifier list shall not be clean up */ - function setDefaultAccess($mode) { /* {{{ */ + function setDefaultAccess($mode, $noclean=false) { /* {{{ */ $db = $this->_dms->getDB(); $queryStr = "UPDATE tblFolders set defaultAccess = " . (int) $mode . " WHERE id = " . $this->_id; @@ -350,33 +351,29 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $this->_defaultAccess = $mode; - // If any of the notification subscribers no longer have read access, - // remove their subscription. - if (empty($this->_notifyList)) - $this->getNotifyList(); - - /* Make a copy of both notifier lists because removeNotify will empty - * $this->_notifyList and the second foreach will not work anymore. - */ - $nusers = $this->_notifyList["users"]; - $ngroups = $this->_notifyList["groups"]; - foreach ($nusers as $u) { - if ($this->getAccessMode($u) < M_READ) { - $this->removeNotify($u->getID(), true); - } - } - foreach ($ngroups as $g) { - if ($this->getGroupAccessMode($g) < M_READ) { - $this->removeNotify($g->getID(), false); - } - } + if(!$noclean) + self::cleanNotifyList(); return true; } /* }}} */ function inheritsAccess() { return $this->_inheritAccess; } - function setInheritAccess($inheritAccess) { /* {{{ */ + /** + * Set inherited access mode + * Setting inherited access mode will set or unset the internal flag which + * controls if the access mode is inherited from the parent folder or not. + * It will not modify the + * access control list for the current object. It will remove all + * notifications of users which do not even have read access anymore + * after setting or unsetting inherited access. + * + * @param boolean $inheritAccess set to true for setting and false for + * unsetting inherited access mode + * @param boolean $noclean set to true if notifier list shall not be clean up + * @return boolean true if operation was successful otherwise false + */ + function setInheritAccess($inheritAccess, $noclean=false) { /* {{{ */ $db = $this->_dms->getDB(); $inheritAccess = ($inheritAccess) ? "1" : "0"; @@ -387,20 +384,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $this->_inheritAccess = $inheritAccess; - // If any of the notification subscribers no longer have read access, - // remove their subscription. - if (empty($this->_notifyList)) - $this->getNotifyList(); - foreach ($this->_notifyList["users"] as $u) { - if ($this->getAccessMode($u) < M_READ) { - $this->removeNotify($u->getID(), true); - } - } - foreach ($this->_notifyList["groups"] as $g) { - if ($this->getGroupAccessMode($g) < M_READ) { - $this->removeNotify($g->getID(), false); - } - } + if(!$noclean) + self::cleanNotifyList(); return true; } /* }}} */ @@ -1187,6 +1172,33 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->_notifyList; } /* }}} */ + /** + * Make sure only users/groups with read access are in the notify list + * + */ + function cleanNotifyList() { /* {{{ */ + // If any of the notification subscribers no longer have read access, + // remove their subscription. + if (empty($this->_notifyList)) + $this->getNotifyList(); + + /* Make a copy of both notifier lists because removeNotify will empty + * $this->_notifyList and the second foreach will not work anymore. + */ + $nusers = $this->_notifyList["users"]; + $ngroups = $this->_notifyList["groups"]; + foreach ($nusers as $u) { + if ($this->getAccessMode($u) < M_READ) { + $this->removeNotify($u->getID(), true); + } + } + foreach ($ngroups as $g) { + if ($this->getGroupAccessMode($g) < M_READ) { + $this->removeNotify($g->getID(), false); + } + } + } /* }}} */ + /* * Add a user/group to the notification list * This function does not check if the currently logged in user