Skip to content

Commit

Permalink
method to add user to collection added
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Aug 17, 2023
1 parent 41151dd commit c039328
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions transkribus_utils/transkribus_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c039328

Please sign in to comment.