mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 02:48:51 +00:00
[system admin] set inst for users, add members to inst: improvement & bugfix
This commit is contained in:
@@ -37,7 +37,7 @@ def get_account_info(user):
|
|||||||
info['email'] = email
|
info['email'] = email
|
||||||
info['name'] = email2nickname(email)
|
info['name'] = email2nickname(email)
|
||||||
info['department'] = d_profile.department if d_profile else ''
|
info['department'] = d_profile.department if d_profile else ''
|
||||||
info['institution_name'] = profile.institution if profile else ''
|
info['institution'] = profile.institution if profile else ''
|
||||||
info['id'] = user.id
|
info['id'] = user.id
|
||||||
info['is_staff'] = user.is_staff
|
info['is_staff'] = user.is_staff
|
||||||
info['is_active'] = user.is_active
|
info['is_active'] = user.is_active
|
||||||
@@ -146,13 +146,13 @@ class Account(APIView):
|
|||||||
seafile_api.set_user_quota(email, space_quota)
|
seafile_api.set_user_quota(email, space_quota)
|
||||||
|
|
||||||
# update user institution
|
# update user institution
|
||||||
institution_name = request.data.get("institution_name", None)
|
institution = request.data.get("institution", None)
|
||||||
if institution_name is not None:
|
if institution is not None:
|
||||||
inst_profile = Profile.objects.get_profile_by_user(email)
|
profile = Profile.objects.get_profile_by_user(email)
|
||||||
if inst_profile is None:
|
if profile is None:
|
||||||
inst_profile = Profile(user=email)
|
profile = Profile(user=email)
|
||||||
inst_profile.institution = institution_name
|
profile.institution = institution
|
||||||
inst_profile.save()
|
profile.save()
|
||||||
|
|
||||||
# update is_trial
|
# update is_trial
|
||||||
is_trial = request.data.get("is_trial", None)
|
is_trial = request.data.get("is_trial", None)
|
||||||
@@ -206,13 +206,13 @@ class Account(APIView):
|
|||||||
_(u'Department is too long (maximum is 512 characters)'))
|
_(u'Department is too long (maximum is 512 characters)'))
|
||||||
|
|
||||||
# argument check for institution
|
# argument check for institution
|
||||||
institution_name = request.data.get("institution_name", None)
|
institution = request.data.get("institution", None)
|
||||||
if institution_name is not None and institution_name != '':
|
if institution is not None and institution != '':
|
||||||
try:
|
try:
|
||||||
obj_insti = Institution.objects.get(name=institution_name)
|
obj_insti = Institution.objects.get(name=institution)
|
||||||
except Institution.DoesNotExist:
|
except Institution.DoesNotExist:
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||||
"Institution %s does not exists" % institution_name)
|
"Institution %s does not exist" % institution)
|
||||||
|
|
||||||
# argument check for storage
|
# argument check for storage
|
||||||
space_quota_mb = request.data.get("storage", None)
|
space_quota_mb = request.data.get("storage", None)
|
||||||
|
@@ -31,7 +31,7 @@ class AdminUsersBatch(APIView):
|
|||||||
permission_classes = (IsAdminUser,)
|
permission_classes = (IsAdminUser,)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
""" Set user quota / delete users in batch.
|
""" Set user quota, set user institution, delete users, in batch.
|
||||||
|
|
||||||
Permission checking:
|
Permission checking:
|
||||||
1. admin user.
|
1. admin user.
|
||||||
@@ -45,7 +45,7 @@ class AdminUsersBatch(APIView):
|
|||||||
|
|
||||||
operation = request.POST.get('operation', None)
|
operation = request.POST.get('operation', None)
|
||||||
if operation not in ('set-quota', 'delete-user', 'set-institution'):
|
if operation not in ('set-quota', 'delete-user', 'set-institution'):
|
||||||
error_msg = "operation can only be 'set-quota' or 'delete-user'."
|
error_msg = "operation can only be 'set-quota', 'delete-user', or 'set-institution'."
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
@@ -124,28 +124,28 @@ class AdminUsersBatch(APIView):
|
|||||||
operation=USER_DELETE, detail=admin_op_detail)
|
operation=USER_DELETE, detail=admin_op_detail)
|
||||||
|
|
||||||
if operation == 'set-institution':
|
if operation == 'set-institution':
|
||||||
institution_name = request.POST.get('institution_name', None)
|
institution = request.POST.get('institution', None)
|
||||||
if institution_name is None:
|
if institution is None:
|
||||||
error_msg = 'institution name can not be blank.'
|
error_msg = 'Institution can not be blank.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
emails = [email.strip() for email in emails if email.strip()]
|
|
||||||
if institution_name != '':
|
|
||||||
try:
|
|
||||||
obj_insti = Institution.objects.get(name=institution_name)
|
|
||||||
except Institution.DoesNotExist:
|
|
||||||
error_msg = 'institution %s does not exists' % institution_name
|
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
|
||||||
for email in emails:
|
|
||||||
try:
|
|
||||||
User.objects.get(email=email)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for email in emails:
|
if institution != '':
|
||||||
|
try:
|
||||||
|
obj_insti = Institution.objects.get(name=institution)
|
||||||
|
except Institution.DoesNotExist:
|
||||||
|
error_msg = 'Institution %s does not exist' % institution
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
|
for user in existed_users:
|
||||||
|
email = user.email
|
||||||
profile = Profile.objects.get_profile_by_user(email)
|
profile = Profile.objects.get_profile_by_user(email)
|
||||||
if profile is None:
|
if profile is None:
|
||||||
profile = Profile(user=email)
|
profile = Profile(user=email)
|
||||||
profile.institution = institution_name
|
profile.institution = institution
|
||||||
profile.save()
|
profile.save()
|
||||||
|
result['success'].append({
|
||||||
|
'email': email,
|
||||||
|
'institution': institution
|
||||||
|
})
|
||||||
|
|
||||||
return Response(result)
|
return Response(result)
|
||||||
|
@@ -168,5 +168,5 @@ def update_profile_cache(sender, instance, **kwargs):
|
|||||||
@receiver(institution_deleted)
|
@receiver(institution_deleted)
|
||||||
def remove_user_for_inst_deleted(sender, **kwargs):
|
def remove_user_for_inst_deleted(sender, **kwargs):
|
||||||
inst_name = kwargs.get("inst_name", "")
|
inst_name = kwargs.get("inst_name", "")
|
||||||
Profile.objects.filter(institution=inst_name).delete()
|
Profile.objects.filter(institution=inst_name).update(institution="")
|
||||||
|
|
||||||
|
@@ -2,6 +2,11 @@
|
|||||||
{% load i18n seahub_tags %}
|
{% load i18n seahub_tags %}
|
||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block extra_style %}
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static "css/select2-3.5.2.css" %}" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static "css/select2.custom.css" %}" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
<div class="tabnav">
|
<div class="tabnav">
|
||||||
<ul class="tabnav-tabs">
|
<ul class="tabnav-tabs">
|
||||||
@@ -9,16 +14,16 @@
|
|||||||
<li class="tabnav-tab"><a href="{% url 'sys_inst_info_admins' inst.pk %}">{% trans "Admins" %}</a></li>
|
<li class="tabnav-tab"><a href="{% url 'sys_inst_info_admins' inst.pk %}">{% trans "Admins" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="js-op-for-all fright">
|
<div class="js-op-for-all fright">
|
||||||
<button id="add-user-btn">{% trans "Add user" %}</button>
|
<button id="add-member-btn">{% trans "Add members" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
<form id="add-member-form" action="" method="" class="hide">
|
||||||
<h3>{% trans "Add user" %}</h3>
|
<h3>{% trans "Add members" %}</h3>
|
||||||
<label for="id_email">{% trans "Email" %}</label><br />
|
<label>{% trans "Email" %}</label><br />
|
||||||
<input id="id_email" style="width:300px;height:30px;"/>
|
<input type="hidden" name="emails" /><br />
|
||||||
|
<p class="error hide"></p>
|
||||||
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
<p id="id_error" class="error hide" style="margin-top:30px;"></p>
|
|
||||||
</form>
|
</form>
|
||||||
{% if users %}
|
{% if users %}
|
||||||
<table>
|
<table>
|
||||||
@@ -43,10 +48,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td style="font-size:11px;">
|
<td style="font-size:11px;">
|
||||||
<p> {{ user.space_usage|seahub_filesizeformat }} {% if user.space_quota > 0 %} / {{ user.space_quota|seahub_filesizeformat }} {% endif %} </p>
|
{{ user.space_usage|seahub_filesizeformat }} {% if user.space_quota > 0 %} / {{ user.space_quota|seahub_filesizeformat }} {% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td style="font-size:11px;">
|
<td style="font-size:11px;">
|
||||||
{{ user.ctime|tsstr_sec }} / {% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
{{ user.ctime|tsstr_sec }} / {% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" class="js-toggle-admin op vh" data-url="{% url 'sys_inst_toggle_admin' inst.pk user.email %}" data-target="{{ user.email }}">{% if user.inst_admin %}{% trans "Revoke Admin" %}{% else %}{% trans "Set Admin" %}{% endif %}</a>
|
<a href="#" class="js-toggle-admin op vh" data-url="{% url 'sys_inst_toggle_admin' inst.pk user.email %}" data-target="{{ user.email }}">{% if user.inst_admin %}{% trans "Revoke Admin" %}{% else %}{% trans "Set Admin" %}{% endif %}</a>
|
||||||
@@ -65,9 +70,6 @@
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_style %}
|
|
||||||
<link rel="stylesheet" type="text/css" href="{% static "css/select2-3.5.2.css" %}"/>
|
|
||||||
{% endblock %}
|
|
||||||
{% block extra_script %}{{ block.super }}
|
{% block extra_script %}{{ block.super }}
|
||||||
<script type="text/javascript" src= "{% static "scripts/lib/select2-3.5.2.js" %}"></script>
|
<script type="text/javascript" src= "{% static "scripts/lib/select2-3.5.2.js" %}"></script>
|
||||||
|
|
||||||
@@ -90,89 +92,6 @@ $('.user-status-edit-icon').click(function() {
|
|||||||
$(this).parent().addClass('hide');
|
$(this).parent().addClass('hide');
|
||||||
$(this).parent().next().removeClass('hide'); // show 'select'
|
$(this).parent().next().removeClass('hide'); // show 'select'
|
||||||
});
|
});
|
||||||
$('#add-user-btn').click(function(){
|
|
||||||
$('#add-user-form').modal();
|
|
||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
|
||||||
|
|
||||||
$("#id_email").select2({
|
|
||||||
minimumInputLength: 1,
|
|
||||||
maximumSelectionSize:5,
|
|
||||||
multiple: true,
|
|
||||||
tags: [],
|
|
||||||
ajax: {
|
|
||||||
url: "{% url 'search-user' %}",
|
|
||||||
dataType: 'json',
|
|
||||||
delay: 250,
|
|
||||||
data: function (term, page) {
|
|
||||||
return {
|
|
||||||
q: term, // search term
|
|
||||||
};
|
|
||||||
},
|
|
||||||
results: function(data, page){
|
|
||||||
var group_list = [], groups = data.users;
|
|
||||||
for (var i =0, len = groups.length; i < len; i++){
|
|
||||||
group_list.push({
|
|
||||||
"id": i,
|
|
||||||
"email": groups[i].email,
|
|
||||||
"avatar_url": groups[i].avatar_url,
|
|
||||||
"name": groups[i].name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {results:group_list};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
formatResult: function(item) {
|
|
||||||
var markup = '<li>'+
|
|
||||||
'<div ><img src="' + item.avatar_url + '" width="32" height="32" class="avatar" />'+
|
|
||||||
'<span class="text ellipsis">' + item.name + '<br>' + item.email + '</span></div></li>'
|
|
||||||
return markup;
|
|
||||||
},
|
|
||||||
formatSelection:function(item) {
|
|
||||||
return (item.email);
|
|
||||||
},
|
|
||||||
escapeMarkup: function (m) { return m; }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$('#add-user-form').submit(function(){
|
|
||||||
var form = $(this),
|
|
||||||
data = ""
|
|
||||||
form_id = $(this).attr('id'),
|
|
||||||
email = $("#id_email").select2("data"),
|
|
||||||
submit_btn = $(this).find('[type="submit"]');
|
|
||||||
if (!email){
|
|
||||||
apply_form_error(form_id, "{% trans "Email can not be blank "%}");
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for (var i=0; i < email.length; i++){
|
|
||||||
data += email[i].email;
|
|
||||||
data += ',';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disable(submit_btn);
|
|
||||||
$.ajax({
|
|
||||||
url: "{% url 'sys_inst_add_user' inst.id %}",
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
data: {
|
|
||||||
'email': data
|
|
||||||
},
|
|
||||||
beforeSend: prepareCSRFToken,
|
|
||||||
success: function(data){
|
|
||||||
if(data['success']){
|
|
||||||
location.reload(true);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(xhr, textStatus, errorThrown){
|
|
||||||
if (xhr.responseText) {
|
|
||||||
var error = $.parseJSON(xhr.responseText).error;
|
|
||||||
apply_form_error(form_id, error);
|
|
||||||
enable(submit_btn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.user-status-select').change(function() {
|
$('.user-status-select').change(function() {
|
||||||
var select = $(this),
|
var select = $(this),
|
||||||
select_val = select.val(),
|
select_val = select.val(),
|
||||||
@@ -220,5 +139,57 @@ $(document).click(function(e) {
|
|||||||
$('.user-status-select').addClass('hide');
|
$('.user-status-select').addClass('hide');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add members
|
||||||
|
$('#add-member-btn').click(function(){
|
||||||
|
var $form = $('#add-member-form');
|
||||||
|
$form.modal({focus: false});
|
||||||
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
|
|
||||||
|
$('[name="emails"]', $form).select2($.extend({
|
||||||
|
width: '280px',
|
||||||
|
placeholder: "{% trans "Search users or enter emails and press Enter" %}",
|
||||||
|
formatInputTooShort: "{% trans "Please enter 1 or more character" %}",
|
||||||
|
formatNoMatches: "{% trans "No matches" %}",
|
||||||
|
formatSearching: "{% trans "Searching..." %}",
|
||||||
|
formatAjaxError: "{% trans "Loading failed" %}"
|
||||||
|
}, userInputOPtionsForSelect2('{% url 'search-user' %}')));
|
||||||
|
});
|
||||||
|
$('#add-member-form').submit(function(){
|
||||||
|
var $form = $(this);
|
||||||
|
var $error = $('.error', $form);
|
||||||
|
var $submit = $('[type="submit"]', $form);
|
||||||
|
var emails = $('[name="emails"]', $form).select2('val');
|
||||||
|
|
||||||
|
if (!emails.length) {
|
||||||
|
$error.html("{% trans "It is required." %}").show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
disable($submit);
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'sys_inst_add_user' inst.id %}",
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
'emails': emails.join(',')
|
||||||
|
},
|
||||||
|
beforeSend: prepareCSRFToken,
|
||||||
|
success: function(data) {
|
||||||
|
location.reload(true);
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
var error_msg;
|
||||||
|
if (xhr.responseText) {
|
||||||
|
error_msg = $.parseJSON(xhr.responseText).error;
|
||||||
|
} else {
|
||||||
|
error_msg = "{% trans "Failed. Please check the network." %}";
|
||||||
|
}
|
||||||
|
$error.html(error_msg).show();
|
||||||
|
enable($submit);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -24,25 +24,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="js-op-for-selected fright hide">
|
<div class="js-op-for-selected fright hide">
|
||||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
{% if show_institution %}
|
||||||
|
<button id="set-institution-btn">{% trans "Set institution" %}</button>
|
||||||
|
{% endif %}
|
||||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if users %}
|
{% if users %}
|
||||||
{% with is_admin_page=False%}
|
{% with is_admin_page=False %}
|
||||||
{% include "sysadmin/useradmin_table.html" %}
|
{% include "sysadmin/useradmin_table.html" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% include "snippets/admin_paginator.html" %}
|
{% include "snippets/admin_paginator.html" %}
|
||||||
<form id="set-quota-form" method="post" action="" class="hide">{% csrf_token %}
|
|
||||||
<h3>{% trans "Set user storage limit" %}</h3>
|
|
||||||
<input type="text" name="space_quota" class="input" /> MB
|
|
||||||
<p class="tip">
|
|
||||||
<span>{% trans "An integer that is greater than or equal to 0." %}</span><br />
|
|
||||||
<span>{% trans "Tip: 0 means default limit" %}</span>
|
|
||||||
</p>
|
|
||||||
<p class="error hide"></p>
|
|
||||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
|
||||||
</form>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="empty-tips">
|
<div class="empty-tips">
|
||||||
<h2 class="alc">{% trans "No LDAP users have been imported" %}</h2>
|
<h2 class="alc">{% trans "No LDAP users have been imported" %}</h2>
|
||||||
@@ -52,6 +45,21 @@
|
|||||||
<div id="activate-msg" class="hide">
|
<div id="activate-msg" class="hide">
|
||||||
<p>{% trans "Activating..., please wait" %}</p>
|
<p>{% trans "Activating..., please wait" %}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if show_institution %}
|
||||||
|
<form class="hide" id="batch-set-institution-form" method="" action="">
|
||||||
|
<h3>{% trans "Set institution" %}</h3>
|
||||||
|
<select name="institution" class="w100">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for inst in institutions %}
|
||||||
|
<option value="{{inst}}">{{inst}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<p class="error hide"></p>
|
||||||
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
{% extends "sysadmin/base.html" %}
|
{% extends "sysadmin/base.html" %}
|
||||||
{% load seahub_tags i18n %}
|
{% load seahub_tags i18n %}
|
||||||
{% load staticfiles %}
|
|
||||||
{% block cur_users %}tab-cur{% endblock %}
|
{% block cur_users %}tab-cur{% endblock %}
|
||||||
|
|
||||||
{% block left_panel %}{{block.super}}
|
{% block left_panel %}{{block.super}}
|
||||||
@@ -29,10 +28,10 @@
|
|||||||
<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">
|
<div class="js-op-for-selected fright hide">
|
||||||
{% if multi_institution %}
|
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
||||||
|
{% if show_institution %}
|
||||||
<button id="set-institution-btn">{% trans "Set institution" %}</button>
|
<button id="set-institution-btn">{% trans "Set institution" %}</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<button id="set-quota-btn">{% trans "Set quota" %}</button>
|
|
||||||
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
<button id="delete-users-btn">{% trans "Delete users" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -80,7 +79,7 @@
|
|||||||
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% with is_admin_page=False%}
|
{% with is_admin_page=False %}
|
||||||
{% include "sysadmin/useradmin_table.html" %}
|
{% include "sysadmin/useradmin_table.html" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% include "snippets/admin_paginator.html" %}
|
{% include "snippets/admin_paginator.html" %}
|
||||||
@@ -88,12 +87,22 @@
|
|||||||
<div id="activate-msg" class="hide">
|
<div id="activate-msg" class="hide">
|
||||||
<p>{% trans "Activating..., please wait" %}</p>
|
<p>{% trans "Activating..., please wait" %}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
|
||||||
{% block extra_style %}
|
{% if show_institution %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static "css/select2-3.5.2.css" %}"/>
|
<form class="hide" id="batch-set-institution-form" method="" action="">
|
||||||
|
<h3>{% trans "Set institution" %}</h3>
|
||||||
|
<select name="institution" class="w100">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for inst in institutions %}
|
||||||
|
<option value="{{inst}}">{{inst}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<p class="error hide"></p>
|
||||||
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
<script type="text/javascript" src= "{% static "scripts/lib/select2-3.5.2.js" %}"></script>
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){
|
$(function(){
|
||||||
// check if server version is the latest one
|
// check if server version is the latest one
|
||||||
|
@@ -45,14 +45,14 @@ $('.user-status-select, .user-role-select, .user-institution-select').change(fun
|
|||||||
data = {'s': select_val};
|
data = {'s': select_val};
|
||||||
} else if (select.hasClass('user-institution-select')){
|
} else if (select.hasClass('user-institution-select')){
|
||||||
url = "{{ SITE_ROOT }}api2/accounts/" + uid + "/";
|
url = "{{ SITE_ROOT }}api2/accounts/" + uid + "/";
|
||||||
data = {'institution_name': select_val};
|
data = {'institution': select_val};
|
||||||
ajax_type = 'PUT';
|
ajax_type = 'PUT';
|
||||||
} else {
|
} else {
|
||||||
url = "{{ SITE_ROOT }}useradmin/toggle_role/" + uid + "/";
|
url = "{{ SITE_ROOT }}useradmin/toggle_role/" + uid + "/";
|
||||||
data = {'r': select_val};
|
data = {'r': select_val};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (select_val == 1) {
|
if (select.hasClass('user-status-select') && select_val == 1) {
|
||||||
// show activating popup
|
// show activating popup
|
||||||
$('#activate-msg').modal();
|
$('#activate-msg').modal();
|
||||||
$('#simplemodal-container').css({'height':'auto'});
|
$('#simplemodal-container').css({'height':'auto'});
|
||||||
@@ -72,12 +72,7 @@ $('.user-status-select, .user-role-select, .user-institution-select').change(fun
|
|||||||
} else {
|
} else {
|
||||||
feedback("{% trans "Edit succeeded" %}", 'success');
|
feedback("{% trans "Edit succeeded" %}", 'success');
|
||||||
}
|
}
|
||||||
if (select.children('option[value="' +select.val() + '"]').text() == "None"){
|
$('.user-status-cur-value, .user-role-cur-value, .user-institution-cur-value', $select_prev).html(select.children('option[value="' +select.val() + '"]').text());
|
||||||
$('.user-status-cur-value, .user-role-cur-value, .user-institution-cur-value', $select_prev).html("");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$('.user-status-cur-value, .user-role-cur-value, .user-institution-cur-value', $select_prev).html(select.children('option[value="' +select.val() + '"]').text());
|
|
||||||
}
|
|
||||||
select.addClass('hide');
|
select.addClass('hide');
|
||||||
$select_prev.removeClass('hide');
|
$select_prev.removeClass('hide');
|
||||||
$.modal.close();
|
$.modal.close();
|
||||||
@@ -128,94 +123,71 @@ $('#set-quota-btn').click(function() {
|
|||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#set-institution-btn').click(function(){
|
{% if show_institution %}
|
||||||
$('#set-institution-form').data({'batch': true}).modal();
|
$('#set-institution-btn').click(function() {
|
||||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
$('#batch-set-institution-form').modal({focus: false, minWidth: 280});
|
||||||
|
$('#simplemodal-container').css({'height':'auto'});
|
||||||
|
});
|
||||||
|
$("#batch-set-institution-form").submit(function() {
|
||||||
|
var $form = $(this);
|
||||||
|
var $error = $('.error', $form);
|
||||||
|
var $submit = $('[type="submit"]', $form);
|
||||||
|
|
||||||
$("#institution_name").select2({
|
var institution = $('[name="institution"]', $form).val();
|
||||||
minimumInputLength: 1,
|
var emails = [];
|
||||||
maximumSelectionSize:1,
|
|
||||||
multiple: true,
|
|
||||||
tags: [],
|
|
||||||
ajax: {
|
|
||||||
url: "{% url 'sys_inst_search_inst' %}",
|
|
||||||
dataType: 'json',
|
|
||||||
delay: 250,
|
|
||||||
data: function (term, page) {
|
|
||||||
return {
|
|
||||||
q: term, // search term
|
|
||||||
};
|
|
||||||
},
|
|
||||||
results: function(data, page){
|
|
||||||
var insts_list = [], insts = data.insts;
|
|
||||||
for (var i =0, len = insts.length; i < len; i++){
|
|
||||||
insts_list.push({
|
|
||||||
"id": i,
|
|
||||||
"name": insts[i].name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {results:insts_list};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
formatResult: function(item) {
|
|
||||||
var markup = '<li><div ><span class="text ellipsis">' + item.name + '</span></div></li>'
|
|
||||||
return markup;
|
|
||||||
},
|
|
||||||
formatSelection:function(item) {
|
|
||||||
return (item.name);
|
|
||||||
},
|
|
||||||
escapeMarkup: function (m) { return m; }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$("#set-institution-form").submit(function(){
|
|
||||||
var insts = $("#institution_name").select2("data"),
|
|
||||||
data = "",
|
|
||||||
emails = [],
|
|
||||||
form_id = $(this).attr('id'),
|
|
||||||
submit_btn = $(this).find('[type="submit"]');
|
|
||||||
if (!insts){
|
|
||||||
apply_form_error(form_id, "Institution can not be blank" );
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
data = insts[0].name;
|
|
||||||
}
|
|
||||||
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
$('td [type="checkbox"]:checked').closest('tr').each(function(index, item) {
|
||||||
emails.push($(item).attr('data-userid'));
|
emails.push($(item).attr('data-userid'));
|
||||||
});
|
});
|
||||||
if (data == "None"){
|
|
||||||
data = "";
|
disable($submit);
|
||||||
}
|
$.ajax({
|
||||||
disable(submit_btn);
|
url: "{% url 'api-v2.1-admin-users-batch' %}",
|
||||||
var batch = $(this).data('batch');
|
type: "POST",
|
||||||
if (batch){
|
dataType: 'json',
|
||||||
$.ajax({
|
cache: false,
|
||||||
url: "{% url 'api-v2.1-admin-users-batch' %}",
|
data: {
|
||||||
type: "POST",
|
'operation': 'set-institution',
|
||||||
dataType: 'json',
|
'email': emails,
|
||||||
cache: false,
|
'institution': institution
|
||||||
data: {
|
},
|
||||||
'operation': 'set-institution',
|
traditional: true,
|
||||||
'email': emails,
|
beforeSend: prepareCSRFToken,
|
||||||
'institution_name': data
|
success: function(data) {
|
||||||
},
|
if (data.success.length) {
|
||||||
traditional: true,
|
var emails = [];
|
||||||
beforeSend: prepareCSRFToken,
|
$(data.success).each(function(index, item) {
|
||||||
success: function(data){
|
var $tr = $('tr[data-userid="' + item.email + '"]');
|
||||||
if(data['success']){
|
$('.user-institution-cur-value', $tr).html(HTMLescape(item.institution));
|
||||||
location.reload(true);
|
emails.push(item.email);
|
||||||
}
|
});
|
||||||
},
|
var msg = "{% trans "Successfully set institution for {users}." %}".replace('{users}', HTMLescape(emails.join(', ')));
|
||||||
error: function(xhr, textStatus, errorThrown){
|
feedback(msg, 'success');
|
||||||
if (xhr.responseText) {
|
|
||||||
var error = $.parseJSON(xhr.responseText).error;
|
|
||||||
apply_form_error(form_id, error);
|
|
||||||
enable(submit_btn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
if (data.failed.length) {
|
||||||
return false;
|
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();
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
var error_msg;
|
||||||
|
if (xhr.responseText) {
|
||||||
|
var parsed_resp = $.parseJSON(xhr.responseText);
|
||||||
|
error_msg = parsed_resp.error_msg||parsed_resp.detail;
|
||||||
|
} else {
|
||||||
|
error_msg = gettext("Failed. Please check the network.");
|
||||||
|
}
|
||||||
|
$error.html(error_msg).show();
|
||||||
|
enable($submit);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
$('#delete-users-btn').click(function() {
|
$('#delete-users-btn').click(function() {
|
||||||
var title = "{% trans "Delete User" %}";
|
var title = "{% trans "Delete User" %}";
|
||||||
|
@@ -10,11 +10,11 @@
|
|||||||
<th width="33%">{% 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 %}
|
||||||
{% if multi_institution %}
|
{% if show_institution %}
|
||||||
|
<th width="14%">{% trans "Space Used / Quota" %}</th>
|
||||||
<th width="10%">{% trans "Institution" %}</th>
|
<th width="10%">{% trans "Institution" %}</th>
|
||||||
<th width="16%">{% trans "Space Used / Quota" %}</th>
|
<th width="18%">{% trans "Create At / Last Login" %}</th>
|
||||||
<th width="15%">{% trans "Create At / Last Login" %}</th>
|
<th width="10%"></th>
|
||||||
<th width="11%"></th>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<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>
|
||||||
@@ -73,21 +73,6 @@
|
|||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if multi_institution %}
|
|
||||||
<td>
|
|
||||||
<div class="user-institution">
|
|
||||||
<span class="user-institution-cur-value"> {{ user.institution }} </span>
|
|
||||||
<span title="{% trans "Edit"%}" class="user-institution-edit-icon sf2-icon-edit op-icon vh"></span>
|
|
||||||
</div>
|
|
||||||
<select name="institution" class="user-institution-select hide">
|
|
||||||
{% for inst in institutions %}
|
|
||||||
<option value={{inst}} {% if user.institution == inst %} selected="selected"{% endif %}>{{inst}}</option>
|
|
||||||
{% endfor %}
|
|
||||||
<option value="" {% if user.institution == "" %} selected="selected"{% endif %}>None</option>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<td style="font-size:11px;">
|
<td style="font-size:11px;">
|
||||||
{{ user.space_usage|seahub_filesizeformat }} /
|
{{ user.space_usage|seahub_filesizeformat }} /
|
||||||
<span class="user-space-quota">
|
<span class="user-space-quota">
|
||||||
@@ -99,6 +84,22 @@
|
|||||||
</span>
|
</span>
|
||||||
<span title="{% trans "Edit Quota" %}" class="quota-edit-icon sf2-icon-edit op-icon vh"></span>
|
<span title="{% trans "Edit Quota" %}" class="quota-edit-icon sf2-icon-edit op-icon vh"></span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{% if show_institution %}
|
||||||
|
<td>
|
||||||
|
<div class="user-institution">
|
||||||
|
<span class="user-institution-cur-value">{{ user.institution }}</span>
|
||||||
|
<span title="{% trans "Edit"%}" class="user-institution-edit-icon sf2-icon-edit op-icon vh"></span>
|
||||||
|
</div>
|
||||||
|
<select name="institution" class="user-institution-select hide">
|
||||||
|
<option value="" {% if user.institution == "" %} selected="selected"{% endif %}></option>
|
||||||
|
{% for inst in institutions %}
|
||||||
|
<option value="{{inst}}" {% if user.institution == inst %} selected="selected"{% endif %}>{{inst}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
{% if user.source == "DB" %}
|
{% if user.source == "DB" %}
|
||||||
{{ user.ctime|tsstr_sec }} /<br />
|
{{ user.ctime|tsstr_sec }} /<br />
|
||||||
@@ -132,22 +133,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>
|
||||||
<form id="set-institution-form" method="post" action="" class="hide">{% csrf_token %}
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th width="75%">{% trans "Institution" %}</th>
|
|
||||||
<th width="25%"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<td>
|
|
||||||
<input id="institution_name" class="w100"/>
|
|
||||||
<p class="error hide"></p>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
|
||||||
</td>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</form>
|
|
||||||
|
@@ -350,7 +350,6 @@ urlpatterns = patterns(
|
|||||||
url(r'^sys/orgadmin/(?P<org_id>\d+)/library/$', sys_org_info_library, name='sys_org_info_library'),
|
url(r'^sys/orgadmin/(?P<org_id>\d+)/library/$', sys_org_info_library, name='sys_org_info_library'),
|
||||||
url(r'^sys/orgadmin/(?P<org_id>\d+)/setting/$', sys_org_info_setting, name='sys_org_info_setting'),
|
url(r'^sys/orgadmin/(?P<org_id>\d+)/setting/$', sys_org_info_setting, name='sys_org_info_setting'),
|
||||||
url(r'^sys/instadmin/$', sys_inst_admin, name='sys_inst_admin'),
|
url(r'^sys/instadmin/$', sys_inst_admin, name='sys_inst_admin'),
|
||||||
url(r'^sys/instadmin/search-inst/$$', sys_inst_search_inst, name='sys_inst_search_inst'),
|
|
||||||
url(r'^sys/instadmin/(?P<inst_id>\d+)/remove/$', sys_inst_remove, name='sys_inst_remove'),
|
url(r'^sys/instadmin/(?P<inst_id>\d+)/remove/$', sys_inst_remove, name='sys_inst_remove'),
|
||||||
url(r'^sys/instadmin/(?P<inst_id>\d+)/users/$', sys_inst_info_user, name='sys_inst_info_users'),
|
url(r'^sys/instadmin/(?P<inst_id>\d+)/users/$', sys_inst_info_user, name='sys_inst_info_users'),
|
||||||
url(r'^sys/instadmin/(?P<inst_id>\d+)/users/add/$', sys_inst_add_user, name='sys_inst_add_user'),
|
url(r'^sys/instadmin/(?P<inst_id>\d+)/users/add/$', sys_inst_add_user, name='sys_inst_add_user'),
|
||||||
|
@@ -228,15 +228,21 @@ def sys_user_admin(request):
|
|||||||
if trial_user.user_or_org == user.email:
|
if trial_user.user_or_org == user.email:
|
||||||
user.trial_info = {'expire_date': trial_user.expire_date}
|
user.trial_info = {'expire_date': trial_user.expire_date}
|
||||||
|
|
||||||
profile = Profile.objects.get_profile_by_user(user.email)
|
|
||||||
user.institution = profile.institution if profile else ''
|
|
||||||
|
|
||||||
platform = get_platform_name()
|
platform = get_platform_name()
|
||||||
server_id = get_server_id()
|
server_id = get_server_id()
|
||||||
pro_server = 1 if is_pro_version() else 0
|
pro_server = 1 if is_pro_version() else 0
|
||||||
extra_user_roles = [x for x in get_available_roles()
|
extra_user_roles = [x for x in get_available_roles()
|
||||||
if x not in get_basic_user_roles()]
|
if x not in get_basic_user_roles()]
|
||||||
institutions = [inst.name for inst in Institution.objects.all()]
|
|
||||||
|
multi_institution = getattr(dj_settings, 'MULTI_INSTITUTION', False)
|
||||||
|
show_institution = False
|
||||||
|
institutions = None
|
||||||
|
if multi_institution:
|
||||||
|
show_institution = True
|
||||||
|
institutions = [inst.name for inst in Institution.objects.all()]
|
||||||
|
for user in users:
|
||||||
|
profile = Profile.objects.get_profile_by_user(user.email)
|
||||||
|
user.institution = profile.institution if profile else ''
|
||||||
|
|
||||||
return render_to_response(
|
return render_to_response(
|
||||||
'sysadmin/sys_useradmin.html', {
|
'sysadmin/sys_useradmin.html', {
|
||||||
@@ -255,8 +261,8 @@ def sys_user_admin(request):
|
|||||||
'pro_server': pro_server,
|
'pro_server': pro_server,
|
||||||
'enable_user_plan': enable_user_plan,
|
'enable_user_plan': enable_user_plan,
|
||||||
'extra_user_roles': extra_user_roles,
|
'extra_user_roles': extra_user_roles,
|
||||||
|
'show_institution': show_institution,
|
||||||
'institutions': institutions,
|
'institutions': institutions,
|
||||||
'multi_institution': getattr(dj_settings, 'MULTI_INSTITUTION', False),
|
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -411,6 +417,16 @@ def sys_user_admin_ldap_imported(request):
|
|||||||
extra_user_roles = [x for x in get_available_roles()
|
extra_user_roles = [x for x in get_available_roles()
|
||||||
if x not in get_basic_user_roles()]
|
if x not in get_basic_user_roles()]
|
||||||
|
|
||||||
|
multi_institution = getattr(dj_settings, 'MULTI_INSTITUTION', False)
|
||||||
|
show_institution = False
|
||||||
|
institutions = None
|
||||||
|
if multi_institution:
|
||||||
|
show_institution = True
|
||||||
|
institutions = [inst.name for inst in Institution.objects.all()]
|
||||||
|
for user in users:
|
||||||
|
profile = Profile.objects.get_profile_by_user(user.email)
|
||||||
|
user.institution = profile.institution if profile else ''
|
||||||
|
|
||||||
return render_to_response(
|
return render_to_response(
|
||||||
'sysadmin/sys_user_admin_ldap_imported.html', {
|
'sysadmin/sys_user_admin_ldap_imported.html', {
|
||||||
'users': users,
|
'users': users,
|
||||||
@@ -423,6 +439,8 @@ def sys_user_admin_ldap_imported(request):
|
|||||||
'extra_user_roles': extra_user_roles,
|
'extra_user_roles': extra_user_roles,
|
||||||
'default_user': DEFAULT_USER,
|
'default_user': DEFAULT_USER,
|
||||||
'guest_user': GUEST_USER,
|
'guest_user': GUEST_USER,
|
||||||
|
'show_institution': show_institution,
|
||||||
|
'institutions': institutions,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -2098,51 +2116,40 @@ def sys_inst_admin(request):
|
|||||||
'page_next': page_next,
|
'page_next': page_next,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
|
||||||
@sys_staff_required
|
|
||||||
def sys_inst_search_inst(request):
|
|
||||||
key = request.GET.get('q', '')
|
|
||||||
if not key:
|
|
||||||
return HttpResponse(json.dumps({'error': "q invalid"}),
|
|
||||||
status=400)
|
|
||||||
institutions = [dict([('name', inst.name)]) for inst in Institution.objects.filter(name__contains=key)]
|
|
||||||
institutions.append({'name': 'None'})
|
|
||||||
return HttpResponse(json.dumps({"insts": institutions}), status=200,
|
|
||||||
content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@sys_staff_required
|
@sys_staff_required
|
||||||
@require_POST
|
@require_POST
|
||||||
def sys_inst_add_user(request, inst_id):
|
def sys_inst_add_user(request, inst_id):
|
||||||
content_type = 'application/json; charset=utf-8'
|
content_type = 'application/json; charset=utf-8'
|
||||||
get_email = request.POST.get('email', '')
|
|
||||||
email_list = [em.strip() for em in get_email.split(',') if em.strip()]
|
emails = request.POST.get('emails', '')
|
||||||
|
email_list = [em.strip() for em in emails.split(',') if em.strip()]
|
||||||
if len(email_list) == 0:
|
if len(email_list) == 0:
|
||||||
return HttpResponse(json.dumps({'error': "User can't be empty"}),
|
return HttpResponse(json.dumps({'error': "Emails can't be empty"}),
|
||||||
status=400)
|
status=400)
|
||||||
try:
|
try:
|
||||||
inst = Institution.objects.get(pk=inst_id)
|
inst = Institution.objects.get(pk=inst_id)
|
||||||
except Institution.DoesNotExist:
|
except Institution.DoesNotExist:
|
||||||
return HttpResponse(json.dumps({'error': "Inst does not exists"}),
|
return HttpResponse(json.dumps({'error': "Institution does not exist"}),
|
||||||
status=400)
|
status=400)
|
||||||
|
|
||||||
for email in email_list:
|
for email in email_list:
|
||||||
try:
|
try:
|
||||||
User.objects.get(email=email)
|
User.objects.get(email=email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.error(request, u'Failed to add %s to institution: user does not exist.' % email)
|
messages.error(request, u'Failed to add %s to the institution: user does not exist.' % email)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
profile = Profile.objects.get_profile_by_user(email)
|
profile = Profile.objects.get_profile_by_user(email)
|
||||||
if not profile:
|
if not profile:
|
||||||
profile = Profile.objects.add_or_update(email, email)
|
profile = Profile.objects.add_or_update(email, email)
|
||||||
if profile.institution:
|
if profile.institution:
|
||||||
messages.error(request, _(u"Failed to add %s to institution: user already have institution") % email)
|
messages.error(request, _(u"Failed to add %s to the institution: user already belongs to an institution") % email)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
profile.institution = inst.name
|
profile.institution = inst.name
|
||||||
profile.save()
|
profile.save()
|
||||||
messages.success(request, _(u'Successfully add %s to institution.') % email)
|
messages.success(request, _(u'Successfully added %s to the institution.') % email)
|
||||||
|
|
||||||
return HttpResponse(json.dumps({'success': True}),
|
return HttpResponse(json.dumps({'success': True}),
|
||||||
content_type=content_type)
|
content_type=content_type)
|
||||||
|
Reference in New Issue
Block a user