Skip to content

Commit

Permalink
[org] Add org member quota option
Browse files Browse the repository at this point in the history
  • Loading branch information
xiez committed Dec 4, 2014
1 parent 07414cb commit f338324
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
8 changes: 7 additions & 1 deletion seahub/templates/sysadmin/sys_org_info_setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ <h3>{% trans "Rename Organization" %}</h3>
<input type="text" name="new_name" class="input" value="{{ org.org_name }}"/></br>
<input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>

{% if org_member_quota %}
<h3>{% trans "Limit Organization User Number" %}</h3>
<form id="org_member_quota" action="" method="post" class="form">{% csrf_token %}
<label>{% trans "Max User Number" %}</label></br>
<input type="text" name="member_quota" class="input" value="{{ org_member_quota }}"/></br>
<p class="error hide"></p>
<input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>
{% endif %}
</div>

{% endblock %}

{% block extra_script %}
<script type="text/javascript">
{% include 'sysadmin/sys_org_set_quota_js.html' %}

{% if org_member_quota %}
$('#org_member_quota').submit(function() {
var form = $(this),
form_id = form.attr('id'),
Expand All @@ -47,7 +52,7 @@ <h3>{% trans "Limit Organization User Number" %}</h3>
apply_form_error(form_id, "{% trans "Input should be a number" %}");
return false;
} else if (member_quota <= 0) {
apply_form_error(form_id, "{% trans "Input number should be greater than 1" %}");
apply_form_error(form_id, "{% trans "Input number should be greater than 0" %}");
return false;
}

Expand All @@ -69,5 +74,6 @@ <h3>{% trans "Limit Organization User Number" %}</h3>
});
return false;
});
{% endif %}
</script>
{% endblock %}
30 changes: 19 additions & 11 deletions seahub/views/sysadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ENABLE_GUEST
from seahub.utils import send_html_email, get_user_traffic_list, get_server_id
from seahub.utils.sysinfo import get_platform_name
from seahub_extra.organizations.models import OrgMemberQuota

logger = logging.getLogger(__name__)

@login_required
Expand Down Expand Up @@ -886,18 +886,20 @@ def sys_org_set_member_quota(request, org_id):

try:
member_quota = int(request.POST.get('member_quota', '0'))
if member_quota > 0:
OrgMemberQuota.objects.set_quota(org_id, member_quota)
messages.success(request, _(u'Success'))
return HttpResponse(json.dumps({'success': True}), status=200,
content_type=content_type)
else:
return HttpResponse(json.dumps({ 'error': _('Input number should be greater than 1')}),
status=400, content_type=content_type)
except ValueError:
return HttpResponse(json.dumps({ 'error': _('Input should be a number')}),
status=400, content_type=content_type)

if member_quota > 0:
from seahub_extra.organizations.models import OrgMemberQuota
OrgMemberQuota.objects.set_quota(org_id, member_quota)
messages.success(request, _(u'Success'))
return HttpResponse(json.dumps({'success': True}), status=200,
content_type=content_type)
else:
return HttpResponse(json.dumps({ 'error': _('Input number should be greater than 0')}),
status=400, content_type=content_type)

def sys_get_org_base_info(org_id):

org = ccnet_threaded_rpc.get_org_by_id(org_id)
Expand Down Expand Up @@ -994,10 +996,16 @@ def sys_org_info_setting(request, org_id):

org_id = int(org_id)
org_basic_info = sys_get_org_base_info(org_id)
org_basic_info['org_member_quota'] = OrgMemberQuota.objects.get_quota(org_id)

if getattr(settings, 'ORG_MEMBER_QUOTA_ENABLED', False):
from seahub_extra.organizations.models import OrgMemberQuota
org_basic_info['org_member_quota'] = OrgMemberQuota.objects.get_quota(org_id)
else:
org_basic_info['org_member_quota'] = None

return render_to_response('sysadmin/sys_org_info_setting.html',
org_basic_info, context_instance=RequestContext(request))
org_basic_info,
context_instance=RequestContext(request))

@login_required
@sys_staff_required
Expand Down

0 comments on commit f338324

Please sign in to comment.