Commit a48887db authored by Simone Scalabrino's avatar Simone Scalabrino
Browse files

First attempt to fix bug 328616

As reported in https://bugs.kde.org/show_bug.cgi?id=328616, when a user
accepts an invitation to an event, when it is loaded on Google Calendar,
it creates a new event with the user as the organizer. To prevent this,
the "import" API should be used instead of the "insert" API.
With this change, the organizer is checked against the account name of
the user: if they match, the event is created (previous implementation),
otherwise the event is imported ("import" API).
This still requires some tests to check if it does not break anything.

BUG: 328616
FIXED-IN: 5.17
parent 919ab172
POST https://www.googleapis.com/calendar/v3/calendars/MockAccount/events?sendUpdates=all&prettyPrint=false
POST https://www.googleapis.com/calendar/v3/calendars/MockAccount/events/import?sendUpdates=all&prettyPrint=false
Content-Type: application/json
{
......
......@@ -44,8 +44,8 @@
}
],
"organizer": {
"displayName": "KDE Hacker 0",
"email": "hacker@kde.test"
"displayName": "MockAccount",
"email": "MockAccount"
},
"creator": {
"self": true,
......
......@@ -18,8 +18,8 @@ Content-Type: application/json
"kind": "calendar#event",
"location": "Toulouse, France",
"organizer": {
"displayName": "KDE Hacker 0 <hacker@kde.test>",
"email": "hacker@kde.test"
"displayName": "MockAccount <MockAccount>",
"email": "MockAccount"
},
"recurrence": [
"RRULE:FREQ=YEARLY;BYMONTHDAY=20;BYMONTH=4"
......
......@@ -47,8 +47,8 @@ Content-type: application/json; charset=UTF-8
}
],
"organizer": {
"displayName": "KDE Hacker 0",
"email": "hacker@kde.test"
"displayName": "MockAccount",
"email": "MockAccount"
},
"creator": {
"self": true,
......
......@@ -19,8 +19,8 @@ Content-Type: application/json
"kind": "calendar#event",
"location": "Toulouse, France",
"organizer": {
"displayName": "KDE Hacker 0 <hacker@kde.test>",
"email": "hacker@kde.test"
"displayName": "MockAccount <MockAccount>",
"email": "MockAccount"
},
"recurrence": [
"RRULE:FREQ=YEARLY;BYMONTHDAY=20;BYMONTH=4"
......
......@@ -47,8 +47,8 @@ Content-type: application/json; charset=UTF-8
}
],
"organizer": {
"displayName": "KDE Hacker 0",
"email": "hacker@kde.test"
"displayName": "MockAccount",
"email": "MockAccount"
},
"creator": {
"self": true,
......
......@@ -60,8 +60,8 @@ Content-type: application/json; charset=UTF-8
}
],
"organizer": {
"displayName": "KDE Hacker 0",
"email": "hacker@kde.test"
"displayName": "MockAccount",
"email": "MockAccount"
},
"creator": {
"self": true,
......
......@@ -162,6 +162,16 @@ QUrl createEventUrl(const QString& calendarID, SendUpdatesPolicy updatePolicy)
return url;
}
QUrl importEventUrl(const QString& calendarID, SendUpdatesPolicy updatePolicy)
{
QUrl url(Private::GoogleApisUrl);
url.setPath(Private::CalendarBasePath % QLatin1Char('/') % calendarID % QLatin1String("/events") % QLatin1String("/import"));
QUrlQuery query(url);
query.addQueryItem(sendUpatesQueryParam, sendUpdatesPolicyToString(updatePolicy));
url.setQuery(query);
return url;
}
QUrl removeEventUrl(const QString& calendarID, const QString& eventID)
{
QUrl url(Private::GoogleApisUrl);
......
......@@ -154,6 +154,14 @@ namespace CalendarService
* @param updatesPolicy Whether to send notification to participants
*/
KGAPICALENDAR_EXPORT QUrl createEventUrl(const QString &calendarID, SendUpdatesPolicy updatesPolicy);
/**
* @brief Returns URL importing private copies of existing events.
*
* @param calendarID ID of calendar in which to create the event
* @param updatesPolicy Whether to send notification to participants
*/
KGAPICALENDAR_EXPORT QUrl importEventUrl(const QString &calendarID, SendUpdatesPolicy updatesPolicy);
/**
* @brief Returns URL for removing events
......
......@@ -68,7 +68,18 @@ void EventCreateJob::start()
}
const EventPtr event = d->events.current();
const auto request = CalendarService::prepareRequest(CalendarService::createEventUrl(d->calendarId, d->updatesPolicy));
QUrl requestUrl;
// If the organizer is different from the account name, import a private copy of the event in the user's calendar,
// or normally create it otherwise. This prevents that Google Calendar creates a copy event when accepting invitations
// to events created by others.
if (!event->attendees().isEmpty() && !event->organizer().isEmpty() && event->organizer().email() != this->account()->accountName()) {
requestUrl = CalendarService::importEventUrl(d->calendarId, d->updatesPolicy);
} else {
requestUrl = CalendarService::createEventUrl(d->calendarId, d->updatesPolicy);
}
const auto request = CalendarService::prepareRequest(requestUrl);
const QByteArray rawData = CalendarService::eventToJSON(event, CalendarService::EventSerializeFlag::NoID);
enqueueRequest(request, rawData, QStringLiteral("application/json"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment