aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-18 11:54:37 +0300
committerBonfaceKilz2021-10-25 14:00:14 +0300
commitff2813b8c0522d780ffc8bc44692a749de9f45e6 (patch)
treeca0d082393d68b5391599738c3a710792e2eb5f5 /wqflask
parent8eedaab544d5bd1ab667bdd88d055b671bbee1d0 (diff)
downloadgenenetwork2-ff2813b8c0522d780ffc8bc44692a749de9f45e6.tar.gz
Add "GET /resource-management/resources/<resource_id>"
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/__init__.py5
-rw-r--r--wqflask/wqflask/resource_manager.py36
2 files changed, 40 insertions, 1 deletions
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py
index 5758b13e..5b2d05d1 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -8,6 +8,9 @@ from flask import Flask
from typing import Tuple
from urllib.parse import urlparse
from utility import formatting
+
+from wqflask.resource_manager import resource_management
+
from wqflask.api.markdown import glossary_blueprint
from wqflask.api.markdown import references_blueprint
from wqflask.api.markdown import links_blueprint
@@ -55,6 +58,8 @@ app.register_blueprint(facilities_blueprint, url_prefix="/facilities")
app.register_blueprint(blogs_blueprint, url_prefix="/blogs")
app.register_blueprint(news_blueprint, url_prefix="/news")
+app.register_blueprint(resource_management, url_prefix="/resource-management")
+
@app.before_request
def before_request():
diff --git a/wqflask/wqflask/resource_manager.py b/wqflask/wqflask/resource_manager.py
index 16bab250..9665ebb0 100644
--- a/wqflask/wqflask/resource_manager.py
+++ b/wqflask/wqflask/resource_manager.py
@@ -4,10 +4,15 @@ import functools
from enum import Enum, unique
-
+from flask import Blueprint
+from flask import current_app
+from flask import g
+from flask import render_template
from typing import Dict
+from wqflask.decorators import login_required
+
@functools.total_ordering
class OrderedEnum(Enum):
@@ -36,6 +41,10 @@ class AdminRole(OrderedEnum):
EDIT_ACCESS = "edit-access"
EDIT_ADMINS = "edit-admins"
+
+resource_management = Blueprint('resource_management', __name__)
+
+
def get_user_membership(conn: redis.Redis, user_id: str,
group_id: str) -> Dict:
"""Return a dictionary that indicates whether the `user_id` is a
@@ -152,3 +161,28 @@ unique identifiers so they aren't human readable names.
json.loads(conn.hget("groups", group_id)).get('name'))
return resource
+
+@resource_management.route("/resources/<resource_id>")
+@login_required
+def manage_resource(resource_id: str):
+ user_id = (g.user_session.record.get(b"user_id",
+ b"").decode("utf-8") or
+ g.user_session.record.get("user_id", ""))
+ redis_conn = redis.from_url(
+ current_app.config["REDIS_URL"],
+ decode_responses=True)
+
+ # Abort early if the resource can't be found
+ if not (resource := redis_conn.hget("resources", resource_id)):
+ return f"Resource: {resource_id} Not Found!", 401
+
+ return render_template(
+ "admin/manage_resource.html",
+ resource_info=(embellished_resource:=add_extra_resource_metadata(
+ conn=redis_conn,
+ resource=json.loads(resource))),
+ access_role=get_user_access_roles(
+ conn=redis_conn,
+ resource_info=embellished_resource,
+ user_id=user_id),
+ DataRole=DataRole, AdminRole=AdminRole)