diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 46b7ff1f3..7e238f049 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * 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 @@ -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; diff --git a/src/core/Entry.h b/src/core/Entry.h index 7fc69c8fb..88f878e98 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * 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 @@ -91,6 +91,7 @@ public: QStringList tagList() const; const TimeInfo& timeInfo() const; bool autoTypeEnabled() const; + bool groupAutoTypeEnabled() const; int autoTypeObfuscation() const; QString defaultAutoTypeSequence() const; QString effectiveAutoTypeSequence() const; diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 440df2afc..cd5435038 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2021 KeePassXC Team * * 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 @@ -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; diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index a8ae0511c..dd2853b97 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2021 KeePassXC Team * * 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 @@ -116,6 +116,7 @@ public: #ifdef WITH_XC_SSHAGENT bool currentEntryHasSshKey(); #endif + bool currentEntryHasAutoTypeEnabled(); QByteArray entryViewState() const; bool setEntryViewState(const QByteArray& state) const; diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index c8d0b974d..5693d424f 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2012 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * 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 @@ -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() diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index b09706246..50e6eb4e6 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2020 KeePassXC Team * * 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 @@ -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); diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 54ce9e9ec..22807c878 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * 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 @@ -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()); +} diff --git a/tests/TestGroup.h b/tests/TestGroup.h index 0c8fee937..d3326e464 100644 --- a/tests/TestGroup.h +++ b/tests/TestGroup.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2010 Felix Geyer - * Copyright (C) 2017 KeePassXC Team * * 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 @@ -49,6 +49,7 @@ private slots: void testUsernamesRecursive(); void testMoveUpDown(); void testPreviousParentGroup(); + void testAutoTypeState(); }; #endif // KEEPASSX_TESTGROUP_H