diff --git a/seahub/templates/sysadmin/sys_useradmin.html b/seahub/templates/sysadmin/sys_useradmin.html index 393f2a806c..220d22920e 100644 --- a/seahub/templates/sysadmin/sys_useradmin.html +++ b/seahub/templates/sysadmin/sys_useradmin.html @@ -24,20 +24,35 @@ -
{% csrf_token %} -

{% trans "Add user" %}

-
-
-
-
-
-
+{% csrf_token %} +

{% trans "Add user" %}

+
+
+
+
+
+
+

+ +
+
{% csrf_token %} +

{% trans "Add admins"%}

+
+ +
+
+

{% trans "Tip: the emails should be the users already added."%}

+
+
+

- - + +
+ {% include "sysadmin/useradmin_table.html"%} - {% include "sysadmin/useradmin_add_form.html" %}

{% trans "Activating..., please wait" %}

@@ -45,7 +60,7 @@
{% endblock %} -{% block extra_script %}{{block.super}} +{% block extra_script %} {% endblock %} diff --git a/seahub/templates/sysadmin/useradmin_add_form.html b/seahub/templates/sysadmin/useradmin_add_form.html deleted file mode 100644 index c7b1f1e63c..0000000000 --- a/seahub/templates/sysadmin/useradmin_add_form.html +++ /dev/null @@ -1,43 +0,0 @@ -{% load i18n avatar_tags %} -
{% csrf_token %} -

{% trans "Add admins"%}

-
- -
-
- {% if cloud_mode and not org %} -

{% trans "Tip: an invitation will be sent if the email is not registered."%}

- {% else %} -

{% trans "Tip: the emails should be the users already added."%}

- {% endif %} -
- {%comment%} -
-
    - {% for user in users %} - {% if not user.is_self %} - {% if not user.is_staff %} -
  • - -
  • - {% endif %} - {% endif %} - {% endfor %} -
-
- {%endcomment%} -
-
-

- -
-
- diff --git a/seahub/templates/sysadmin/useradmin_add_js.html b/seahub/templates/sysadmin/useradmin_add_js.html deleted file mode 100644 index e1ef1a5bf5..0000000000 --- a/seahub/templates/sysadmin/useradmin_add_js.html +++ /dev/null @@ -1,66 +0,0 @@ -{% load i18n %} - -var user_list = [], user_email; -{% for user in users %} -{% if not user.is_self %} -{% if not user.is_staff %} -user_email = '{{ user.email }}'; -user_list.push({value:user_email, label:user_email}); -{% endif %} -{% endif %} -{% endfor %} - -$('#add-admin-btn').click(function() { - var form = $("#add-admin-form"); - form.modal({appendTo: "#main", focus:false}); - $('#simplemodal-container').css({'height':'auto', 'padding':0}); - $('#add-admin-tabs').tabs(); - - addAutocomplete('#added-member-name', '#enter', user_list); -}); - -$('#add-admin-form').submit(function() { - var form = $(this), - cur_tab_id = $('.ui-tabs-selected a', form).attr('href'), - post_data = '', - input = $('[name="user_email"]', form); - switch(cur_tab_id) { - case '#enter': - post_data = input.val(); - break; - case '#user-options': - $(cur_tab_id + ' .checkbox-checked .checkbox-orig').each(function() { - post_data += $(this).val() + ','; - }); - input.val(post_data); - } - if (!post_data) { - apply_form_error(form.attr('id'), '{% trans "Please enter emails, or select some." %}'); - return false; - } - - var submit_btn = $('[type="submit"]', form); - disable(submit_btn); - $.ajax({ - url: '{% url 'batch_user_make_admin' %}', - type: 'POST', - dataType: 'json', - cache: false, - beforeSend: prepareCSRFToken, - data: { - 'set_admin_emails': post_data - }, - success: function(data) { - location.reload('true'); - }, - error: function(data, textStatus, jqXHR) { - var errors = $.parseJSON(data.responseText); - $.each(errors, function(index, value) { - apply_form_error(form.attr('id'), value); - }); - enable(submit_btn); - } - }); - - return false; -}); diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index fa26f53ee3..a796deb285 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -718,17 +718,23 @@ def batch_user_make_admin(request): set_admin_emails = request.POST.get('set_admin_emails') set_admin_emails = string2list(set_admin_emails) - try: - for email in set_admin_emails: - print email + success = [] + failed = [] + + for email in set_admin_emails: + try: user = User.objects.get(email=email) user.is_staff = True user.save() - result['success'] = True - messages.success(request, _(u'Successfully patch set admin')) - return HttpResponse(json.dumps(result), content_type=content_type) - except Exception, e: - result['success'] = False - messages.error(request, _(e)) - return HttpResponse(json.dumps(result), status=500, content_type=content_type) + success.append(email) + except User.DoesNotExist: + failed.append(email) + + for item in success: + messages.success(request, _(u'Successfully set %s as admin') % item) + for item in failed: + messages.error(request, _(u'Failed set %s as admin') % item) + + result['success'] = True + return HttpResponse(json.dumps(result), content_type=content_type)