Bläddra i källkod

HUE-6312 [useradmin] Add error notifications on Hue 4 for sync ldap users/group modal

Enrico Berti 8 år sedan
förälder
incheckning
0a6f77f

+ 6 - 3
apps/useradmin/src/useradmin/templates/list_users.mako

@@ -220,11 +220,14 @@ ${layout.menubar(section='users')}
           $usersComponents.find('.sync-ldap form').ajaxForm({
             dataType:  'json',
             success: function(data) {
-              if (data && data.url){
+              if (data && data.status == -1) {
+                renderUseradminErrors(data.errors);
+              }
+              else if (data && data.url) {
                 huePubSub.publish('open.link', data.url);
+                $.jHueNotify.info("${ _('The users and groups were update correctly.') }")
+                $usersComponents.find(".sync-ldap").modal("hide");
               }
-              $.jHueNotify.info("${ _('The users and groups were update correctly.') }")
-              $usersComponents.find(".sync-ldap").modal("hide");
             }
           });
           % endif

+ 1 - 1
apps/useradmin/src/useradmin/templates/sync_ldap_users_groups.mako

@@ -53,6 +53,6 @@ from django.utils.translation import ugettext as _
   </div>
   <div class="modal-footer">
     <a href="#" class="btn" data-dismiss="modal">${_('Cancel')}</a>
-    <input type="submit" class="btn btn-primary" value="${_('Sync')}"/>
+    <input type="submit" class="btn btn-primary disable-feedback" value="${_('Sync')}"/>
   </div>
 </form>

+ 5 - 1
apps/useradmin/src/useradmin/views.py

@@ -718,7 +718,11 @@ def sync_ldap_users_groups(request):
   else:
     form = SyncLdapUsersGroupsForm()
 
-  return render("sync_ldap_users_groups.mako", request, dict(path=request.path, form=form, is_embeddable=is_embeddable))
+  if request.method == 'POST' and is_embeddable:
+    return JsonResponse(
+      {'status': -1, 'errors': [{'id': f.id_for_label, 'message': f.errors} for f in form if f.errors]})
+  else:
+    return render("sync_ldap_users_groups.mako", request, dict(path=request.path, form=form, is_embeddable=is_embeddable))
 
 
 def sync_ldap_users_and_groups(connection, is_ensuring_home_directory=False, fs=None, failed_users=None):