mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-21 03:18:23 +00:00
update institution admin page (#5303)
can't operate system/institution admin Co-authored-by: lian <lian@seafile.com>
This commit is contained in:
@@ -34,7 +34,9 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<span class="user-status-cur-value">{% trans "Inactive" %}</span>
|
<span class="user-status-cur-value">{% trans "Inactive" %}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if not user.is_self and not user.is_staff and not user.is_institution_admin %}
|
||||||
<span title="{% trans "Edit"%}" class="user-status-edit-icon sf2-icon-edit op-icon vh"></span>
|
<span title="{% trans "Edit"%}" class="user-status-edit-icon sf2-icon-edit op-icon vh"></span>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<select name="permission" class="user-status-select hide">
|
<select name="permission" class="user-status-select hide">
|
||||||
<option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
|
<option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
|
||||||
@@ -53,7 +55,7 @@
|
|||||||
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if not user.is_self %}
|
{% if not user.is_self and not user.is_staff and not user.is_institution_admin %}
|
||||||
<a href="#" class="remove-user-btn op vh" data-url="{% url 'institutions:user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
|
<a href="#" class="remove-user-btn op vh" data-url="{% url 'institutions:user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
@@ -51,7 +51,7 @@
|
|||||||
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if not user.is_self %}
|
{% if not user.is_self and not user.is_staff and not user.is_institution_admin %}
|
||||||
<a href="#" class="remove-user-btn op vh" data-url="{% url 'institutions:user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
|
<a href="#" class="remove-user-btn op vh" data-url="{% url 'institutions:user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
@@ -23,7 +23,8 @@ from seahub.profile.models import Profile, DetailedProfile
|
|||||||
from seahub.utils import is_valid_username
|
from seahub.utils import is_valid_username
|
||||||
from seahub.utils.rpc import mute_seafile_api
|
from seahub.utils.rpc import mute_seafile_api
|
||||||
from seahub.utils.file_size import get_file_size_unit
|
from seahub.utils.file_size import get_file_size_unit
|
||||||
from seahub.views.sysadmin import email_user_on_activation, populate_user_info
|
from seahub.views.sysadmin import email_user_on_activation
|
||||||
|
from seahub.institutions.models import InstitutionAdmin
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ def _populate_user_quota_usage(user):
|
|||||||
user.space_usage = -1
|
user.space_usage = -1
|
||||||
user.space_quota = -1
|
user.space_quota = -1
|
||||||
|
|
||||||
|
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
def info(request):
|
def info(request):
|
||||||
"""List instituion info.
|
"""List instituion info.
|
||||||
@@ -52,6 +54,7 @@ def info(request):
|
|||||||
'inst': inst,
|
'inst': inst,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
def useradmin(request):
|
def useradmin(request):
|
||||||
"""List users in the institution.
|
"""List users in the institution.
|
||||||
@@ -71,10 +74,15 @@ def useradmin(request):
|
|||||||
page_next = True
|
page_next = True
|
||||||
else:
|
else:
|
||||||
page_next = False
|
page_next = False
|
||||||
users = [User.objects.get(x) for x in usernames[:per_page]]
|
|
||||||
|
|
||||||
|
users = [User.objects.get(x) for x in usernames[:per_page]]
|
||||||
|
admin_emails = [user.user for user in InstitutionAdmin.objects.filter(institution=inst)]
|
||||||
last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users])
|
last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users])
|
||||||
|
|
||||||
for u in users:
|
for u in users:
|
||||||
|
|
||||||
|
u.is_institution_admin = u.email in admin_emails
|
||||||
|
|
||||||
if u.username == request.user.username:
|
if u.username == request.user.username:
|
||||||
u.is_self = True
|
u.is_self = True
|
||||||
|
|
||||||
@@ -94,6 +102,7 @@ def useradmin(request):
|
|||||||
'page_next': page_next,
|
'page_next': page_next,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
def useradmin_search(request):
|
def useradmin_search(request):
|
||||||
"""Search users in the institution.
|
"""Search users in the institution.
|
||||||
@@ -107,9 +116,13 @@ def useradmin_search(request):
|
|||||||
profiles = Profile.objects.filter(institution=inst.name)
|
profiles = Profile.objects.filter(institution=inst.name)
|
||||||
usernames = [x.user for x in profiles if q in x.user]
|
usernames = [x.user for x in profiles if q in x.user]
|
||||||
users = [User.objects.get(x) for x in usernames]
|
users = [User.objects.get(x) for x in usernames]
|
||||||
|
admin_emails = [user.user for user in InstitutionAdmin.objects.filter(institution=inst)]
|
||||||
last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users])
|
last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users])
|
||||||
|
|
||||||
for u in users:
|
for u in users:
|
||||||
|
|
||||||
|
u.is_institution_admin = u.email in admin_emails
|
||||||
|
|
||||||
if u.username == request.user.username:
|
if u.username == request.user.username:
|
||||||
u.is_self = True
|
u.is_self = True
|
||||||
|
|
||||||
@@ -125,6 +138,7 @@ def useradmin_search(request):
|
|||||||
'q': q,
|
'q': q,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
@inst_admin_can_manage_user
|
@inst_admin_can_manage_user
|
||||||
def user_info(request, email):
|
def user_info(request, email):
|
||||||
@@ -165,18 +179,20 @@ def user_info(request, email):
|
|||||||
|
|
||||||
available_quota = get_institution_available_quota(request.user.institution)
|
available_quota = get_institution_available_quota(request.user.institution)
|
||||||
|
|
||||||
return render(request,
|
return render(request,
|
||||||
'institutions/user_info.html', {
|
'institutions/user_info.html',
|
||||||
'owned_repos': owned_repos,
|
{
|
||||||
'space_quota': space_quota,
|
'owned_repos': owned_repos,
|
||||||
'space_usage': space_usage,
|
'space_quota': space_quota,
|
||||||
'in_repos': in_repos,
|
'space_usage': space_usage,
|
||||||
'email': email,
|
'in_repos': in_repos,
|
||||||
'profile': profile,
|
'email': email,
|
||||||
'd_profile': d_profile,
|
'profile': profile,
|
||||||
'personal_groups': personal_groups,
|
'd_profile': d_profile,
|
||||||
'available_quota': available_quota,
|
'personal_groups': personal_groups,
|
||||||
})
|
'available_quota': available_quota,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
@@ -189,13 +205,19 @@ def user_remove(request, email):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(email=email)
|
user = User.objects.get(email=email)
|
||||||
user.delete()
|
|
||||||
messages.success(request, _('Successfully deleted %s') % user.username)
|
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
messages.error(request, _('Failed to delete: the user does not exist'))
|
messages.error(request, _('Failed to delete: the user does not exist'))
|
||||||
|
return HttpResponseRedirect(next_page)
|
||||||
|
|
||||||
|
if user.is_staff:
|
||||||
|
messages.error(request, _('Failed to delete: the user is system administrator'))
|
||||||
|
return HttpResponseRedirect(next_page)
|
||||||
|
|
||||||
|
user.delete()
|
||||||
|
messages.success(request, _('Successfully deleted %s') % user.username)
|
||||||
return HttpResponseRedirect(next_page)
|
return HttpResponseRedirect(next_page)
|
||||||
|
|
||||||
|
|
||||||
@login_required_ajax
|
@login_required_ajax
|
||||||
@require_POST
|
@require_POST
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
@@ -208,14 +230,14 @@ def user_set_quota(request, email):
|
|||||||
available_quota = get_institution_available_quota(request.user.institution)
|
available_quota = get_institution_available_quota(request.user.institution)
|
||||||
if available_quota < quota:
|
if available_quota < quota:
|
||||||
result = {}
|
result = {}
|
||||||
result['error'] = _('Failed to set quota: maximum quota is %d MB' % \
|
result['error'] = _('Failed to set quota: maximum quota is %d MB' % (available_quota / 10 ** 6))
|
||||||
(available_quota / 10 ** 6))
|
|
||||||
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
||||||
|
|
||||||
seafile_api.set_user_quota(email, quota)
|
seafile_api.set_user_quota(email, quota)
|
||||||
|
|
||||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
||||||
|
|
||||||
|
|
||||||
@login_required_ajax
|
@login_required_ajax
|
||||||
@require_POST
|
@require_POST
|
||||||
@inst_admin_required
|
@inst_admin_required
|
||||||
@@ -257,4 +279,3 @@ def user_toggle_status(request, email):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return HttpResponse(json.dumps({'success': False}), status=500,
|
return HttpResponse(json.dumps({'success': False}), status=500,
|
||||||
content_type=content_type)
|
content_type=content_type)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user