1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 14:50:29 +00:00

[repo] online GC.

This commit is contained in:
llj
2014-09-29 18:50:39 +08:00
parent bf9b3be2fb
commit c0553b304b
4 changed files with 122 additions and 1 deletions

View File

@@ -6,7 +6,12 @@
{% block main_panel %}
<div class="w100 ovhd">
<h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
<button data="{% url 'repo' repo.id %}" class="fright" id="back">{% trans "Back to Library" %}</button>
<div class="fright">
{% if is_repo_owner and not use_sqlite %}
<button data="{% url 'repo' repo.id %}" id="online-gc">{% trans "Clean" %}</button>
{% endif %}
<button data="{% url 'repo' repo.id %}" id="back">{% trans "Back to Library" %}</button>
</div>
</div>
<div class="repo-file-list-outer-container">
@@ -92,6 +97,17 @@
</table>
</div>
</div>
{% if is_repo_owner and not use_sqlite %}
<form id="gc-form" class="hide">
<h3>{% trans "Clean" %}</h3>
<p>{% trans "Clean items deleted before the following days:" %}</p>
<input type="text" name="day" class="input" value="" placeholder="{% trans "please input an integer greater than 0" %}" /><br />
<p class="error hide"></p>
<button type="submit" class="submit">{% trans "Submit" %}</button>
<button type="button" class="simplemodal-close">{% trans "Cancel" %}</button>
</form>
{% endif %}
{% endblock %}
{% block extra_script %}
@@ -99,5 +115,35 @@
$('#back').click(function() {
location.href = $(this).attr('data');
});
{% if is_repo_owner and not use_sqlite %}
$('#online-gc').click(function() {
$('#gc-form').modal();
});
$('#gc-form').submit(function () {
var form = $(this);
var day = parseInt($.trim($('[name="day"]', form).val())); // turn the string into int
if (!day || day < 0) { // day can be NaN, 0, -n
apply_form_error(form.attr('id'), "{% trans "Please input a valid number" %}");
return false;
}
disable($('[type="submit"]', form));
form.append('<p style="color:#222;">' + "{% trans "It could take a while, you can close this popup now." %}" + '</p>');
$.ajax({
url: '{% url "repo_online_gc" repo.id %}?day=' + parseInt(day),
dataType: 'json',
cache: false,
success: function () {
$.modal.close();
feedback("{% trans "Clean is done." %}", 'success');
},
error: function (xhr, textStatus, errorThrown) {
$.modal.close();
ajaxErrorHandler(xhr, textStatus, errorThrown);
}
});
return false;
});
{% endif %}
</script>
{% endblock %}

View File

@@ -154,6 +154,7 @@ urlpatterns = patterns('',
url(r'^ajax/space_and_traffic/$', space_and_traffic, name='space_and_traffic'),
url(r'^ajax/my-shared-and-group-repos/$', my_shared_and_group_repos, name='my_shared_and_group_repos'),
url(r'^ajax/events/$', events, name="events"),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/online_gc/$', repo_online_gc, name='repo_online_gc'),
### Organizaion ###
url(r'^pubinfo/libraries/$', pubrepo, name='pubrepo'),

View File

@@ -302,12 +302,26 @@ def render_recycle_root(request, repo_id):
file_list.sort(lambda x, y : cmp(y.delete_time,
x.delete_time))
username = request.user.username
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
use_sqlite = False
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
if 'sqlite' in db_backend:
use_sqlite = True
return render_to_response('repo_recycle_view.html', {
'show_recycle_root': True,
'repo': repo,
'dir_list': dir_list,
'file_list': file_list,
'days': days,
'is_repo_owner': is_repo_owner,
'use_sqlite': use_sqlite,
}, context_instance=RequestContext(request))
def render_recycle_dir(request, repo_id, commit_id):
@@ -334,6 +348,18 @@ def render_recycle_dir(request, repo_id, commit_id):
days = show_delete_days(request)
username = request.user.username
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
use_sqlite = False
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
if 'sqlite' in db_backend:
use_sqlite = True
return render_to_response('repo_recycle_view.html', {
'show_recycle_root': False,
'repo': repo,
@@ -344,6 +370,8 @@ def render_recycle_dir(request, repo_id, commit_id):
'basedir': basedir,
'path': path,
'days': days,
'is_repo_owner': is_repo_owner,
'use_sqlite': use_sqlite,
}, context_instance=RequestContext(request))
@login_required

View File

@@ -1819,3 +1819,49 @@ def events(request):
'events_more': events_more,
'new_start': start}),
content_type='application/json; charset=utf-8')
@login_required_ajax
def repo_online_gc(request, repo_id):
content_type='application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
error = _(u'Library does not exist.')
return HttpResponse(json.dumps({'error': error}), status=400,
content_type=content_type)
day = int(request.GET.get('day'))
if not day:
error = _('Argument missing')
return HttpResponse(json.dumps({'error': error}), status=400,
content_type=content_type)
username = request.user.username
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
if not is_repo_owner:
error = _('Permission denied')
return HttpResponse(json.dumps({'error': error}), status=400,
content_type=content_type)
use_sqlite = False
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
if 'sqlite' in db_backend:
use_sqlite = True
if use_sqlite:
error = _('It is not supported for SQLite')
return HttpResponse(json.dumps({'error': error}), status=400,
content_type=content_type)
try:
seafile_api.clean_up_repo_history(repo.id, day)
except SearpcError, e:
error = _('Internal server error')
return HttpResponse(json.dumps({'error': error}), status=500,
content_type=content_type)
return HttpResponse(json.dumps({'success': True}), content_type=content_type)