From: lombardofr Date: Wed, 3 Oct 2018 09:52:15 +0000 (+0200) Subject: user upadate: add/revoke project access X-Git-Tag: v5.0.0~26 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F6609%2F1;p=osm%2FLW-UI.git user upadate: add/revoke project access Change-Id: I81565801160e91fc10bb68ce92431bdab9383477 --- diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index ad7072e..414019e 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -117,14 +117,15 @@ class Client(object): _url = "{0}/admin/v1/users/{1}".format(self._base_path, id) try: - r = requests.post(_url, json=user_data, verify=False, headers=headers) + r = requests.patch(_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: + if r.status_code == requests.codes.no_content: result['error'] = False - result['data'] = Util.json_loads_byteified(r.text) + else: + result['data'] = Util.json_loads_byteified(r.text) return result def user_delete(self, token, id): diff --git a/static/src/userhandler/user_list.js b/static/src/userhandler/user_list.js index 0c53b9e..afa1ae3 100644 --- a/static/src/userhandler/user_list.js +++ b/static/src/userhandler/user_list.js @@ -26,59 +26,36 @@ function openModalCreateUser(args) { } function openModalEditUser(args) { - var url = '/admin/users/'+args.user_id; - console.log(url) + var url = '/admin/users/' + args.user_id; + var user_projects = args.projects ? args.projects.split(',') : []; $("#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']}) - } - } + $("#projects_old").val(user_projects.toString()); + $('#projects_edit').val(null).trigger('change'); + $('#default_project_edit').val(null).trigger('change'); - return { - results: projects - }; - } + if (user_projects.length > 0) { + // Create a DOM Option and pre-select by default + var newOption = new Option(user_projects[0], user_projects[0], true, true); + // Append it to the select + $('#default_project_edit').append(newOption).trigger('change'); + + for (var d in user_projects) { + var project = user_projects[d]; + // Create a DOM Option and pre-select by default + var newOption = new Option(project, project, true, true); + // Append it to the select + $('#projects_edit').append(newOption).trigger('change'); } - }); - 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) { + var delete_url = '/admin/users/' + user_id + '/delete'; + bootbox.confirm("Are you sure want to delete " + name + "?", function (confirm) { if (confirm) { var dialog = bootbox.dialog({ message: '
Loading...
', diff --git a/userhandler/templates/modal/user_edit.html b/userhandler/templates/modal/user_edit.html index d3c3d38..caeeb3a 100644 --- a/userhandler/templates/modal/user_edit.html +++ b/userhandler/templates/modal/user_edit.html @@ -10,14 +10,15 @@ class="form-horizontal" method="post" enctype="multipart/form-data"> {% csrf_token %} +