Commit 75dba6e0 authored by Shashwat Jolly's avatar Shashwat Jolly

Remove server url and encryption password while reconfiguring resource

Also fix config dialog behaviour when password is changed and token expires. Set resource offline when incorrect credentials are detected.
parent 84a0e54d
Pipeline #32161 failed with stage
in 7 minutes and 45 seconds
......@@ -49,7 +49,7 @@ void EntriesFetchJob::fetchEntries()
if (status == ERROR) {
qCDebug(ETESYNC_LOG) << "Returning error from entries fetch job";
setError(UserDefinedError);
setError(etesync_get_error_code());
CharPtr err(etesync_get_error_message());
setErrorText(QStringFromCharPtr(err));
}
......
......@@ -62,6 +62,16 @@ public:
return mUsername;
}
QString serverUrl() const
{
return mServerUrl;
}
bool isInitialized()
{
return !mServerUrl.isEmpty();
}
public Q_SLOTS:
void refreshToken();
......
......@@ -106,8 +106,9 @@ void EteSyncResource::configure(WId windowId)
if (result == QDialog::Accepted) {
synchronize();
mClientState->saveSettings();
Q_EMIT configurationDialogAccepted();
mCredentialsRequired = false;
setOnline(true);
Q_EMIT configurationDialogAccepted();
} else {
Q_EMIT configurationDialogRejected();
}
......@@ -116,6 +117,11 @@ void EteSyncResource::configure(WId windowId)
void EteSyncResource::retrieveCollections()
{
qCDebug(ETESYNC_LOG) << "Retrieving collections";
if (credentialsRequired()) {
return;
}
setCollectionStreamingEnabled(true);
mJournalsCache.clear();
......@@ -154,7 +160,7 @@ void EteSyncResource::slotCollectionsRetrieved(KJob *job)
if (job->error()) {
qCWarning(ETESYNC_LOG) << "Error in fetching journals";
qCWarning(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
handleError();
handleError(job->error());
return;
}
EteSyncJournal **journals = qobject_cast<JournalsFetchJob *>(job)->journals();
......@@ -179,9 +185,10 @@ void EteSyncResource::slotCollectionsRetrieved(KJob *job)
* To be called immediately after an EteSync operation.
* CONFLICT error has been handled seperately in BaseHandler.
*/
bool EteSyncResource::handleError()
bool EteSyncResource::handleError(int errorCode)
{
switch (etesync_get_error_code()) {
qCDebug(ETESYNC_LOG) << "handleError - code" << errorCode;
switch (errorCode) {
case ETESYNC_ERROR_CODE_UNAUTHORIZED: {
qCDebug(ETESYNC_LOG) << "Invalid token";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
......@@ -208,15 +215,28 @@ bool EteSyncResource::handleError()
return false;
}
bool EteSyncResource::handleError()
{
return handleError(etesync_get_error_code());
}
bool EteSyncResource::credentialsRequired()
{
if (mCredentialsRequired) {
showErrorDialog(i18n("Your EteSync credentials were changed. Please click OK to re-enter your credentials."), i18n(CharPtr(etesync_get_error_message()).get()), i18n("Credentials Changed"));
configure(winIdForDialogs());
setOnline(false);
deferTask();
}
return mCredentialsRequired;
}
void EteSyncResource::slotTokenRefreshed(bool successful)
{
if (!successful) {
if (etesync_get_error_code() == ETESYNC_ERROR_CODE_HTTP) {
qCDebug(ETESYNC_LOG) << "HTTP Error while tokenRefresh - calling reconfigure";
showErrorDialog(i18n("Your EteSync credentials were changed. Please click OK to re-enter your credentials."), i18n(CharPtr(etesync_get_error_message()).get()), i18n("Credentials Changed"));
qCDebug(ETESYNC_LOG) << "Setting offline";
setOnline(false);
configure(winIdForDialogs());
mCredentialsRequired = true;
}
}
taskDone();
......@@ -322,6 +342,10 @@ void EteSyncResource::retrieveItems(const Akonadi::Collection &collection)
}
}
if (credentialsRequired()) {
return;
}
auto job = new EntriesFetchJob(mClientState->client(), collection, this);
connect(job, &EntriesFetchJob::finished, this, &EteSyncResource::slotItemsRetrieved);
......@@ -334,7 +358,7 @@ void EteSyncResource::slotItemsRetrieved(KJob *job)
if (job->error()) {
qCDebug(ETESYNC_LOG) << "Error in fetching entries";
qCWarning(ETESYNC_LOG) << job->errorText();
handleError();
handleError(job->error());
return;
}
......@@ -403,6 +427,10 @@ void EteSyncResource::itemAdded(const Akonadi::Item &item,
qCDebug(ETESYNC_LOG) << "Item added" << item.mimeType();
qCDebug(ETESYNC_LOG) << "Journal UID" << collection.remoteId();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForMimeType(item.mimeType());
if (handler) {
handler->itemAdded(item, collection);
......@@ -418,6 +446,10 @@ void EteSyncResource::itemChanged(const Akonadi::Item &item,
qCDebug(ETESYNC_LOG) << "Item changed" << item.mimeType();
qCDebug(ETESYNC_LOG) << "Journal UID" << item.parentCollection().remoteId();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForMimeType(item.mimeType());
if (handler) {
handler->itemChanged(item, parts);
......@@ -431,6 +463,10 @@ void EteSyncResource::itemRemoved(const Akonadi::Item &item)
{
qCDebug(ETESYNC_LOG) << "Item removed" << item.mimeType();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForMimeType(item.mimeType());
if (handler) {
handler->itemRemoved(item);
......@@ -444,6 +480,10 @@ void EteSyncResource::collectionAdded(const Akonadi::Collection &collection, con
{
qCDebug(ETESYNC_LOG) << "Collection added" << collection.mimeType();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForCollection(collection);
if (handler) {
handler->collectionAdded(collection, parent);
......@@ -457,6 +497,10 @@ void EteSyncResource::collectionChanged(const Akonadi::Collection &collection)
{
qCDebug(ETESYNC_LOG) << "Collection changed" << collection.mimeType();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForCollection(collection);
if (handler) {
handler->collectionChanged(collection);
......@@ -470,6 +514,10 @@ void EteSyncResource::collectionRemoved(const Akonadi::Collection &collection)
{
qCDebug(ETESYNC_LOG) << "Collection removed" << collection.mimeType();
if (credentialsRequired()) {
return;
}
auto handler = fetchHandlerForCollection(collection);
if (handler) {
handler->collectionRemoved(collection);
......
......@@ -68,6 +68,8 @@ protected:
QString baseDirectoryPath() const;
bool handleError();
bool handleError(int errorCode);
bool credentialsRequired();
const EteSyncJournalPtr &getJournal(const QString &journalUid)
{
......@@ -87,6 +89,7 @@ private:
std::vector<BaseHandler::Ptr> mHandlers;
std::map<QString, EteSyncJournalPtr> mJournalsCache;
QDateTime mJournalsCacheUpdateTime;
bool mCredentialsRequired;
ContactHandler::Ptr mContactHandler;
CalendarHandler::Ptr mCalendarHandler;
......
......@@ -32,7 +32,7 @@ namespace EteSyncAPI {
void start() override;
EteSyncJournal **journals()
EteSyncJournal **journals() const
{
return mJournals;
}
......
......@@ -72,8 +72,23 @@ LoginPage::LoginPage(QWidget *parent)
connect(mAdvancedSettings, SIGNAL(toggled(bool)), layout->labelForField(mServerUrl), SLOT(setVisible(bool)));
}
void LoginPage::initializePage()
{
qCDebug(ETESYNC_LOG) << "Login page - isInitialized" << mIsInitialized;
mIsInitialized = static_cast<SetupWizard *>(wizard())->mClientState->isInitialized();
if (mIsInitialized) {
mAdvancedSettings->setVisible(false);
setField(QStringLiteral("credentialsServerUrl"), static_cast<SetupWizard *>(wizard())->mClientState->serverUrl());
QString username = static_cast<SetupWizard *>(wizard())->mClientState->username();
mUserName->setText(username);
}
}
int LoginPage::nextId() const
{
if (mIsInitialized) {
return -1;
}
return SetupWizard::W_EncryptionPasswordPage;
}
......
......@@ -58,6 +58,7 @@ class LoginPage : public QWizardPage
public:
explicit LoginPage(QWidget *parent = nullptr);
int nextId() const override;
void initializePage() override;
bool validatePage() override;
private:
......@@ -66,6 +67,7 @@ private:
QCheckBox *mAdvancedSettings = nullptr;
QLineEdit *mServerUrl = nullptr;
QLabel *mLoginLabel = nullptr;
bool mIsInitialized;
};
class EncryptionPasswordPage : public QWizardPage
......
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