Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert async Access Confirm Dialog #8665

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 6 additions & 46 deletions src/browser/BrowserAccessControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,28 @@ BrowserAccessControlDialog::BrowserAccessControlDialog(QWidget* parent)

m_ui->setupUi(this);

connect(m_ui->allowButton, SIGNAL(clicked()), SLOT(acceptSelections()));
connect(m_ui->denyButton, SIGNAL(clicked()), SLOT(rejectSelections()));
connect(this, SIGNAL(rejected()), this, SIGNAL(closed()));
connect(m_ui->allowButton, SIGNAL(clicked()), SLOT(accept()));
connect(m_ui->denyButton, SIGNAL(clicked()), SLOT(reject()));
}

BrowserAccessControlDialog::~BrowserAccessControlDialog()
{
}

void BrowserAccessControlDialog::closeEvent(QCloseEvent* event)
void BrowserAccessControlDialog::setItems(const QList<Entry*>& items, const QString& urlString, bool httpAuth)
{
// Emits closed signal when clicking X from title bar
emit closed();
event->accept();
}

void BrowserAccessControlDialog::setItems(const QList<Entry*>& entriesToConfirm,
const QList<Entry*>& allowedEntries,
const QString& urlString,
bool httpAuth)
{
m_entriesToConfirm = entriesToConfirm;
m_allowedEntries = allowedEntries;

QUrl url(urlString);
m_ui->siteLabel->setText(m_ui->siteLabel->text().arg(
url.toDisplayString(QUrl::RemoveUserInfo | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment)));

m_ui->rememberDecisionCheckBox->setVisible(!httpAuth);
m_ui->rememberDecisionCheckBox->setChecked(false);

m_ui->itemsTable->setRowCount(entriesToConfirm.count());
m_ui->itemsTable->setRowCount(items.count());
m_ui->itemsTable->setColumnCount(2);

int row = 0;
for (const auto& entry : entriesToConfirm) {
for (const auto& entry : items) {
auto item = new QTableWidgetItem();
item->setText(entry->title() + " - " + entry->username());
item->setData(Qt::UserRole, row);
Expand All @@ -77,23 +63,18 @@ void BrowserAccessControlDialog::setItems(const QList<Entry*>& entriesToConfirm,

auto disableButton = new QPushButton(tr("Disable for this site"));
disableButton->setAutoDefault(false);

connect(disableButton, &QAbstractButton::pressed, [&, item] {
emit disableAccess(item);
m_ui->itemsTable->removeRow(item->row());

if (m_ui->itemsTable->rowCount() == 0) {
emit closed();
reject();
}
});
m_ui->itemsTable->setCellWidget(row, 1, disableButton);

++row;
}

m_ui->itemsTable->resizeColumnsToContents();
m_ui->itemsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

m_ui->allowButton->setFocus();
}

Expand All @@ -102,11 +83,6 @@ bool BrowserAccessControlDialog::remember() const
return m_ui->rememberDecisionCheckBox->isChecked();
}

bool BrowserAccessControlDialog::entriesAccepted() const
{
return m_entriesAccepted;
}

QList<QTableWidgetItem*> BrowserAccessControlDialog::getSelectedEntries() const
{
QList<QTableWidgetItem*> selected;
Expand All @@ -130,19 +106,3 @@ QList<QTableWidgetItem*> BrowserAccessControlDialog::getNonSelectedEntries() con
}
return notSelected;
}

void BrowserAccessControlDialog::acceptSelections()
{
auto selectedEntries = getSelectedEntries();

m_entriesAccepted = true;
emit acceptEntries(selectedEntries, m_entriesToConfirm, m_allowedEntries);
emit closed();
}

void BrowserAccessControlDialog::rejectSelections()
{
auto rejectedEntries = getNonSelectedEntries();
emit rejectEntries(rejectedEntries, m_entriesToConfirm);
emit closed();
}
16 changes: 1 addition & 15 deletions src/browser/BrowserAccessControlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,14 @@ class BrowserAccessControlDialog : public QDialog
explicit BrowserAccessControlDialog(QWidget* parent = nullptr);
~BrowserAccessControlDialog() override;

void setItems(const QList<Entry*>& entriesToConfirm,
const QList<Entry*>& allowedEntries,
const QString& urlString,
bool httpAuth);
void setItems(const QList<Entry*>& items, const QString& urlString, bool httpAuth);
bool remember() const;
bool entriesAccepted() const;

QList<QTableWidgetItem*> getSelectedEntries() const;
QList<QTableWidgetItem*> getNonSelectedEntries() const;

signals:
void disableAccess(QTableWidgetItem* item);
void acceptEntries(QList<QTableWidgetItem*> items, QList<Entry*> entriesToConfirm, QList<Entry*> allowedEntries);
void rejectEntries(QList<QTableWidgetItem*> items, QList<Entry*> entriesToConfirm);
void closed();

public slots:
void acceptSelections();
void rejectSelections();

private:
void closeEvent(QCloseEvent* event) override;

private:
QScopedPointer<Ui::BrowserAccessControlDialog> m_ui;
Expand Down
36 changes: 12 additions & 24 deletions src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QJsonObject BrowserAction::handleAction(QLocalSocket* socket, const QJsonObject&
} else if (action.compare("test-associate") == 0) {
return handleTestAssociate(json, action);
} else if (action.compare("get-logins") == 0) {
return handleGetLogins(socket, json, action);
return handleGetLogins(json, action);
} else if (action.compare("generate-password") == 0) {
return handleGeneratePassword(socket, json, action);
} else if (action.compare("set-login") == 0) {
Expand Down Expand Up @@ -231,7 +231,7 @@ QJsonObject BrowserAction::handleTestAssociate(const QJsonObject& json, const QS
return buildResponse(action, message, newNonce);
}

QJsonObject BrowserAction::handleGetLogins(QLocalSocket* socket, const QJsonObject& json, const QString& action)
QJsonObject BrowserAction::handleGetLogins(const QJsonObject& json, const QString& action)
{
const QString hash = browserService()->getDatabaseHash();
const QString nonce = json.value("nonce").toString();
Expand Down Expand Up @@ -264,31 +264,19 @@ QJsonObject BrowserAction::handleGetLogins(QLocalSocket* socket, const QJsonObje
const QString formUrl = decrypted.value("submitUrl").toString();
const QString auth = decrypted.value("httpAuth").toString();
const bool httpAuth = auth.compare(TRUE_STR) == 0;
auto requestId = decrypted.value("requestID").toString();

if (browserService()->isAccessConfirmRequested()) {
auto errorReply = getErrorReply(action, ERROR_KEEPASS_ACTION_CANCELLED_OR_DENIED);

if (!requestId.isEmpty()) {
errorReply["requestID"] = requestId;
}

return errorReply;
const QJsonArray users = browserService()->findMatchingEntries(id, siteUrl, formUrl, "", keyList, httpAuth);
if (users.isEmpty()) {
return getErrorReply(action, ERROR_KEEPASS_NO_LOGINS_FOUND);
}

browserService()->findEntries(socket,
incrementedNonce,
m_clientPublicKey,
m_secretKey,
id,
hash,
requestId,
siteUrl,
formUrl,
"",
keyList,
httpAuth);
return QJsonObject();
QJsonObject message = browserMessageBuilder()->buildMessage(incrementedNonce);
message["count"] = users.count();
message["entries"] = users;
message["hash"] = hash;
message["id"] = id;

return buildResponse(action, message, incrementedNonce);
}

QJsonObject BrowserAction::handleGeneratePassword(QLocalSocket* socket, const QJsonObject& json, const QString& action)
Expand Down
2 changes: 1 addition & 1 deletion src/browser/BrowserAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BrowserAction
QJsonObject handleGetDatabaseHash(const QJsonObject& json, const QString& action);
QJsonObject handleAssociate(const QJsonObject& json, const QString& action);
QJsonObject handleTestAssociate(const QJsonObject& json, const QString& action);
QJsonObject handleGetLogins(QLocalSocket* socket, const QJsonObject& json, const QString& action);
QJsonObject handleGetLogins(const QJsonObject& json, const QString& action);
QJsonObject handleGeneratePassword(QLocalSocket* socket, const QJsonObject& json, const QString& action);
QJsonObject handleSetLogin(const QJsonObject& json, const QString& action);
QJsonObject handleLockDatabase(const QJsonObject& json, const QString& action);
Expand Down
Loading