From 2e0db1ef0b25fd55a43ce26928d460f501e2acdf Mon Sep 17 00:00:00 2001 From: Brad Shuttleworth Date: Thu, 8 Jun 2006 15:01:02 +0000 Subject: [PATCH] missing ktworkflowtriggers. --- plugins/ktcore/KTWorkflowTriggers.inc.php | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+), 0 deletions(-) create mode 100644 plugins/ktcore/KTWorkflowTriggers.inc.php diff --git a/plugins/ktcore/KTWorkflowTriggers.inc.php b/plugins/ktcore/KTWorkflowTriggers.inc.php new file mode 100644 index 0000000..589829c --- /dev/null +++ b/plugins/ktcore/KTWorkflowTriggers.inc.php @@ -0,0 +1,128 @@ +sFriendlyName = _kt("Permission Restrictions"); + $this->sDescription = _kt("Prevents users who do not have the specified permission from using this transition."); + } + + // override the allow transition hook. + function allowTransition($oDocument, $oUser) { + if (!$this->isLoaded()) { + return true; + } + // the actual permissions are stored in the array. + foreach ($this->aConfig['perms'] as $sPermName) { + $oPerm = KTPermission::getByName($sPermName); + if (PEAR::isError($oPerm)) { + continue; // possible loss of referential integrity, just ignore it for now. + } + $res = KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument); + if (!$res) { + return false; + } + } + return true; + } + + function displayConfiguration($args) { + // permissions + $aPermissions = KTPermission::getList(); + $aKeyPermissions = array(); + foreach ($aPermissions as $oPermission) { $aKeyPermissions[$oPermission->getName()] = $oPermission; } + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate("ktcore/workflowtriggers/permissions"); + $aTemplateData = array( + "context" => $this, + "perms" => $aKeyPermissions, + 'args' => $args, + ); + return $oTemplate->render($aTemplateData); + } + + function saveConfiguration() { + $perms = KTUtil::arrayGet($_REQUEST, 'trigger_perms', array()); + if (!is_array($perms)) { + $perms = (array) $perms; + } + $aFinalPerms = array(); + foreach ($perms as $sPermName => $ignore) { + $oPerm = KTPermission::getByName($sPermName); + if (!PEAR::isError($oPerm)) { + $aFinalPerms[] = $sPermName; + } + } + + $config = array(); + $config['perms'] = $aFinalPerms; + + $this->oTriggerInstance->setConfig($config); + $res = $this->oTriggerInstance->update(); + + return $res; + } + + function getConfigDescription() { + if (!$this->isLoaded()) { + return _kt('This trigger has no configuration.'); + } + // the actual permissions are stored in the array. + $perms = array(); + foreach ($this->aConfig['perms'] as $sPermName) { + $oPerm = KTPermission::getByName($sPermName); + if (!PEAR::isError($oPerm)) { + $perms[] = $oPerm->getHumanName(); + } + } + if (empty($perms)) { + return _kt('No permissions are required to perform this transition'); + } + + $perm_string = implode(', ', $perms); + return sprintf(_kt('The following permissions are required: %s'), $perm_string); + } +} + +?> \ No newline at end of file -- libgit2 0.21.4