diff --git a/docs/integration.org b/docs/integration.org index 0c17bd9..f94abc7 100644 --- a/docs/integration.org +++ b/docs/integration.org @@ -1,7 +1,5 @@ * Integration guide/process -[2020-05-19 Tue] - Here I'll be documenting the process of replacing the SQL queries in GN2's show_trait.py, including creating the proxy resource types, and populating Redis with resource entries. @@ -222,9 +220,6 @@ with name "resource1" at Redis ID 0: "17465") #+end_src -Additionally, users and groups have to exist in Redis. We can -use the GN2 users already in Redis from GN2, but for completeness' -sake: ** Using the API diff --git a/example.py b/example.py new file mode 100644 index 0000000..dcf2cd5 --- /dev/null +++ b/example.py @@ -0,0 +1,36 @@ +import requests + + +# Querying which actions are available on resource 0 to user with ID 0 +r_available = requests.get('http://localhost:8080/available/?resource=0&user=0') + +# The result is a JSON object with a key for each action branch, and +# each branch consisting of an array of strings, each element being +# an action name available to that user + +print(r_available.json()) +# Assuming this is the same resource as added in ** Populating Redis in +# docs/integration.org, the result would be: + +# >>> print(ra.json()) +# {u'data': [u'no-access', u'view']} + +# To perform an action, we use the /run-action endpoint, which takes +# a branch name and action name in addition to the resource and user. + +# The result of the /available query tells us exactly which branches and +# actions we can perform +r_view = requests.get('http://localhost:8080/run-action/?resource=0&user=0&branch=data&action=view') + +# In this case, the output of the 'view' action is a JSON array representation of the SQL output +print(r_view.json()) + +# Thus, each of the fields can be accessed as in any other array; for example +# we can retrieve the Phenotype.Pre_publication_description field: +print(r_view.json()[3]) + + +r_na = requests.get('http://localhost:8080/run-action/?resource=0&user=0&branch=data&action=no-access') + +# If the user doesn't have access, the string "no-action" is returned, +# as the no-access-action is used by default diff --git a/server/resource.rkt b/server/resource.rkt index 77674f0..1d96467 100644 --- a/server/resource.rkt +++ b/server/resource.rkt @@ -151,8 +151,12 @@ user-id)) (action-set (apply-mask (dict-ref resource-types (resource-type res)) mask))) + (let ((action (assoc action-id (hash-ref action-set branch-id)))) + (if action + (cdr action) + no-access-action)))) - (cdr (assoc action-id (hash-ref action-set branch-id))))) + ;; (cdr (assoc action-id (hash-ref action-set branch-id))))) ;; The general "no access" action -- may change in the future (define no-access-action