mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 07:55:36 +00:00
revert file from history
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
<td>
|
||||
{% if not commit.is_current_version %}
|
||||
{% if is_owner %}
|
||||
<a href="{{ SITE_ROOT }}repo/file_revisions/{{ repo.id }}/?commit={{ commit.id }}&p={{path|urlencode}}&op=revert" class="file-revert op">还原</a>
|
||||
<a href="{{ SITE_ROOT }}repo/revert_file/{{ repo.id }}/?commit={{ commit.id }}&p={{path|urlencode}}" class="file-revert op">还原</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<a href="{{ SITE_ROOT }}repo/file_revisions/{{ repo.id }}/?commit={{ commit.id }}&p={{path|urlencode}}&op=download" class="file-download op">下载</a>
|
||||
|
@@ -185,6 +185,9 @@
|
||||
<li><a class="op file-cp" href="#" data="{{ dirent.obj_name }}">复制</a></li>
|
||||
<li><a class="op file-update" href="{{ SITE_ROOT }}repo/update_file/{{repo.id}}/?p={{ path|urlencode }}{{dirent.obj_name|urlencode}}">更新</a></li>
|
||||
{% endif %}
|
||||
{% if view_history and request.user.is_authenticated %}
|
||||
<li><a href="{{ SITE_ROOT }}repo/revert_file/{{ repo.id }}/?commit={{ current_commit.id }}&p={{path|urlencode}}{{ dirent.obj_name|urlencode }}" class="op file-revert">还原</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
3
urls.py
3
urls.py
@@ -11,7 +11,7 @@ from seahub.views import root, myhome, \
|
||||
seafile_access_check, repo_history_changes, \
|
||||
repo_upload_file, file_upload_progress_page, \
|
||||
get_subdir, file_move, repo_new_dir, repo_new_file, repo_rename_file, validate_filename, \
|
||||
repo_create, repo_update_file, file_revisions, \
|
||||
repo_create, repo_update_file, repo_revert_file, file_revisions, \
|
||||
get_shared_link, view_shared_file, remove_shared_link, send_shared_link, \
|
||||
crocodoc_upload, crocodoc_status, crocodoc_session
|
||||
from seahub.notifications.views import notification_list
|
||||
@@ -55,6 +55,7 @@ urlpatterns = patterns('',
|
||||
(r'^repo/create/$', repo_create),
|
||||
(r'^repo/upload_check/$', validate_filename),
|
||||
(r'^repo/file_rename/$', repo_rename_file),
|
||||
url(r'^repo/revert_file/(?P<repo_id>[^/]+)/$', repo_revert_file, name='repo_revert_file'),
|
||||
url(r'^repo/upload_file/(?P<repo_id>[^/]+)/$', repo_upload_file, name='repo_upload_file'),
|
||||
url(r'^repo/update_file/(?P<repo_id>[^/]+)/$', repo_update_file, name='repo_update_file'),
|
||||
url(r'^repo/file_revisions/(?P<repo_id>[^/]+)/$', file_revisions, name='file_revisions'),
|
||||
|
44
views.py
44
views.py
@@ -468,11 +468,8 @@ def repo_history_revert(request, repo_id):
|
||||
if not commit_id:
|
||||
return render_error(request, u'请指定历史记录 ID')
|
||||
|
||||
res = request.user.username.split('@')
|
||||
user_name = res[0]
|
||||
|
||||
try:
|
||||
seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, user_name)
|
||||
seafserv_threaded_rpc.revert_on_server(repo_id, commit_id, request.user.username)
|
||||
except SearpcError, e:
|
||||
if e.msg == 'Bad arguments':
|
||||
return render_error(request, u'非法参数')
|
||||
@@ -1599,6 +1596,30 @@ def render_file_revisions (request, repo_id):
|
||||
'is_owner': is_owner,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def repo_revert_file (request, repo_id):
|
||||
commit_id = request.GET.get('commit')
|
||||
path = request.GET.get('p')
|
||||
|
||||
if not (commit_id and path):
|
||||
return render_error(request, u"参数错误")
|
||||
|
||||
try:
|
||||
ret = seafserv_threaded_rpc.revert_file (repo_id, commit_id,
|
||||
path.encode('utf-8'), request.user.username)
|
||||
except Exception, e:
|
||||
return render_error(request, str(e))
|
||||
else:
|
||||
url = reverse('repo', args=[repo_id])
|
||||
if ret == 1:
|
||||
msg = u"已经还原被删除的文件 %s 到根目录下" % path.lstrip('/')
|
||||
messages.add_message(request, messages.INFO, msg)
|
||||
else:
|
||||
msg = u"已经还原文件 %s" % path.lstrip('/')
|
||||
messages.add_message(request, messages.INFO, msg)
|
||||
url += u'?p=%s' % os.path.dirname(path)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@login_required
|
||||
def file_revisions(request, repo_id):
|
||||
if request.method != 'GET':
|
||||
@@ -1607,7 +1628,7 @@ def file_revisions(request, repo_id):
|
||||
op = request.GET.get('op')
|
||||
if not op:
|
||||
return render_file_revisions(request, repo_id)
|
||||
elif op != 'revert' and op != 'download' and op != 'view':
|
||||
elif op != 'download' and op != 'view':
|
||||
return render_error(request)
|
||||
|
||||
commit_id = request.GET.get('commit')
|
||||
@@ -1616,18 +1637,7 @@ def file_revisions(request, repo_id):
|
||||
if not (commit_id and path):
|
||||
return render_error(request)
|
||||
|
||||
if op == 'revert':
|
||||
try:
|
||||
seafserv_threaded_rpc.revert_file (repo_id, commit_id,
|
||||
path, request.user.username)
|
||||
except Exception, e:
|
||||
return render_error(request, str(e))
|
||||
else:
|
||||
parent_dir = os.path.dirname(path)
|
||||
url = reverse('repo', args=[repo_id]) + ('?p=%s' % parent_dir)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
elif op == 'download':
|
||||
if op == 'download':
|
||||
def handle_download():
|
||||
parent_dir = os.path.dirname(path)
|
||||
file_name = os.path.basename(path)
|
||||
|
Reference in New Issue
Block a user