From 1118ba1c2d90971bc998c319eca5c169daab0084 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 11 Nov 2024 09:37:31 +0200 Subject: [PATCH] Fix folder assignment --- nc_password_client/nc_password_client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nc_password_client/nc_password_client.py b/nc_password_client/nc_password_client.py index 44f02f4..5d9b518 100755 --- a/nc_password_client/nc_password_client.py +++ b/nc_password_client/nc_password_client.py @@ -545,6 +545,8 @@ r.status_code def create_password(self, post_obj): '''Create/add a password''' + if 'folder' in post_obj: + post_obj['folder'] = self.get_folder_id(post_obj['folder']) if not self.exists_password(post_obj): r = requests.post( f'{self.http}://{self.host}/index.php/apps/passwords/api/1.0/password/create', @@ -623,6 +625,13 @@ r.status_code return True return False + def get_folder_id(self, folder_name): + '''Get a folder id from the name''' + for folder in self.list_passwords_folders(): + if folder['label'] == folder_name: + return folder['id'] + return False + class NcPasswordClient: '''Nextcloud Password Client''' @@ -648,6 +657,7 @@ class NcPasswordClient: "api_token": api_token, "cse_password": cse_password, "timeout": timeout, + "details": True, } self.nc = NextcloudHandler(params) @@ -699,7 +709,7 @@ class NcPasswordClient: store = passpy.store.Store() count = 0 for item in store.find(''): - if limit > -1 and limit > count: + if limit == -1 or limit > count: obj = { "label": os.path.basename(item), }