Skip to content

Added editor project permission #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ htmlcov
.pytest_cache
deps
venv
.vscode/settings.json
18 changes: 13 additions & 5 deletions mergin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,21 @@ def share(ctx, project):
return
access_list = mc.project_user_permissions(project)

for username in access_list.get("owners"):
owners = access_list.get("owners", [])
writers = access_list.get("writers", [])
editors = access_list.get("editors", [])
readers = access_list.get("readers", [])

for username in owners:
click.echo("{:20}\t{:20}".format(username, "owner"))
for username in access_list.get("writers"):
if username not in access_list.get("owners"):
for username in writers:
if username not in owners:
click.echo("{:20}\t{:20}".format(username, "writer"))
for username in access_list.get("readers"):
if username not in access_list.get("writers"):
for username in editors:
if username not in writers:
click.echo("{:20}\t{:20}".format(username, "editor"))
for username in readers:
if username not in editors:
click.echo("{:20}\t{:20}".format(username, "reader"))


Expand Down
37 changes: 26 additions & 11 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,11 @@ def set_project_access(self, project_path, access):
"""
Updates access for given project.
:param project_path: project full name (<namespace>/<name>)
:param access: dict <readersnames, writersnames, ownersnames> -> list of str username we want to give access to
:param access: dict <readersnames, editorsnames, writersnames, ownersnames> -> list of str username we want to give access to (editorsnames are only supported on servers at version 2024.4.0 or later)
"""
if "editorsnames" in access and not is_version_acceptable(self.server_version(), "2024.4"):
raise NotImplementedError("Editors are only supported on servers at version 2024.4.0 or later")

if not self._user_info:
raise Exception("Authentication required")

Expand All @@ -782,19 +785,25 @@ def add_user_permissions_to_project(self, project_path, usernames, permission_le
Add specified permissions to specified users to project
:param project_path: project full name (<namespace>/<name>)
:param usernames: list of usernames to be granted specified permission level
:param permission_level: string (reader, writer, owner)
:param permission_level: string (reader, editor, writer, owner)

Editor permission_level is only supported on servers at version 2024.4.0 or later.
"""
if permission_level not in ["owner", "reader", "writer"]:
if permission_level not in ["owner", "reader", "writer", "editor"] or (
permission_level == "editor" and not is_version_acceptable(self.server_version(), "2024.4")
):
raise ClientError("Unsupported permission level")

project_info = self.project_info(project_path)
access = project_info.get("access")
for name in usernames:
if permission_level == "owner":
access.get("ownersnames").append(name)
if permission_level == "writer" or permission_level == "owner":
if permission_level in ("writer", "owner"):
access.get("writersnames").append(name)
if permission_level == "writer" or permission_level == "owner" or permission_level == "reader":
if permission_level in ("writer", "owner", "editor") and "editorsnames" in access:
access.get("editorsnames").append(name)
if permission_level in ("writer", "owner", "editor", "reader"):
access.get("readersnames").append(name)
self.set_project_access(project_path, access)

Expand All @@ -807,11 +816,13 @@ def remove_user_permissions_from_project(self, project_path, usernames):
project_info = self.project_info(project_path)
access = project_info.get("access")
for name in usernames:
if name in access.get("ownersnames"):
if name in access.get("ownersnames", []):
access.get("ownersnames").remove(name)
if name in access.get("writersnames"):
if name in access.get("writersnames", []):
access.get("writersnames").remove(name)
if name in access.get("readersnames"):
if name in access.get("editorsnames", []):
access.get("editorsnames").remove(name)
if name in access.get("readersnames", []):
access.get("readersnames").remove(name)
self.set_project_access(project_path, access)

Expand All @@ -821,14 +832,18 @@ def project_user_permissions(self, project_path):
:param project_path: project full name (<namespace>/<name>)
:return dict("owners": list(usernames),
"writers": list(usernames),
"editors": list(usernames) - only on servers at version 2024.4.0 or later,
"readers": list(usernames))
"""
project_info = self.project_info(project_path)
access = project_info.get("access")
result = {}
result["owners"] = access.get("ownersnames")
result["writers"] = access.get("writersnames")
result["readers"] = access.get("readersnames")
if "editorsnames" in access:
result["editors"] = access.get("editorsnames", [])

result["owners"] = access.get("ownersnames", [])
result["writers"] = access.get("writersnames", [])
result["readers"] = access.get("readersnames", [])
return result

def push_project(self, directory):
Expand Down
Loading
Loading