Commit d677a08c authored by Fabian Vogt's avatar Fabian Vogt
Browse files

Don't cache promises for AccountManager::findAccount

Unlike AccountManager::getAccount and AccountManager::refreshTokens, this
method does not return an authenticated account. However, the promises are
cached for all of them in the same store, so it was possible for a call to
e.g. refreshTokens to get a promise created by findAccount instead, resulting
in an unexpected result. Just don't cache promises created by findAccount.

BUG: 406839
BUG: 409122
BUG: 421664
BUG: 456923
parent b5a581d9
Pipeline #273759 passed with stage
in 3 minutes and 55 seconds
......@@ -265,30 +265,28 @@ AccountPromise *AccountManager::refreshTokens(const QString &apiKey, const QStri
AccountPromise *AccountManager::findAccount(const QString &apiKey, const QString &accountName, const QList<QUrl> &scopes)
{
auto promise = d->createPromise(apiKey, accountName);
if (!promise->d->isRunning()) {
QTimer::singleShot(0, this, [=]() {
d->ensureStore([=](bool storeOpened) {
if (!storeOpened) {
promise->d->setError(tr("Failed to open account store"));
return;
}
auto promise = new AccountPromise(this);
QTimer::singleShot(0, this, [=]() {
d->ensureStore([=](bool storeOpened) {
if (!storeOpened) {
promise->d->setError(tr("Failed to open account store"));
return;
}
const auto account = d->mStore->getAccount(apiKey, accountName);
if (!account) {
promise->d->setAccount({});
const auto account = d->mStore->getAccount(apiKey, accountName);
if (!account) {
promise->d->setAccount({});
} else {
const auto currentScopes = account->scopes();
if (scopes.isEmpty() || d->compareScopes(currentScopes, scopes)) {
promise->d->setAccount(account);
} else {
const auto currentScopes = account->scopes();
if (scopes.isEmpty() || d->compareScopes(currentScopes, scopes)) {
promise->d->setAccount(account);
} else {
promise->d->setAccount({});
}
promise->d->setAccount({});
}
});
}
});
promise->d->setRunning();
}
});
promise->d->setRunning();
return promise;
}
......
Supports Markdown
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