2018-03-08 16:44:02 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, Georg Ehrke
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2019-12-03 21:57:53 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-03-08 16:44:02 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-08 16:44:02 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2018-03-08 16:44:02 +03:00
|
|
|
namespace OCA\DAV\Command;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class ListCalendars extends Command {
|
|
|
|
|
|
|
|
/** @var IUserManager */
|
|
|
|
protected $userManager;
|
|
|
|
|
|
|
|
/** @var CalDavBackend */
|
|
|
|
private $caldav;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param CalDavBackend $caldav
|
|
|
|
*/
|
2020-04-10 17:51:06 +03:00
|
|
|
public function __construct(IUserManager $userManager, CalDavBackend $caldav) {
|
2018-03-08 16:44:02 +03:00
|
|
|
parent::__construct();
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->caldav = $caldav;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('dav:list-calendars')
|
|
|
|
->setDescription('List all calendars of a user')
|
2019-01-15 15:59:54 +03:00
|
|
|
->addArgument('uid',
|
2018-03-08 16:44:02 +03:00
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'User for whom all calendars will be listed');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
2019-01-15 15:59:54 +03:00
|
|
|
$user = $input->getArgument('uid');
|
2018-03-08 16:44:02 +03:00
|
|
|
if (!$this->userManager->userExists($user)) {
|
|
|
|
throw new \InvalidArgumentException("User <$user> is unknown.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$calendars = $this->caldav->getCalendarsForUser("principals/users/$user");
|
|
|
|
|
|
|
|
$calendarTableData = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($calendars as $calendar) {
|
2018-03-08 16:44:02 +03:00
|
|
|
// skip birthday calendar
|
|
|
|
if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$readOnly = false;
|
|
|
|
$readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
|
|
|
|
if (isset($calendar[$readOnlyIndex])) {
|
|
|
|
$readOnly = $calendar[$readOnlyIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
$calendarTableData[] = [
|
|
|
|
$calendar['uri'],
|
|
|
|
$calendar['{DAV:}displayname'],
|
|
|
|
$calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'],
|
|
|
|
$calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'],
|
|
|
|
$readOnly ? ' x ' : ' ✓ ',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($calendarTableData) > 0) {
|
|
|
|
$table = new Table($output);
|
|
|
|
$table->setHeaders(['uri', 'displayname', 'owner\'s userid', 'owner\'s displayname', 'writable'])
|
|
|
|
->setRows($calendarTableData);
|
|
|
|
|
|
|
|
$table->render();
|
|
|
|
} else {
|
|
|
|
$output->writeln("<info>User <$user> has no calendars</info>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|