From 8cd44860bec35e07c996cf804a000910605fcb83 Mon Sep 17 00:00:00 2001 From: Stefanie Stamer Date: Fri, 3 Apr 2020 13:26:23 +0200 Subject: [PATCH] feature(Addressbook): set private grant cli script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibfc9cd4c8f520ee9dd2120a70bf583eacdd6dbfd Reviewed-on: http://gerrit.tine20.com/customers/16239 Tested-by: Jenkins CI (http://ci.tine20.com/) Reviewed-by: Philipp Schüle --- tine20/Addressbook/Frontend/Cli.php | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tine20/Addressbook/Frontend/Cli.php b/tine20/Addressbook/Frontend/Cli.php index 987ce529114..e2540557425 100644 --- a/tine20/Addressbook/Frontend/Cli.php +++ b/tine20/Addressbook/Frontend/Cli.php @@ -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; + } }