Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement getAcl method #75

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Currently implemented Services
- [ ] removePolicy
- [ ] getAppliedPolicies
- AclSservice
- [ ] getACL
- [x] getACL
- [ ] applyACL


Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"require": {
"ext-json": "*",
"php": ">=7.0.0",
"dkd/enumeration": "~0.1",
"dkd/php-populate": "^1",
Expand Down
89 changes: 89 additions & 0 deletions examples/GetAcl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* This example will list the children of the CMIS root folder.
* The list is created recursively but is limited to 5 items per level.
*/

require_once(__DIR__ . '/../vendor/autoload.php');
if (!is_file(__DIR__ . '/conf/Configuration.php')) {
die("Please add your connection credentials to the file \"" . __DIR__ . "/conf/Configuration.php\".\n");
} else {
require_once(__DIR__ . '/conf/Configuration.php');
}

$httpInvoker = new \GuzzleHttp\Client(
[
'auth' => [
CMIS_BROWSER_USER,
CMIS_BROWSER_PASSWORD
]
]
);

$parameters = [
\Dkd\PhpCmis\SessionParameter::BINDING_TYPE => \Dkd\PhpCmis\Enum\BindingType::BROWSER,
\Dkd\PhpCmis\SessionParameter::BROWSER_URL => CMIS_BROWSER_URL,
\Dkd\PhpCmis\SessionParameter::BROWSER_SUCCINCT => false,
\Dkd\PhpCmis\SessionParameter::HTTP_INVOKER_OBJECT => $httpInvoker,
];

$sessionFactory = new \Dkd\PhpCmis\SessionFactory();

// If no repository id is defined use the first repository
if (CMIS_REPOSITORY_ID === null) {
$repositories = $sessionFactory->getRepositories($parameters);
$parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = $repositories[0]->getId();
} else {
$parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = CMIS_REPOSITORY_ID;
}

$session = $sessionFactory->createSession($parameters);

// Get the root folder of the repository
$rootFolder = $session->getRootFolder();

echo '+ [ROOT FOLDER]: ' . $rootFolder->getName() . "\n";
printAcl($rootFolder);

printFolderContent($rootFolder);

function printFolderContent(\Dkd\PhpCmis\Data\FolderInterface $folder, $levelIndention = ' ')
{
$i = 0;
foreach ($folder->getChildren() as $children) {
echo $levelIndention;
$i++;
if ($i > 10) {
echo "| ...\n";
break;
}

if ($children instanceof \Dkd\PhpCmis\Data\FolderInterface) {
echo '+ [FOLDER]: ' . $children->getName() . "\n";
printAcl($children, $levelIndention);
} elseif ($children instanceof \Dkd\PhpCmis\Data\DocumentInterface) {
echo '- [DOCUMENT]: ' . $children->getName() . "\n";
printAcl($children, $levelIndention);
} else {
echo '- [ITEM]: ' . $children->getName() . "\n";
printAcl($children, $levelIndention);
}
}
}

function printAcl(\Dkd\PhpCmis\CmisObject\CmisObjectInterface $item, $levelIndention = '')
{
$acl = $item->getAcl();
if ($acl !== null) {
foreach ($acl->getAces() as $ace) {
printf(
"%s > [ACE]: Principal ID = %s, Permissions = %s\n",
$levelIndention,
$ace->getPrincipalId(),
implode(',', $ace->getPermissions())
);
}
} else {
echo $levelIndention . " > [ACE]: Nothing found. Maybe ACE could not be loaded or does not exist\n";
}
}
5 changes: 4 additions & 1 deletion src/Bindings/Browser/AclService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

use Dkd\PhpCmis\AclServiceInterface;
use Dkd\PhpCmis\Constants;
use Dkd\PhpCmis\Data\AclInterface;
use Dkd\PhpCmis\Data\ExtensionDataInterface;
use Dkd\PhpCmis\Enum\AclPropagation;
Expand Down Expand Up @@ -62,6 +63,8 @@ public function getAcl(
$onlyBasicPermissions = true,
ExtensionDataInterface $extension = null
) {
// TODO: Implement getAcl() method.
$url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_ACL);
$responseData = $this->readJson($url);
return $this->getJsonConverter()->convertAcl($responseData);
}
}
2 changes: 1 addition & 1 deletion src/DataObjects/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function getChildren(OperationContextInterface $context = null)
*
* @param integer $depth
* @param OperationContextInterface|null $context
* @return TreeInterface A tree that contains FileableCmisObject objects
* @return TreeInterface[] A tree that contains FileableCmisObject objects
* @see FileableCmisObject FileableCmisObject contained in returned TreeInterface
*/
public function getDescendants($depth, OperationContextInterface $context = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public function deleteType($typeId)
*/
public function getAcl(ObjectIdInterface $objectId, $onlyBasicPermissions)
{
// TODO: Implement getAcl() method.
return $this->getBinding()->getAclService()->getAcl($this->getRepositoryId(), $objectId->getId(), $onlyBasicPermissions);
}

/**
Expand Down