Revert Domain-Wide Delegation — not applicable for personal Gmail accounts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 15:18:11 +01:00
co-authored by Claude Sonnet 4.6
parent 804d454618
commit ae890c81ee
3 changed files with 10 additions and 31 deletions
-1
View File
@@ -3,4 +3,3 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$config['gcal_service_account_path'] = APPPATH . 'config/service-account-key.json'; $config['gcal_service_account_path'] = APPPATH . 'config/service-account-key.json';
$config['gcal_evelin_calendar_id'] = 'katozoltan0804@gmail.com'; // Evelin's Calendar ID (e.g. her Gmail address) $config['gcal_evelin_calendar_id'] = 'katozoltan0804@gmail.com'; // Evelin's Calendar ID (e.g. her Gmail address)
$config['gcal_impersonate_email'] = ''; // Workspace user to impersonate (e.g. evelin@studiobeve.no) — required for attendee invitations
+4 -4
View File
@@ -451,11 +451,11 @@ class Pages extends CI_Controller {
$workerEventId = null; $workerEventId = null;
$ownerEventId = null; $ownerEventId = null;
if(!empty($worker->google_calendar_id)){ if(!empty($worker->google_calendar_id)){
$workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); $workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd);
} }
$evelinCalId = $this->config->item('gcal_evelin_calendar_id'); $evelinCalId = $this->config->item('gcal_evelin_calendar_id');
if(!empty($evelinCalId)){ if(!empty($evelinCalId)){
$ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); $ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd);
} }
$this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId); $this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId);
} }
@@ -873,10 +873,10 @@ class Pages extends CI_Controller {
$newWorkerEventId = null; $newWorkerEventId = null;
$newOwnerEventId = null; $newOwnerEventId = null;
if(!empty($worker->google_calendar_id)){ if(!empty($worker->google_calendar_id)){
$newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); $newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd);
} }
if(!empty($evelinCalId)){ if(!empty($evelinCalId)){
$newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); $newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd);
} }
$this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId); $this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId);
+6 -26
View File
@@ -4,7 +4,6 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class GoogleCalendar { class GoogleCalendar {
private $service = null; private $service = null;
private $canInvite = false;
public function __construct() { public function __construct() {
require_once FCPATH . 'vendor/autoload.php'; require_once FCPATH . 'vendor/autoload.php';
@@ -21,14 +20,6 @@ class GoogleCalendar {
$client = new Google_Client(); $client = new Google_Client();
$client->setAuthConfig($serviceAccountPath); $client->setAuthConfig($serviceAccountPath);
$client->setScopes([Google_Service_Calendar::CALENDAR]); $client->setScopes([Google_Service_Calendar::CALENDAR]);
// Domain-Wide Delegation: impersonate a Workspace user to unlock attendee invitations
$impersonateEmail = $CI->config->item('gcal_impersonate_email');
if (!empty($impersonateEmail)) {
$client->setSubject($impersonateEmail);
$this->canInvite = true;
}
$this->service = new Google_Service_Calendar($client); $this->service = new Google_Service_Calendar($client);
} catch (Exception $e) { } catch (Exception $e) {
// Silently fail — calendar errors must never break the booking flow // Silently fail — calendar errors must never break the booking flow
@@ -37,25 +28,18 @@ class GoogleCalendar {
/** /**
* Create a calendar event. * Create a calendar event.
* If Domain-Wide Delegation is configured and $attendeeEmail is provided,
* the attendee receives an invitation push notification via Google Calendar.
* @return string|null The new event ID, or null on failure. * @return string|null The new event ID, or null on failure.
*/ */
public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime) {
if (!$this->service || empty($calendarId)) return null; if (!$this->service || empty($calendarId)) return null;
try { try {
$eventData = [ $event = new Google_Service_Calendar_Event([
'summary' => $title, 'summary' => $title,
'description' => $description, 'description' => $description,
'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'], 'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'],
'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'], 'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'],
]; ]);
if ($this->canInvite && !empty($attendeeEmail)) { $result = $this->service->events->insert($calendarId, $event);
$eventData['attendees'] = [['email' => $attendeeEmail]];
}
$event = new Google_Service_Calendar_Event($eventData);
$params = ($this->canInvite && !empty($attendeeEmail)) ? ['sendUpdates' => 'all'] : [];
$result = $this->service->events->insert($calendarId, $event, $params);
return $result->getId(); return $result->getId();
} catch (Exception $e) { } catch (Exception $e) {
return null; return null;
@@ -66,7 +50,7 @@ class GoogleCalendar {
* Update an existing calendar event. * Update an existing calendar event.
* @return string|null The event ID, or null on failure. * @return string|null The event ID, or null on failure.
*/ */
public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime) {
if (!$this->service || empty($calendarId) || empty($eventId)) return null; if (!$this->service || empty($calendarId) || empty($eventId)) return null;
try { try {
$event = $this->service->events->get($calendarId, $eventId); $event = $this->service->events->get($calendarId, $eventId);
@@ -80,11 +64,7 @@ class GoogleCalendar {
'dateTime' => $endDatetime, 'dateTime' => $endDatetime,
'timeZone' => 'Europe/Oslo', 'timeZone' => 'Europe/Oslo',
])); ]));
if ($this->canInvite && !empty($attendeeEmail)) { $result = $this->service->events->update($calendarId, $eventId, $event);
$event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]);
}
$params = ($this->canInvite && !empty($attendeeEmail)) ? ['sendUpdates' => 'all'] : [];
$result = $this->service->events->update($calendarId, $eventId, $event, $params);
return $result->getId(); return $result->getId();
} catch (Exception $e) { } catch (Exception $e) {
return null; return null;