Skip to content

Commit 091ccb4

Browse files
authored
[Feature] Add calendar public flag option (#200)
1 parent 13c8987 commit 091ccb4

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ CALDAV_ENABLED=true
6969
CARDDAV_ENABLED=true
7070
WEBDAV_ENABLED=false
7171

72+
# Can calendar be public available ?
73+
PUBLIC_CALENDAR_ENABLED=true
74+
7275
# What mail is used as the sender for invites ?
7376
INVITE_FROM_ADDRESS=[email protected]
7477

config/services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ parameters:
77
default_database_driver: "mysql"
88
default_admin_auth_bypass: "false"
99
timezone: '%env(APP_TIMEZONE)%'
10+
public_calendar_enabled: '%env(default:default_public_calendar_enabled:bool:PUBLIC_CALENDAR_ENABLED)%'
11+
default_public_calendar_enabled: "true"
1012

1113
services:
1214
# default configuration for services in *this* file
@@ -49,6 +51,7 @@ services:
4951
$calDAVEnabled: "%env(bool:CALDAV_ENABLED)%"
5052
$cardDAVEnabled: "%env(bool:CARDDAV_ENABLED)%"
5153
$webDAVEnabled: "%env(bool:WEBDAV_ENABLED)%"
54+
$publicCalendarEnabled: "%env(default:default_public_calendar_enabled:bool:PUBLIC_CALENDAR_ENABLED)%"
5255
$inviteAddress: "%env(INVITE_FROM_ADDRESS)%"
5356
$authMethod: "%env(AUTH_METHOD)%"
5457
$authRealm: "%env(AUTH_REALM)%"

src/Controller/Admin/CalendarController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,22 @@ public function calendarEdit(ManagerRegistry $doctrine, Request $request, string
8080
$calendarInstance->setCalendar($calendar);
8181
}
8282

83+
$isPublicCalendarEnabled = $this->getParameter('public_calendar_enabled');
84+
8385
$form = $this->createForm(CalendarInstanceType::class, $calendarInstance, [
8486
'new' => !$id,
8587
'shared' => $calendarInstance->isShared(),
88+
'public_calendar_enabled' => $isPublicCalendarEnabled
8689
]);
8790

8891
$components = explode(',', $calendarInstance->getCalendar()->getComponents());
8992

9093
$form->get('events')->setData(in_array(Calendar::COMPONENT_EVENTS, $components));
9194
$form->get('todos')->setData(in_array(Calendar::COMPONENT_TODOS, $components));
9295
$form->get('notes')->setData(in_array(Calendar::COMPONENT_NOTES, $components));
93-
$form->get('public')->setData($calendarInstance->isPublic());
96+
if ($isPublicCalendarEnabled) {
97+
$form->get('public')->setData($calendarInstance->isPublic());
98+
}
9499
$form->get('principalUri')->setData(Principal::PREFIX.$username);
95100

96101
$form->handleRequest($request);
@@ -110,7 +115,7 @@ public function calendarEdit(ManagerRegistry $doctrine, Request $request, string
110115
if ($form->get('notes')->getData()) {
111116
$components[] = Calendar::COMPONENT_NOTES;
112117
}
113-
if (true === $form->get('public')->getData()) {
118+
if ($isPublicCalendarEnabled && true === $form->get('public')->getData()) {
114119
$calendarInstance->setAccess(CalendarInstance::ACCESS_PUBLIC);
115120
} else {
116121
$calendarInstance->setAccess(CalendarInstance::ACCESS_SHAREDOWNER);
@@ -120,7 +125,7 @@ public function calendarEdit(ManagerRegistry $doctrine, Request $request, string
120125
}
121126

122127
// We want to remove all shares if a calendar goes public
123-
if (true === $form->get('public')->getData() && $id) {
128+
if ($isPublicCalendarEnabled && true === $form->get('public')->getData() && $id) {
124129
$calendarId = $calendarInstance->getCalendar()->getId();
125130
$instances = $doctrine->getRepository(CalendarInstance::class)->findSharedInstancesOfInstance($calendarId, false);
126131
foreach ($instances as $instance) {

src/Controller/DAVController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class DAVController extends AbstractController
4747
*/
4848
protected $webDAVEnabled;
4949

50+
/**
51+
* is Public Calendar enabled?
52+
*
53+
* @var bool
54+
*/
55+
protected $publicCalendarEnabled;
56+
5057
/**
5158
* Mail address to send mails from.
5259
*
@@ -135,13 +142,14 @@ class DAVController extends AbstractController
135142
*/
136143
protected $server;
137144

138-
public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, string $publicDir, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, ?string $inviteAddress = null, ?string $authMethod = null, ?string $authRealm = null, ?string $webdavPublicDir = null, ?string $webdavHomesDir = null, ?string $webdavTmpDir = null)
145+
public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, string $publicDir, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, bool $publicCalendarEnabled, ?string $inviteAddress = null, ?string $authMethod = null, ?string $authRealm = null, ?string $webdavPublicDir = null, ?string $webdavHomesDir = null, ?string $webdavTmpDir = null)
139146
{
140147
$this->publicDir = $publicDir;
141148

142149
$this->calDAVEnabled = $calDAVEnabled;
143150
$this->cardDAVEnabled = $cardDAVEnabled;
144151
$this->webDAVEnabled = $webDAVEnabled;
152+
$this->publicCalendarEnabled = $publicCalendarEnabled;
145153
$this->inviteAddress = $inviteAddress ?? null;
146154

147155
$this->webdavPublicDir = $webdavPublicDir;
@@ -230,7 +238,7 @@ private function initServer(string $authMethod, string $authRealm = User::DEFAUL
230238
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin(false)); // We disable the file creation / upload / sharing in the browser
231239
$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
232240

233-
$aclPlugin = new PublicAwareDAVACLPlugin($this->em);
241+
$aclPlugin = new PublicAwareDAVACLPlugin($this->em, $this->publicCalendarEnabled);
234242
$aclPlugin->hideNodesFromListings = true;
235243

236244
// Fetch admins, if any

src/Form/CalendarInstanceType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
7373
->add('save', SubmitType::class, [
7474
'label' => 'save',
7575
]);
76+
77+
if (!$options['public_calendar_enabled']) {
78+
$builder->remove('public');
79+
}
7680
}
7781

7882
public function configureOptions(OptionsResolver $resolver): void
@@ -81,6 +85,7 @@ public function configureOptions(OptionsResolver $resolver): void
8185
'new' => false,
8286
'shared' => false,
8387
'data_class' => CalendarInstance::class,
88+
'public_calendar_enabled' => true
8489
]);
8590
}
8691
}

src/Plugins/PublicAwareDAVACLPlugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ class PublicAwareDAVACLPlugin extends \Sabre\DAVACL\Plugin
1414
*/
1515
protected $em;
1616

17-
public function __construct(EntityManagerInterface $entityManager)
17+
/**
18+
* @var bool
19+
*/
20+
protected $public_calendar_enabled;
21+
22+
public function __construct(EntityManagerInterface $entityManager, bool $public_enabled)
1823
{
1924
$this->em = $entityManager;
25+
$this->public_calendar_enabled = $public_enabled;
2026
}
2127

2228
/**
@@ -55,7 +61,7 @@ public function getAcl($node): array
5561

5662
$calendar = $this->em->getRepository(CalendarInstance::class)->findOneById($calendarInstanceId);
5763

58-
if ($calendar && $calendar->isPublic()) {
64+
if ($calendar && $calendar->isPublic() && $this->public_calendar_enabled) {
5965
// We must add the ACL on the object itself
6066
$acl[] = [
6167
'principal' => '{DAV:}unauthenticated',

0 commit comments

Comments
 (0)