mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +00:00
[system admin] users: added 'set quota / delete users in batch'
This commit is contained in:
@@ -135,7 +135,7 @@ function showConfirm(title, content, yesCallback) {
|
|||||||
|
|
||||||
$cont.html('<h3>' + title + '</h3><p>' + content + '</p>');
|
$cont.html('<h3>' + title + '</h3><p>' + content + '</p>');
|
||||||
$popup.modal({appendTo: '#main'});
|
$popup.modal({appendTo: '#main'});
|
||||||
$('#simplemodal-container').css({'height':'auto'});
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
|
|
||||||
$yesBtn.click(yesCallback);
|
$yesBtn.click(yesCallback);
|
||||||
}
|
}
|
||||||
|
@@ -18,21 +18,30 @@
|
|||||||
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_ldap_imported' %}">{% trans "LDAP(imported)" %}</a></li>
|
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_ldap_imported' %}">{% trans "LDAP(imported)" %}</a></li>
|
||||||
<li class="tabnav-tab"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
<li class="tabnav-tab"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<a class="sf-btn-link btn-white js-export-excel fright" href="{% url "sys_useradmin_export_excel" %}">{% trans "Export Excel" %}</a>
|
|
||||||
|
<div class="js-op-for-all fright">
|
||||||
|
<button id="export-excel">{% trans "Export Excel" %}</button>
|
||||||
|
</div>
|
||||||
|
<div class="js-op-for-selected fright hide">
|
||||||
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if users %}
|
{% if users %}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="36%">{% trans "Email" %}</th>
|
<th width="3%"><input type="checkbox" /></th>
|
||||||
|
<th width="33%">{% trans "Email" %}</th>
|
||||||
<th width="12%">{% trans "Status" %}</th>
|
<th width="12%">{% trans "Status" %}</th>
|
||||||
<th width="18%">{% trans "Space Used / Quota" %}</th>
|
<th width="18%">{% trans "Space Used / Quota" %}</th>
|
||||||
<th width="18%">{% trans "Last Login" %}</th>
|
<th width="18%">{% trans "Last Login" %}</th>
|
||||||
<th width="16%">{% trans "Operations" %}</th>
|
<th width="16%"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<tr data-userid="{{user.email}}">
|
<tr data-userid="{{user.email}}">
|
||||||
|
<td><input type="checkbox" /></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
||||||
{% if user.name %}<br />{{ user.name }}{% endif %}
|
{% if user.name %}<br />{{ user.name }}{% endif %}
|
||||||
@@ -98,6 +107,9 @@
|
|||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
$("#export-excel").click(function() {
|
||||||
|
location.href = "{% url 'sys_useradmin_export_excel' %}";
|
||||||
|
});
|
||||||
{% include "sysadmin/useradmin_js.html" %}
|
{% include "sysadmin/useradmin_js.html" %}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -21,11 +21,16 @@
|
|||||||
<li class="tabnav-tab"><a href="{% url 'sys_useradmin' %}?filter=paid">Paid</a></li>
|
<li class="tabnav-tab"><a href="{% url 'sys_useradmin' %}?filter=paid">Paid</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="fright">
|
|
||||||
|
<div class="js-op-for-all fright">
|
||||||
<button id="import-users-btn">{% trans "Import users" %}</button>
|
<button id="import-users-btn">{% trans "Import users" %}</button>
|
||||||
<button id="add-user-btn">{% trans "Add user" %}</button>
|
<button id="add-user-btn">{% trans "Add user" %}</button>
|
||||||
<button id="export-excel">{% trans "Export Excel" %}</button>
|
<button id="export-excel">{% trans "Export Excel" %}</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="js-op-for-selected fright hide">
|
||||||
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
||||||
|
@@ -18,7 +18,14 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin_admins' %}">{% trans "Admins" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<button id="add-admin-btn" class="fright">{% trans "Add admin" %}</button>
|
|
||||||
|
<div class="js-op-for-all fright">
|
||||||
|
<button id="add-admin-btn">{% trans "Add admin" %}</button>
|
||||||
|
</div>
|
||||||
|
<div class="js-op-for-selected fright hide">
|
||||||
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="add-admin-form" method="post" name="add-admin-form" class="tab-popup hide">{% csrf_token %}
|
<form id="add-admin-form" method="post" name="add-admin-form" class="tab-popup hide">{% csrf_token %}
|
||||||
|
@@ -10,7 +10,13 @@
|
|||||||
<label>{% trans "Email" %}</label><input type="text" name="email" class="input" value="{{email}}" /><br />
|
<label>{% trans "Email" %}</label><input type="text" name="email" class="input" value="{{email}}" /><br />
|
||||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||||
</form>
|
</form>
|
||||||
<h3>{% trans "Result"%}</h3>
|
<div class="ovhd">
|
||||||
|
<h3 class="fleft">{% trans "Result"%}</h3>
|
||||||
|
<div class="js-op-for-selected fright hide">
|
||||||
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% if users %}
|
{% if users %}
|
||||||
{% include "sysadmin/useradmin_table.html"%}
|
{% include "sysadmin/useradmin_table.html"%}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@@ -81,12 +81,112 @@ $('.user-status-select, .user-role-select').change(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if user.source == "DB" or user.source == 'LDAPImport' %}
|
// for 'select'
|
||||||
|
var $opForAll = $('.js-op-for-all');
|
||||||
|
var $opForSelected = $('.js-op-for-selected');
|
||||||
|
$('th [type="checkbox"]').click(function() {
|
||||||
|
var all_checked = $(this).prop('checked');
|
||||||
|
if (all_checked) {
|
||||||
|
$('td [type="checkbox"]').prop('checked', true);
|
||||||
|
$opForAll.hide();
|
||||||
|
$opForSelected.show();
|
||||||
|
} else {
|
||||||
|
$('td [type="checkbox"]').prop('checked', false);
|
||||||
|
$opForAll.show();
|
||||||
|
$opForSelected.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('td [type="checkbox"]').click(function() {
|
||||||
|
if ($('td [type="checkbox"]:checked').length) {
|
||||||
|
$opForAll.hide();
|
||||||
|
$opForSelected.show();
|
||||||
|
} else {
|
||||||
|
$opForAll.show();
|
||||||
|
$opForSelected.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('td [type="checkbox"]:checked').length == $('td [type="checkbox"]').length) {
|
||||||
|
$('th [type="checkbox"]').prop('checked', true);
|
||||||
|
} else {
|
||||||
|
$('th [type="checkbox"]').prop('checked', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#set-quota-btn').click(function() {
|
||||||
|
$('#set-quota-form').data({'batch': true}).modal();
|
||||||
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#delete-users-btn').click(function() {
|
||||||
|
var title = "{% trans "Delete User" %}";
|
||||||
|
var content = "{% trans "Are you sure you want to delete the selected user(s) ?" %}";
|
||||||
|
var yesCallback = function() {
|
||||||
|
var emails = [];
|
||||||
|
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
||||||
|
var email = $(item).attr('data-userid');
|
||||||
|
if (email != "{{request.user.username|escapejs}}") {
|
||||||
|
emails.push(email);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$.ajax({
|
||||||
|
url: '{% url "api-v2.1-admin-users-batch" %}',
|
||||||
|
type: 'POST',
|
||||||
|
cache: false,
|
||||||
|
data: {
|
||||||
|
'operation': 'delete-user',
|
||||||
|
'email': emails
|
||||||
|
},
|
||||||
|
traditional: true,
|
||||||
|
dataType: 'json',
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
success: function(data) {
|
||||||
|
if (data.success.length) {
|
||||||
|
var emails = [];
|
||||||
|
$(data.success).each(function(index, item) {
|
||||||
|
$('tr[data-userid="' + item.email + '"]').remove();
|
||||||
|
emails.push(item.email);
|
||||||
|
});
|
||||||
|
var msg = "{% trans "Successfully deleted {users}." %}".replace('{users}', HTMLescape(emails.join(', ')));
|
||||||
|
feedback(msg, 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
// all selected items are deleted
|
||||||
|
if ($('td [type="checkbox"]:checked').length == 0) {
|
||||||
|
$opForAll.show();
|
||||||
|
$opForSelected.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.failed.length) {
|
||||||
|
var err_msg = '';
|
||||||
|
$(data.failed).each(function(index, item) {
|
||||||
|
err_msg += HTMLescape(item.email) + ': ' + item.error_msg + '<br />';
|
||||||
|
});
|
||||||
|
setTimeout(function() { feedback(err_msg, 'error'); }, 1500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
var err_msg;
|
||||||
|
if (xhr.responseText) {
|
||||||
|
err_msg = $.parseJSON(xhr.responseText).error_msg;
|
||||||
|
} else {
|
||||||
|
err_msg = "{% trans "Failed. Please check the network." %}";
|
||||||
|
}
|
||||||
|
feedback(err_msg, 'error');
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$.modal.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
showConfirm(title, content, yesCallback);
|
||||||
|
});
|
||||||
|
|
||||||
// edit quota
|
// edit quota
|
||||||
$('.quota-edit-icon').click(function() {
|
$('.quota-edit-icon').click(function() {
|
||||||
var email = $(this).closest('tr').attr('data-userid');
|
var email = $(this).closest('tr').attr('data-userid');
|
||||||
var $spaceQuota = $(this).prev('.user-space-quota');
|
var $spaceQuota = $(this).prev('.user-space-quota');
|
||||||
$('#set-quota-form').data({'email': email, '$spaceQuota': $spaceQuota}).modal();
|
$('#set-quota-form').data({'batch': false, 'email': email, '$spaceQuota': $spaceQuota}).modal();
|
||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -101,23 +201,72 @@ $('#set-quota-form').submit(function() {
|
|||||||
var $submitBtn = $('[type="submit"]', $(this));
|
var $submitBtn = $('[type="submit"]', $(this));
|
||||||
disable($submitBtn);
|
disable($submitBtn);
|
||||||
|
|
||||||
var email = $(this).data('email');
|
var batch = $(this).data('batch');
|
||||||
var $spaceQuota = $(this).data('$spaceQuota');
|
var options = {};
|
||||||
$.ajax({
|
if (batch) {
|
||||||
url: '{{ SITE_ROOT }}api2/accounts/' + encodeURIComponent(email) + '/',
|
var emails = [];
|
||||||
type: 'PUT',
|
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
||||||
|
emails.push($(item).attr('data-userid'));
|
||||||
|
});
|
||||||
|
options = {
|
||||||
|
url: '{% url "api-v2.1-admin-users-batch" %}',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
'operation': 'set-quota',
|
||||||
|
'email': emails,
|
||||||
|
'quota_total': space_quota
|
||||||
|
},
|
||||||
|
traditional: true,
|
||||||
|
success: function(data) {
|
||||||
|
if (data.success.length) {
|
||||||
|
var emails = [];
|
||||||
|
$(data.success).each(function(index, item) {
|
||||||
|
var $tr = $('tr[data-userid="' + item.email + '"]');
|
||||||
|
var $quota = $('.user-space-quota', $tr);
|
||||||
|
if (space_quota == 0) {
|
||||||
|
$quota.html('--');
|
||||||
|
} else {
|
||||||
|
$quota.html(quotaSizeFormat(parseInt(item.quota_total), 1));
|
||||||
|
}
|
||||||
|
emails.push(item.email);
|
||||||
|
});
|
||||||
|
var msg = "{% trans "Successfully set quota for {users}." %}".replace('{users}', HTMLescape(emails.join(', ')));
|
||||||
|
feedback(msg, 'success');
|
||||||
|
}
|
||||||
|
if (data.failed.length) {
|
||||||
|
var err_msg = '';
|
||||||
|
$(data.failed).each(function(index, item) {
|
||||||
|
err_msg += HTMLescape(item.email) + ': ' + item.error_msg + '<br />';
|
||||||
|
});
|
||||||
|
setTimeout(function() { feedback(err_msg, 'error'); }, 1500);
|
||||||
|
}
|
||||||
|
$.modal.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
var email = $(this).data('email');
|
||||||
|
var $spaceQuota = $(this).data('$spaceQuota');
|
||||||
|
options = {
|
||||||
|
url: '{{ SITE_ROOT }}api2/accounts/' + encodeURIComponent(email) + '/',
|
||||||
|
type: 'PUT',
|
||||||
|
data: {'storage': space_quota},
|
||||||
|
success: function(data) {
|
||||||
|
if (space_quota == 0) {
|
||||||
|
$spaceQuota.html('--');
|
||||||
|
} else {
|
||||||
|
$spaceQuota.html(quotaSizeFormat(parseInt(data['total']), 1));
|
||||||
|
}
|
||||||
|
var msg = "{% trans "Successfully set quota for {user}." %}".replace('{user}', HTMLescape(data.email));
|
||||||
|
feedback(msg, 'success');
|
||||||
|
$.modal.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax($.extend({
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: prepareCSRFToken,
|
beforeSend: prepareCSRFToken,
|
||||||
data: {'storage': space_quota},
|
|
||||||
success: function(data) {
|
|
||||||
if (space_quota == 0) {
|
|
||||||
$spaceQuota.html('--');
|
|
||||||
} else {
|
|
||||||
$spaceQuota.html(quotaSizeFormat(parseInt(data['total']), 1));
|
|
||||||
}
|
|
||||||
$.modal.close();
|
|
||||||
},
|
|
||||||
error: function(xhr, textStatus, errorThrown) {
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
var err_msg;
|
var err_msg;
|
||||||
if (xhr.responseText) {
|
if (xhr.responseText) {
|
||||||
@@ -128,11 +277,10 @@ $('#set-quota-form').submit(function() {
|
|||||||
$error.html(err_msg).show();
|
$error.html(err_msg).show();
|
||||||
enable($submitBtn);
|
enable($submitBtn);
|
||||||
}
|
}
|
||||||
});
|
}, options));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
// select shows, but the user doesn't select a value, or doesn't change the permission, click other place to hide the select
|
// select shows, but the user doesn't select a value, or doesn't change the permission, click other place to hide the select
|
||||||
$(document).click(function(e) {
|
$(document).click(function(e) {
|
||||||
|
@@ -1,21 +1,23 @@
|
|||||||
{% load seahub_tags i18n %}
|
{% load seahub_tags i18n %}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th width="3%"><input type="checkbox" /></th>
|
||||||
{% if is_pro %}
|
{% if is_pro %}
|
||||||
<th width="24%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
<th width="21%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||||
<th width="12%">{% trans "Status" %}</th>
|
<th width="12%">{% trans "Status" %}</th>
|
||||||
<th width="12%">{% trans "Role" %}</th>
|
<th width="12%">{% trans "Role" %}</th>
|
||||||
{% else %}
|
{% else %}
|
||||||
<th width="36%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
<th width="33%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
|
||||||
<th width="12%">{% trans "Status" %}</th>
|
<th width="12%">{% trans "Status" %}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th width="16%">{% trans "Space Used / Quota" %}</th>
|
<th width="16%">{% trans "Space Used / Quota" %}</th>
|
||||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||||
<th width="14%">{% trans "Operations" %}</th>
|
<th width="14%"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<tr data-userid="{{user.email}}">
|
<tr data-userid="{{user.email}}">
|
||||||
|
<td><input type="checkbox" /></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
<a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
|
||||||
{% if user.name %}<br />{{ user.name }}{% endif %}
|
{% if user.name %}<br />{{ user.name }}{% endif %}
|
||||||
@@ -105,7 +107,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if user.source == "DB" or user.source == 'LDAPImport' %}
|
|
||||||
<form id="set-quota-form" method="post" action="" class="hide">{% csrf_token %}
|
<form id="set-quota-form" method="post" action="" class="hide">{% csrf_token %}
|
||||||
<h3>{% trans "Set user storage limit" %}</h3>
|
<h3>{% trans "Set user storage limit" %}</h3>
|
||||||
<input type="text" name="space_quota" class="input" /> MB
|
<input type="text" name="space_quota" class="input" /> MB
|
||||||
@@ -116,4 +117,3 @@
|
|||||||
<p class="error hide"></p>
|
<p class="error hide"></p>
|
||||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
|
||||||
|
Reference in New Issue
Block a user