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(); if (empty($this->aConfig) || is_null($this->aConfig['perms'])) { return _kt('No permissions are required to perform this transition'); } 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); } } ?>