Skip to content

Commit cccddff

Browse files
committed
Improve arguments description
1 parent c92a145 commit cccddff

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

mergin/client.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import typing
1818
import warnings
1919

20+
from typing import List
21+
2022
from .common import ClientError, LoginError, WorkspaceRole, ProjectRole
2123
from .merginproject import MerginProject
2224
from .client_pull import (
@@ -1243,9 +1245,16 @@ def create_user(
12431245
workspace_role: WorkspaceRole,
12441246
username: str = None,
12451247
notify_user: bool = False,
1246-
):
1248+
) -> dict:
12471249
"""
12481250
Create a new user in a workspace. The username is generated from the email address.
1251+
1252+
param email: email of the new user - must be unique
1253+
param password: password - must meet the requirements
1254+
param workspace_id: id of the workspace user is created in
1255+
param workspace_role: workspace role of the user
1256+
param username: username - will be autogenerated from the email if not provided
1257+
param notify_user: flag for email notifications - confirmation email will be sent
12491258
"""
12501259
params = {
12511260
"email": email,
@@ -1256,16 +1265,17 @@ def create_user(
12561265
}
12571266
if username:
12581267
params["username"] = username
1259-
self.post("v2/users", params, json_headers)
1268+
user_info = self.post("v2/users", params, json_headers)
1269+
return json.load(user_info)
12601270

1261-
def get_workspace_member(self, workspace_id: int, user_id: int):
1271+
def get_workspace_member(self, workspace_id: int, user_id: int) -> dict:
12621272
"""
12631273
Get a workspace member detail
12641274
"""
12651275
resp = self.get(f"v2/workspaces/{workspace_id}/members/{user_id}")
12661276
return json.load(resp)
12671277

1268-
def list_workspace_members(self, workspace_id: int):
1278+
def list_workspace_members(self, workspace_id: int) -> List[dict]:
12691279
"""
12701280
Get a list of workspace members
12711281
"""
@@ -1274,41 +1284,47 @@ def list_workspace_members(self, workspace_id: int):
12741284

12751285
def update_workspace_member(
12761286
self, workspace_id: int, user_id: int, workspace_role: WorkspaceRole, reset_projects_roles: bool = False
1277-
):
1287+
) -> dict:
12781288
"""
12791289
Update workspace role of a workspace member, optionally resets the projects role
1290+
1291+
param reset_projects_roles: all project specific roles will be removed
12801292
"""
12811293
params = {
12821294
"reset_projects_roles": reset_projects_roles,
12831295
"workspace_role": workspace_role.value,
12841296
}
1285-
resp = self.patch(f"v2/workspaces/{workspace_id}/members/{user_id}", params, json_headers)
1286-
return json.load(resp)
1297+
workspace_member = self.patch(f"v2/workspaces/{workspace_id}/members/{user_id}", params, json_headers)
1298+
return json.load(workspace_member)
12871299

12881300
def remove_workspace_member(self, workspace_id: int, user_id: int):
12891301
"""
12901302
Remove a user from workspace members
12911303
"""
12921304
self.delete(f"v2/workspaces/{workspace_id}/members/{user_id}")
12931305

1294-
def list_project_collaborators(self, project_id: int):
1306+
def list_project_collaborators(self, project_id: int) -> List[dict]:
12951307
"""
12961308
Get a list of project collaborators
12971309
"""
12981310
project_collaborators = self.get(f"v2/projects/{project_id}/collaborators")
12991311
return json.load(project_collaborators)
13001312

1301-
def add_project_collaborator(self, project_id: int, user: str, project_role: ProjectRole):
1313+
def add_project_collaborator(self, project_id: int, user: str, project_role: ProjectRole) -> dict:
13021314
"""
1303-
Add a user to project collaborators and grant them a project role
1315+
Add a user to project collaborators and grant them a project role.
1316+
Fails if user is already a member of the project.
1317+
1318+
param user: login (username or email) of the user
13041319
"""
13051320
params = {"role": project_role.value, "user": user}
13061321
project_collaborator = self.post(f"v2/projects/{project_id}/collaborators", params, json_headers)
13071322
return json.load(project_collaborator)
13081323

1309-
def update_project_collaborator(self, project_id: int, user_id: int, project_role: ProjectRole):
1324+
def update_project_collaborator(self, project_id: int, user_id: int, project_role: ProjectRole) -> dict:
13101325
"""
1311-
Update project role of the existing project collaborator
1326+
Update project role of the existing project collaborator.
1327+
Fails if user is not a member of the project yet.
13121328
"""
13131329
params = {"role": project_role.value}
13141330
project_collaborator = self.patch(f"v2/projects/{project_id}/collaborators/{user_id}", params, json_headers)

mergin/test/test_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,10 @@ def test_access_management(mc: MerginClient, mc2: MerginClient):
27522752
email = "create_user" + str(random.randint(1000, 9999)) + "@client.py"
27532753
password = "Il0vemergin"
27542754
ws_role = WorkspaceRole.WRITER
2755-
mc.create_user(email, password, workspace_id, ws_role)
2755+
user_info = mc.create_user(email, password, workspace_id, ws_role)
2756+
assert user_info["email"] == email
2757+
assert user_info["receive_notifications"] is False
2758+
# list workspace members
27562759
workspace_members = mc.list_workspace_members(workspace_id)
27572760
new_user = next((m for m in workspace_members if m["email"] == email))
27582761
assert new_user

0 commit comments

Comments
 (0)