diff options
author | BonfaceKilz | 2021-10-19 16:46:09 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-10-25 14:00:14 +0300 |
commit | 666c0df4c6536b831a2c08ea61c87de8f37a696d (patch) | |
tree | 76c28fd58cea3f8e109632b2cd93167be80163f1 /wqflask | |
parent | 6fed3eec407f9457260fb586067d76a35318445c (diff) | |
download | genenetwork2-666c0df4c6536b831a2c08ea61c87de8f37a696d.tar.gz |
Add `POST resource-management/resources/<resource-id>/make-public`
This endpoint either makes resources public or non-public by tweaking
the access-masks.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/resource_manager.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/wqflask/wqflask/resource_manager.py b/wqflask/wqflask/resource_manager.py index 94c351a4..fe25902e 100644 --- a/wqflask/wqflask/resource_manager.py +++ b/wqflask/wqflask/resource_manager.py @@ -6,9 +6,13 @@ from flask import Blueprint from flask import current_app from flask import g from flask import render_template +from flask import redirect +from flask import request +from flask import url_for from typing import Dict +from wqflask.decorators import edit_access_required from wqflask.decorators import login_required from wqflask.access_roles import AdminRole from wqflask.access_roles import DataRole @@ -164,3 +168,33 @@ def view_resource(resource_id: str): resource_info=embellished_resource, user_id=user_id), DataRole=DataRole, AdminRole=AdminRole) + + +@resource_management.route("/resources/<resource_id>/make-public", + methods=('POST',)) +@edit_access_required +@login_required +def update_resource_publicity(resource_id: str): + redis_conn = redis.from_url( + current_app.config["REDIS_URL"], + decode_responses=True) + resource_info = json.loads(redis_conn.hget("resources", resource_id)) + + if (is_open_to_public := request + .form + .to_dict() + .get("open_to_public")) == "True": + resource_info['default_mask'] = { + 'data': DataRole.VIEW.value, + 'admin': AdminRole.NOT_ADMIN.value, + 'metadata': DataRole.VIEW.value, + } + elif is_open_to_public == "False": + resource_info['default_mask'] = { + 'data': DataRole.NO_ACCESS.value, + 'admin': AdminRole.NOT_ADMIN.value, + 'metadata': DataRole.NO_ACCESS.value, + } + redis_conn.hset("resources", resource_id, json.dumps(resource_info)) + return redirect(url_for("resource_management.view_resource", + resource_id=resource_id)) |