1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 07:41:26 +00:00

Enable library transfer for admin

This commit is contained in:
zhengxie
2013-09-23 16:58:33 +08:00
parent afed88311d
commit dae8c4b575
3 changed files with 64 additions and 4 deletions

View File

@@ -12,8 +12,8 @@
<th width="15%">{% trans "Name" %}</th>
<th width="25%">ID</th>
<th width="20%">{% trans "Owner" %}</th>
<th width="30%">{% trans "Description" %}</th>
<th width="10%">{% trans "Operations" %}</th>
<th width="27%">{% trans "Description" %}</th>
<th width="13%">{% trans "Operations" %}</th>
</tr>
{% for repo in repos %}
<tr>
@@ -21,7 +21,11 @@
<td style="font-size:11px;">{{ repo.id }}</td>
<td><a href="{{ SITE_ROOT }}useradmin/info/{{ repo.owner }}/">{{ repo.owner}}</a></td>
<td>{{ repo.props.desc }}</td>
<td><a href="#" data-url="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/?next={{ request.path }}" data-target="{{ repo.props.name }}" class="repo-delete-btn op">{% trans "Delete" %}</a></td>
<td>
<a href="#" data-url="{{ SITE_ROOT }}repo/remove/{{ repo.props.id }}/?next={{ request.path }}" data-target="{{ repo.props.name }}" class="repo-delete-btn op">{% trans "Delete" %}</a>
<a href="#" data-id="{{repo.id}}" data-name="{{repo.name}}" class="repo-transfer-btn op">{% trans "Transfer" %}</a>
</td>
</tr>
{% endfor %}
</table>
@@ -56,6 +60,18 @@
{% else %}
<p>{% trans "Empty" %}</p>
{% endif %}
<form id="repo-transfer-form" method="post" action="{% url 'sys_repo_transfer' %}" class="simple-input-popup hide">{% csrf_token %}
<h3>{% trans "Transfer Library"%}</h3>
<label>{% trans "Email" %}</label><br />
<input type="text" name="email" value="" class="long-input"/><br />
<input type="hidden" name="repo_id" value="" />
<p class="error hide"></p>
<input type="submit" value="{% trans "Submit" %}" class="submit" />
<button class="simplemodal-close">{% trans "Cancel" %}</button>
</form>
{% endblock %}
{% block extra_script %}
@@ -69,6 +85,26 @@ $('#search-repo-btn').click(function() {
location.href = "{% url 'sys_repo_search' %}";
});
$('.repo-transfer-btn').click(function(){
var repo_id = $(this).data('id'),
repo_name = $(this).data('name'),
form = $('#repo-transfer-form');
$('#repo-transfer-form input[name="repo_id"]').val(repo_id);
form.modal({appendTo:'#main'});
return false;
});
$('#repo-transfer-form').submit(function() {
var form = $(this),
form_id = form.attr('id'),
email = $.trim(form.children('[name="email"]').val());
if (!email) {
apply_form_error(form_id, "{% trans "Email cannot be blank" %}");
return false;
}
form.submit();
});
</script>
{% endblock %}

View File

@@ -18,7 +18,7 @@ from seahub.views.wiki import personal_wiki, personal_wiki_pages, \
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_search, sys_repo_transfer
from seahub.views.ajax import *
# Uncomment the next two lines to enable the admin:
@@ -145,6 +145,7 @@ urlpatterns = patterns('',
### system admin ###
(r'^sys/seafadmin/$', sys_repo_admin),
url(r'^sys/seafadmin/search/$', sys_repo_search, name='sys_repo_search'),
url(r'^sys/seafadmin/transfer/$', sys_repo_transfer, name='sys_repo_transfer'),
url(r'^sys/useradmin/$', sys_user_admin, name='sys_useradmin'),
url(r'^sys/groupadmin/$', sys_group_admin, name='sys_group_admin'),
url(r'^sys/publinkadmin/$', sys_publink_admin, name='sys_publink_admin'),

View File

@@ -531,3 +531,26 @@ def user_search(request):
'page_next': page_next,
}, context_instance=RequestContext(request))
@login_required
@sys_staff_required
def sys_repo_transfer(request):
"""Transfer a repo to others.
"""
if request.method != 'POST':
raise Http404
repo_id = request.POST.get('repo_id', None)
new_owner = request.POST.get('email', None)
if repo_id and new_owner:
try:
User.objects.get(email=new_owner)
seafile_api.set_repo_owner(repo_id, new_owner)
messages.success(request, _(u'Successfully transfered.'))
except User.DoesNotExist:
messages.error(request, _(u'Failed to transfer, user %s not found') % new_owner)
else:
messages.error(request, _(u'Failed to transfer, invalid arguments.'))
return HttpResponseRedirect(reverse(sys_repo_admin))