From 88d09568efc69901d4e12f62021239096f8d69f8 Mon Sep 17 00:00:00 2001 From: lombardofr Date: Tue, 11 Sep 2018 18:14:39 +0200 Subject: [PATCH] [WIP] user editing Change-Id: I0cb42614bb750d95bd03376924cf8c85d60cb2b7 --- lib/osm/osmclient/clientv2.py | 19 +++ static/src/userhandler/user_list.js | 54 +++++- userhandler/templates/modal/user_create.html | 2 +- userhandler/templates/modal/user_edit.html | 17 +- userhandler/templates/user_list.html | 169 +++++++++++-------- userhandler/urls.py | 3 +- userhandler/views.py | 16 ++ 7 files changed, 200 insertions(+), 80 deletions(-) diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 482ff07..fa4117e 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -107,6 +107,25 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def user_update(self, token, id, user_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/users/{1}".format(self._base_path, id) + print _url + print user_data + try: + r = requests.post(_url, json=user_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code == requests.codes.created: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def user_delete(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", diff --git a/static/src/userhandler/user_list.js b/static/src/userhandler/user_list.js index 88f4770..0c53b9e 100644 --- a/static/src/userhandler/user_list.js +++ b/static/src/userhandler/user_list.js @@ -1,6 +1,5 @@ function openModalCreateUser(args) { - console.log(args) - // load projects list + select2_groups = $('#projects').select2({ placeholder: 'Select Projects', width: '100%', @@ -26,6 +25,57 @@ function openModalCreateUser(args) { $('#modal_new_user').modal('show'); } +function openModalEditUser(args) { + var url = '/admin/users/'+args.user_id; + console.log(url) + $("#formEditUser").attr("action", url); + select2_groups = $('#projects_edit').select2({ + placeholder: 'Select Projects', + width: '100%', + ajax: { + url: '/projects/list', + dataType: 'json', + processResults: function (data) { + projects = []; + if (data['projects']) { + for (d in data['projects']) { + var project = data['projects'][d]; + projects.push({id: project['_id'], text: project['name']}) + } + } + + return { + results: projects + }; + } + } + }); + + select2_single = $('#default_project_edit').select2({ + placeholder: 'Select Default Project', + width: '100%', + ajax: { + url: '/projects/list', + dataType: 'json', + processResults: function (data) { + projects = []; + if (data['projects']) { + for (d in data['projects']) { + var project = data['projects'][d]; + projects.push({id: project['_id'], text: project['name']}) + } + } + + return { + results: projects + }; + } + } + }); + + $('#modal_edit_user').modal('show'); +} + function deleteUser(user_id, name) { var delete_url = '/admin/users/'+user_id+'/delete'; bootbox.confirm("Are you sure want to delete "+name+"?", function (confirm) { diff --git a/userhandler/templates/modal/user_create.html b/userhandler/templates/modal/user_create.html index 7967cc6..21afce0 100644 --- a/userhandler/templates/modal/user_create.html +++ b/userhandler/templates/modal/user_create.html @@ -6,7 +6,7 @@ -
{% csrf_token %} diff --git a/userhandler/templates/modal/user_edit.html b/userhandler/templates/modal/user_edit.html index b278e22..d3c3d38 100644 --- a/userhandler/templates/modal/user_edit.html +++ b/userhandler/templates/modal/user_edit.html @@ -4,32 +4,31 @@ - {% csrf_token %}