Skip to content

Commit

Permalink
Disable entry level Auto-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu authored and droidmonkey committed Jul 30, 2023
1 parent b8f9ac8 commit 3f78e5f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 11 deletions.
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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2021 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2021 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2012 Felix Geyer <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2020 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* 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 <[email protected]>
* Copyright (C) 2010 Felix Geyer <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* 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

0 comments on commit 3f78e5f

Please sign in to comment.