1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 10:58:33 +00:00

[sys-user-info] Set user share quota

This commit is contained in:
lian
2014-12-25 17:17:29 +08:00
parent 67ea9ce75c
commit c6f4e67329
3 changed files with 50 additions and 30 deletions

View File

@@ -161,9 +161,11 @@ class SetUserQuotaForm(forms.Form):
Form for setting user quota. Form for setting user quota.
""" """
email = forms.CharField(error_messages={'required': _('Email is required')}) email = forms.CharField(error_messages={'required': _('Email is required')})
quota = forms.IntegerField(min_value=0, space_quota = forms.IntegerField(min_value=0,
error_messages={'required': _('Quota can\'t be empty'), error_messages={'required': _('Space quota can\'t be empty'),
'min_value': _('Quota is too low (minimum value is 0)')}) 'min_value': _('Space quota is too low (minimum value is 0)')})
share_quota = forms.IntegerField(min_value=0, required = False,
error_messages={'min_value': _('Share quota is too low (minimum value is 0)')})
class RepoSettingForm(forms.Form): class RepoSettingForm(forms.Form):
""" """

View File

@@ -51,7 +51,10 @@
<form id="set-quota-form" method="post" class="hide">{% csrf_token %} <form id="set-quota-form" method="post" class="hide">{% csrf_token %}
<h3>{% trans "Set user storage limit" %}</h3> <h3>{% trans "Set user storage limit" %}</h3>
<input type="hidden" name="email" value="{{ email }}" /> <input type="hidden" name="email" value="{{ email }}" />
<input type="text" name="quota" /> MB <input type="text" name="space_quota" /> MB
{% if CALC_SHARE_USAGE %}
<br /><input type="text" name="share_quota" placeholder=" Share quota" /> MB<br />
{% endif %}
<p class="tip">{% trans "Tip: 0 means default limit" %}</p> <p class="tip">{% trans "Tip: 0 means default limit" %}</p>
<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" />
@@ -179,14 +182,25 @@ $('#set-quota').click(function() {
$('#set-quota-form .submit').click(function() { $('#set-quota-form .submit').click(function() {
var form = $('#set-quota-form'), var form = $('#set-quota-form'),
form_id = form.attr('id'); form_id = form.attr('id'),
space_quota = $('input[name="space_quota"]', form).val();
var quota = $('input[name="quota"]', form).val(); if (!$.trim(space_quota)) {
if (!$.trim(quota)) { apply_form_error(form_id, "{% trans "Space Quota can't be empty" %}");
apply_form_error(form_id, "{% trans "Quota can't be empty" %}");
return false; return false;
} }
data = { 'email': $('input[name="email"]', form).val(), 'space_quota': space_quota };
{% if CALC_SHARE_USAGE %}
var share_quota = $('input[name="share_quota"]', form).val();
if (!$.trim(share_quota)) {
apply_form_error(form_id, "{% trans "Share Quota can't be empty" %}");
return false;
}
data['share_quota'] = share_quota;
{% endif %}
var sb_btn = $(this); var sb_btn = $(this);
disable(sb_btn); disable(sb_btn);
$.ajax({ $.ajax({
@@ -195,10 +209,7 @@ $('#set-quota-form .submit').click(function() {
dataType: 'json', dataType: 'json',
cache: 'false', cache: 'false',
beforeSend: prepareCSRFToken, beforeSend: prepareCSRFToken,
data: { data: data,
'email': $('input[name="email"]', form).val(),
'quota': quota
},
success: function(data) { success: function(data) {
location.reload(true); location.reload(true);
}, },

View File

@@ -429,7 +429,7 @@ def user_info(request, email):
'profile': profile, 'profile': profile,
'd_profile': d_profile, 'd_profile': d_profile,
'org_name': org_name, 'org_name': org_name,
"user_shared_links": user_shared_links, 'user_shared_links': user_shared_links,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@login_required_ajax @login_required_ajax
@@ -444,22 +444,29 @@ def user_set_quota(request, email):
f = SetUserQuotaForm(request.POST) f = SetUserQuotaForm(request.POST)
if f.is_valid(): if f.is_valid():
email = f.cleaned_data['email'] email = f.cleaned_data['email']
quota_mb = f.cleaned_data['quota'] space_quota_mb = f.cleaned_data['space_quota']
quota = quota_mb * (1 << 20) space_quota = space_quota_mb * (1 << 20)
share_quota_mb = f.cleaned_data['share_quota']
share_quota = None
if share_quota_mb is not None:
share_quota = share_quota_mb * (1 << 20)
org = ccnet_threaded_rpc.get_orgs_by_user(email) org = ccnet_threaded_rpc.get_orgs_by_user(email)
try: try:
if not org: if not org:
seafile_api.set_user_quota(email, quota) seafile_api.set_user_quota(email, space_quota)
if share_quota is not None:
seafile_api.set_user_share_quota(email, share_quota)
else: else:
org_id = org[0].org_id org_id = org[0].org_id
org_quota_mb = seafserv_threaded_rpc.get_org_quota(org_id) / (1 << 20) org_quota_mb = seafserv_threaded_rpc.get_org_quota(org_id) / (1 << 20)
if quota_mb > org_quota_mb: if space_quota_mb > org_quota_mb:
result['error'] = _(u'Failed to set quota: maximum quota is %d MB' % \ result['error'] = _(u'Failed to set quota: maximum quota is %d MB' % \
org_quota_mb) org_quota_mb)
return HttpResponse(json.dumps(result), status=400, content_type=content_type) return HttpResponse(json.dumps(result), status=400, content_type=content_type)
else: else:
seafserv_threaded_rpc.set_org_user_quota(org_id, email, quota) seafserv_threaded_rpc.set_org_user_quota(org_id, email, space_quota)
except: except:
result['error'] = _(u'Failed to set quota: internal server error') result['error'] = _(u'Failed to set quota: internal server error')
return HttpResponse(json.dumps(result), status=500, content_type=content_type) return HttpResponse(json.dumps(result), status=500, content_type=content_type)