From 666c0df4c6536b831a2c08ea61c87de8f37a696d Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 19 Oct 2021 16:46:09 +0300 Subject: Add `POST resource-management/resources//make-public` This endpoint either makes resources public or non-public by tweaking the access-masks. --- wqflask/wqflask/resource_manager.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'wqflask') 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//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)) -- cgit v1.2.3