Skip to content
New issue

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

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

Already on GitHub? # to your account

Disable entry level Auto-Type when disabled on the entry or group level #9672

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
7 changes: 6 additions & 1 deletion src/core/Entry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -205,6 +205,11 @@ bool Entry::autoTypeEnabled() const
return m_data.autoTypeEnabled;
}

bool Entry::groupAutoTypeEnabled() const
{
return group() && group()->resolveAutoTypeEnabled();
}

int Entry::autoTypeObfuscation() const
{
return m_data.autoTypeObfuscation;
Expand Down
3 changes: 2 additions & 1 deletion src/core/Entry.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -91,6 +91,7 @@ class Entry : public ModifiableObject
QStringList tagList() const;
const TimeInfo& timeInfo() const;
bool autoTypeEnabled() const;
bool groupAutoTypeEnabled() const;
int autoTypeObfuscation() const;
QString defaultAutoTypeSequence() const;
QString effectiveAutoTypeSequence() const;
Expand Down
12 changes: 11 additions & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1977,6 +1977,16 @@ bool DatabaseWidget::currentEntryHasNotes()
return !currentEntry->resolveMultiplePlaceholders(currentEntry->notes()).isEmpty();
}

bool DatabaseWidget::currentEntryHasAutoTypeEnabled()
{
auto currentEntry = currentSelectedEntry();
if (!currentEntry) {
return false;
}

return currentEntry->autoTypeEnabled() && currentEntry->groupAutoTypeEnabled();
}

GroupView* DatabaseWidget::groupView()
{
return m_groupView;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -116,6 +116,7 @@ class DatabaseWidget : public QStackedWidget
#ifdef WITH_XC_SSHAGENT
bool currentEntryHasSshKey();
#endif
bool currentEntryHasAutoTypeEnabled();

QByteArray entryViewState() const;
bool setEntryViewState(const QByteArray& state) const;
Expand Down
6 changes: 4 additions & 2 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -468,7 +468,9 @@ void EntryPreviewWidget::updateEntryAutotypeTab()
}

m_ui->entryAutotypeTree->addTopLevelItems(items);
setTabEnabled(m_ui->entryTabWidget, m_ui->entryAutotypeTab, m_currentEntry->autoTypeEnabled());
setTabEnabled(m_ui->entryTabWidget,
m_ui->entryAutotypeTab,
m_currentEntry->autoTypeEnabled() && m_currentEntry->groupAutoTypeEnabled());
}

void EntryPreviewWidget::updateGroupHeaderLine()
Expand Down
7 changes: 4 additions & 3 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -929,8 +929,9 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);
m_ui->menuEntryTotp->setEnabled(singleEntrySelected);
m_ui->menuTags->setEnabled(entriesSelected);
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected);
m_ui->actionEntryAutoType->menu()->setEnabled(singleEntrySelected);
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected && dbWidget->currentEntryHasAutoTypeEnabled());
m_ui->actionEntryAutoType->menu()->setEnabled(singleEntrySelected
&& dbWidget->currentEntryHasAutoTypeEnabled());
m_ui->actionEntryAutoTypeSequence->setText(
singleEntrySelected ? dbWidget->currentSelectedEntry()->effectiveAutoTypeSequence()
: Group::RootAutoTypeSequence);
Expand Down
28 changes: 27 additions & 1 deletion tests/TestGroup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1293,3 +1293,29 @@ void TestGroup::testPreviousParentGroup()
QVERIFY(group1->previousParentGroupUuid() == group2->uuid());
QVERIFY(group1->previousParentGroup() == group2);
}

void TestGroup::testAutoTypeState()
{
Database db;
auto* root = db.rootGroup();

auto* entry1 = new Entry();
entry1->setGroup(root);

auto subGroup = new Group();
subGroup->setParent(root);
auto* entry2 = new Entry();
entry2->setGroup(subGroup);

// Disable Auto-Type from root group
root->setAutoTypeEnabled(Group::TriState::Disable);
QVERIFY(!entry1->groupAutoTypeEnabled());
QVERIFY(!entry2->groupAutoTypeEnabled());

// Enable Auto-Type for sub group
subGroup->setAutoTypeEnabled(Group::TriState::Enable);
QVERIFY(root->autoTypeEnabled() == Group::TriState::Disable);
QVERIFY(subGroup->autoTypeEnabled() == Group::TriState::Enable);
QVERIFY(!entry1->groupAutoTypeEnabled());
QVERIFY(entry2->groupAutoTypeEnabled());
}
3 changes: 2 additions & 1 deletion tests/TestGroup.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,6 +49,7 @@ private slots:
void testUsernamesRecursive();
void testMoveUpDown();
void testPreviousParentGroup();
void testAutoTypeState();
};

#endif // KEEPASSX_TESTGROUP_H