1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 18:29:23 +00:00

handle office preview perm check in file revisions

This commit is contained in:
Shuai Lin
2015-07-16 15:31:01 +08:00
parent 075b0d04f6
commit fcf2c992ec
4 changed files with 24 additions and 10 deletions

View File

@@ -1,10 +1,12 @@
{% load i18n %} {% load i18n %}
var OfficePreviewer = function(repo_id, path, token) { var OfficePreviewer = function(repo_id, path, token, commit_id) {
this.repo_id = repo_id; this.repo_id = repo_id;
this.path = path; this.path = path;
this.total_pages = null; this.total_pages = null;
// only non-null when viewing in shared links
this.token = token; this.token = token;
this.commit_id = commit_id;
this.orig_page_width = null; this.orig_page_width = null;
this.orig_page_height = null; this.orig_page_height = null;
@@ -15,11 +17,12 @@ var OfficePreviewer = function(repo_id, path, token) {
this.FIT_TO_WIDTH = 850; // hardcoded in seafevents this.FIT_TO_WIDTH = 850; // hardcoded in seafevents
this.scale_ratio = 1; this.scale_ratio = 1;
this.static_prefix = '{{ SITE_ROOT}}office-convert/static/{{ repo.id }}{{ path|urlencode }}/'; this.static_prefix = '{{ SITE_ROOT}}office-convert/static/{{ repo.id }}/' + this.commit_id + '{{ path|urlencode }}/';
this.page_status_url = function(page) { this.page_status_url = function(page) {
var params = { var params = {
repo_id: repo_id, repo_id: repo_id,
commit_id: this.commit_id,
path: path, path: path,
page: page page: page
}; };
@@ -30,7 +33,11 @@ var OfficePreviewer = function(repo_id, path, token) {
} }
this.page_content_url = function(page) { this.page_content_url = function(page) {
var url = this.static_prefix + page + '.page'; var url = this.static_prefix + page + '.page';
return this.token ? url + '?token=' + this.token : url; var params = {};
if (this.token) {
params['token'] = token;
}
return params ? url + '?' + $.param(params) : url;
} }
var url = window.location.href; var url = window.location.href;
@@ -164,5 +171,6 @@ OfficePreviewer.prototype.load_page = function(index) {
}; };
$(function() { $(function() {
new OfficePreviewer('{{ repo.id }}', '{{ path }}', '{{ shared_token }}').start(); var commit_id = '{{ current_commit.id }}' || '{{ repo.head_cmmt_id }}';
new OfficePreviewer('{{ repo.id }}', '{{ path }}', '{{ shared_token }}', commit_id).start();
}); });

View File

@@ -1,8 +1,10 @@
{% load i18n %} {% load i18n %}
$(function() {
var commit_id = '{{ current_commit.id }}' || '{{ repo.head_cmmt_id }}';
function load_excel() { function load_excel() {
$('#convert-loading').remove(); $('#convert-loading').remove();
var iframe = document.createElement('iframe'); var iframe = document.createElement('iframe');
iframe.src = '{{ SITE_ROOT}}office-convert/static/{{ repo.id }}{{ path|urlencode }}/index.html?token=' + '{{ shared_token }}'; iframe.src = '{{ SITE_ROOT}}office-convert/static/{{ repo.id }}/' + commit_id + '{{ path|urlencode }}/index.html?token=' + '{{ shared_token }}';
$('#spreadsheet-container').append(iframe); $('#spreadsheet-container').append(iframe);
} }
@@ -11,6 +13,7 @@
repo_id: '{{ repo.id }}', repo_id: '{{ repo.id }}',
path: '{{ path }}', path: '{{ path }}',
token: '{{ shared_token }}', token: '{{ shared_token }}',
commit_id: commit_id,
doctype: 'spreadsheet' doctype: 'spreadsheet'
}); });
$.ajax({ $.ajax({
@@ -38,3 +41,4 @@
} }
check_status(); check_status();
});

View File

@@ -302,7 +302,7 @@ if HAS_OFFICE_CONVERTER:
office_convert_query_status, office_convert_get_page, office_convert_add_task office_convert_query_status, office_convert_get_page, office_convert_add_task
) )
urlpatterns += patterns('', urlpatterns += patterns('',
url(r'^office-convert/static/(?P<repo_id>[-0-9a-f]{36})/(?P<path>.+)/(?P<filename>[^/].+)$', url(r'^office-convert/static/(?P<repo_id>[-0-9a-f]{36})/(?P<commit_id>[0-9a-f]{40})/(?P<path>.+)/(?P<filename>[^/].+)$',
office_convert_get_page, office_convert_get_page,
name='office_convert_get_page'), name='office_convert_get_page'),
url(r'^office-convert/status/$', office_convert_query_status, name='office_convert_query_status'), url(r'^office-convert/status/$', office_convert_query_status, name='office_convert_query_status'),

View File

@@ -1333,8 +1333,9 @@ def office_convert_query_status(request, internal=False):
raise Http404 raise Http404
repo_id = request.GET.get('repo_id', '') repo_id = request.GET.get('repo_id', '')
commit_id = request.GET.get('commit_id', '')
path = request.GET.get('path', '') path = request.GET.get('path', '')
if not (repo_id and path): if not (repo_id and path and commit_id):
return HttpResponseBadRequest('invalid params') return HttpResponseBadRequest('invalid params')
page = request.GET.get('page', '') page = request.GET.get('page', '')
@@ -1350,7 +1351,8 @@ def office_convert_query_status(request, internal=False):
if not _check_office_convert_perm(request, repo_id, path): if not _check_office_convert_perm(request, repo_id, path):
return HttpResponseForbidden() return HttpResponseForbidden()
file_id = get_file_id_by_path(repo_id, path) file_id = seafserv_threaded_rpc.get_file_id_by_commit_and_path(repo_id, commit_id, path)
ret = {'success': False} ret = {'success': False}
try: try:
ret = query_office_convert_status(file_id, page, internal=internal) ret = query_office_convert_status(file_id, page, internal=internal)
@@ -1365,7 +1367,7 @@ def office_convert_query_status(request, internal=False):
# * 1.page 2.page for pdf/doc/ppt # * 1.page 2.page for pdf/doc/ppt
# * index.html for spreadsheets and index_html_xxx.png for images embedded in spreadsheets # * index.html for spreadsheets and index_html_xxx.png for images embedded in spreadsheets
_OFFICE_PAGE_PATTERN = re.compile(r'^[\d]+\.page|file\.css|file\.outline|index.html|index_html_.*.png$') _OFFICE_PAGE_PATTERN = re.compile(r'^[\d]+\.page|file\.css|file\.outline|index.html|index_html_.*.png$')
def office_convert_get_page(request, repo_id, path, filename, internal=False): def office_convert_get_page(request, repo_id, commit_id, path, filename, internal=False):
if not HAS_OFFICE_CONVERTER: if not HAS_OFFICE_CONVERTER:
raise Http404 raise Http404
@@ -1376,7 +1378,7 @@ def office_convert_get_page(request, repo_id, path, filename, internal=False):
if not _check_office_convert_perm(request, repo_id, path): if not _check_office_convert_perm(request, repo_id, path):
return HttpResponseForbidden() return HttpResponseForbidden()
file_id = get_file_id_by_path(repo_id, path) file_id = seafserv_threaded_rpc.get_file_id_by_commit_and_path(repo_id, commit_id, path)
resp = get_office_converted_page(request, filename, file_id, internal=internal) resp = get_office_converted_page(request, filename, file_id, internal=internal)
if filename.endswith('.page'): if filename.endswith('.page'):
content_type = 'text/html' content_type = 'text/html'