mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 10:58:33 +00:00
[org] Fix quota related
This commit is contained in:
@@ -4,23 +4,49 @@
|
|||||||
{% block cur_org %}tab-cur{% endblock %}
|
{% block cur_org %}tab-cur{% endblock %}
|
||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
<h3>{% trans "All Organizations" %}</h3>
|
<div class="hd ovhd">
|
||||||
|
<h3 class="fleft">{% trans "All Organizations" %}</h3>
|
||||||
|
<button id="add-btn" class="fright">{% trans "Add organization" %}</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="add-org-form" action="" method="post" class="hide">{% csrf_token %}
|
||||||
|
<h3>{% trans "Add organization" %}</h3>
|
||||||
|
<label for="id_name">{% trans "Name" %}</label><br />
|
||||||
|
<input type="text" name="name" id="id_name" class="input" /><br />
|
||||||
|
|
||||||
|
<label for="id_url">{% trans "Url Prefix" %}</label><br />
|
||||||
|
<input type="text" name="url" id="id_url" class="input" /><br />
|
||||||
|
|
||||||
|
<label for="id_owner">{% trans "Owner" %}</label><span class="icon-question-sign" title="{% trans "Owner can use admin panel in an organization, must be a new account." %}" style="color:#666; margin-left:3px;"></span><br />
|
||||||
|
<input type="text" name="owner" id="id_owner" class="input" /><br />
|
||||||
|
<label for="id_password1">{% trans "Password" %}</label><br />
|
||||||
|
<input type="password" name="password1" id="id_password1" class="input" /><br />
|
||||||
|
<label for="id_password2">{% trans "Confirm Password" %}</label><br />
|
||||||
|
<input type="password" name="password2" id="id_password2" class="input" /><br />
|
||||||
|
|
||||||
|
<p class="error hide"></p>
|
||||||
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
{% if orgs %}
|
{% if orgs %}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="20%">{% trans "Name" %}</th>
|
<th width="20%">{% trans "Name" %}</th>
|
||||||
<th width="18%">{% trans "Url Prefix" %}</th>
|
<th width="18%">{% trans "Url Prefix" %}</th>
|
||||||
<th width="27%">{% trans "Creator" %}</th>
|
<th width="25%">{% trans "Creator" %}</th>
|
||||||
<th width="23%">{% trans "Created At" %}</th>
|
<th width="17%">{% trans "Space Used" %}</th>
|
||||||
<th width="12%">{% trans "Operations" %}</th>
|
<th width="20%">{% trans "Created At" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for org in orgs %}
|
{% for org in orgs %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url 'sys_org_info' org.org_id %}">{{ org.org_name }}</a></td>
|
<td><a href="{% url 'sys_org_info' org.org_id %}">{{ org.org_name }}</a></td>
|
||||||
<td>{{ org.url_prefix }}</td>
|
<td>{{ org.url_prefix }}</td>
|
||||||
<td>{{ org.creator }}</td>
|
<td><a href="{% url 'user_info' org.creator %}">{{ org.creator }}</a></td>
|
||||||
|
<td>
|
||||||
|
{{ org.quota_usage|filesizeformat }} {% if org.total_quota > 0 %} / {{ org.total_quota|filesizeformat }} {% endif %}
|
||||||
|
</td>
|
||||||
<td>{{ org.ctime|tsstr_sec }}</td>
|
<td>{{ org.ctime|tsstr_sec }}</td>
|
||||||
<td><a href="#" data-url="{{ SITE_ROOT}}org/remove/{{ org.org_id }}/" data-target="{{ org.org_name }}" class="remove-btn op vh">{% trans "Delete" %}</a></td>
|
<!-- <td><a href="#" data-url="{{ SITE_ROOT}}org/remove/{{ org.org_id }}/" data-target="{{ org.org_name }}" class="remove-btn op vh">{% trans "Delete" %}</a></td> -->
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
@@ -34,9 +60,77 @@
|
|||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
addConfirmTo($('.remove-btn'), {
|
$('#add-btn').click(function() {
|
||||||
'title':'{% trans "Delete Organization" %}',
|
$('#add-org-form').modal();
|
||||||
'con':'{% trans "Are you sure you want to delete %s ?" %}'
|
$('#simplemodal-container').css({'width':'auto'});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add-org-form').submit(function() {
|
||||||
|
var form = $(this),
|
||||||
|
form_id = form.attr('id'),
|
||||||
|
submit_btn = form.find('[type="submit"]'),
|
||||||
|
name = $.trim(form.children('[name="name"]').val()),
|
||||||
|
url_prefix = $.trim(form.children('[name="url"]').val()),
|
||||||
|
owner = $.trim(form.children('[name="owner"]').val()),
|
||||||
|
pwd1 = $.trim(form.children('[name="password1"]').val()),
|
||||||
|
pwd2 = $.trim(form.children('[name="password2"]').val());
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
apply_form_error(form_id, "{% trans "Name can not be blank"%}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!url_prefix) {
|
||||||
|
apply_form_error(form_id, "{% trans "Url can not be blank"%}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!owner) {
|
||||||
|
apply_form_error(form_id, "{% trans "Owner can not be blank"%}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!pwd1) {
|
||||||
|
apply_form_error(form_id, "{% trans "Password can not be blank" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!pwd2) {
|
||||||
|
apply_form_error(form_id, "{% trans "Please enter the password again" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (pwd1 != pwd2) {
|
||||||
|
apply_form_error(form_id, "{% trans "Passwords do not match" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
disable(submit_btn);
|
||||||
|
$.ajax({
|
||||||
|
url: '{% url 'org_add' %}',
|
||||||
|
type: 'POST',
|
||||||
|
datatype: 'json',
|
||||||
|
cache: 'false',
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
data: {
|
||||||
|
'org_name': name,
|
||||||
|
'url_prefix': url_prefix,
|
||||||
|
'email': owner,
|
||||||
|
'password1': pwd1,
|
||||||
|
'password2': pwd2
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
if (data['success']) {
|
||||||
|
location.reload(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
|
if (jqXHR.responseText) {
|
||||||
|
apply_form_error(form_id, $.parseJSON(jqXHR.responseText).error);
|
||||||
|
} else {
|
||||||
|
apply_form_error(form_id, "{% trans "Failed. Please check the network." %}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).complete(function() {
|
||||||
|
enable(submit_btn);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
{% block left_panel %}
|
{% block left_panel %}
|
||||||
<div class="side-info">
|
<div class="side-info">
|
||||||
|
<a class="go-back" title="{% trans "Back to organization list" %}" href="{% url 'sys_org_admin' %}"><span class="icon-chevron-left"></span></a>
|
||||||
|
|
||||||
<h3 class="hd">{{ org.org_name }}</h3>
|
<h3 class="hd">{{ org.org_name }}</h3>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>{% trans "Number of members" %}</dt>
|
<dt>{% trans "Number of members" %}</dt>
|
||||||
@@ -88,5 +90,42 @@ $('#set-quota').click(function() {
|
|||||||
$("#set-quota-form").modal({appendTo: "#main"});
|
$("#set-quota-form").modal({appendTo: "#main"});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#set-quota-form .submit').click(function() {
|
||||||
|
var form = $('#set-quota-form'),
|
||||||
|
form_id = form.attr('id');
|
||||||
|
|
||||||
|
var quota = $('input[name="quota"]', form).val();
|
||||||
|
if (!$.trim(quota)) {
|
||||||
|
apply_form_error(form_id, "{% trans "Quota can not be empty" %}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb_btn = $(this);
|
||||||
|
disable(sb_btn);
|
||||||
|
$.ajax({
|
||||||
|
url: '{% url 'sys_org_set_quota' org.org_id %}',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
cache: 'false',
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
data: {
|
||||||
|
'quota': quota
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
location.reload(true);
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
if (xhr.responseText) {
|
||||||
|
apply_form_error(form_id, $.parseJSON(xhr.responseText).error);
|
||||||
|
} else {
|
||||||
|
apply_form_error(form_id, "{% trans "Failed. Please check the network." %}");
|
||||||
|
}
|
||||||
|
enable(sb_btn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -187,6 +187,7 @@ urlpatterns = patterns('',
|
|||||||
url(r'^sys/groupadmin/$', sys_group_admin, name='sys_group_admin'),
|
url(r'^sys/groupadmin/$', sys_group_admin, name='sys_group_admin'),
|
||||||
url(r'^sys/orgadmin/$', sys_org_admin, name='sys_org_admin'),
|
url(r'^sys/orgadmin/$', sys_org_admin, name='sys_org_admin'),
|
||||||
url(r'^sys/orgadmin/(?P<org_id>\d+)/$', sys_org_info, name='sys_org_info'),
|
url(r'^sys/orgadmin/(?P<org_id>\d+)/$', sys_org_info, name='sys_org_info'),
|
||||||
|
url(r'^sys/orgadmin/(?P<org_id>\d+)/set_quota/$', sys_org_set_quota, name='sys_org_set_quota'),
|
||||||
url(r'^sys/publinkadmin/$', sys_publink_admin, name='sys_publink_admin'),
|
url(r'^sys/publinkadmin/$', sys_publink_admin, name='sys_publink_admin'),
|
||||||
url(r'^sys/notificationadmin/', notification_list, name='notification_list'),
|
url(r'^sys/notificationadmin/', notification_list, name='notification_list'),
|
||||||
url(r'^useradmin/add/$', user_add, name="user_add"),
|
url(r'^useradmin/add/$', user_add, name="user_add"),
|
||||||
|
@@ -384,6 +384,30 @@ def user_set_quota(request, email):
|
|||||||
result['error'] = str(f.errors.values()[0])
|
result['error'] = str(f.errors.values()[0])
|
||||||
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required_ajax
|
||||||
|
@sys_staff_required
|
||||||
|
def sys_org_set_quota(request, org_id):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
content_type = 'application/json; charset=utf-8'
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
org_id = int(org_id)
|
||||||
|
quota_mb = int(request.POST.get('quota', 0))
|
||||||
|
quota = quota_mb * (1 << 20)
|
||||||
|
|
||||||
|
try:
|
||||||
|
seafserv_threaded_rpc.set_org_quota(org_id, quota)
|
||||||
|
except SearpcError as e:
|
||||||
|
logger.error(e)
|
||||||
|
result['error'] = _(u'Failed to set quota: internal server error')
|
||||||
|
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
||||||
|
|
||||||
|
result['success'] = True
|
||||||
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@sys_staff_required
|
@sys_staff_required
|
||||||
def user_remove(request, user_id):
|
def user_remove(request, user_id):
|
||||||
@@ -709,6 +733,9 @@ def sys_org_admin(request):
|
|||||||
orgs_plus_one = ccnet_threaded_rpc.get_all_orgs(per_page * (current_page - 1),
|
orgs_plus_one = ccnet_threaded_rpc.get_all_orgs(per_page * (current_page - 1),
|
||||||
per_page + 1)
|
per_page + 1)
|
||||||
orgs = orgs_plus_one[:per_page]
|
orgs = orgs_plus_one[:per_page]
|
||||||
|
for org in orgs:
|
||||||
|
org.quota_usage = seafserv_threaded_rpc.get_org_quota_usage(org.org_id)
|
||||||
|
org.total_quota = seafserv_threaded_rpc.get_org_quota(org.org_id)
|
||||||
|
|
||||||
if len(orgs_plus_one) == per_page + 1:
|
if len(orgs_plus_one) == per_page + 1:
|
||||||
page_next = True
|
page_next = True
|
||||||
|
Reference in New Issue
Block a user