aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2020-07-22 17:46:37 -0500
committerzsloan2020-07-22 17:46:37 -0500
commit81c35e99a7ff808bf2fcf1f5e19631adf07d42e8 (patch)
tree0efcd9fb846a9301a6ad073c5ab7b1f717e2909f /wqflask
parent1775b713478bff182e0047dd5f92b751d7e68a20 (diff)
downloadgenenetwork2-81c35e99a7ff808bf2fcf1f5e19631adf07d42e8.tar.gz
It should add new resources to Redis automatically now
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/utility/authentication_tools.py61
-rw-r--r--wqflask/utility/redis_tools.py5
2 files changed, 47 insertions, 19 deletions
diff --git a/wqflask/utility/authentication_tools.py b/wqflask/utility/authentication_tools.py
index f9028f32..ed7462d1 100644
--- a/wqflask/utility/authentication_tools.py
+++ b/wqflask/utility/authentication_tools.py
@@ -6,7 +6,7 @@ import requests
from base import data_set, webqtlConfig
from utility import hmac
-from utility.redis_tools import get_redis_conn, get_resource_info, get_resource_id
+from utility.redis_tools import get_redis_conn, get_resource_info, get_resource_id, add_resource
Redis = get_redis_conn()
from flask import Flask, g, redirect, url_for
@@ -16,13 +16,7 @@ logger = logging.getLogger(__name__ )
def check_resource_availability(dataset, trait_id=None):
- #ZS: Check if super-user - we should probably come up with some way to integrate this into the proxy
- if g.user_session.user_id in Redis.smembers("super_users"):
- return webqtlConfig.SUPER_PRIVILEGES
-
- response = None
-
- #At least for now assume temporary entered traits are accessible#At least for now assume temporary entered traits are accessible
+ #At least for now assume temporary entered traits are accessible
if type(dataset) == str:
return webqtlConfig.DEFAULT_PRIVILEGES
if dataset.type == "Temp":
@@ -33,9 +27,13 @@ def check_resource_availability(dataset, trait_id=None):
if resource_id:
resource_info = get_resource_info(resource_id)
if not resource_info:
- return webqtlConfig.DEFAULT_PRIVILEGES
- else:
- return response #ZS: Need to substitute in something that creates the resource in Redis later
+ resource_info = add_new_resource(dataset, trait_id)
+
+ #ZS: Check if super-user - we should probably come up with some way to integrate this into the proxy
+ if g.user_session.user_id in Redis.smembers("super_users"):
+ return webqtlConfig.SUPER_PRIVILEGES
+
+ response = None
the_url = "http://localhost:8080/available?resource={}&user={}".format(resource_id, g.user_session.user_id)
try:
@@ -43,10 +41,43 @@ def check_resource_availability(dataset, trait_id=None):
except:
response = resource_info['default_mask']
- if response:
- return response
- else: #ZS: No idea how this would happen, but just in case
- return False
+ return response
+
+def add_new_resource(dataset, trait_id=None):
+ resource_ob = {
+ 'owner_id' : webqtlConfig.DEFAULT_OWNER_ID,
+ 'default_mask': webqtlConfig.DEFAULT_PRIVILEGES,
+ 'group_masks' : {}
+ }
+
+ if dataset.type == "Publish":
+ resource_ob['name'] = get_group_code(dataset) + "_" + str(trait_id)
+ resource_ob['data'] = {
+ 'dataset': dataset.id,
+ 'trait' : trait_id
+ }
+ resource_ob['type'] = 'dataset-publish'
+ elif dataset.type == "Geno":
+ resource_ob['name'] = dataset.name
+ resource_ob['data'] = {
+ 'dataset': dataset.id
+ }
+ resource_ob['type'] = 'dataset-geno'
+ else:
+ resource_ob['name'] = dataset.name
+ resource_ob['data'] = {
+ 'dataset': dataset.id
+ }
+ resource_ob['type'] = 'dataset-probeset'
+
+ resource_info = add_resource(resource_ob, update=False)
+
+ return resource_info
+
+def get_group_code(dataset):
+ results = g.db.execute("SELECT InbredSetCode from InbredSet where Name='{}'".format(dataset.group.name)).fetchone()
+
+ return results[0]
def check_admin(resource_id=None):
the_url = "http://localhost:8080/available?resource={}&user={}".format(resource_id, g.user_session.user_id)
diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py
index 6c912a23..1377a564 100644
--- a/wqflask/utility/redis_tools.py
+++ b/wqflask/utility/redis_tools.py
@@ -264,17 +264,14 @@ def get_resources():
return resource_list
def get_resource_id(dataset, trait_id=None):
+ resource_id = False
if dataset.type == "Publish":
if trait_id:
resource_id = hmac.hmac_creation("{}:{}:{}".format('dataset-publish', dataset.id, trait_id))
- else:
- return False
elif dataset.type == "ProbeSet":
resource_id = hmac.hmac_creation("{}:{}".format('dataset-probeset', dataset.id))
elif dataset.type == "Geno":
resource_id = hmac.hmac_creation("{}:{}".format('dataset-geno', dataset.id))
- else:
- return False
return resource_id