mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 02:48:51 +00:00
add 'add-admin' to sys/useradmin/
This commit is contained in:
@@ -9,38 +9,65 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block right_panel %}
|
||||
<div class="tabnav ovhd">
|
||||
<ul class="tabnav-tabs fleft">
|
||||
<li class="tabnav-tab tabnav-tab-cur"><a href="{% url 'sys_useradmin' %}">{% trans "Database" %}</a></li>
|
||||
<div id="tabs" class="tab-tabs">
|
||||
<div class="hd ovhd">
|
||||
<ul class="tab-tabs-nav fleft">
|
||||
<li class="tab"><a href="#user" class="a" id="user-tab">{% trans "User" %}</a></li>
|
||||
<li class="tab"><a href="#admin" class="a" id="admin-tab">{% trans "Admin" %}</a></li>
|
||||
{% if have_ldap %}
|
||||
<li class="tabnav-tab"><a href="{% url 'sys_ldap_useradmin' %}">{% trans "LDAP" %}</a></li>
|
||||
<li class="tab"><a href="{% url 'sys_ldap_useradmin' %}" class="a" id="ldap-tab">{% trans "LDAP" %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<button id="add-user-btn" class="fright"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "Add user" %}</span></button>
|
||||
</div>
|
||||
<div class="fright">
|
||||
<button id="add-user-btn" class="hide"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "Add user"%}</span></button>
|
||||
<button id="add-admin-btn" class="hide"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "Add admin"%}</span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
||||
<h3>{% trans "Add user" %}</h3>
|
||||
<label for="id_email">{% trans "Email" %}</label><br />
|
||||
<input type="text" name="email" id="id_email" 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>
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
<form id="add-user-form" action="" method="post" class="hide">{% csrf_token %}
|
||||
<h3>{% trans "Add user" %}</h3>
|
||||
<label for="id_email">{% trans "Email" %}</label><br />
|
||||
<input type="text" name="email" id="id_email" 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>
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
|
||||
{% include "sysadmin/useradmin_table.html"%}
|
||||
{% include "sysadmin/useradmin_paginator.html" %}
|
||||
{% include "sysadmin/useradmin_table.html"%}
|
||||
{% include "sysadmin/useradmin_add_form.html" %}
|
||||
|
||||
<div id="activate-msg" class="hide">
|
||||
<p>{% trans "Activating..., please wait" %}</p>
|
||||
<div id="activate-msg" class="hide">
|
||||
<p>{% trans "Activating..., please wait" %}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
{% block extra_script %}{{block.super}}
|
||||
<script type="text/javascript">
|
||||
|
||||
var cur_tab = $('.ui-tabs-selected .a');
|
||||
var add_user_btn = $('#add-user-btn'),
|
||||
add_admin_btn = $('#add-admin-btn');
|
||||
if (cur_tab.attr('id') == 'user-tab') {
|
||||
add_user_btn.removeClass('hide');
|
||||
}
|
||||
if (cur_tab.attr('id') == 'admin-tab') {
|
||||
add_admin_btn.removeClass('hide');
|
||||
}
|
||||
$('#user-tab').click(function() {
|
||||
add_user_btn.removeClass('hide');
|
||||
add_admin_btn.addClass('hide');
|
||||
});
|
||||
$('#admin-tab').click(function() {
|
||||
add_admin_btn.removeClass('hide');
|
||||
add_user_btn.addClass('hide');
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('#add-user-form').submit(function() {
|
||||
var form = $(this),
|
||||
form_id = $(this).attr('id'),
|
||||
@@ -96,5 +123,6 @@ $('#add-user-form').submit(function() {
|
||||
});
|
||||
|
||||
{% include "sysadmin/useradmin_js.html" %}
|
||||
{% include "sysadmin/useradmin_add_js.html" %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
43
seahub/templates/sysadmin/useradmin_add_form.html
Normal file
43
seahub/templates/sysadmin/useradmin_add_form.html
Normal file
@@ -0,0 +1,43 @@
|
||||
{% load i18n avatar_tags %}
|
||||
<form id="add-admin-form" method="post" name="add-admin-form" class="tab-popup hide">{% csrf_token %}
|
||||
<h3 class="hd">{% trans "Add admins"%}</h3>
|
||||
<div id="add-admin-tabs" class="tab-popup-tabs">
|
||||
<ul class="tab-popup-tabs-nav">
|
||||
<li class="tab"><a href="#enter" class="a">{% trans 'Enter' %}</a></li>
|
||||
{%comment%}
|
||||
<li class="tab"><a href="#user-options" class="a">{% trans 'Users' %}</a></li>
|
||||
{%endcomment%}
|
||||
</ul>
|
||||
<div id="enter">
|
||||
<textarea id="added-member-name" name="user_email" placeholder="{% trans "emails, separated by ','" %}"></textarea><br />
|
||||
{% if cloud_mode and not org %}
|
||||
<p class="tip">{% trans "Tip: an invitation will be sent if the email is not registered."%}</p>
|
||||
{% else %}
|
||||
<p class="tip">{% trans "Tip: the emails should be the users already added."%}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%comment%}
|
||||
<div id="user-options" class="hide">
|
||||
<ul class="option-list">
|
||||
{% for user in users %}
|
||||
{% if not user.is_self %}
|
||||
{% if not user.is_staff %}
|
||||
<li>
|
||||
<label class="checkbox-label">
|
||||
<span class="checkbox"><input type="checkbox" name="user" value="{{ user.email }}" class="checkbox-orig" /></span>
|
||||
{% avatar user.email 20 %} <span class="checkbox-option">{{ user.email }}</span>
|
||||
</label>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{%endcomment%}
|
||||
</div>
|
||||
<div class="bot">
|
||||
<p class="error hide"></p>
|
||||
<input type="submit" value="{% trans "Submit"%}" />
|
||||
</div>
|
||||
</form>
|
||||
|
66
seahub/templates/sysadmin/useradmin_add_js.html
Normal file
66
seahub/templates/sysadmin/useradmin_add_js.html
Normal file
@@ -0,0 +1,66 @@
|
||||
{% load i18n %}
|
||||
|
||||
var user_list = [], user_email;
|
||||
{% for user in users %}
|
||||
{% if not user.is_self %}
|
||||
{% if not user.is_staff %}
|
||||
user_email = '{{ user.email }}';
|
||||
user_list.push({value:user_email, label:user_email});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
$('#add-admin-btn').click(function() {
|
||||
var form = $("#add-admin-form");
|
||||
form.modal({appendTo: "#main", focus:false});
|
||||
$('#simplemodal-container').css({'height':'auto', 'padding':0});
|
||||
$('#add-admin-tabs').tabs();
|
||||
|
||||
addAutocomplete('#added-member-name', '#enter', user_list);
|
||||
});
|
||||
|
||||
$('#add-admin-form').submit(function() {
|
||||
var form = $(this),
|
||||
cur_tab_id = $('.ui-tabs-selected a', form).attr('href'),
|
||||
post_data = '',
|
||||
input = $('[name="user_email"]', form);
|
||||
switch(cur_tab_id) {
|
||||
case '#enter':
|
||||
post_data = input.val();
|
||||
break;
|
||||
case '#user-options':
|
||||
$(cur_tab_id + ' .checkbox-checked .checkbox-orig').each(function() {
|
||||
post_data += $(this).val() + ',';
|
||||
});
|
||||
input.val(post_data);
|
||||
}
|
||||
if (!post_data) {
|
||||
apply_form_error(form.attr('id'), '{% trans "Please enter emails, or select some." %}');
|
||||
return false;
|
||||
}
|
||||
|
||||
var submit_btn = $('[type="submit"]', form);
|
||||
disable(submit_btn);
|
||||
$.ajax({
|
||||
url: '{% url 'batch_user_make_admin' %}',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: prepareCSRFToken,
|
||||
data: {
|
||||
'set_admin_emails': post_data
|
||||
},
|
||||
success: function(data) {
|
||||
location.reload('true');
|
||||
},
|
||||
error: function(data, textStatus, jqXHR) {
|
||||
var errors = $.parseJSON(data.responseText);
|
||||
$.each(errors, function(index, value) {
|
||||
apply_form_error(form.attr('id'), value);
|
||||
});
|
||||
enable(submit_btn);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
@@ -1,60 +1,126 @@
|
||||
{% load seahub_tags i18n %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="25%">{% trans "Email" %}</th>
|
||||
<th width="15%">{% trans "Status" %}</th>
|
||||
<th width="15%">{% trans "Space Used" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="23%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
<div id="user">
|
||||
<table>
|
||||
<tr>
|
||||
<th width="28%">{% trans "Email" %}</th>
|
||||
<th width="15%">{% trans "Status" %}</th>
|
||||
<th width="15%">{% trans "Space Used" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="20%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td data="{{user.id}}"><a href="{{ SITE_ROOT }}useradmin/info/{{ user.props.email }}/">{{ user.email }}</a></td>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td data="{{user.id}}"><a href="{{ SITE_ROOT }}useradmin/info/{{ user.props.email }}/">{{ user.email }}</a></td>
|
||||
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
<div class="user-status">
|
||||
{% if user.is_active %}
|
||||
<span class="user-status-cur-value">{% trans "Active" %}</span>
|
||||
{% else %}
|
||||
<span class="user-status-cur-value">{% trans "Inactive" %}</span>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
<div class="user-status">
|
||||
{% if user.is_active %}
|
||||
<span class="user-status-cur-value">{% trans "Active" %}</span>
|
||||
{% else %}
|
||||
<span class="user-status-cur-value">{% trans "Inactive" %}</span>
|
||||
{% endif %}
|
||||
<img src="{{MEDIA_URL}}img/edit_12.png" alt="{% trans "Edit"%}" title="{% trans "Edit"%}" class="user-status-edit-icon cspt vh" />
|
||||
</div>
|
||||
<select name="permission" class="user-status-select hide">
|
||||
<option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
|
||||
<option value="0" {%if not user.is_active %}selected="selected"{% endif %}>{% trans "Inactive"%}</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
<img src="{{MEDIA_URL}}img/edit_12.png" alt="{% trans "Edit"%}" title="{% trans "Edit"%}" class="user-status-edit-icon cspt vh" />
|
||||
</div>
|
||||
<select name="permission" class="user-status-select hide">
|
||||
<option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
|
||||
<option value="0" {%if not user.is_active %}selected="selected"{% endif %}>{% trans "Inactive"%}</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
</td>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% if CALC_SHARE_USAGE %}
|
||||
{{ user.self_usage|filesizeformat }} + {{ user.share_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% else %}
|
||||
{{ user.self_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{{ user.ctime|tsstr_sec }} /<br />
|
||||
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{% if not user.is_self %}
|
||||
<a href="#" class="remove-user-btn op vh" data-url="{{ SITE_ROOT }}useradmin/remove/{{ user.props.id }}/" data-target="{{ user.props.email }}">{% trans "Delete" %}</a>
|
||||
<a href="#" class="reset-user-btn op vh" data-url="{% url 'user_reset' user.id %}" data-target="{{ user.props.email }}">{% trans "ResetPwd" %}</a>
|
||||
{%comment%}
|
||||
{% if user.is_staff %}
|
||||
<a href="#" data-url="{% url 'user_remove_admin' user.id %}" data-target="{{ user.props.email }}" class="revoke-admin-btn op vh">{% trans "Revoke Admin" %}</a>
|
||||
{% else %}
|
||||
<a href="#" data-url="{% url 'user_make_admin' user.id %}" data-target="{{ user.props.email }}" class="set-admin-btn op vh">{% trans "Set Admin" %}</a>
|
||||
{% endif %}
|
||||
{%endcomment%}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% include "sysadmin/useradmin_paginator.html" %}
|
||||
</div>
|
||||
<div class="hide" id="admin">
|
||||
<table>
|
||||
<tr>
|
||||
<th width="28%">{% trans "Email" %}</th>
|
||||
<th width="15%">{% trans "Status" %}</th>
|
||||
<th width="15%">{% trans "Space Used" %}</th>
|
||||
<th width="22%">{% trans "Create At / Last Login" %}</th>
|
||||
<th width="20%">{% trans "Operations" %}</th>
|
||||
</tr>
|
||||
|
||||
{% for user in users %}
|
||||
{% if user.is_staff %}
|
||||
<tr>
|
||||
<td data="{{user.id}}"><a href="{{ SITE_ROOT }}useradmin/info/{{ user.props.email }}/">{{ user.email }}</a></td>
|
||||
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
<div class="user-status">
|
||||
{% if user.is_active %}
|
||||
<span class="user-status-cur-value">{% trans "Active" %}</span>
|
||||
{% else %}
|
||||
<span class="user-status-cur-value">{% trans "Inactive" %}</span>
|
||||
{% endif %}
|
||||
<img src="{{MEDIA_URL}}img/edit_12.png" alt="{% trans "Edit"%}" title="{% trans "Edit"%}" class="user-status-edit-icon cspt vh" />
|
||||
</div>
|
||||
<select name="permission" class="user-status-select hide">
|
||||
<option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
|
||||
<option value="0" {%if not user.is_active %}selected="selected"{% endif %}>{% trans "Inactive"%}</option>
|
||||
</select>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% if CALC_SHARE_USAGE %}
|
||||
{{ user.self_usage|filesizeformat }} + {{ user.share_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% else %}
|
||||
{{ user.self_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{{ user.ctime|tsstr_sec }} /<br />
|
||||
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{% if not user.is_self %}
|
||||
<a href="#" class="remove-user-btn op vh" data-url="{{ SITE_ROOT }}useradmin/remove/{{ user.props.id }}/" data-target="{{ user.props.email }}">{% trans "Delete" %}</a>
|
||||
<a href="#" class="reset-user-btn op vh" data-url="{% url 'user_reset' user.id %}" data-target="{{ user.props.email }}">{% trans "ResetPwd" %}</a>
|
||||
<a href="#" data-url="{% url 'user_remove_admin' user.id %}" data-target="{{ user.props.email }}" class="revoke-admin-btn op vh">{% trans "Revoke Admin" %}</a>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<td>
|
||||
{% if CALC_SHARE_USAGE %}
|
||||
{{ user.self_usage|filesizeformat }} + {{ user.share_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% else %}
|
||||
{{ user.self_usage|filesizeformat }} {% if user.quota > 0 %} / {{ user.quota|filesizeformat }} {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{{ user.ctime|tsstr_sec }} /<br />
|
||||
{% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.source != 'LDAP' %}
|
||||
{% if not user.is_self %}
|
||||
<a href="#" class="remove-user-btn op vh" data-url="{{ SITE_ROOT }}useradmin/remove/{{ user.props.id }}/" data-target="{{ user.props.email }}">{% trans "Delete" %}</a>
|
||||
<a href="#" class="reset-user-btn op vh" data-url="{% url 'user_reset' user.id %}" data-target="{{ user.props.email }}">{% trans "ResetPwd" %}</a>
|
||||
{% if user.is_staff %}
|
||||
<a href="#" data-url="{% url 'user_remove_admin' user.id %}" data-target="{{ user.props.email }}" class="revoke-admin-btn op vh">{% trans "Revoke Admin" %}</a>
|
||||
{% else %}
|
||||
<a href="#" data-url="{% url 'user_make_admin' user.id %}" data-target="{{ user.props.email }}" class="set-admin-btn op vh">{% trans "Set Admin" %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@@ -20,7 +20,8 @@ from seahub.views.sysadmin import sys_repo_admin, sys_user_admin, user_search,\
|
||||
sys_group_admin, user_info, user_add, user_remove, user_make_admin, \
|
||||
user_remove_admin, user_reset, user_activate, sys_publink_admin, \
|
||||
sys_repo_search, sys_repo_transfer, sys_list_orphan, user_deactivate, \
|
||||
user_toggle_status, user_set_quota, sys_ldap_user_admin, sys_list_system
|
||||
user_toggle_status, user_set_quota, sys_ldap_user_admin, sys_list_system, \
|
||||
batch_user_make_admin
|
||||
from seahub.views.ajax import *
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
@@ -194,6 +195,9 @@ urlpatterns = patterns('',
|
||||
url(r'^useradmin/(?P<email>[^/]+)/set_quota/$', user_set_quota, name='user_set_quota'),
|
||||
|
||||
url(r'^useradmin/password/reset/(?P<user_id>[^/]+)/$', user_reset, name='user_reset'),
|
||||
|
||||
url(r'^useradmin/batchmakeadmin/$', batch_user_make_admin, name='batch_user_make_admin'),
|
||||
|
||||
)
|
||||
|
||||
if settings.SERVE_STATIC:
|
||||
|
@@ -23,7 +23,7 @@ from seahub.base.accounts import User
|
||||
from seahub.base.models import UserLastLogin
|
||||
from seahub.base.decorators import sys_staff_required
|
||||
from seahub.auth.decorators import login_required
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED, string2list
|
||||
from seahub.views import get_system_default_repo_id
|
||||
from seahub.forms import SetUserQuotaForm, AddUserForm
|
||||
from seahub.profile.models import Profile, DetailedProfile
|
||||
@@ -708,3 +708,27 @@ def sys_traffic_admin(request):
|
||||
'page_next': page_next,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
@sys_staff_required
|
||||
def batch_user_make_admin(request):
|
||||
result = {}
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
||||
set_admin_emails = request.POST.get('set_admin_emails')
|
||||
set_admin_emails = string2list(set_admin_emails)
|
||||
|
||||
try:
|
||||
for email in set_admin_emails:
|
||||
print email
|
||||
user = User.objects.get(email=email)
|
||||
user.is_staff = True
|
||||
user.save()
|
||||
result['success'] = True
|
||||
messages.success(request, _(u'Successfully patch set admin'))
|
||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||
except Exception, e:
|
||||
result['success'] = False
|
||||
messages.error(request, _(e))
|
||||
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
||||
|
||||
|
Reference in New Issue
Block a user