Skip to content

Commit ae56070

Browse files
author
tchapi
committed
Refactoring and renaming public_calendars_enabled
1 parent 091ccb4 commit ae56070

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

.env

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

72-
# Can calendar be public available ?
73-
PUBLIC_CALENDAR_ENABLED=true
72+
# Do we allow calendars to be public ?
73+
PUBLIC_CALENDARS_ENABLED=true
7474

7575
# What mail is used as the sender for invites ?
7676
INVITE_FROM_ADDRESS=[email protected]

config/services.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +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"
10+
public_calendars_enabled: '%env(default:default_public_calendars_enabled:bool:PUBLIC_CALENDARS_ENABLED)%'
11+
default_public_calendars_enabled: "true"
1212

1313
services:
1414
# default configuration for services in *this* file
@@ -51,7 +51,7 @@ services:
5151
$calDAVEnabled: "%env(bool:CALDAV_ENABLED)%"
5252
$cardDAVEnabled: "%env(bool:CARDDAV_ENABLED)%"
5353
$webDAVEnabled: "%env(bool:WEBDAV_ENABLED)%"
54-
$publicCalendarEnabled: "%env(default:default_public_calendar_enabled:bool:PUBLIC_CALENDAR_ENABLED)%"
54+
$publicCalendarsEnabled: "%public_calendars_enabled%"
5555
$inviteAddress: "%env(INVITE_FROM_ADDRESS)%"
5656
$authMethod: "%env(AUTH_METHOD)%"
5757
$authRealm: "%env(AUTH_REALM)%"

src/Controller/Admin/CalendarController.php

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

83-
$isPublicCalendarEnabled = $this->getParameter('public_calendar_enabled');
83+
$arePublicCalendarsEnabled = $this->getParameter('public_calendars_enabled');
8484

8585
$form = $this->createForm(CalendarInstanceType::class, $calendarInstance, [
8686
'new' => !$id,
8787
'shared' => $calendarInstance->isShared(),
88-
'public_calendar_enabled' => $isPublicCalendarEnabled
88+
'public_calendars_enabled' => $arePublicCalendarsEnabled,
8989
]);
9090

9191
$components = explode(',', $calendarInstance->getCalendar()->getComponents());
9292

9393
$form->get('events')->setData(in_array(Calendar::COMPONENT_EVENTS, $components));
9494
$form->get('todos')->setData(in_array(Calendar::COMPONENT_TODOS, $components));
9595
$form->get('notes')->setData(in_array(Calendar::COMPONENT_NOTES, $components));
96-
if ($isPublicCalendarEnabled) {
96+
if ($arePublicCalendarsEnabled) {
9797
$form->get('public')->setData($calendarInstance->isPublic());
9898
}
9999
$form->get('principalUri')->setData(Principal::PREFIX.$username);
@@ -115,7 +115,7 @@ public function calendarEdit(ManagerRegistry $doctrine, Request $request, string
115115
if ($form->get('notes')->getData()) {
116116
$components[] = Calendar::COMPONENT_NOTES;
117117
}
118-
if ($isPublicCalendarEnabled && true === $form->get('public')->getData()) {
118+
if ($arePublicCalendarsEnabled && true === $form->get('public')->getData()) {
119119
$calendarInstance->setAccess(CalendarInstance::ACCESS_PUBLIC);
120120
} else {
121121
$calendarInstance->setAccess(CalendarInstance::ACCESS_SHAREDOWNER);
@@ -125,7 +125,7 @@ public function calendarEdit(ManagerRegistry $doctrine, Request $request, string
125125
}
126126

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

src/Controller/DAVController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ class DAVController extends AbstractController
4848
protected $webDAVEnabled;
4949

5050
/**
51-
* is Public Calendar enabled?
51+
* Are public calendars enabled?
5252
*
5353
* @var bool
5454
*/
55-
protected $publicCalendarEnabled;
55+
protected $publicCalendarsEnabled;
5656

5757
/**
5858
* Mail address to send mails from.
@@ -142,14 +142,14 @@ class DAVController extends AbstractController
142142
*/
143143
protected $server;
144144

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)
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 $publicCalendarsEnabled = true, ?string $inviteAddress = null, ?string $authMethod = null, ?string $authRealm = null, ?string $webdavPublicDir = null, ?string $webdavHomesDir = null, ?string $webdavTmpDir = null)
146146
{
147147
$this->publicDir = $publicDir;
148148

149149
$this->calDAVEnabled = $calDAVEnabled;
150150
$this->cardDAVEnabled = $cardDAVEnabled;
151151
$this->webDAVEnabled = $webDAVEnabled;
152-
$this->publicCalendarEnabled = $publicCalendarEnabled;
152+
$this->publicCalendarsEnabled = $publicCalendarsEnabled;
153153
$this->inviteAddress = $inviteAddress ?? null;
154154

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

241-
$aclPlugin = new PublicAwareDAVACLPlugin($this->em, $this->publicCalendarEnabled);
241+
$aclPlugin = new PublicAwareDAVACLPlugin($this->em, $this->publicCalendarsEnabled);
242242
$aclPlugin->hideNodesFromListings = true;
243243

244244
// Fetch admins, if any

src/Entity/CalendarInstance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function getOwnerAccesses(): array
4040
#[ORM\Column(type: 'integer')]
4141
private $id;
4242

43-
#[ORM\ManyToOne(targetEntity: "App\Entity\Calendar", cascade: ['persist'], inversedBy: "instances")]
43+
#[ORM\ManyToOne(targetEntity: "App\Entity\Calendar", cascade: ['persist'], inversedBy: 'instances')]
4444
#[ORM\JoinColumn(name: 'calendarid', nullable: false)]
4545
private $calendar;
4646

src/Form/CalendarInstanceType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
7474
'label' => 'save',
7575
]);
7676

77-
if (!$options['public_calendar_enabled']) {
77+
if (!$options['public_calendars_enabled']) {
7878
$builder->remove('public');
7979
}
8080
}
@@ -85,7 +85,7 @@ public function configureOptions(OptionsResolver $resolver): void
8585
'new' => false,
8686
'shared' => false,
8787
'data_class' => CalendarInstance::class,
88-
'public_calendar_enabled' => true
88+
'public_calendars_enabled' => true,
8989
]);
9090
}
9191
}

src/Plugins/PublicAwareDAVACLPlugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class PublicAwareDAVACLPlugin extends \Sabre\DAVACL\Plugin
1717
/**
1818
* @var bool
1919
*/
20-
protected $public_calendar_enabled;
20+
protected $public_calendars_enabled;
2121

22-
public function __construct(EntityManagerInterface $entityManager, bool $public_enabled)
22+
public function __construct(EntityManagerInterface $entityManager, bool $public_calendars_enabled)
2323
{
2424
$this->em = $entityManager;
25-
$this->public_calendar_enabled = $public_enabled;
25+
$this->public_calendars_enabled = $public_calendars_enabled;
2626
}
2727

2828
/**
@@ -44,7 +44,7 @@ public function getAcl($node): array
4444
$acl = parent::getAcl($node);
4545

4646
if ($node instanceof \Sabre\CalDAV\Calendar) {
47-
if (CalendarInstance::ACCESS_PUBLIC === $node->getShareAccess()) {
47+
if (CalendarInstance::ACCESS_PUBLIC === $node->getShareAccess() && $this->public_calendars_enabled) {
4848
// We must add the ACL on the calendar itself
4949
$acl[] = [
5050
'principal' => '{DAV:}unauthenticated',
@@ -61,7 +61,7 @@ public function getAcl($node): array
6161

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

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

0 commit comments

Comments
 (0)