libkeepass / pykeepass

Python library to interact with keepass databases (supports KDBX3 and KDBX4)
https://pypi.org/project/pykeepass/
GNU General Public License v3.0
403 stars 96 forks source link

entry: move entries within a group #347

Closed pwall2222 closed 8 months ago

pwall2222 commented 11 months ago

Code changes:

Explanation: To move Entries around we need to remove and then insert at the desired index, the KDBX format makes it so that Entries and group info is all mixed, so we have to get the first element index to position correctly the Entries.

If you know a better method to get the index of the first entry I'll put it in.

What it does:

It moves entries around a group, pretty self explanatory, like the Keepass and KeepassXC functionality.

pwall2222 commented 8 months ago

Is just for feature parity with the KeePassXC client.

Evidlo commented 8 months ago

Perhaps it would be better to call this .reindex() or something similar. I'd like to avoid confusion with the move_entry() function, which is for hierarchical operations. Also needs a test in tests.py

Is just for feature parity with the KeePassXC client.

How do you do this in KeePassXC? As far as I can tell, the entries are just automatically sorted by Title/Username/URL/etc.

pwall2222 commented 8 months ago

As you sugggested I added a test and I rename the function to reindex. The keepassxc custom reorder, but anyway it was a feature in the original keepass. https://github.com/keepassxreboot/keepassxc/issues/2295 https://github.com/keepassxreboot/keepassxc/pull/4357 To replicate you will first need to click the current sorting column till it shows no icon, then in the context menu you will see move up and move down.

Evidlo commented 8 months ago

Thanks! This looks good so far.

Would you mind adding docstrings on reindex and index and also in README.md beneath move_entry? Sorry, I should've mentioned that before. After that it looks good to merge.

pwall2222 commented 8 months ago

Shouldn't it be near Entry.delete_attachment since its in the Entry class it self?

Evidlo commented 8 months ago

Shouldn't it be near Entry.delete_attachment since its in the Entry class it self?

Actually there doesn't appear to be sections for Group/Entry member functions in the README, so you can ignore that for now.

Thanks for the contribution!