setDefaultAccess() propperly removes notifier without read access

This commit is contained in:
Uwe Steinmann 2015-06-19 12:52:49 +02:00
parent de7d9acb06
commit 1f19d7daaf

View File

@ -415,6 +415,14 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
return $this->_defaultAccess; return $this->_defaultAccess;
} /* }}} */ } /* }}} */
/**
* Set default access mode
*
* This method sets the default access mode and also removes all notifiers which
* will not have read access anymore.
*
* @param integer $mode access mode
*/
function setDefaultAccess($mode) { /* {{{ */ function setDefaultAccess($mode) { /* {{{ */
$db = $this->_dms->getDB(); $db = $this->_dms->getDB();
@ -426,18 +434,22 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
// If any of the notification subscribers no longer have read access, // If any of the notification subscribers no longer have read access,
// remove their subscription. // remove their subscription.
if(isset($this->_notifyList["users"])) { if (empty($this->_notifyList))
foreach ($this->_notifyList["users"] as $u) { $this->getNotifyList();
if ($this->getAccessMode($u) < M_READ) {
$this->removeNotify($u->getID(), true); /* 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);
} }
} }
if(isset($this->_notifyList["groups"])) { foreach ($ngroups as $g) {
foreach ($this->_notifyList["groups"] as $g) { if ($this->getGroupAccessMode($g) < M_READ) {
if ($this->getGroupAccessMode($g) < M_READ) { $this->removeNotify($g->getID(), false);
$this->removeNotify($g->getID(), false);
}
} }
} }