Commit 525a5e73350ad3004d3d6aa5d8d67afdfd9d9e2a
1 parent
144424a9
Add permission object and lookup attributes. Also clean up things a
bit. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3511 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
41 additions
and
306 deletions
lib/foldermanagement/Folder.inc
| ... | ... | @@ -47,10 +47,10 @@ class Folder extends KTEntity { |
| 47 | 47 | var $sParentFolderIDs; |
| 48 | 48 | /** forward slash deliminated path from file system root */ |
| 49 | 49 | var $sFullPath; |
| 50 | - /** whether to inherit parent permissions or not */ | |
| 51 | - var $bInheritParentPermission; | |
| 52 | - /** which folder I get permissions from (eases search lookups) */ | |
| 53 | - var $iPermissionFolderID; | |
| 50 | + /** which permission object I get permissions from */ | |
| 51 | + var $iPermissionObjectID; | |
| 52 | + /** lookup accelerator id */ | |
| 53 | + var $iPermissionLookupID; | |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Folder class constructor |
| ... | ... | @@ -72,162 +72,40 @@ class Folder extends KTEntity { |
| 72 | 72 | $this->iCreatorID = $iNewCreatorID; |
| 73 | 73 | $this->iUnitID = $iNewUnitID; |
| 74 | 74 | $this->bIsPublic = $bNewIsPublic; |
| 75 | - $this->bInheritParentPermissions = true; | |
| 76 | 75 | } |
| 77 | 76 | |
| 78 | - /** | |
| 79 | - * Get the primary key of the current folder object | |
| 80 | - * | |
| 81 | - * @return integer primary key of folder | |
| 82 | - * | |
| 83 | - */ | |
| 84 | - function getID() { | |
| 85 | - return $this->iId; | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * Get the folder name | |
| 90 | - * | |
| 91 | - * @return String folder name | |
| 92 | - */ | |
| 93 | - function getName() { | |
| 94 | - return $this->sName; | |
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * Set the folder name | |
| 99 | - * | |
| 100 | - * @param $sNewValue New folder name | |
| 101 | - */ | |
| 102 | - function setName($sNewValue) { | |
| 103 | - $this->sName = $sNewValue; | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * Get the folder description | |
| 108 | - * | |
| 109 | - * @return String folder description | |
| 110 | - */ | |
| 111 | - function getDescription() { | |
| 112 | - return $this->sDescription; | |
| 113 | - } | |
| 114 | - | |
| 115 | - /** | |
| 116 | - * Set the folder description | |
| 117 | - * | |
| 118 | - * @param $sNewValue New folder description | |
| 119 | - * | |
| 120 | - */ | |
| 121 | - function setDescription($sNewValue) { | |
| 122 | - $this->sDescription = $sNewValue; | |
| 123 | - } | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * Get the parent folder primary key | |
| 127 | - * | |
| 128 | - * @return integer parent folder primary key | |
| 129 | - * | |
| 130 | - */ | |
| 131 | - function getParentID() { | |
| 132 | - return $this->iParentID; | |
| 133 | - } | |
| 134 | - | |
| 135 | - /** | |
| 136 | - * Set the parent folder primary key | |
| 137 | - * | |
| 138 | - * @param $iNewValue New parent folder primary key | |
| 139 | - * | |
| 140 | - */ | |
| 141 | - function setParentID($iNewValue) { | |
| 142 | - $this->iParentID = $iNewValue; | |
| 143 | - } | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * Get the creator user id | |
| 147 | - * | |
| 148 | - * @return integer creator user id | |
| 149 | - * | |
| 150 | - */ | |
| 151 | - function getCreatorID() { | |
| 152 | - return $this->iCreatorID; | |
| 153 | - } | |
| 154 | - | |
| 155 | - /** | |
| 156 | - * Set the creator user id | |
| 157 | - * | |
| 158 | - * @param $iNewValue New creator user id | |
| 159 | - * | |
| 160 | - */ | |
| 161 | - function setCreatorID($iNewValue) { | |
| 162 | - $this->iCreatorID = $iNewValue; | |
| 163 | - } | |
| 164 | - | |
| 165 | - /** | |
| 166 | - * Get the unit primary key | |
| 167 | - * | |
| 168 | - * @return integer primary key of unit to which the folder belongs | |
| 169 | - * | |
| 170 | - */ | |
| 171 | - function getUnitID() { | |
| 172 | - return $this->iUnitID; | |
| 173 | - } | |
| 174 | - | |
| 175 | - /** | |
| 176 | - * Set the unit prinary key | |
| 177 | - * | |
| 178 | - * @param $iNewValue New primary key of unit to which folder belongs | |
| 179 | - * | |
| 180 | - */ | |
| 181 | - function setUnitID($iNewValue) { | |
| 182 | - $this->iUnitID = $iNewValue; | |
| 183 | - } | |
| 184 | - | |
| 185 | - /** | |
| 186 | - * Get the folder public status | |
| 187 | - * | |
| 188 | - * @return boolean true if folder is public, false if folder is not | |
| 189 | - * | |
| 190 | - */ | |
| 191 | - function getIsPublic() { | |
| 192 | - return $this->bIsPublic; | |
| 193 | - } | |
| 194 | - | |
| 195 | - /** | |
| 196 | - * Set the folder public status | |
| 197 | - * | |
| 198 | - * @param $bNewValue New folder public status | |
| 199 | - * | |
| 200 | - */ | |
| 201 | - function setIsPublic($bNewValue) { | |
| 202 | - $this->bIsPublic = $bNewValue; | |
| 203 | - } | |
| 204 | - | |
| 205 | - function getFullPath() { | |
| 206 | - return $this->sFullPath; | |
| 207 | - } | |
| 208 | - | |
| 209 | - function getParentFolderIDs() { | |
| 210 | - return $this->sParentFolderIDs; | |
| 211 | - } | |
| 212 | - | |
| 213 | - function getInheritParentPermission() { | |
| 214 | - return $this->bInheritParentPermissions; | |
| 215 | - } | |
| 216 | - | |
| 217 | - function setInheritParentPermission($bNewValue) { | |
| 218 | - $this->bInheritParentPermissions = $bNewValue; | |
| 219 | - } | |
| 77 | + function getID() { return $this->iId; } | |
| 78 | + function getName() { return $this->sName; } | |
| 79 | + function setName($sNewValue) { $this->sName = $sNewValue; } | |
| 80 | + function getDescription() { return $this->sDescription; } | |
| 81 | + function setDescription($sNewValue) { $this->sDescription = $sNewValue; } | |
| 82 | + function getParentID() { return $this->iParentID; } | |
| 83 | + function setParentID($iNewValue) { $this->iParentID = $iNewValue; } | |
| 84 | + function getCreatorID() { return $this->iCreatorID; } | |
| 85 | + function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; } | |
| 86 | + function getUnitID() { return $this->iUnitID; } | |
| 87 | + function setUnitID($iNewValue) { $this->iUnitID = $iNewValue; } | |
| 88 | + function getIsPublic() { return $this->bIsPublic; } | |
| 89 | + function setIsPublic($bNewValue) { $this->bIsPublic = $bNewValue; } | |
| 90 | + function getFullPath() { return $this->sFullPath; } | |
| 91 | + function getParentFolderIDs() { return $this->sParentFolderIDs; } | |
| 220 | 92 | |
| 221 | - /** | |
| 222 | - * Get the permission folder id | |
| 223 | - * | |
| 224 | - * @return integer permission folder id | |
| 225 | - * | |
| 226 | - */ | |
| 227 | - function getPermissionFolderID() { | |
| 228 | - return $this->iPermissionFolderID; | |
| 229 | - } | |
| 230 | - | |
| 93 | + function getPermissionObjectID() { return $this->iPermissionObjectID; } | |
| 94 | + function setPermissionObjectID($iPermissionObjectID) { $this->iPermissionObjectID = $iPermissionObjectID; } | |
| 95 | + function getPermissionLookupID() { return $this->iPermissionLookupID; } | |
| 96 | + function setPermissionLookupID($iPermissionLookupID) { $this->iPermissionLookupID = $iPermissionLookupID; } | |
| 97 | + | |
| 98 | + // {{{ create() | |
| 99 | + function create () { | |
| 100 | + $oParentFolder = Folder::get($this->iParentID); | |
| 101 | + $this->iPermissionObjectID = $oParentFolder->getPermissionObjectID(); | |
| 102 | + $res = parent::create(); | |
| 103 | + if ($res === true) { | |
| 104 | + KTPermissionUtil::updatePermissionLookup($this); | |
| 105 | + } | |
| 106 | + return $res; | |
| 107 | + } | |
| 108 | + // }}} | |
| 231 | 109 | /** |
| 232 | 110 | * Recursive function to generate a comma delimited string containing |
| 233 | 111 | * the parent folder ids |
| ... | ... | @@ -241,7 +119,7 @@ class Folder extends KTEntity { |
| 241 | 119 | $sql = $default->db; |
| 242 | 120 | $sql->query(array("SELECT parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/ |
| 243 | 121 | $sql->next_record(); |
| 244 | - return $this->generateParentFolderIDS($sql->f("parent_id")) . ",$iFolderID"; | |
| 122 | + return Folder::generateParentFolderIDS($sql->f("parent_id")) . ",$iFolderID"; | |
| 245 | 123 | } |
| 246 | 124 | return; |
| 247 | 125 | |
| ... | ... | @@ -253,7 +131,7 @@ class Folder extends KTEntity { |
| 253 | 131 | * @return String comma delimited string containing the parent folder ids |
| 254 | 132 | */ |
| 255 | 133 | function generateFolderIDs($iFolderID) { |
| 256 | - $sFolderIDs = $this->generateParentFolderIDS($iFolderID); | |
| 134 | + $sFolderIDs = Folder::generateParentFolderIDS($iFolderID); | |
| 257 | 135 | return substr($sFolderIDs, 1, strlen($sFolderIDs)); |
| 258 | 136 | } |
| 259 | 137 | |
| ... | ... | @@ -296,8 +174,8 @@ class Folder extends KTEntity { |
| 296 | 174 | 'is_public' => KTUtil::anyToBool($this->bIsPublic), |
| 297 | 175 | 'full_path' => $this->sFullPath, |
| 298 | 176 | 'parent_folder_ids' => $this->sParentFolderIDs, |
| 299 | - 'inherit_parent_folder_permission' => $this->bInheritParentPermissions, | |
| 300 | - 'permission_folder_id' => $this->iPermissionFolderID, | |
| 177 | + 'permission_object_id' => $this->iPermissionObjectID, | |
| 178 | + 'permission_lookup_id' => $this->iPermissionLookupID, | |
| 301 | 179 | ); |
| 302 | 180 | } |
| 303 | 181 | |
| ... | ... | @@ -418,7 +296,8 @@ class Folder extends KTEntity { |
| 418 | 296 | $oFolder->iId = $iFolderID; |
| 419 | 297 | $oFolder->sFullPath = $sql->f("full_path"); |
| 420 | 298 | $oFolder->sParentFolderIDs = $sql->f("parent_folder_ids"); |
| 421 | - $oFolder->iPermissionFolderID = $sql->f("permission_folder_id"); | |
| 299 | + $oFolder->iPermissionObjectID = $sql->f("permission_object_id"); | |
| 300 | + $oFolder->iPermissionLookupID = $sql->f("permission_lookup_id"); | |
| 422 | 301 | return $oFolder; |
| 423 | 302 | } |
| 424 | 303 | $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderID . " table = folders"; |
| ... | ... | @@ -724,150 +603,6 @@ class Folder extends KTEntity { |
| 724 | 603 | return false; |
| 725 | 604 | } |
| 726 | 605 | } |
| 727 | - | |
| 728 | - function calculatePermissionFolder() { | |
| 729 | - global $default; | |
| 730 | - $oInheritedFolder = $this; | |
| 731 | - while ($bFoundPermissions !== true) { | |
| 732 | - /*ok*/$aCheckQuery = array('SELECT id FROM groups_folders_link WHERE folder_id = ? LIMIT 1', $oInheritedFolder->getID()); | |
| 733 | - if (count(DBUtil::getResultArrayKey($aCheckQuery, 'id')) == 0) { | |
| 734 | - $default->log->debug('No direct permissions on folder ' . $oInheritedFolder->getID()); | |
| 735 | - $bInherited = true; | |
| 736 | - $oInheritedFolder =& Folder::get($oInheritedFolder->getParentID()); | |
| 737 | - if ($oInheritedFolder === false) { | |
| 738 | - break; | |
| 739 | - } | |
| 740 | - // if our parent knows the permission folder, use that. | |
| 741 | - if ($oInheritedFolder->getPermissionFolderID()) { | |
| 742 | - $this->iPermissionFolderID = $oInheritedFolder->getPermissionFolderID(); | |
| 743 | - } | |
| 744 | - $default->log->debug('... trying parent: ' . $oInheritedFolder->getID()); | |
| 745 | - } else { | |
| 746 | - $default->log->debug('Found direct permissions on folder ' . $oInheritedFolder->getID()); | |
| 747 | - $this->iPermissionFolderID = $oInheritedFolder->getID(); | |
| 748 | - return; | |
| 749 | - } | |
| 750 | - } | |
| 751 | - | |
| 752 | - $default->log->error('No permissions whatsoever for folder ' . $this->getID()); | |
| 753 | - // 0, which can never exist, for non-existent. null for not set yet (database upgrade). | |
| 754 | - $this->iPermissionFolderID = 0; | |
| 755 | - } | |
| 756 | - | |
| 757 | - // {{{ copyPermissionsFromFolder() | |
| 758 | - function copyPermissionsFromFolder ($oFolder) { | |
| 759 | - $sQuery = DBUtil::compactQuery(" | |
| 760 | - SELECT | |
| 761 | - GFL.group_id AS group_id, | |
| 762 | - GFL.can_read AS can_read, | |
| 763 | - GFL.can_write AS can_write | |
| 764 | - FROM | |
| 765 | - $default->groups_folders_table AS GFL | |
| 766 | - WHERE GFL.folder_id = ?"); | |
| 767 | - $aParams = array($oFolder->getID()); | |
| 768 | - $aPermissions = DBUtil::getResultArray(array($sQuery, $aParams)); | |
| 769 | - | |
| 770 | - if (PEAR::isError($aPermissions)) { | |
| 771 | - return $aPermissions; | |
| 772 | - } | |
| 773 | - | |
| 774 | - foreach ($aPermissions as $aRow) { | |
| 775 | - $aRow['folder_id'] = $this->getID(); | |
| 776 | - $res = DBUtil::autoInsert($default->groups_folders_table, $aRow); | |
| 777 | - if (PEAR::isError($res)) { | |
| 778 | - return $res; | |
| 779 | - } | |
| 780 | - } | |
| 781 | - | |
| 782 | - $this->updatePermissions(); | |
| 783 | - } | |
| 784 | - // }}} | |
| 785 | - | |
| 786 | - // {{{ create() | |
| 787 | - function create () { | |
| 788 | - $this->calculatePermissionFolder(); | |
| 789 | - return parent::create(); | |
| 790 | - } | |
| 791 | - // }}} | |
| 792 | - | |
| 793 | - // {{{ updatePermissions() | |
| 794 | - function updatePermissions () { | |
| 795 | - // Update PermissionFolderIDs on folder and all folders in this | |
| 796 | - // branch. | |
| 797 | - $this->updatePermissionFolders(); | |
| 798 | - | |
| 799 | - // Now, we need to redo the permissions for all documents that | |
| 800 | - // share are in this branch of the tree that are in folders that | |
| 801 | - // share our PermissionFolderID. | |
| 802 | - | |
| 803 | - // First, we update the documents in this folder | |
| 804 | - $sQuery = "SELECT D.id AS id FROM documents AS D WHERE D.folder_id = ?"; | |
| 805 | - $aParams = array($this->getID()); | |
| 806 | - $aDocumentIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); | |
| 807 | - // OPT: We could just do the work for the first, and copy it to | |
| 808 | - // the others... | |
| 809 | - foreach ($aDocumentIDs as $iDocumentID) { | |
| 810 | - Permission::updateSearchPermissionsForDocument($iDocumentID); | |
| 811 | - } | |
| 812 | - | |
| 813 | - // Then, we update the documents in our subfolders | |
| 814 | - $sFolderIDs = $this->generateFolderIDs($this->getID()); | |
| 815 | - $sFolderIDs .= '%'; | |
| 816 | - $sQuery = "SELECT D.id AS id FROM documents AS D INNER JOIN folders AS F on D.folder_id = F.id WHERE F.parent_folder_ids LIKE ?"; | |
| 817 | - $aParams = array($sFolderIDs); | |
| 818 | - $aDocumentIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); | |
| 819 | - | |
| 820 | - // OPT: We could just do the work for the first, and copy it to | |
| 821 | - // the others... | |
| 822 | - foreach ($aDocumentIDs as $iDocumentID) { | |
| 823 | - Permission::updateSearchPermissionsForDocument($iDocumentID); | |
| 824 | - } | |
| 825 | - } | |
| 826 | - // }}} | |
| 827 | - | |
| 828 | - // {{{ updatePermissionFolders() | |
| 829 | - /** | |
| 830 | - * Update the PermissionFolderID on this folder and all folders on | |
| 831 | - * this branch. | |
| 832 | - * | |
| 833 | - */ | |
| 834 | - function updatePermissionFolders() { | |
| 835 | - $iOldPermissionFolderID = $this->iPermissionFolderID; | |
| 836 | - $this->calculatePermissionFolder(); | |
| 837 | - $iNewPermissionFolderID = $this->iPermissionFolderID; | |
| 838 | - | |
| 839 | - // If our permission folder hasn't changed, our children's won't | |
| 840 | - // have. | |
| 841 | - if ($iOldPermissionFolderID === $iNewPermissionFolderID) { | |
| 842 | - return; | |
| 843 | - } | |
| 844 | - | |
| 845 | - // XXX: Non-explicit update... Have to update, or the children | |
| 846 | - // wouldn't have access to it for the shortcut... | |
| 847 | - $this->update(); | |
| 848 | - $aChildren = Folder::getList(array('parent_id = ?', $this->getID())); | |
| 849 | - foreach ($aChildren as $oChild) { | |
| 850 | - $oChild->updatePermissionFolders(); | |
| 851 | - } | |
| 852 | - } | |
| 853 | - // }}} | |
| 854 | - | |
| 855 | - function addPermission ($oGroup, $bCanRead, $bCanWrite) { | |
| 856 | - $oGroupFolderLink = & new GroupFolderLink($this->getID(), $oGroup->getID(), $bCanRead, $bCanWrite); | |
| 857 | - | |
| 858 | - if ($oGroupFolderLink->exists()) { | |
| 859 | - return new PEAR_Error(_("A folder access entry for the selected folder and group already exists.")); | |
| 860 | - } | |
| 861 | - | |
| 862 | - if (!$oGroupFolderLink->create()) { | |
| 863 | - //otherwise display an error message | |
| 864 | - return new PEAR_Error(_("A folder access entry for the selected folder and group already exists.")); | |
| 865 | - } | |
| 866 | - | |
| 867 | - $this->updatePermissions(); | |
| 868 | - return true; | |
| 869 | - } | |
| 870 | - | |
| 871 | 606 | } |
| 872 | 607 | |
| 873 | 608 | ?> | ... | ... |