Commit 08572d2ec497f3319d74de52111148fe89e145ca
1 parent
5be2067c
Allow for dynamic permissions - permissions that are available only if a
certain condition on a document is met, using a saved search/condition. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3973 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
65 additions
and
36 deletions
presentation/lookAndFeel/knowledgeTree/foldermanagement/folderPermissions.php
| ... | ... | @@ -14,6 +14,9 @@ require_once(KT_LIB_DIR . "/permissions/permissionobject.inc.php"); |
| 14 | 14 | require_once(KT_LIB_DIR . "/permissions/permissionassignment.inc.php"); |
| 15 | 15 | require_once(KT_LIB_DIR . "/permissions/permissiondescriptor.inc.php"); |
| 16 | 16 | require_once(KT_LIB_DIR . "/permissions/permissionutil.inc.php"); |
| 17 | +require_once(KT_LIB_DIR . "/permissions/permissiondynamiccondition.inc.php"); | |
| 18 | + | |
| 19 | +require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); | |
| 17 | 20 | |
| 18 | 21 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); |
| 19 | 22 | $sectionName = "Manage Documents"; |
| ... | ... | @@ -27,12 +30,12 @@ function displayFolderPathLink($aPathArray, $aPathNameArray, $sLinkPage = "") { |
| 27 | 30 | $default->log->debug("displayFolderPathLink: slinkPage=$sLinkPage"); |
| 28 | 31 | // display a separate link to each folder in the path |
| 29 | 32 | for ($i=0; $i<count($aPathArray); $i++) { |
| 30 | - $iFolderID = $aPathArray[$i]; | |
| 33 | + $iFolderId = $aPathArray[$i]; | |
| 31 | 34 | // retrieve the folder name for this folder |
| 32 | 35 | $sFolderName = $aPathNameArray[$i]; |
| 33 | - // generate a link back to this page setting fFolderID | |
| 36 | + // generate a link back to this page setting fFolderId | |
| 34 | 37 | $sLink = generateLink($sLinkPage, |
| 35 | - "fBrowseType=folder&fFolderID=$iFolderID", | |
| 38 | + "fBrowseType=folder&fFolderID=$iFolderId", | |
| 36 | 39 | $sFolderName); |
| 37 | 40 | $sPathLinks = (strlen($sPathLinks) > 0) ? $sPathLinks . " > " . $sLink : $sLink; |
| 38 | 41 | } |
| ... | ... | @@ -41,11 +44,19 @@ function displayFolderPathLink($aPathArray, $aPathNameArray, $sLinkPage = "") { |
| 41 | 44 | |
| 42 | 45 | |
| 43 | 46 | class FolderPermissions extends KTStandardDispatcher { |
| 47 | + var $bAutomaticTransaction = true; | |
| 48 | + | |
| 49 | + function check() { | |
| 50 | + if (KTUtil::arrayGet($_REQUEST, 'fFolderID')) { | |
| 51 | + $_REQUEST['fFolderId'] = $_REQUEST['fFolderID']; | |
| 52 | + } | |
| 53 | + $this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']); | |
| 54 | + return true; | |
| 55 | + } | |
| 44 | 56 | function do_main() { |
| 45 | 57 | $oTemplating = new KTTemplating; |
| 46 | - $oTemplate = $oTemplating->loadTemplate("ktcore/manage_folder_permissions"); | |
| 47 | - $oFolder = Folder::get($_REQUEST['fFolderID']); | |
| 48 | - $oPO = KTPermissionObject::get($oFolder->getPermissionObjectID()); | |
| 58 | + $oTemplate = $oTemplating->loadTemplate("ktcore/folder/permissions"); | |
| 59 | + $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId()); | |
| 49 | 60 | $aPermissions = KTPermission::getList(); |
| 50 | 61 | $aMapPermissionGroup = array(); |
| 51 | 62 | foreach ($aPermissions as $oPermission) { |
| ... | ... | @@ -53,45 +64,48 @@ class FolderPermissions extends KTStandardDispatcher { |
| 53 | 64 | if (PEAR::isError($oPA)) { |
| 54 | 65 | continue; |
| 55 | 66 | } |
| 56 | - $oDescriptor = KTPermissionDescriptor::get($oPA->getPermissionDescriptorID()); | |
| 57 | - $iPermissionID = $oPermission->getID(); | |
| 58 | - $aIDs = $oDescriptor->getGroups(); | |
| 59 | - $aMapPermissionGroup[$iPermissionID] = array(); | |
| 60 | - foreach ($aIDs as $iID) { | |
| 61 | - $aMapPermissionGroup[$iPermissionID][$iID] = true; | |
| 67 | + $oDescriptor = KTPermissionDescriptor::get($oPA->getPermissionDescriptorId()); | |
| 68 | + $iPermissionId = $oPermission->getId(); | |
| 69 | + $aIds = $oDescriptor->getGroups(); | |
| 70 | + $aMapPermissionGroup[$iPermissionId] = array(); | |
| 71 | + foreach ($aIds as $iId) { | |
| 72 | + $aMapPermissionGroup[$iPermissionId][$iId] = true; | |
| 62 | 73 | } |
| 63 | 74 | } |
| 64 | 75 | $aMapPermissionUser = array(); |
| 65 | 76 | $aUsers = User::getList(); |
| 66 | 77 | foreach ($aPermissions as $oPermission) { |
| 67 | - $iPermissionID = $oPermission->getID(); | |
| 78 | + $iPermissionId = $oPermission->getId(); | |
| 68 | 79 | foreach ($aUsers as $oUser) { |
| 69 | - if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oFolder)) { | |
| 70 | - $aMapPermissionUser[$iPermissionID][$oUser->getID()] = true; | |
| 80 | + if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $this->oFolder)) { | |
| 81 | + $aMapPermissionUser[$iPermissionId][$oUser->getId()] = true; | |
| 71 | 82 | } |
| 72 | 83 | } |
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | $oInherited = KTPermissionUtil::findRootObjectForPermissionObject($oPO); |
| 76 | - if ($oInherited === $oFolder) { | |
| 87 | + if ($oInherited === $this->oFolder) { | |
| 77 | 88 | $bEdit = true; |
| 78 | 89 | } else { |
| 79 | - $iInheritedFolderID = $oInherited->getID(); | |
| 80 | - $sInherited = displayFolderPathLink(Folder::getFolderPathAsArray($iInheritedFolderID), | |
| 81 | - Folder::getFolderPathNamesAsArray($iInheritedFolderID), | |
| 90 | + $iInheritedFolderId = $oInherited->getId(); | |
| 91 | + $sInherited = displayFolderPathLink(Folder::getFolderPathAsArray($iInheritedFolderId), | |
| 92 | + Folder::getFolderPathNamesAsArray($iInheritedFolderId), | |
| 82 | 93 | "$default->rootUrl/control.php?action=editFolderPermissions"); |
| 83 | 94 | $bEdit = false; |
| 84 | 95 | } |
| 85 | 96 | |
| 97 | + $aDynamicConditions = KTPermissionDynamicCondition::getByPermissionObject($oPO); | |
| 86 | 98 | $aTemplateData = array( |
| 87 | 99 | "permissions" => $aPermissions, |
| 88 | 100 | "groups" => Group::getList(), |
| 89 | - "iFolderID" => $_REQUEST['fFolderID'], | |
| 101 | + "iFolderId" => $this->oFolder->getId(), | |
| 90 | 102 | "aMapPermissionGroup" => $aMapPermissionGroup, |
| 91 | 103 | "users" => $aUsers, |
| 92 | 104 | "aMapPermissionUser" => $aMapPermissionUser, |
| 93 | 105 | "edit" => $bEdit, |
| 94 | 106 | "inherited" => $sInherited, |
| 107 | + "conditions" => KTSavedSearch::getConditions(), | |
| 108 | + "dynamic_conditions" => $aDynamicConditions, | |
| 95 | 109 | ); |
| 96 | 110 | return $oTemplate->render($aTemplateData); |
| 97 | 111 | } |
| ... | ... | @@ -104,35 +118,50 @@ class FolderPermissions extends KTStandardDispatcher { |
| 104 | 118 | } |
| 105 | 119 | |
| 106 | 120 | function do_update() { |
| 107 | - $oFolder = Folder::get($_REQUEST['fFolderID']); | |
| 108 | - $oPO = KTPermissionObject::get($oFolder->getPermissionObjectID()); | |
| 121 | + $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId()); | |
| 109 | 122 | $aFoo = $_REQUEST['foo']; |
| 110 | 123 | $aPermissions = KTPermission::getList(); |
| 111 | 124 | foreach ($aPermissions as $oPermission) { |
| 112 | - $iPermID = $oPermission->getID(); | |
| 113 | - $aAllowed = KTUtil::arrayGet($aFoo, $iPermID, array()); | |
| 114 | - KTPermissionUtil::setPermissionForID($oPermission, $oPO, $aAllowed); | |
| 125 | + $iPermId = $oPermission->getId(); | |
| 126 | + $aAllowed = KTUtil::arrayGet($aFoo, $iPermId, array()); | |
| 127 | + KTPermissionUtil::setPermissionForId($oPermission, $oPO, $aAllowed); | |
| 115 | 128 | } |
| 116 | 129 | KTPermissionUtil::updatePermissionLookupForPO($oPO); |
| 117 | - return $this->errorRedirectToMain('Permissions updated', | |
| 118 | - array('fFolderID' => $oFolder->getID())); | |
| 130 | + return $this->successRedirectToMain('Permissions updated', | |
| 131 | + array('fFolderId' => $this->oFolder->getId())); | |
| 119 | 132 | } |
| 120 | 133 | |
| 121 | 134 | function do_copyPermissions() { |
| 122 | - $oFolder = Folder::get($_REQUEST['fFolderID']); | |
| 123 | - KTPermissionUtil::copyPermissionObject($oFolder); | |
| 124 | - return $this->errorRedirectToMain('Permissions updated', | |
| 125 | - array('fFolderID' => $oFolder->getID())); | |
| 135 | + KTPermissionUtil::copyPermissionObject($this->oFolder); | |
| 136 | + return $this->successRedirectToMain('Permissions updated', | |
| 137 | + array('fFolderId' => $oFolder->getId())); | |
| 126 | 138 | } |
| 127 | 139 | |
| 128 | 140 | function do_inheritPermissions() { |
| 129 | - $oFolder = Folder::get($_REQUEST['fFolderID']); | |
| 130 | - KTPermissionUtil::inheritPermissionObject($oFolder); | |
| 131 | - return $this->errorRedirectToMain('Permissions updated', | |
| 132 | - array('fFolderID' => $oFolder->getID())); | |
| 141 | + KTPermissionUtil::inheritPermissionObject($this->oFolder); | |
| 142 | + return $this->successRedirectToMain('Permissions updated', | |
| 143 | + array('fFolderId' => $this->oFolder->getId())); | |
| 133 | 144 | } |
| 134 | 145 | |
| 135 | - | |
| 146 | + function do_newDynamicPermission() { | |
| 147 | + $oGroup =& $this->oValidator->validateGroup($_REQUEST['fGroupId']); | |
| 148 | + $oCondition =& $this->oValidator->validateCondition($_REQUEST['fConditionId']); | |
| 149 | + $aPermissionIds = $_REQUEST['fPermissionIds']; | |
| 150 | + $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId()); | |
| 151 | + | |
| 152 | + $oDynamicCondition = KTPermissionDynamicCondition::createFromArray(array( | |
| 153 | + 'groupid' => $oGroup->getId(), | |
| 154 | + 'conditionid' => $oCondition->getId(), | |
| 155 | + 'permissionobjectid' => $oPO->getId(), | |
| 156 | + )); | |
| 157 | + $aOptions = array( | |
| 158 | + 'redirect_to' => array('main', 'fFolderId=' . $this->oFolder->getId()), | |
| 159 | + ); | |
| 160 | + $this->oValidator->notError($oDynamicCondition, $aOptions); | |
| 161 | + $res = $oDynamicCondition->saveAssignment($aPermissionIds); | |
| 162 | + $this->oValidator->notError($res, $aOptions); | |
| 163 | + $this->successRedirectToMain("Dynamic permission added", "fFolderId=" . $this->oFolder->getId()); | |
| 164 | + } | |
| 136 | 165 | } |
| 137 | 166 | |
| 138 | 167 | $oDispatcher = new FolderPermissions; | ... | ... |