From kde-commits Thu Oct 31 23:15:00 2013 From: Sergio Martins Date: Thu, 31 Oct 2013 23:15:00 +0000 To: kde-commits Subject: [kdepimlibs/KDE/4.11] akonadi/calendar: Don't modify the event after the user canceling the modifica Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=138326131108638 Git commit 3d610eca1ef7ff88068c0d321197c3ad18228688 by Sergio Martins. Committed on 31/10/2013 at 23:13. Pushed by smartins into branch 'KDE/4.11'. Don't modify the event after the user canceling the modification. When the user gets asked "You're not the organizer, do you really want to edit?" we were ignoring the return value and modifying it anyway. M +7 -1 akonadi/calendar/incidencechanger.cpp M +36 -13 akonadi/calendar/tests/itiphandlertest.cpp M +1 -0 akonadi/calendar/tests/itiphandlertest.h http://commits.kde.org/kdepimlibs/3d610eca1ef7ff88068c0d321197c3ad18228688 diff --git a/akonadi/calendar/incidencechanger.cpp b/akonadi/calendar/incid= encechanger.cpp index 47d1f05..d65a60a 100644 --- a/akonadi/calendar/incidencechanger.cpp +++ b/akonadi/calendar/incidencechanger.cpp @@ -959,7 +959,13 @@ void IncidenceChanger::Private::performModification( C= hange::Ptr change ) return; } = - handleInvitationsBeforeChange( change ); + const bool userCancelled =3D !handleInvitationsBeforeChange( change ); + if ( userCancelled ) { + // User got a "You're not the organizer, do you really want to send" d= ialog, and said "no" + kDebug() << "User cancelled, giving up"; + emitModifyFinished( q, changeId, newItem, ResultCodeUserCanceled, QStr= ing() ); + return; + } = QHash &latestRevisionByItemId =3D ConflictPreventer::self()= ->mLatestRevisionByItemId; diff --git a/akonadi/calendar/tests/itiphandlertest.cpp b/akonadi/calendar/= tests/itiphandlertest.cpp index 4f0cb43..30a6e71 100644 --- a/akonadi/calendar/tests/itiphandlertest.cpp +++ b/akonadi/calendar/tests/itiphandlertest.cpp @@ -53,6 +53,7 @@ void ITIPHandlerTest::initTestCase() m_pendingIncidenceChangerSignal =3D 0; MailClient::sRunningUnitTests =3D true; m_itipHandler =3D 0; + m_cancelExpected =3D false; m_changer =3D new IncidenceChanger(this); m_changer->setHistoryEnabled(false); m_changer->setGroupwareCommunication(true); @@ -341,6 +342,10 @@ void ITIPHandlerTest::testOutgoingInvitations_data() QTest::addColumn("changeType");= // creation, deletion, modification QTest::addColumn("expectedEmailCount"); QTest::addColumn("invitationPolicy= "); + QTest::addColumn("userCancels"); + + const bool userDoesntCancel =3D false; + const bool userCancels =3D true; = Akonadi::Item item; KCalCore::Incidence::Ptr incidence; @@ -366,7 +371,8 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); incidence->addAttendee(jules); expectedEmailCount =3D 1; - QTest::newRow("Creation. We organize.") << item << changeType << expec= tedEmailCount << invitationPolicySend; + QTest::newRow("Creation. We organize.") << item << changeType << expec= tedEmailCount + << invitationPolicySend << use= rDoesntCancel; //--------------------------------------------------------------------= -------------------------- // Creation. We are organizer. We invite another person. But we choose= not to send invitation e-mail. changeType =3D IncidenceChanger::ChangeTypeCreate; @@ -375,7 +381,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); incidence->addAttendee(jules); expectedEmailCount =3D 0; - QTest::newRow("Creation. We organize.2") << item << changeType << expe= ctedEmailCount << invitationPolicyDontSend; + QTest::newRow("Creation. We organize.2") << item << changeType << expe= ctedEmailCount << invitationPolicyDontSend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event that we organized, and has attendees, that will = be notified. changeType =3D IncidenceChanger::ChangeTypeDelete; @@ -384,7 +390,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); incidence->addAttendee(jules); expectedEmailCount =3D 1; - QTest::newRow("Deletion. We organized.") << item << changeType << expe= ctedEmailCount << invitationPolicySend; + QTest::newRow("Deletion. We organized.") << item << changeType << expe= ctedEmailCount << invitationPolicySend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event that we organized, and has attendees. We won't s= end e-mail notifications. changeType =3D IncidenceChanger::ChangeTypeDelete; @@ -393,7 +399,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); incidence->addAttendee(jules); expectedEmailCount =3D 0; - QTest::newRow("Deletion. We organized.2") << item << changeType << exp= ectedEmailCount << invitationPolicyDontSend; + QTest::newRow("Deletion. We organized.2") << item << changeType << exp= ectedEmailCount << invitationPolicyDontSend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event that we organized, and has attendees, who will b= e notified. changeType =3D IncidenceChanger::ChangeTypeModify; @@ -402,7 +408,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); incidence->addAttendee(jules); expectedEmailCount =3D 1; - QTest::newRow("Modification. We organizd.") << item << changeType << e= xpectedEmailCount << invitationPolicySend; + QTest::newRow("Modification. We organizd.") << item << changeType << e= xpectedEmailCount << invitationPolicySend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event that we organized, and has attendees, who wont b= e notified. changeType =3D IncidenceChanger::ChangeTypeModify; @@ -411,7 +417,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() incidence->addAttendee(vincent); // TODO: test that all attendees got = the e-mail incidence->addAttendee(jules); expectedEmailCount =3D 0; - QTest::newRow("Modification. We organizd.2") << item << changeType << = expectedEmailCount << invitationPolicyDontSend; + QTest::newRow("Modification. We organizd.2") << item << changeType << = expectedEmailCount << invitationPolicyDontSend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event which we're not the organizer of. Organizer gets= REPLY with PartState=3DDeclined changeType =3D IncidenceChanger::ChangeTypeDelete; @@ -422,7 +428,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() us->setStatus(Attendee::Accepted); // TODO: Test without accepted stat= us incidence->addAttendee(us); // TODO: test that attendees didn't receiv= e the REPLY expectedEmailCount =3D 1; // REPLY is always sent, there are no dialog= s to control this. Dialogs only control REQUEST and CANCEL. Bug or feature ? - QTest::newRow("Deletion. We didnt organize.") << item << changeType <<= expectedEmailCount << invitationPolicyDontSend; + QTest::newRow("Deletion. We didnt organize.") << item << changeType <<= expectedEmailCount << invitationPolicyDontSend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- // We delete an event which we're not the organizer of. Organizer gets= REPLY with PartState=3DDeclined changeType =3D IncidenceChanger::ChangeTypeDelete; @@ -433,9 +439,20 @@ void ITIPHandlerTest::testOutgoingInvitations_data() us->setStatus(Attendee::Accepted); // TODO: Test without accepted stat= us incidence->addAttendee(us); expectedEmailCount =3D 1; - QTest::newRow("Deletion. We didnt organize.2") << item << changeType <= < expectedEmailCount << invitationPolicySend; + QTest::newRow("Deletion. We didnt organize.2") << item << changeType <= < expectedEmailCount << invitationPolicySend << userDoesntCancel; + //--------------------------------------------------------------------= -------------------------- + // We modified an event which we're not the organizer of. And, when th= e "do you really want to modify", we choose "yes". + changeType =3D IncidenceChanger::ChangeTypeModify; + item =3D generateIncidence(uid, /**organizer=3D*/mia->email()); + incidence =3D item.payload(); + incidence->addAttendee(vincent); + incidence->addAttendee(jules); + us->setStatus(Attendee::Accepted); + incidence->addAttendee(us); + expectedEmailCount =3D 0; + QTest::newRow("Modification. We didnt organize") << item << changeType= << expectedEmailCount << invitationPolicySend << userDoesntCancel; //--------------------------------------------------------------------= -------------------------- - // We modified an event which we're not the organizer of. + // We modified an event which we're not the organizer of. And, when th= e "do you really want to modify", we choose "no". changeType =3D IncidenceChanger::ChangeTypeModify; item =3D generateIncidence(uid, /**organizer=3D*/mia->email()); incidence =3D item.payload(); @@ -444,7 +461,7 @@ void ITIPHandlerTest::testOutgoingInvitations_data() us->setStatus(Attendee::Accepted); incidence->addAttendee(us); expectedEmailCount =3D 0; - QTest::newRow("Modification. We didnt organize") << item << changeType= << expectedEmailCount << invitationPolicyAsk; + QTest::newRow("Modification. We didnt organize.2") << item << changeTy= pe << expectedEmailCount << invitationPolicyAsk << userCancels; //--------------------------------------------------------------------= -------------------------- } = @@ -454,12 +471,15 @@ void ITIPHandlerTest::testOutgoingInvitations() QFETCH(IncidenceChanger::ChangeType, changeType); QFETCH(int, expectedEmailCount); QFETCH(IncidenceChanger::InvitationPolicy, invitationPolicy); + QFETCH(bool, userCancels); KCalCore::Incidence::Ptr incidence =3D item.payload(); = m_pendingIncidenceChangerSignal =3D 1; MailClient::sUnitTestResults.clear(); m_changer->setInvitationPolicy(invitationPolicy); = + m_cancelExpected =3D userCancels; + switch(changeType) { case IncidenceChanger::ChangeTypeCreate: m_changer->createIncidence(incidence, mCollection); @@ -474,6 +494,7 @@ void ITIPHandlerTest::testOutgoingInvitations() m_changer->setGroupwareCommunication(true); QCOMPARE(MailClient::sUnitTestResults.count(), 0); QVERIFY(mLastInsertedItem.isValid()); + m_pendingIncidenceChangerSignal =3D 1; Incidence::Ptr oldIncidence =3D Incidence::Ptr(incidence->clone()); incidence->setSummary(QLatin1String("the-new-summary")); @@ -585,12 +606,12 @@ void ITIPHandlerTest::onCreateFinished(int changeId, = const Item &item, Q_UNUSED(changeId); Q_UNUSED(errorString); mLastInsertedItem =3D item; - QCOMPARE(resultCode, IncidenceChanger::ResultCodeSuccess); m_pendingIncidenceChangerSignal--; QVERIFY(m_pendingIncidenceChangerSignal >=3D 0); if (m_pendingIncidenceChangerSignal =3D=3D 0) { stopWaiting(); } + QCOMPARE(resultCode, IncidenceChanger::ResultCodeSuccess); } = void ITIPHandlerTest::onDeleteFinished(int changeId, const QVector &deletedIds, @@ -600,12 +621,13 @@ void ITIPHandlerTest::onDeleteFinished(int changeId, = const QVector & Q_UNUSED(changeId); Q_UNUSED(errorString); Q_UNUSED(deletedIds); - QCOMPARE(resultCode, IncidenceChanger::ResultCodeSuccess); + m_pendingIncidenceChangerSignal--; QVERIFY(m_pendingIncidenceChangerSignal >=3D 0); if (m_pendingIncidenceChangerSignal =3D=3D 0) { stopWaiting(); } + QCOMPARE(resultCode, IncidenceChanger::ResultCodeSuccess); } = void ITIPHandlerTest::onModifyFinished(int changeId, const Item &item, @@ -616,12 +638,13 @@ void ITIPHandlerTest::onModifyFinished(int changeId, = const Item &item, Q_UNUSED(errorString); Q_UNUSED(item); = - QCOMPARE(resultCode, IncidenceChanger::ResultCodeSuccess); m_pendingIncidenceChangerSignal--; QVERIFY(m_pendingIncidenceChangerSignal >=3D 0); if (m_pendingIncidenceChangerSignal =3D=3D 0) { stopWaiting(); } + QCOMPARE(resultCode, m_cancelExpected ? IncidenceChanger::ResultCodeUs= erCanceled + : IncidenceChanger::ResultCodeSu= ccess); } = QTEST_AKONADIMAIN(ITIPHandlerTest, GUI) diff --git a/akonadi/calendar/tests/itiphandlertest.h b/akonadi/calendar/te= sts/itiphandlertest.h index df3844c..a9657e1 100644 --- a/akonadi/calendar/tests/itiphandlertest.h +++ b/akonadi/calendar/tests/itiphandlertest.h @@ -87,6 +87,7 @@ private: Akonadi::ITIPHandler::Result m_expectedResult; Akonadi::ITIPHandler *m_itipHandler; Akonadi::IncidenceChanger *m_changer; + bool m_cancelExpected; }; = #endif