Commit 2e0db1ef0b25fd55a43ce26928d460f501e2acdf
1 parent
ea5761c8
missing ktworkflowtriggers.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5546 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
128 additions
and
0 deletions
plugins/ktcore/KTWorkflowTriggers.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id: KTWorkflowTriggers.php 5439 2006-05-25 13:20:15Z bryndivey $ | |
| 5 | + * | |
| 6 | + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com | |
| 7 | + * | |
| 8 | + * This program is free software; you can redistribute it and/or modify | |
| 9 | + * it under the terms of the GNU General Public License as published by | |
| 10 | + * the Free Software Foundation; using version 2 of the License. | |
| 11 | + * | |
| 12 | + * This program is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | + * GNU General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License | |
| 18 | + * along with this program; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * ------------------------------------------------------------------------- | |
| 22 | + * | |
| 23 | + * You can contact the copyright owner regarding licensing via the contact | |
| 24 | + * details that can be found on the KnowledgeTree web site: | |
| 25 | + * | |
| 26 | + * http://www.ktdms.com/ | |
| 27 | + */ | |
| 28 | + | |
| 29 | +require_once(KT_LIB_DIR . "/workflow/workflowtrigger.inc.php"); | |
| 30 | + | |
| 31 | +require_once(KT_LIB_DIR . "/permissions/permission.inc.php"); | |
| 32 | +require_once(KT_LIB_DIR . "/permissions/permissionutil.inc.php"); | |
| 33 | + | |
| 34 | +class PermissionGuardTrigger extends KTWorkflowTrigger { | |
| 35 | + var $sNamespace = 'ktcore.workflowtriggers.permissionguard'; | |
| 36 | + var $sFriendlyName; | |
| 37 | + var $sDescription; | |
| 38 | + var $oTriggerInstance; | |
| 39 | + var $aConfig = array(); | |
| 40 | + | |
| 41 | + // generic requirements - both can be true | |
| 42 | + var $bIsGuard = true; | |
| 43 | + var $bIsAction = false; | |
| 44 | + | |
| 45 | + function PermissionGuardTrigger() { | |
| 46 | + $this->sFriendlyName = _kt("Permission Restrictions"); | |
| 47 | + $this->sDescription = _kt("Prevents users who do not have the specified permission from using this transition."); | |
| 48 | + } | |
| 49 | + | |
| 50 | + // override the allow transition hook. | |
| 51 | + function allowTransition($oDocument, $oUser) { | |
| 52 | + if (!$this->isLoaded()) { | |
| 53 | + return true; | |
| 54 | + } | |
| 55 | + // the actual permissions are stored in the array. | |
| 56 | + foreach ($this->aConfig['perms'] as $sPermName) { | |
| 57 | + $oPerm = KTPermission::getByName($sPermName); | |
| 58 | + if (PEAR::isError($oPerm)) { | |
| 59 | + continue; // possible loss of referential integrity, just ignore it for now. | |
| 60 | + } | |
| 61 | + $res = KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument); | |
| 62 | + if (!$res) { | |
| 63 | + return false; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + return true; | |
| 67 | + } | |
| 68 | + | |
| 69 | + function displayConfiguration($args) { | |
| 70 | + // permissions | |
| 71 | + $aPermissions = KTPermission::getList(); | |
| 72 | + $aKeyPermissions = array(); | |
| 73 | + foreach ($aPermissions as $oPermission) { $aKeyPermissions[$oPermission->getName()] = $oPermission; } | |
| 74 | + | |
| 75 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 76 | + $oTemplate = $oTemplating->loadTemplate("ktcore/workflowtriggers/permissions"); | |
| 77 | + $aTemplateData = array( | |
| 78 | + "context" => $this, | |
| 79 | + "perms" => $aKeyPermissions, | |
| 80 | + 'args' => $args, | |
| 81 | + ); | |
| 82 | + return $oTemplate->render($aTemplateData); | |
| 83 | + } | |
| 84 | + | |
| 85 | + function saveConfiguration() { | |
| 86 | + $perms = KTUtil::arrayGet($_REQUEST, 'trigger_perms', array()); | |
| 87 | + if (!is_array($perms)) { | |
| 88 | + $perms = (array) $perms; | |
| 89 | + } | |
| 90 | + $aFinalPerms = array(); | |
| 91 | + foreach ($perms as $sPermName => $ignore) { | |
| 92 | + $oPerm = KTPermission::getByName($sPermName); | |
| 93 | + if (!PEAR::isError($oPerm)) { | |
| 94 | + $aFinalPerms[] = $sPermName; | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + $config = array(); | |
| 99 | + $config['perms'] = $aFinalPerms; | |
| 100 | + | |
| 101 | + $this->oTriggerInstance->setConfig($config); | |
| 102 | + $res = $this->oTriggerInstance->update(); | |
| 103 | + | |
| 104 | + return $res; | |
| 105 | + } | |
| 106 | + | |
| 107 | + function getConfigDescription() { | |
| 108 | + if (!$this->isLoaded()) { | |
| 109 | + return _kt('This trigger has no configuration.'); | |
| 110 | + } | |
| 111 | + // the actual permissions are stored in the array. | |
| 112 | + $perms = array(); | |
| 113 | + foreach ($this->aConfig['perms'] as $sPermName) { | |
| 114 | + $oPerm = KTPermission::getByName($sPermName); | |
| 115 | + if (!PEAR::isError($oPerm)) { | |
| 116 | + $perms[] = $oPerm->getHumanName(); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + if (empty($perms)) { | |
| 120 | + return _kt('No permissions are required to perform this transition'); | |
| 121 | + } | |
| 122 | + | |
| 123 | + $perm_string = implode(', ', $perms); | |
| 124 | + return sprintf(_kt('The following permissions are required: %s'), $perm_string); | |
| 125 | + } | |
| 126 | +} | |
| 127 | + | |
| 128 | +?> | |
| 0 | 129 | \ No newline at end of file | ... | ... |