rest: add/remove pis to/from authority
authorLoic Baron <loic.baron@lip6.fr>
Wed, 22 Apr 2015 17:30:04 +0000 (19:30 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Wed, 22 Apr 2015 17:30:04 +0000 (19:30 +0200)
myslice/urls.py
rest/authority.py [new file with mode: 0644]

index e2b85cc..236e5ca 100644 (file)
@@ -88,6 +88,7 @@ urls = [
     (r'^credentials/(?P<action>[^/]+)/?$', 'rest.credentials.dispatch'),
     (r'^cache/(?P<action>[^/]+)/?$', 'rest.cache.dispatch'),
     (r'^initscript/(?P<action>[^/]+)/?$', 'rest.initscript.dispatch'),
+    (r'^authority/(?P<action>[^/]+)/?$', 'rest.authority.dispatch'),
     #
     # REST monitoring
     (r'^monitor/services/?$', 'rest.monitor.servicesStatus'),
diff --git a/rest/authority.py b/rest/authority.py
new file mode 100644 (file)
index 0000000..8f3c31d
--- /dev/null
@@ -0,0 +1,29 @@
+from django.http                    import HttpResponse
+from portal.actions                 import authority_add_pis, authority_remove_pis
+import json
+
+def dispatch(request, action):
+    
+    try:
+        if request.method == 'POST':
+            req_items = request.POST
+        elif request.method == 'GET':
+            req_items = request.GET
+
+        if 'user_hrn' in req_items:
+            user_hrn = str(req_items['user_hrn'])
+        if 'authority_hrn' in req_items:
+            authority_hrn = str(req_items['authority_hrn'])
+
+        if (action == 'add') :
+            new_pis = authority_add_pis(request, authority_hrn, user_hrn)
+            result = {'ret':1}
+        elif (action == 'remove'):
+            new_pis = authority_remove_pis(request, authority_hrn, user_hrn)
+            result = {'ret':1}
+        else:
+            raise Exception, "action not supported"
+    except Exception as e:
+        result = {'ret': -1, 'msg':'error: %s' % e}
+    return HttpResponse(json.dumps(result), content_type="application/json")
+