Commit cbcfc8077c12eea4cdffaf5448bf790fe2fd397d

Authored by Brad Shuttleworth
1 parent 43686f9f

fix for KTS-583: delete fails


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5060 c91229c3-7414-0410-bfa2-8a42b809f60b
browse.php
@@ -43,6 +43,8 @@ require_once(KT_LIB_DIR . "/widgets/portlet.inc.php"); @@ -43,6 +43,8 @@ require_once(KT_LIB_DIR . "/widgets/portlet.inc.php");
43 require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); 43 require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
44 require_once(KT_DIR . '/plugins/ktcore/KTFolderActions.php'); 44 require_once(KT_DIR . '/plugins/ktcore/KTFolderActions.php');
45 45
  46 +require_once(KT_LIB_DIR . "/permissions/permissionutil.inc.php");
  47 +require_once(KT_LIB_DIR . "/permissions/permission.inc.php");
46 48
47 /******* NBM's FAMOUS MOVECOLUMN HACK 49 /******* NBM's FAMOUS MOVECOLUMN HACK
48 * 50 *
@@ -683,6 +685,7 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -683,6 +685,7 @@ class BrowseDispatcher extends KTStandardDispatcher {
683 $aFolderSelection = KTUtil::arrayGet($_REQUEST, 'selection_f' , array()); 685 $aFolderSelection = KTUtil::arrayGet($_REQUEST, 'selection_f' , array());
684 $aDocumentSelection = KTUtil::arrayGet($_REQUEST, 'selection_d' , array()); 686 $aDocumentSelection = KTUtil::arrayGet($_REQUEST, 'selection_d' , array());
685 687
  688 + $oPerm = KTPermission::getByName('ktcore.permissions.delete');
686 689
687 // now show the items... 690 // now show the items...
688 $delItems = array(); 691 $delItems = array();
@@ -696,6 +699,9 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -696,6 +699,9 @@ class BrowseDispatcher extends KTStandardDispatcher {
696 $folderStr = '<strong>' . _('Folders: ') . '</strong>'; 699 $folderStr = '<strong>' . _('Folders: ') . '</strong>';
697 foreach ($aFolderSelection as $iFolderId) { 700 foreach ($aFolderSelection as $iFolderId) {
698 $oF = Folder::get($iFolderId); 701 $oF = Folder::get($iFolderId);
  702 + if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oF)) {
  703 + $this->errorRedirectToMain(_('You do not have permission to delete the folder: ') . $oF->getName());
  704 + }
699 $delItems['folders'][] = $oF->getName(); 705 $delItems['folders'][] = $oF->getName();
700 } 706 }
701 $folderStr .= implode(', ', $delItems['folders']); 707 $folderStr .= implode(', ', $delItems['folders']);
@@ -705,7 +711,12 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -705,7 +711,12 @@ class BrowseDispatcher extends KTStandardDispatcher {
705 $documentStr = '<strong>' . _('Documents: ') . '</strong>'; 711 $documentStr = '<strong>' . _('Documents: ') . '</strong>';
706 foreach ($aDocumentSelection as $iDocId) { 712 foreach ($aDocumentSelection as $iDocId) {
707 $oD = Document::get($iDocId); 713 $oD = Document::get($iDocId);
708 - $delItems['documents'][] = $oD->getName(); 714 + if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oD)) {
  715 + $this->errorRedirectToMain(_('You do not have permission to delete the document: ') . $oD->getName());
  716 + }
  717 + if (!PEAR::isError($oD)) {
  718 + $delItems['documents'][] = $oD->getName();
  719 + }
709 } 720 }
710 $documentStr .= implode(', ', $delItems['documents']); 721 $documentStr .= implode(', ', $delItems['documents']);
711 } 722 }
@@ -734,7 +745,7 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -734,7 +745,7 @@ class BrowseDispatcher extends KTStandardDispatcher {
734 $fFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1); 745 $fFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1);
735 746
736 747
737 - 748 + $oPerm = KTPermission::getByName('ktcore.permissions.delete');
738 $res = KTUtil::arrayGet($_REQUEST,'sReason'); 749 $res = KTUtil::arrayGet($_REQUEST,'sReason');
739 $sReason = $res; 750 $sReason = $res;
740 if (empty($res)) { 751 if (empty($res)) {
@@ -751,17 +762,19 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -751,17 +762,19 @@ class BrowseDispatcher extends KTStandardDispatcher {
751 $oF = Folder::get($id); 762 $oF = Folder::get($id);
752 if (PEAR::isError($oF) || ($oF == false)) { 763 if (PEAR::isError($oF) || ($oF == false)) {
753 return $this->errorRedirectToMain(_('Invalid Folder selected.')); 764 return $this->errorRedirectToMain(_('Invalid Folder selected.'));
754 - } else { 765 + } else if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oF)) {
  766 + return $this->errorRedirectToMain(sprintf(_('You do not have permissions to delete the folder: %s'), $oF->getName()));
  767 + } else{
755 $aFolders[] = $oF; 768 $aFolders[] = $oF;
756 } 769 }
757 } 770 }
758 foreach ($aDocumentSelection as $id) { 771 foreach ($aDocumentSelection as $id) {
759 $oD = Document::get($id); 772 $oD = Document::get($id);
760 - if (!Permission::userHasDocumentWritePermission($oD)) {  
761 - return $this->errorRedirectToMain(sprintf(_('You do not have permissions to delete the documen: %s'), $oD->getName()));  
762 - } 773 +
763 if (PEAR::isError($oD) || ($oD == false)) { 774 if (PEAR::isError($oD) || ($oD == false)) {
764 return $this->errorRedirectToMain(_('Invalid Document selected.')); 775 return $this->errorRedirectToMain(_('Invalid Document selected.'));
  776 + } else if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oD)) {
  777 + return $this->errorRedirectToMain(sprintf(_('You do not have permissions to delete the document: %s'), $oD->getName()));
765 } else { 778 } else {
766 $aDocuments[] = $oD; 779 $aDocuments[] = $oD;
767 } 780 }
lib/foldermanagement/folderutil.inc.php
@@ -203,8 +203,7 @@ class KTFolderUtil { @@ -203,8 +203,7 @@ class KTFolderUtil {
203 function delete($oStartFolder, $oUser, $sReason, $aOptions = null) { 203 function delete($oStartFolder, $oUser, $sReason, $aOptions = null) {
204 require_once(KT_LIB_DIR . '/unitmanagement/Unit.inc'); 204 require_once(KT_LIB_DIR . '/unitmanagement/Unit.inc');
205 205
206 - // FIXME: we need to work out if "write" is the right perm.  
207 - $oPerm = KTPermission::getByName('ktcore.permissions.write'); 206 + $oPerm = KTPermission::getByName('ktcore.permissions.delete');
208 207
209 $bIgnorePermissions = KTUtil::arrayGet($aOptions, 'ignore_permissions'); 208 $bIgnorePermissions = KTUtil::arrayGet($aOptions, 'ignore_permissions');
210 209
@@ -270,7 +269,7 @@ class KTFolderUtil { @@ -270,7 +269,7 @@ class KTFolderUtil {
270 269
271 // now we can go ahead. 270 // now we can go ahead.
272 foreach ($aDocuments as $oDocument) { 271 foreach ($aDocuments as $oDocument) {
273 - $res = KTDocumentUtil::delete($oDocument, $sReason, 1); // id of destination folder = ROOT 272 + $res = KTDocumentUtil::delete($oDocument, $sReason);
274 if (PEAR::isError($res)) { 273 if (PEAR::isError($res)) {
275 DBUtil::rollback(); 274 DBUtil::rollback();
276 return PEAR::raiseError(_('Delete Aborted. Unexpected failure to delete document: ') . $oDocument->getName() . $res->getMessage()); 275 return PEAR::raiseError(_('Delete Aborted. Unexpected failure to delete document: ') . $oDocument->getName() . $res->getMessage());
plugins/ktcore/KTDocumentActions.php
@@ -359,7 +359,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -359,7 +359,7 @@ class KTDocumentEditAction extends KTDocumentAction {
359 class KTDocumentDeleteAction extends KTDocumentAction { 359 class KTDocumentDeleteAction extends KTDocumentAction {
360 var $sName = 'ktcore.actions.document.delete'; 360 var $sName = 'ktcore.actions.document.delete';
361 361
362 - var $_sShowPermission = "ktcore.permissions.write"; 362 + var $_sShowPermission = "ktcore.permissions.delete";
363 363
364 function getDisplayName() { 364 function getDisplayName() {
365 return _('Delete'); 365 return _('Delete');