Commit fe772a4ae80579cd528ebd618a929ca6c82c0653
1 parent
a69452c4
Throw exception on attempting to access the parent of the root folder.
KTS-4448. CMIS request for root folder parent should return valid error response Fixed Committed by: Paul Barrett Reviewed by: Jarrett Jordaan
Showing
4 changed files
with
43 additions
and
5 deletions
lib/api/ktcmis/ktNavigationService.inc.php
| @@ -157,8 +157,16 @@ class KTNavigationService extends KTCMISBase { | @@ -157,8 +157,16 @@ class KTNavigationService extends KTCMISBase { | ||
| 157 | */ | 157 | */ |
| 158 | public function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') | 158 | public function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') |
| 159 | { | 159 | { |
| 160 | - $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, | ||
| 161 | - $includeRelationships, $returnToRoot); | 160 | + try { |
| 161 | + $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, | ||
| 162 | + $includeRelationships, $returnToRoot); | ||
| 163 | + } | ||
| 164 | + catch (Exception $e) { | ||
| 165 | + return array( | ||
| 166 | + "status_code" => 1, | ||
| 167 | + "message" => "Failed getting ancestry for folder: " . $e->getMessage() | ||
| 168 | + ); | ||
| 169 | + } | ||
| 162 | 170 | ||
| 163 | if (PEAR::isError($ancestryResult)) | 171 | if (PEAR::isError($ancestryResult)) |
| 164 | { | 172 | { |
lib/api/ktcmis/services/CMISNavigationService.inc.php
| @@ -71,7 +71,7 @@ class CMISNavigationService { | @@ -71,7 +71,7 @@ class CMISNavigationService { | ||
| 71 | */ | 71 | */ |
| 72 | 72 | ||
| 73 | // NOTE This method does NOT support paging as defined in the paging section | 73 | // NOTE This method does NOT support paging as defined in the paging section |
| 74 | - // NOTE If the Repository supports the optional “VersionSpecificFiling†capability, | 74 | + // NOTE If the Repository supports the optional “VersionSpecificFiling� capability, |
| 75 | // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. | 75 | // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. |
| 76 | // Otherwise, the latest version of the documents SHALL be returned. | 76 | // Otherwise, the latest version of the documents SHALL be returned. |
| 77 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid | 77 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid |
| @@ -112,7 +112,7 @@ class CMISNavigationService { | @@ -112,7 +112,7 @@ class CMISNavigationService { | ||
| 112 | * @param int $skipCount | 112 | * @param int $skipCount |
| 113 | * @return array $descendants | 113 | * @return array $descendants |
| 114 | */ | 114 | */ |
| 115 | - // NOTE If the Repository supports the optional “VersionSpecificFiling†capability, | 115 | + // NOTE If the Repository supports the optional “VersionSpecificFiling� capability, |
| 116 | // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. | 116 | // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. |
| 117 | // Otherwise, the latest version of the documents SHALL be returned. | 117 | // Otherwise, the latest version of the documents SHALL be returned. |
| 118 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid | 118 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid |
| @@ -155,9 +155,14 @@ class CMISNavigationService { | @@ -155,9 +155,14 @@ class CMISNavigationService { | ||
| 155 | */ | 155 | */ |
| 156 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid | 156 | // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid |
| 157 | // TODO If this service method is invoked on the root folder of the Repository, then the Repository SHALL return an empty result set. | 157 | // TODO If this service method is invoked on the root folder of the Repository, then the Repository SHALL return an empty result set. |
| 158 | - // NOTE SHOULD always include the “ObjectId†and “ParentId†properties for all objects returned | 158 | + // NOTE SHOULD always include the “ObjectId� and “ParentId� properties for all objects returned |
| 159 | function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') | 159 | function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') |
| 160 | { | 160 | { |
| 161 | + // NOTE the root folder obviously has no parent, throw an ObjectNotFoundException here if this is the root folder | ||
| 162 | + if (CMISUtil::isRootFolder($repositoryId, $folderId, $this->ktapi)) { | ||
| 163 | + throw new ObjectNotFoundException('Root folder has no parent'); | ||
| 164 | + } | ||
| 165 | + | ||
| 161 | $ancestry = array(); | 166 | $ancestry = array(); |
| 162 | $repository = new CMISRepository($repositoryId); | 167 | $repository = new CMISRepository($repositoryId); |
| 163 | 168 |
lib/api/ktcmis/util/CMISUtil.inc.php
| @@ -614,6 +614,16 @@ class CMISUtil { | @@ -614,6 +614,16 @@ class CMISUtil { | ||
| 614 | return $tempfilename; | 614 | return $tempfilename; |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | + /** | ||
| 618 | + * attempts to fetch the folder id from a name | ||
| 619 | + * | ||
| 620 | + * NOTE this won't be reliable if there is more than one folder in the system with the same name | ||
| 621 | + * the only reason this exists is to accomodate the method of browsing used by the drupal module | ||
| 622 | + * | ||
| 623 | + * @param string $name | ||
| 624 | + * @param object $ktapi | ||
| 625 | + * @return string | ||
| 626 | + */ | ||
| 617 | static public function getIdFromName($name, &$ktapi) | 627 | static public function getIdFromName($name, &$ktapi) |
| 618 | { | 628 | { |
| 619 | $folder = $ktapi->get_folder_by_name($name); | 629 | $folder = $ktapi->get_folder_by_name($name); |
| @@ -621,10 +631,22 @@ class CMISUtil { | @@ -621,10 +631,22 @@ class CMISUtil { | ||
| 621 | return self::encodeObjectId(FOLDER, $folder->get_folderid()); | 631 | return self::encodeObjectId(FOLDER, $folder->get_folderid()); |
| 622 | } | 632 | } |
| 623 | 633 | ||
| 634 | + /** | ||
| 635 | + * Checks for the root folder | ||
| 636 | + * | ||
| 637 | + * @param unknown_type $repositoryId | ||
| 638 | + * @param unknown_type $folderId | ||
| 639 | + * @param unknown_type $ktapi | ||
| 640 | + * @return unknown | ||
| 641 | + */ | ||
| 624 | static public function isRootFolder($repositoryId, $folderId, &$ktapi) | 642 | static public function isRootFolder($repositoryId, $folderId, &$ktapi) |
| 625 | { | 643 | { |
| 626 | $repository = new CMISRepository($repositoryId); | 644 | $repository = new CMISRepository($repositoryId); |
| 627 | $repositoryInfo = $repository->getRepositoryInfo(); | 645 | $repositoryInfo = $repository->getRepositoryInfo(); |
| 646 | + | ||
| 647 | + // NOTE this call is required to accomodate the definition of the root folder id in the config as required by the drupal module | ||
| 648 | + // we should try to update the drupal module to not require this, but this way is just easier at the moment, and most of | ||
| 649 | + // the code accomodates it without any serious hacks | ||
| 628 | $rootFolder = self::getIdFromName($repositoryInfo->getRootFolderId(), $ktapi); | 650 | $rootFolder = self::getIdFromName($repositoryInfo->getRootFolderId(), $ktapi); |
| 629 | 651 | ||
| 630 | return $folderId == $rootFolder; | 652 | return $folderId == $rootFolder; |
webservice/classes/atompub/cmis/NavigationService.inc.php
| @@ -77,6 +77,9 @@ class NavigationService extends KTNavigationService { | @@ -77,6 +77,9 @@ class NavigationService extends KTNavigationService { | ||
| 77 | { | 77 | { |
| 78 | return $result['results']; | 78 | return $result['results']; |
| 79 | } | 79 | } |
| 80 | + else { | ||
| 81 | + return new PEAR_Error($result['message']); | ||
| 82 | + } | ||
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | /** | 85 | /** |