-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Warn user if deleting entries that are referenced. #1744
Warn user if deleting entries that are referenced. #1744
Conversation
src/core/Database.cpp
Outdated
@@ -199,6 +201,30 @@ Group* Database::findGroupRecursive(const Uuid& uuid, Group* group) | |||
return nullptr; | |||
} | |||
|
|||
namespace { | |||
QList<Entry*> resolveReferencesRecursive(const Uuid& uuid, const Group* group) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be a member of the Database class. Also recommend overloading the Database::resolveReferences function with this one accepting a specific group.
src/core/Database.cpp
Outdated
}; | ||
|
||
QList<Entry*> result; | ||
std::copy_if(group->entries().begin(), group->entries().end(), std::back_inserter(result), isReference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't mix Qt and std. Recommend the following function call:
auto result = QtConcurrent::blockingFiltered(group->entries(), isReference);
src/core/Database.cpp
Outdated
std::copy_if(group->entries().begin(), group->entries().end(), std::back_inserter(result), isReference); | ||
|
||
for (Group *child : group->children()) | ||
result += resolveReferencesRecursive(uuid, child); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing { and }
src/gui/DatabaseWidget.cpp
Outdated
QList<Entry*> references = m_db->resolveReferences(entry->uuid()); | ||
for (auto const& el : selectedEntries) | ||
references.removeAll(el); | ||
referencesMap.insert(entry, references.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a referencesMap and lumping everything into one message below, you should use this same loop to process the delete function for each selected entry. That way a user can choose to delete or not delete a particular selected entry "in the moment" and not have to cancel the whole operation and deselect a particular one. If there are no entries with references, no message should be shown beyond the "Are you sure you want to delete XX entries?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be the options available for references? Replace
, Ignore
, Keep original
, Cancel
? Depending on selected set of options, flow might get complicated as we will need to track underlying dependencies between every field that might be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep it simple: Copy Values, Delete All, Skip
I envision a message of: "{entry title} has {X} references. What would you like to do?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete all
is far from simple in implementation terms.
I went with Replace / Ignore / Skip for now. What do you think?
src/gui/DatabaseWidget.cpp
Outdated
@@ -530,6 +548,19 @@ void DatabaseWidget::deleteEntries() | |||
} | |||
} | |||
|
|||
QString DatabaseWidget::referencesMessage(QMap<Entry*, int> const& referencesMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unnecessary if you follow my implementation suggestion above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Before you go any further please address my comments. This is become more and more complicated. |
Actually, I have one question - can there possibly be references to all fields of |
Title, Username, Password, URL, and Notes can be referenced |
Then, this will get far more complicated that I expected. 😑 |
I merged with |
Please rebase on develop now that the code format was performed. |
8b33c20
to
46d3e90
Compare
|
8b33c20
to
7576f39
Compare
Any reason why this was closed? |
PR seemed to be stalled from my perspective. If it is still a candidate for a merge, feel free to reopen it. |
For future reference, if it's still open, we still want it. |
b7c7d14
to
4389128
Compare
I finally rebased that feature on top of develop. Most of the code was in conflict state by now. |
…eboot#852. On warning, references can be replaced with original values or ignored. Removal process can be also skipped for each conflicting entry.
6251862
to
7f22151
Compare
I rebased and made some modifications to streamline. My only concern with this PR is there may be a significant performance hit when deleting entries in large databases. There might be some more optimizations to make before merging. Also, to conform with the new Database class structure, the resolve references functions should be moved into the Group class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above about optimization
- New Database Wizard [#1952] - Advanced Search [#1797] - Automatic update checker [#2648] - KeeShare database synchronization [#2109, #1992, #2738, #2742, #2746, #2739] - Improve favicon fetching; transition to Duck-Duck-Go [#2795, #2011, #2439] - Remove KeePassHttp support [#1752] - CLI: output info to stderr for easier scripting [#2558] - CLI: Add --quiet option [#2507] - CLI: Add create command [#2540] - CLI: Add recursive listing of entries [#2345] - CLI: Fix stdin/stdout encoding on Windows [#2425] - SSH Agent: Support OpenSSH for Windows [#1994] - macOS: TouchID Quick Unlock [#1851] - macOS: Multiple improvements; include CLI in DMG [#2165, #2331, #2583] - Linux: Prevent Klipper from storing secrets in clipboard [#1969] - Linux: Use polling based file watching for NFS [#2171] - Linux: Enable use of browser plugin in Snap build [#2802] - TOTP QR Code Generator [#1167] - High-DPI Scaling for 4k screens [#2404] - Make keyboard shortcuts more consistent [#2431] - Warn user if deleting referenced entries [#1744] - Allow toolbar to be hidden and repositioned [#1819, #2357] - Increase max allowed database timeout to 12 hours [#2173] - Password generator uses existing password length by default [#2318] - Improve alert message box button labels [#2376] - Show message when a database merge makes no changes [#2551] - Browser Integration Enhancements [#1497, #2253, #1904, #2232, #1850, #2218, #2391, #2396, #2542, #2622, #2637, #2790] - Overall Code Improvements [#2316, #2284, #2351, #2402, #2410, #2419, #2422, #2443, #2491, #2506, #2610, #2667, #2709, #2731]
Description
User is warned on deletion of entries referenced by other database entries. No warning is shown if all referencing entries are also being removed.
Motivation and context
See #852.
How has this been tested?
Built on top of
develop
, that is2.3.1
withgcc 7.3.0
on 64-bit Linux.Ran tests, of which
testgui
failed. I checked logs for sanitizer output and compared with running same test ondevelop
branch. In both cases, summary was:SUMMARY: AddressSanitizer: 110049 byte(s) leaked in 2162 allocation(s)
.Types of changes
Checklist:
-DWITH_ASAN=ON
. [REQUIRED]