Files
Ghassen kefi 2be108cf79 feat(dav): log calendar and address book sharing and lifecycle
CalDavBackend and CardDavBackend write calendar and address book
creation, trashing, deletion, restore, publishing and share changes to
the audit log through CriticalActionPerformedEvent where the change is
made. The generic dav and calendar events can be dispatched by other
apps as well, so they are not used as the source of these entries.
The public link of a published calendar is not logged.

Calendar export, accepting and declining federated calendars, creating
direct download links and enabling or disabling birthday calendars are
logged where they happen. Direct link tokens are never logged.

Granting and revoking calendar delegation (read or write access to all
calendars of a user, set through the calendar-proxy-read and
calendar-proxy-write principals) is logged once per delegate whose
access actually changed. Setting the same access again is not logged.

Events and contacts created, updated, deleted, moved to the trash,
restored or moved to another calendar or address book are logged with
the object URI, never their content. The birthday calendar and the
system address book are skipped, as the server generates them from
contacts and user accounts; subscribed calendars are not logged either.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
2026-11-05 16:34:43 +01:00

97 lines
2.5 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Controller;
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Settings\CalDAVSettings;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Log\Audit\CriticalActionPerformedEvent;
class BirthdayCalendarController extends Controller {
/**
* BirthdayCalendar constructor.
*
* @param string $appName
* @param IRequest $request
* @param IDBConnection $db
* @param IConfig $config
* @param IJobList $jobList
* @param IUserManager $userManager
* @param CalDavBackend $caldavBackend
* @param IEventDispatcher $eventDispatcher
*/
public function __construct(
$appName,
IRequest $request,
protected IDBConnection $db,
protected IConfig $config,
protected IJobList $jobList,
protected IUserManager $userManager,
protected CalDavBackend $caldavBackend,
protected IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request);
}
/**
* @return Response
*/
#[AuthorizedAdminSetting(settings: CalDAVSettings::class)]
public function enable() {
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
// add background job for each user
$this->userManager->callForSeenUsers(function (IUser $user): void {
$this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [
'userId' => $user->getUID(),
]);
});
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'Birthday calendars were enabled',
[],
false,
'dav.birthday_calendar.enabled',
));
return new JSONResponse([]);
}
/**
* @return Response
*/
#[AuthorizedAdminSetting(settings: CalDAVSettings::class)]
public function disable() {
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
$this->jobList->remove(GenerateBirthdayCalendarBackgroundJob::class);
$this->caldavBackend->deleteAllBirthdayCalendars();
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'Birthday calendars were disabled',
[],
false,
'dav.birthday_calendar.disabled',
));
return new JSONResponse([]);
}
}