Skip to content

Fix show vgrid/workgroup private file rendering #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions mig/shared/functionality/showvgridprivatefile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# showvgridprivatefile - View VGrid private files for owners and members
# Copyright (C) 2003-2020 The MiG Project lead by Brian Vinter
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in mig/shared/functionality/showvgridprivatefile.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -36,8 +36,10 @@
import os

from mig.shared import returnvalues
from mig.shared.fileio import read_file, read_file_lines
from mig.shared.functional import validate_input_and_cert, REJECT_UNSET
from mig.shared.init import initialize_main_variables, find_entry
from mig.shared.init import initialize_main_variables, find_entry, \
start_download
from mig.shared.validstring import valid_user_path
from mig.shared.vgrid import vgrid_is_owner_or_member

Expand All @@ -49,11 +51,12 @@
return ['file_output', defaults]


def main(client_id, user_arguments_dict):

Check failure on line 54 in mig/shared/functionality/showvgridprivatefile.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'main' (60% confidence)
"""Main function used by front end"""

(configuration, logger, output_objects, op_name) = \

Check failure on line 57 in mig/shared/functionality/showvgridprivatefile.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'op_name' (60% confidence)
initialize_main_variables(client_id, op_header=False)
initialize_main_variables(client_id, op_title=False, op_header=False,
op_menu=False)
defaults = signature()[1]
label = configuration.site_vgrid_label
# NOTE: no title or header here since output is usually raw
Expand Down Expand Up @@ -86,6 +89,8 @@
base_dir = os.path.abspath(os.path.join(configuration.vgrid_private_base,
vgrid_name)) + os.sep

start_entry = find_entry(output_objects, 'start')

# Strip leading slashes to avoid join() throwing away prefix

rel_path = path.lstrip(os.sep)
Expand All @@ -97,27 +102,44 @@
private files dir.''' % label})
return (output_objects, returnvalues.CLIENT_ERROR)

# NOTE: we use a simplified version of the cat.py handling here and simply
# return anything but html and txt as downloads.
if abs_path.endswith('.html') or abs_path.endswith('.txt'):
force_file = False
src_mode = "r"
else:
force_file = True
src_mode = "rb"

output_lines = []
try:
# TODO: port to read_file
private_fd = open(abs_path, 'rb')
entry = {'object_type': 'binary',
'data': private_fd.read()}
# Serve web pages directly with default html content type but cut away
# all the usual web page formatting to show only contents otherwise
if abs_path.endswith('.html'):
headers = []
if force_file:
content = read_file(abs_path, logger, mode=src_mode)
lines = [content]
else:
headers = [('Content-Disposition', 'attachment; filename="%s";' %
os.path.basename(abs_path))]
output_objects = [{'object_type': 'start', 'headers': headers}, entry,
{'object_type': 'script_status'},
{'object_type': 'end'}]
private_fd.close()
content = lines = read_file_lines(abs_path, logger,
mode=src_mode)
if content is None:
raise Exception("could not read file")
output_lines += lines
except Exception as exc:
logger.error("reading private file %s failed: %s" % (abs_path, exc))
output_objects.append({'object_type': 'error_text', 'text':
'Error reading %s private file %s' % (label,
path)})
return (output_objects, returnvalues.SYSTEM_ERROR)

entry = {'object_type': 'file_output',
'lines': output_lines,
'wrap_binary': force_file,
'verbatim': not force_file,
'wrap_targets': ['lines']}
# Inject download marker when force_file is set
if force_file:
download_marker = start_download(configuration, abs_path,
output_lines)
start_entry.update(download_marker)
output_objects.append(entry)
# Don't append status or timing info
output_objects.append({'object_type': 'script_status'})
return (output_objects, returnvalues.OK)
9 changes: 6 additions & 3 deletions mig/shared/output.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -38,7 +38,7 @@
from mig.shared.bailout import bailout_title, crash_helper, \
filter_output_objects
from mig.shared.base import hexlify
from mig.shared.defaults import file_dest_sep, keyword_any, keyword_updating

Check failure on line 41 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused import 'keyword_any' (90% confidence)
from mig.shared.htmlgen import get_xgi_html_header, get_xgi_html_footer, \
vgrid_items, html_post_helper, tablesorter_pager
from mig.shared.init import find_entry
Expand All @@ -53,7 +53,7 @@
'yaml', 'xmlrpc', 'resource', 'json', 'file']


def reject_main(client_id, user_arguments_dict):

Check failure on line 56 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'reject_main' (60% confidence)
"""A simple main-function to use if functionality backend is disabled"""
output_objs = [bailout_title(None, 'Access Error'),
{'object_type': 'header', 'text': 'Access Error'},
Expand All @@ -62,7 +62,7 @@
return (output_objs, returnvalues.CLIENT_ERROR)


def dummy_main(client_id, user_arguments_dict):

Check failure on line 65 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'dummy_main' (60% confidence)
"""Dummy main-function to override with backend import"""
output_objs = [bailout_title(None, 'Internal Error'),
{'object_type': 'header', 'text': 'Internal Error'},
Expand Down Expand Up @@ -133,7 +133,7 @@
return table


def txt_link(obj):

Check failure on line 136 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'txt_link' (60% confidence)
"""Text format link"""

return '(Link: __%s__) -> __%s__' % (obj['destination'], obj['text'])
Expand Down Expand Up @@ -370,7 +370,7 @@
content_keys = ['share_id', 'path']
mangle_fields = ['access', 'created', 'invites']
for (key, title) in optional_cols:
if not key in skip_list:

Check warning on line 373 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
header[0].append(title)
# Some fields need mangling for text print
if key in mangle_fields:
Expand Down Expand Up @@ -494,7 +494,7 @@
% obj)
if 'vgrid' in obj:
lines.append('%s: %s'
% (configuration.site_vgrid_label, obj['vgrid']))

Check warning on line 497 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (86 > 80 characters)
if 'finished_timestamp' in obj:
lines.append('Finished: %(finished_timestamp)s\n'
% obj)
Expand All @@ -512,20 +512,20 @@
% count)
if 'queued' in single_history:
lines.append('Queued %s: %s\n' % (count,
single_history['queued']))

Check warning on line 515 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)
if 'executing' in single_history:
lines.append('Executing %s: %s\n' % (count,
single_history['executing']))

Check warning on line 518 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (94 > 80 characters)
if 'resource' in single_history:
lines.append('Resource %s: %s\n' % (count,
single_history['resource']))

Check warning on line 521 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (92 > 80 characters)
if 'vgrid' in single_history:
lines.append('%s %s: %s' %
(configuration.site_vgrid_label,
count, single_history['vgrid']))
if 'failed' in single_history:
lines.append('Failed %s: %s\n' % (count,
single_history['failed']))

Check warning on line 528 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)
if 'failed_message' in single_history:
lines.append('Failed message %s: %s\n'
% (count,
Expand Down Expand Up @@ -745,7 +745,7 @@
html_escape(i['text']))
elif i['object_type'] == 'header':
lines.append('<h1 class="header %s">%s</h1>' % (i.get('class', ''),
html_escape(i['text'])))

Check warning on line 748 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)
elif i['object_type'] == 'sectionheader':
lines.append('<h3 class="sectionheader %s">%s</h3>' %
(i.get('class', ''), html_escape(i['text'])))
Expand Down Expand Up @@ -1082,7 +1082,7 @@
elif i['object_type'] == 'dir_listings':
redirect_name = i.get('redirect_name',
configuration.site_user_redirect)
redirect_path = i.get('redirect_path', redirect_name)

Check failure on line 1085 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'redirect_path' (60% confidence)
ls_url_template = i['ls_url_template']
rmdir_url_template = i['rmdir_url_template']
rm_url_template = i['rm_url_template']
Expand Down Expand Up @@ -1129,7 +1129,7 @@
len(dir_listing['entries'])))
cols += 1
lines.append(
'''<td class="empty_cell narrow" colspan="%d"></td>

Check warning on line 1132 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)
''' % (columns - cols))
lines.append('</tr>')
cols = columns
Expand Down Expand Up @@ -1230,7 +1230,7 @@
rm_link)
cols += 1
filename = this_file['name']
file_stem, file_ext = os.path.splitext(filename)

Check failure on line 1233 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'file_stem' (60% confidence)
open_url = redirect_url_template % this_file
cols += 1
open_link = '''
Expand Down Expand Up @@ -1292,9 +1292,12 @@
elif i['object_type'] == 'file_output':
if 'path' in i:
lines.append('File: %s<br />' % i['path'])
# NOTE: we shouldn't expect user file contents to be safe here
lines.append('<pre>%s</pre><br />' %
html_escape(''.join(i['lines'])))
if i.get('verbatim', False):
lines.append(''.join(i['lines']))
else:
# NOTE: we shouldn't expect user file contents to be safe here
lines.append('<pre>%s</pre><br />' %
html_escape(''.join(i['lines'])))
elif i['object_type'] == 'list':
lines.append('<ul>')
for list_item in i['list']:
Expand Down
Loading