From 52638a40d1451b83038a0a237272158b6ce71b6f Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 18 Feb 2025 06:54:11 -0700 Subject: [PATCH 1/2] fix #3455 --- qiita_db/meta_util.py | 13 +++++++------ qiita_db/support_files/populate_test_db.sql | 1 + qiita_db/util.py | 8 +++++--- .../handlers/artifact_handlers/base_handlers.py | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/qiita_db/meta_util.py b/qiita_db/meta_util.py index 7c48b8493..04b5ad525 100644 --- a/qiita_db/meta_util.py +++ b/qiita_db/meta_util.py @@ -22,7 +22,8 @@ # # The full license is in the file LICENSE, distributed with this software. # ----------------------------------------------------------------------------- -from os import stat, rename +from os import stat +from shutil import move from os.path import join, relpath, basename from time import strftime, localtime import matplotlib.pyplot as plt @@ -48,6 +49,8 @@ "sName", "sVersion", "cID", "cName", "processing_job_id", "parameters", "samples", "columns", "input_size", "extra_info", "MaxRSSRaw", "ElapsedRaw", "Start", "node_name", "node_model"] +RAW_DATA_ARTIFACT_TYPE = { + 'SFF', 'FASTQ', 'FASTA', 'FASTA_Sanger', 'per_sample_FASTQ'} def _get_data_fpids(constructor, object_id): @@ -118,9 +121,7 @@ def validate_filepath_access_by_user(user, filepath_id): if artifact.visibility == 'public': # TODO: https://github.com/biocore/qiita/issues/1724 - if artifact.artifact_type in ['SFF', 'FASTQ', 'FASTA', - 'FASTA_Sanger', - 'per_sample_FASTQ']: + if artifact.artifact_type in RAW_DATA_ARTIFACT_TYPE: study = artifact.study has_access = study.has_access(user, no_public=True) if (not study.public_raw_download and not has_access): @@ -469,7 +470,7 @@ def generate_biom_and_metadata_release(study_status='public'): for c in iter(lambda: f.read(4096), b""): md5sum.update(c) - rename(tgz_name, tgz_name_final) + move(tgz_name, tgz_name_final) vals = [ ('filepath', tgz_name_final[len(working_dir):], r_client.set), @@ -543,7 +544,7 @@ def generate_plugin_releases(): md5sum = md5() for c in iter(lambda: f.read(4096), b""): md5sum.update(c) - rename(tgz_name, tgz_name_final) + move(tgz_name, tgz_name_final) vals = [ ('filepath', tgz_name_final[len(working_dir):], r_client.set), ('md5sum', md5sum.hexdigest(), r_client.set), diff --git a/qiita_db/support_files/populate_test_db.sql b/qiita_db/support_files/populate_test_db.sql index a1f0095d0..52b282adc 100644 --- a/qiita_db/support_files/populate_test_db.sql +++ b/qiita_db/support_files/populate_test_db.sql @@ -88,6 +88,7 @@ INSERT INTO qiita.artifact_type VALUES (5, 'per_sample_FASTQ', NULL, true, false INSERT INTO qiita.artifact_type VALUES (7, 'BIOM', 'BIOM table', false, false, true); + -- -- Data for Name: data_type; Type: TABLE DATA; Schema: qiita; Owner: antoniog -- diff --git a/qiita_db/util.py b/qiita_db/util.py index 33fd63da3..b335643c6 100644 --- a/qiita_db/util.py +++ b/qiita_db/util.py @@ -49,7 +49,7 @@ from bcrypt import hashpw, gensalt from functools import partial from os.path import join, basename, isdir, exists, getsize -from os import walk, remove, listdir, rename, stat, makedirs +from os import walk, remove, listdir, stat, makedirs from glob import glob from shutil import move, rmtree, copy as shutil_copy from openpyxl import load_workbook @@ -542,7 +542,7 @@ def move_upload_files_to_trash(study_id, files_to_move): new_fullpath = join(foldername, trash_folder, filename) if exists(fullpath): - rename(fullpath, new_fullpath) + move(fullpath, new_fullpath) def get_mountpoint(mount_type, retrieve_all=False, retrieve_subdir=False): @@ -2297,7 +2297,9 @@ def send_email(to, subject, body): msg = MIMEMultipart() msg['From'] = qiita_config.smtp_email msg['To'] = to - msg['Subject'] = subject.strip() + # we need to do 'replace' because the subject can have + # new lines in the middle of the string + msg['Subject'] = subject.replace('\n', '') msg.attach(MIMEText(body, 'plain')) # connect to smtp server, using ssl if needed diff --git a/qiita_pet/handlers/artifact_handlers/base_handlers.py b/qiita_pet/handlers/artifact_handlers/base_handlers.py index bdeae6eaf..a1f5f9463 100644 --- a/qiita_pet/handlers/artifact_handlers/base_handlers.py +++ b/qiita_pet/handlers/artifact_handlers/base_handlers.py @@ -21,6 +21,7 @@ from qiita_db.processing_job import ProcessingJob from qiita_db.util import get_visibilities, send_email from qiita_db.logger import LogEntry +from qiita_db.meta_util import RAW_DATA_ARTIFACT_TYPE PREP_TEMPLATE_KEY_FORMAT = 'prep_template_%s' @@ -208,8 +209,7 @@ def artifact_summary_get_request(user, artifact_id): # TODO: https://github.com/biocore/qiita/issues/1724 Remove this hardcoded # values to actually get the information from the database once it stores # the information - if artifact_type in ['SFF', 'FASTQ', 'FASTA', 'FASTA_Sanger', - 'per_sample_FASTQ']: + if artifact_type in RAW_DATA_ARTIFACT_TYPE: # If the artifact is one of the "raw" types, only the owner of the # study and users that has been shared with can see the files study = artifact.study From 2688a554c300abe4b167bf252734f015ee9363cd Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 18 Feb 2025 07:26:24 -0700 Subject: [PATCH 2/2] humanize==4.11 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 62397695e..d782ead36 100644 --- a/setup.py +++ b/setup.py @@ -105,7 +105,8 @@ install_requires=['psycopg2', 'click', 'bcrypt', 'pandas<2.0', 'biom-format', 'tornado<6.0', 'toredis', 'redis', 'scp', 'pyparsing', 'h5py', 'natsort', 'nose', 'pep8', - 'networkx', 'humanize', 'wtforms<3.0.0', 'nltk<=3.8.1', + 'networkx', 'humanize==4.11', 'wtforms<3.0.0', + 'nltk<=3.8.1', 'openpyxl', 'sphinx-bootstrap-theme', 'Sphinx<3.0', 'gitpython', 'redbiom', 'pyzmq', 'sphinx_rtd_theme', 'paramiko', 'seaborn', 'matplotlib', 'scipy<=1.10.1',