user edit - change password 94/6694/1
authorlombardofr <lombardo@everyup.it>
Mon, 15 Oct 2018 12:35:59 +0000 (14:35 +0200)
committerlombardofr <lombardo@everyup.it>
Mon, 15 Oct 2018 12:35:59 +0000 (14:35 +0200)
Change-Id: Iab1efe49f69200dd262fff2b07468d2dcc0ebe66
Signed-off-by: lombardofr <lombardo@everyup.it>
static/src/userhandler/user_list.js
userhandler/templates/modal/user_edit.html
userhandler/urls.py
userhandler/views.py

index afa1ae3..b485e5b 100644 (file)
@@ -32,7 +32,7 @@ function openModalEditUser(args) {
     $("#projects_old").val(user_projects.toString());
     $('#projects_edit').val(null).trigger('change');
     $('#default_project_edit').val(null).trigger('change');
-
+    $('#edit_password').val('');
     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);
index caeeb3a..21dbe8a 100644 (file)
                                    placeholder="Username" required>
                         </div>
                     </div>{% endcomment %}
+                    <div class="form-group">
+                        <label for="password" class="col-sm-3 control-label">New Password</label>
+                        <div class="col-sm-6">
+                           <input class="form-control" id="edit_password" name="password" type="password"
+                                   placeholder="Password">
+                        </div>
+                    </div>
                     <div class="form-group">
                         <label for=projects" class="col-sm-3 control-label">Default project *</label>
                         <div class="col-sm-6">
index 2bd735b..6447d69 100644 (file)
@@ -20,7 +20,7 @@ from userhandler import views
 urlpatterns = [
     url(r'^list$', views.user_list, name='list'),
     url(r'^create$', views.create, name='create'),
-    url(r'^(?P<user_id>[0-9a-zA-Z]+)', views.update, name='update'),
-    url(r'^(?P<user_id>[0-9a-zA-Z]+)/delete$', views.delete, name='delete')
+    url(r'^(?P<user_id>[0-9a-zA-Z]+)/delete$', views.delete, name='delete'),
+    url(r'^(?P<user_id>[0-9a-zA-Z]+)', views.update, name='update')
 
-]
\ No newline at end of file
+]
index 3aa227a..a7c014d 100644 (file)
@@ -58,20 +58,31 @@ def update(request, user_id=None):
         projects_to_add = list(set(projects_new) - set(projects_old))
         projects_to_remove = list(set(projects_old) - set(projects_new))
 
-        payload = {}
+        project_payload = {}
 
         for p in projects_to_remove:
-            payload["$"+str(p)] = None
+            project_payload["$"+str(p)] = None
         for p in projects_to_add:
             if p not in projects_old:
-                payload["$+"+str(p)] = str(p)
-        payload["$" + default_project] = None
-        payload["$+[0]"] = default_project
+                project_payload["$+"+str(p)] = str(p)
+        project_payload["$" + default_project] = None
+        project_payload["$+[0]"] = default_project
+        payload = {}
+        if project_payload:
+            payload["projects"] = project_payload
+        if request.POST.get('password') and request.POST.get('password') is not '':
+            payload["password"] = request.POST.get('password')
 
-        update_res = client.user_update(user.get_token(), user_id, {"projects": payload})
+        update_res = client.user_update(user.get_token(), user_id, payload)
     except Exception as e:
         log.exception(e)
-    return __response_handler(request, {}, 'users:list', to_redirect=True, )
+        update_res = {'error': True, 'data': str(e)}
+    if update_res['error']:
+        return __response_handler(request, update_res['data'], url=None,
+                                  status=update_res['data']['status'] if 'status' in update_res['data'] else 500)
+    else:
+        return __response_handler(request, {}, url=None, status=200)
+        #return __response_handler(request, {}, 'users:list', to_redirect=True, )
 
 
 def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):