From 418b04968b4b452f1ac0fba0beaeabdec713c6fb Mon Sep 17 00:00:00 2001 From: Yasin Date: Tue, 26 Aug 2014 16:18:19 +0200 Subject: [PATCH] requests: reject button added & functional (todo: send email) --- portal/actions.py | 38 +++++++++++++++++- portal/templates/management-tab-requests.html | 40 +++++++++++++++++++ portal/urls.py | 2 +- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/portal/actions.py b/portal/actions.py index 38af28c9..03f1c3a2 100644 --- a/portal/actions.py +++ b/portal/actions.py @@ -383,13 +383,49 @@ def portal_validate_request(wsgi_request, request_ids): return status - def validate_action(request, **kwargs): ids = filter(None, kwargs['id'].split('/')) status = portal_validate_request(request, ids) json_answer = json.dumps(status) return HttpResponse (json_answer, mimetype="application/json") + +def reject_action(request, **kwargs): + ids = filter(None, kwargs['id'].split('/')) + status = portal_reject_request(request, ids) + json_answer = json.dumps(status) + return HttpResponse (json_answer, mimetype="application/json") + + +def portal_reject_request(wsgi_request, request_ids): + status = {} + + if not isinstance(request_ids, list): + request_ids = [request_ids] + + requests = get_request_by_id(request_ids) + for request in requests: + # type, id, timestamp, details, allowed -- MISSING: authority_hrn + # CAREFUL about details + # user : first name, last name, email, password, keypair + # slice : number of nodes, type of nodes, purpose + + request_status = {} + + if request['type'] == 'user': + request_status['SFA user'] = {'status': True } + PendingUser.objects.get(id=request['id']).delete() + elif request['type'] == 'slice': + request_status['SFA slice'] = {'status': True } + PendingSlice.objects.get(id=request['id']).delete() + elif request['type'] == 'authority': + request_status['SFA authority'] = {'status': True } + PendingAuthority.objects.get(id=request['id']).delete() + + status['%s__%s' % (request['type'], request['id'])] = request_status + + return status + # Django and ajax # http://djangosnippets.org/snippets/942/ diff --git a/portal/templates/management-tab-requests.html b/portal/templates/management-tab-requests.html index 2270a3b9..d36027be 100644 --- a/portal/templates/management-tab-requests.html +++ b/portal/templates/management-tab-requests.html @@ -36,6 +36,45 @@ $('#portal__status__' + request_type__id).html(status_str); + }); + } + ); + } + } + function on_click_reject() { + var ids = []; + $('.portal__validate__checkbox').each(function(i, el) { + if ($(el).prop('checked')) { + // portal__validate__checkbox__slice__2 + var id_array = $(el).attr('id').split('__'); + // push(slice__2) + ids.push(id_array[3] + '__' + id_array[4]); + } + }); + if (ids.length > 0) { + var id_str = ids.join('/'); + + // XXX spinner + + $.getJSON('/portal/reject_action/' + id_str, + function(status) { + $.each(status, function(request_type__id, request_status) { + // request_status: NAME -> dict (status, description) + var status_str = ''; + $.each(request_status, function(name, result) { + if (status_str != '') + status_str += ' -- '; + + if (result.status) { + status_str += 'OK'; + $('#portal__validate__checkbox__' + request_type__id).hide(); + } else { + status_str += 'ERROR: ' + result.description + ''; + } + }); + $('#portal__status__' + request_type__id).html(status_str); + + }); } ); @@ -226,4 +265,5 @@
+
diff --git a/portal/urls.py b/portal/urls.py index e6e63e69..8bcdaf24 100644 --- a/portal/urls.py +++ b/portal/urls.py @@ -99,7 +99,7 @@ urlpatterns = patterns('', # http://stackoverflow.com/questions/2360179/django-urls-how-to-pass-a-list-of-items-via-clean-urls # (r'^validate_action/(?P[^/]+)/(?P\w+)/?$', 'portal.views.pres_view_static'), url(r'^validate_action(?P(?:/\w+)+)/?$', 'portal.actions.validate_action'), - + url(r'^reject_action(?P(?:/\w+)+)/?$', 'portal.actions.reject_action'), url(r'^pres_view/?$', PresViewView.as_view(), name='pres_view'), (r'^methods/(?P\w+)/?$', 'portal.views.pres_view_methods'), (r'^animation/(?P[^/]+)/(?P\w+)/?$', 'portal.views.pres_view_animation'), -- 2.43.0