AiC and REST login
[myslice.git] / rest / authority.py
1 from django.http                    import HttpResponse
2 from portal.actions                 import authority_add_pis, authority_remove_pis
3 import json
4
5 def dispatch(request, action):
6     
7     try:
8         if request.method == 'POST':
9             req_items = request.POST
10         elif request.method == 'GET':
11             req_items = request.GET
12
13         if 'user_hrn' in req_items:
14             user_hrn = str(req_items['user_hrn'])
15         if 'authority_hrn' in req_items:
16             authority_hrn = str(req_items['authority_hrn'])
17
18         if (action == 'add') :
19             new_pis = authority_add_pis(request, authority_hrn, user_hrn)
20             result = {'ret':1}
21         elif (action == 'remove'):
22             new_pis = authority_remove_pis(request, authority_hrn, user_hrn)
23             result = {'ret':1}
24         else:
25             raise Exception, "action not supported"
26     except Exception as e:
27         result = {'ret': -1, 'msg':'error: %s' % e}
28     return HttpResponse(json.dumps(result), content_type="application/json")
29