From c039328f95e3abc11ed8f9627a58c8663947c9d4 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Thu, 17 Aug 2023 21:20:45 +0200 Subject: [PATCH] method to add user to collection added --- tests/test_package.py | 7 +++++++ transkribus_utils/transkribus_utils.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/test_package.py b/tests/test_package.py index 6f853da..ad7e771 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -83,3 +83,10 @@ def test_011_user_id(self): client = CLIENT user_id = client.get_user_id(client.user) self.assertTrue(user_id) + + def test_012_add_user(self): + client = CLIENT + col_id = 190357 + status = client.add_user_to_collection(client.user, col_id=col_id, send_mail=False) + self.assertTrue(f"{190357}" in status) + self.assertTrue(f"{client.user}" in status) diff --git a/transkribus_utils/transkribus_utils.py b/transkribus_utils/transkribus_utils.py index 7de2624..0169bcf 100644 --- a/transkribus_utils/transkribus_utils.py +++ b/transkribus_utils/transkribus_utils.py @@ -443,6 +443,22 @@ def get_user_id(self, user_name: str) -> int: user_id = response["trpUser"][0]["userId"] return user_id + def add_user_to_collection(self, user_name: str, col_id: int, role: str = "Owner", send_mail: bool = True) -> str: + """adds user to given collection""" + user_id = self.get_user_id(user_name) + result_msg = f"looks like something went wront adding {user_name} to collection {col_id}" + params = {"userid": user_id, "role": role} + if not send_mail: + params = {"userid": user_id, "role": role, "sendMail": False} + res = requests.post( + f"{self.base_url}/collections/{col_id}/addOrModifyUserInCollection", + cookies=self.login_cookie, + params=params, + ) + if res.status_code == 200: + result_msg = f"added user {user_name} to collection {col_id}" + return result_msg + def create_status_report( self, filter_string: str, transcription_threshold: int = 10 ) -> list: