-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more conservative permissions update
- Loading branch information
Showing
1 changed file
with
72 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,24 @@ | |
import glob | ||
import time | ||
import multiprocessing | ||
import argparse | ||
|
||
# GTN_BOT_ID = https://workflowhub.eu/people/731 | ||
GTN_PROJECT_ID = 12 | ||
# WORKFLOWHUB = "https://dev.workflowhub.eu" | ||
WORKFLOWHUB = "https://workflowhub.eu" | ||
|
||
if len(sys.argv) == 2: | ||
crates = [sys.argv[1]] | ||
argparser = argparse.ArgumentParser() | ||
argparser.add_argument("--prod", action="store_true", help="Upload to production") | ||
argparser.add_argument("--crate", type=str, help="Upload a single crate (defaults to all)") | ||
args = argparser.parse_args() | ||
|
||
if args.prod: | ||
WORKFLOWHUB = "https://workflowhub.eu" | ||
GTN_PROJECT_ID = 12 | ||
else: | ||
WORKFLOWHUB = "https://dev.workflowhub.eu" | ||
GTN_PROJECT_ID = 63 | ||
|
||
if args.crate: | ||
crates = [args.crate] | ||
else: | ||
crates = glob.glob( | ||
"_site/training-material/api/workflows/**/rocrate.zip", recursive=True | ||
|
@@ -37,7 +47,7 @@ def doUpload(crate_path): | |
"workflow[project_ids][]": (None, GTN_PROJECT_ID), # GTN's ID. | ||
} | ||
headers = { | ||
"authorization": "Token " + os.environ["WFH_TOKEN"], | ||
"authorization": "Token " + os.environ["WFH_TOKEN"], | ||
'User-Agent': 'GTN (github.com/galaxyproject/[email protected])', | ||
# 'Content-type': 'application/json', | ||
'Accept': 'application/json', | ||
|
@@ -61,44 +71,75 @@ def doUpload(crate_path): | |
"id": wfid, | ||
"type": "workflows", | ||
"attributes": { | ||
"policy": { | ||
"access": "download", | ||
"permissions": [ | ||
{ | ||
"resource": { | ||
"id": str(GTN_PROJECT_ID), | ||
"type": "projects" | ||
}, | ||
"access": "manage" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
||
current_policy = response.json()['data']['attributes']['policy'] | ||
|
||
updated_policy = {} | ||
if current_policy['access'] != 'download': | ||
updated_policy['access'] = 'download' | ||
|
||
gtn_permission = [x for x in current_policy['permissions'] if x['resource']['id'] == str(GTN_PROJECT_ID)] | ||
if len(gtn_permission) != 1: | ||
updated_policy['permissions'] = current_policy['permissions'] + [ | ||
{ | ||
"resource": { | ||
"id": str(GTN_PROJECT_ID), | ||
"type": "projects" | ||
}, | ||
"access": "manage" | ||
} | ||
] | ||
else: | ||
if gtn_permission[0]['access'] != 'manage': | ||
gtn_permission[0]['access'] = 'manage' | ||
updated_policy['permissions'] = current_policy['permissions'] | ||
|
||
# "policy": { | ||
# "access": "download", | ||
# "permissions": [ | ||
# { | ||
# "resource": { | ||
# "id": str(GTN_PROJECT_ID), | ||
# "type": "projects" | ||
# }, | ||
# "access": "manage" | ||
# } | ||
# ] | ||
# } | ||
|
||
# {'access': 'download', | ||
# 'permissions': [{'access': 'manage', | ||
# 'resource': {'id': '63', 'type': 'projects'}}]} | ||
# | ||
if updated_policy: | ||
push = True | ||
permissions_update['data']['attributes']['policy'] = updated_policy | ||
|
||
dls = response.json()['data']['attributes']['discussion_links'] | ||
print("Discussion links: ", dls) | ||
if dls is None or len(dls) == 0 or (not any( | ||
x['label'] == 'GTN Matrix' for x in response.json()['data']['attributes']['discussion_links'] | ||
)): | ||
push = True | ||
permissions_update['data']['attributes']['discussion_links'] = [ | ||
{ | ||
"label": "GTN Matrix", | ||
"url": "https://matrix.to/#/%23galaxyproject_admin:gitter.im" # Must encode the second # | ||
} | ||
] | ||
|
||
|
||
print(permissions_update) | ||
headers.update({ | ||
'Content-type': 'application/json', | ||
'Accept': 'application/json', | ||
}) | ||
response2 = requests.put(f"{WORKFLOWHUB}/workflows/{wfid}", headers=headers, json=permissions_update) | ||
if response2.status_code != 200: | ||
print(f"Error {response2.status_code} updating permissions for {wfid}: {response2.text}") | ||
|
||
|
||
# https://github.com/seek4science/seek/issues/1957 | ||
if push: | ||
print(f"Permissions update required for {wfid}: {permissions_update['data']['attributes']}") | ||
headers.update({ | ||
'Content-type': 'application/json', | ||
'Accept': 'application/json', | ||
}) | ||
response2 = requests.put(f"{WORKFLOWHUB}/workflows/{wfid}", headers=headers, json=permissions_update) | ||
if response2.status_code != 200: | ||
print(f"Error {response2.status_code} updating permissions for {wfid}: {response2.text}") | ||
|
||
p = crate_path.split("/") | ||
windex = p.index("workflows") | ||
(topic, tutorial, workflow) = p[windex + 1:windex + 4] | ||
|