Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Addressbook): set private grant cli script
Browse files Browse the repository at this point in the history
Change-Id: Ibfc9cd4c8f520ee9dd2120a70bf583eacdd6dbfd
Reviewed-on: http://gerrit.tine20.com/customers/16239
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
  • Loading branch information
sstamer authored and pschuele committed Apr 6, 2020
1 parent 6294eec commit 8cd4486
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tine20/Addressbook/Frontend/Cli.php
Expand Up @@ -382,4 +382,60 @@ public function searchDuplicatesContactByUser($opts)

return 0;
}

/**
* updates addressbook shared containers: set privateData grant for all!
*
* TODO generalize: give set of grants and allow to update containers of all models (move to Tinebase)
*
* @param $opts
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_Backend
* @throws Tinebase_Exception_InvalidArgument
* @throws Tinebase_Exception_NotFound
* @throws Tinebase_Exception_SystemGeneric
*/
public function setPrivateGrantForAll($opts)
{
$containerController = Tinebase_Container::getInstance();

if ($opts->v) {
print_r($opts->d ? '(DRYRUN) Setting private grants for:' . PHP_EOL : 'Setting private grants for:' . PHP_EOL);
}

$filter = [
['field' => 'type', 'operator' => 'equals', 'value' => Tinebase_Model_Container::TYPE_SHARED],
['field' => 'model', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::class],
['field' => 'application_id', 'operator' => 'equals',
'value' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId()],
];
$containerController->doSearchAclFilter(false);
$containers = $containerController->search(
new Tinebase_Model_ContainerFilter($filter)
);
$containerController->doSearchAclFilter(true);

$counter = 0;
foreach ($containers as $container) {
$allgrants = $containerController->getGrantsOfContainer($container, true);
$toUpdate = false;
foreach ($allgrants as $grant) {
if (!$grant->privateDataGrant) {
$toUpdate = true;
$grant->privateDataGrant = true;
}
}
if ($toUpdate) {
if ($opts->v) {
echo "- " . $container->name . PHP_EOL;
}
if (!$opts->d) {
$containerController->setGrants($container, $allgrants, TRUE);
}
$counter++;
}
}

echo "Added privateData grant to $counter shared containers" . PHP_EOL;
}
}

0 comments on commit 8cd4486

Please sign in to comment.