You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ListCalendars.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Citharel <nextcloud@tcit.fr>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\Command;
  26. use OCA\DAV\CalDAV\BirthdayService;
  27. use OCA\DAV\CalDAV\CalDavBackend;
  28. use OCP\IUserManager;
  29. use Symfony\Component\Console\Command\Command;
  30. use Symfony\Component\Console\Helper\Table;
  31. use Symfony\Component\Console\Input\InputArgument;
  32. use Symfony\Component\Console\Input\InputInterface;
  33. use Symfony\Component\Console\Output\OutputInterface;
  34. class ListCalendars extends Command {
  35. /** @var IUserManager */
  36. protected $userManager;
  37. /** @var CalDavBackend */
  38. private $caldav;
  39. /**
  40. * @param IUserManager $userManager
  41. * @param CalDavBackend $caldav
  42. */
  43. function __construct(IUserManager $userManager, CalDavBackend $caldav) {
  44. parent::__construct();
  45. $this->userManager = $userManager;
  46. $this->caldav = $caldav;
  47. }
  48. protected function configure() {
  49. $this
  50. ->setName('dav:list-calendars')
  51. ->setDescription('List all calendars of a user')
  52. ->addArgument('uid',
  53. InputArgument::REQUIRED,
  54. 'User for whom all calendars will be listed');
  55. }
  56. protected function execute(InputInterface $input, OutputInterface $output) {
  57. $user = $input->getArgument('uid');
  58. if (!$this->userManager->userExists($user)) {
  59. throw new \InvalidArgumentException("User <$user> is unknown.");
  60. }
  61. $calendars = $this->caldav->getCalendarsForUser("principals/users/$user");
  62. $calendarTableData = [];
  63. foreach ($calendars as $calendar) {
  64. // skip birthday calendar
  65. if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) {
  66. continue;
  67. }
  68. $readOnly = false;
  69. $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
  70. if (isset($calendar[$readOnlyIndex])) {
  71. $readOnly = $calendar[$readOnlyIndex];
  72. }
  73. $calendarTableData[] = [
  74. $calendar['uri'],
  75. $calendar['{DAV:}displayname'],
  76. $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'],
  77. $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'],
  78. $readOnly ? ' x ' : ' ✓ ',
  79. ];
  80. }
  81. if (count($calendarTableData) > 0) {
  82. $table = new Table($output);
  83. $table->setHeaders(['uri', 'displayname', 'owner\'s userid', 'owner\'s displayname', 'writable'])
  84. ->setRows($calendarTableData);
  85. $table->render();
  86. } else {
  87. $output->writeln("<info>User <$user> has no calendars</info>");
  88. }
  89. }
  90. }