Skip to content

Commit ea6ff72

Browse files
committed
Enable setting of the new global_write= permissions.
1 parent bb8dcaa commit ea6ff72

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/pygobbler/fetch_permissions.py

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def fetch_permissions(project: str, registry: str, url: str, force_remote: bool
4141
authorization does not expire.
4242
- ``trusted`` (optional), whether the uploader is trusted. If not
4343
provided, defaults to false.
44+
45+
The top-level dictionary may also contain `global_write`, a boolean
46+
indicating whether global writes are supported. If true, any user may
47+
create a new asset in this project, and each user can upload new
48+
versions to any asset they created under this mode.
4449
"""
4550
if os.path.exists(registry) and not force_remote:
4651
with open(os.path.join(registry, project, "..permissions"), "r") as f:

src/pygobbler/set_permissions.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
from . import fetch_permissions
44

55

6-
def set_permissions(project: str, registry: str, staging: str, url: str, owners: Optional[List] = None, uploaders: Optional[Dict] = None, append: bool = True):
6+
def set_permissions(
7+
project: str,
8+
registry: str,
9+
staging: str,
10+
url: str,
11+
owners: Optional[List] = None,
12+
uploaders: Optional[Dict] = None,
13+
global_write: Optional[bool] = None,
14+
append: bool = True):
715
"""
816
Set the owner and uploader permissions for a project.
917
@@ -30,6 +38,12 @@ def set_permissions(project: str, registry: str, staging: str, url: str, owners:
3038
:py:func:`~.fetch_permissions` for the expected format. If None,
3139
no change is made to the existing uploaders.
3240
41+
global_write:
42+
Whether to enable global writes for this project, see the
43+
``global_write`` field in the return value of
44+
:py:func:`~.fetch_permissions` for more details. If None, no change
45+
is made to the global write status.
46+
3347
append:
3448
Whether ``owners`` and ``uploaders`` should be appended to the
3549
existing owners and uploaders, respectively. If False, the
@@ -51,4 +65,7 @@ def set_permissions(project: str, registry: str, staging: str, url: str, owners:
5165
if uploaders is not None:
5266
perms["uploaders"] = uploaders
5367

68+
if global_write is not None:
69+
perms["global_write"] = global_write
70+
5471
ut.dump_request(staging, url, "set_permissions", { "project": project, "permissions": perms })

src/pygobbler/start_gobbler.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
test_port = None
1010
test_process = None
1111

12-
def start_gobbler(staging: Optional[str] = None, registry: Optional[str] = None, port: Optional[int] = None, wait: float = 1, version: str = "0.3.2", overwrite: bool = False) -> Tuple[bool, str, str, str]:
12+
def start_gobbler(
13+
staging: Optional[str] = None,
14+
registry: Optional[str] = None,
15+
port: Optional[int] = None,
16+
wait: float = 1,
17+
version: str = "0.3.7",
18+
overwrite: bool = False) -> Tuple[bool, str, str, str]:
1319
"""
1420
Start a test Gobbler service.
1521

tests/test_set_permissions.py

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_set_permissions():
2020
assert len(perms["uploaders"]) == 1
2121
assert perms["uploaders"][0]["id"] == "lawremi"
2222
assert perms["uploaders"][0]["until"] == until
23+
assert not "global_write" in perms
2324

2425
# Checking uploader appending, while also checking owners=NULL.
2526
pyg.set_permissions("test-perms", uploaders=[ { "id": "ArtifactDB-bot", "trusted": True } ], staging=staging, url=url, registry=registry)
@@ -29,6 +30,7 @@ def test_set_permissions():
2930
assert perms["uploaders"][0]["id"] == "lawremi"
3031
assert perms["uploaders"][1]["id"] == "ArtifactDB-bot"
3132
assert perms["uploaders"][1]["trusted"]
33+
assert not "global_write" in perms
3234

3335
# Checking union of owners, and also that uploaders=NULL works.
3436
pyg.set_permissions("test-perms", owners=[ "PeteHaitch", "LTLA" ], staging=staging, url=url, registry=registry)
@@ -47,3 +49,8 @@ def test_set_permissions():
4749
perms = pyg.fetch_permissions("test-perms", registry=registry, url=url)
4850
assert perms["owners"] == [ "LTLA" ]
4951
assert len(perms["uploaders"]) == 0
52+
53+
# Checking that it works with global writes enabled.
54+
pyg.set_permissions("test-perms", global_write=True, staging=staging, url=url, registry=registry)
55+
perms = pyg.fetch_permissions("test-perms", registry=registry, url=url)
56+
assert perms["global_write"]

0 commit comments

Comments
 (0)