nci-cidc-api-modules 1.2.11__py3-none-any.whl → 1.2.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nci-cidc-api-modules might be problematic. Click here for more details.

@@ -108,5 +108,9 @@ else:
108
108
  IS_EMAIL_ON = environ.get("IS_EMAIL_ON")
109
109
 
110
110
 
111
+ # notification emails
112
+ CIDC_CLINICAL_DATA_EMAIL = environ.get("CIDC_CLINICAL_DATA_EMAIL")
113
+ CIDC_ADMIN_EMAIL = environ.get("CIDC_ADMIN_EMAIL")
114
+
111
115
  # Accumulate all constants defined in this file in a single dictionary
112
116
  SETTINGS = {k: v for k, v in globals().items() if k.isupper()}
cidc_api/shared/emails.py CHANGED
@@ -1,11 +1,12 @@
1
1
  """Template functions for CIDC email bodies."""
2
2
 
3
3
  import html
4
+ import pathlib
4
5
  from functools import wraps
5
6
  from typing import List
6
7
 
7
8
  from . import gcloud_client
8
- from ..config.settings import ENV
9
+ from ..config.settings import ENV, ALLOWED_CLIENT_URL, CIDC_CLINICAL_DATA_EMAIL, CIDC_ADMIN_EMAIL
9
10
 
10
11
  # emails this list for
11
12
  # - new user registration,
@@ -44,7 +45,7 @@ def confirm_account_approval(user) -> dict:
44
45
  html_content = f"""
45
46
  <p>Hello {user.first_n},</p>
46
47
  <p>
47
- Your CIMAC-CIDC Portal account has been approved!
48
+ Your CIMAC-CIDC Portal account has been approved!
48
49
  To begin browsing and downloading data, visit https://cidc.nci.nih.gov.
49
50
  </p>
50
51
  <p>
@@ -150,3 +151,32 @@ def notify_mailing_list(subject: str, html_content: str) -> dict:
150
151
  "html_content": html_content,
151
152
  }
152
153
  return email
154
+
155
+
156
+ with open(pathlib.Path(__file__).parent.joinpath("email_layout.html"), encoding="utf-8") as file:
157
+ EMAIL_LAYOUT = file.read()
158
+
159
+
160
+ @sendable
161
+ def new_validation_review(job: dict) -> dict:
162
+ # these two emails are set only in prod env file
163
+ if CIDC_CLINICAL_DATA_EMAIL and CIDC_ADMIN_EMAIL:
164
+ to_emails = [CIDC_CLINICAL_DATA_EMAIL, CIDC_ADMIN_EMAIL]
165
+ else:
166
+ to_emails = CIDC_MAILING_LIST
167
+
168
+ subject = f"Trial {job.trial_id} ({job.version}) Ready for Validation Review"
169
+ html_heading = "Clinical Data Upload Notification"
170
+ job_url = f"{ALLOWED_CLIENT_URL}/upload-clinical-data/{job.id}"
171
+
172
+ html_content = f"""
173
+ <b>Ready for Validation Review:</b><br>
174
+ <b><a class="blue-link" href={job_url}>Trial {job.trial_id} version {job.version} (Job ID {job.id})</a></b>
175
+ Please follow the link to access the trial's clinical data submission page.
176
+ """
177
+
178
+ return {
179
+ "to_emails": to_emails,
180
+ "subject": subject,
181
+ "html_content": EMAIL_LAYOUT.replace("$HEADING", html_heading).replace("$CONTENT", html_content),
182
+ }
@@ -8,22 +8,31 @@ from ..config.settings import GOOGLE_CLINICAL_DATA_BUCKET
8
8
  from ..models import PreprocessedFiles
9
9
  from ..shared.auth import get_current_user
10
10
  from ..shared.gcloud_client import upload_file_to_gcs, move_gcs_file
11
+ from sqlalchemy.orm.session import Session
11
12
 
12
13
  logger = get_logger(__name__)
13
14
 
14
15
 
15
- def set_current_file(file: FileStorage, file_category: str, gcs_folder: str, job_id: int = None) -> PreprocessedFiles:
16
+ def set_current_file(
17
+ file: FileStorage, file_category: str, gcs_folder: str, session: Session, uploader_email: str, job_id: int = None
18
+ ) -> PreprocessedFiles:
16
19
  """
17
20
  Archives any existing 'current' files for the given category and job,
18
21
  then uploads the new file as the latest 'current' version.
19
22
  """
20
- latest_version = PreprocessedFiles.archive_current_files(file_category, job_id=job_id)
21
- latest_file = create_file(file, gcs_folder, file_category, job_id, latest_version + 1)
23
+ latest_version = PreprocessedFiles.archive_current_files(file_category, job_id=job_id, session=session)
24
+ latest_file = create_file(file, gcs_folder, file_category, session, uploader_email, job_id, latest_version + 1)
22
25
  return latest_file
23
26
 
24
27
 
25
28
  def create_file(
26
- file: FileStorage, gcs_folder: str, file_category: str, job_id: int = None, version: int = None
29
+ file: FileStorage,
30
+ gcs_folder: str,
31
+ file_category: str,
32
+ session: Session,
33
+ uploader_email: str,
34
+ job_id: int = None,
35
+ version: int = None,
27
36
  ) -> PreprocessedFiles:
28
37
  """Upload file to GCS and create corresponding metadata record in the database."""
29
38
  status = "pending" if gcs_folder.endswith("pending/") else "current"
@@ -36,10 +45,11 @@ def create_file(
36
45
  file_name=file.filename,
37
46
  object_url=gcs_file_path,
38
47
  file_category=file_category,
39
- uploader_email=get_current_user().email,
48
+ uploader_email=uploader_email,
40
49
  status=status,
41
50
  job_id=job_id,
42
51
  version=version,
52
+ session=session,
43
53
  )
44
54
  return file
45
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nci_cidc_api_modules
3
- Version: 1.2.11
3
+ Version: 1.2.13
4
4
  Summary: SQLAlchemy data models and configuration tools used in the NCI CIDC API
5
5
  Home-page: https://github.com/NCI-CIDC/cidc-api-gae
6
6
  License: MIT license
@@ -2,7 +2,7 @@ cidc_api/config/__init__.py,sha256=5mX8GAPxUKV84iS-aGOoE-4m68LsOCGCDptXNdlgvj0,1
2
2
  cidc_api/config/db.py,sha256=eFCkJDeykRIJZ25kePVjRNrZcrcKTc1s2K0yErr46LI,1683
3
3
  cidc_api/config/logging.py,sha256=abhVYtn8lfhIt0tyV2WHFgSmp_s2eeJh7kodB6LH4J0,1149
4
4
  cidc_api/config/secrets.py,sha256=jRFj7W43pWuPf9DZQLCKF7WPXf5cUv-BAaS3ASqhV_Q,1481
5
- cidc_api/config/settings.py,sha256=v8PmdR_MSmizuV1VaEX24QR0XHzIZ4jn69r6PwxAxV8,4512
5
+ cidc_api/config/settings.py,sha256=ttOGvk_6zVMn4dtxIZ2-0w3wF2fpAUVfGpVZbKJ2b6s,4653
6
6
  cidc_api/models/__init__.py,sha256=bl445G8Zic9YbhZ8ZBni07wtBMhLJRMBA-JqjLxx2bw,66
7
7
  cidc_api/models/migrations.py,sha256=gp9vtkYbA9FFy2s-7woelAmsvQbJ41LO2_DY-YkFIrQ,11464
8
8
  cidc_api/models/models.py,sha256=b7HWj8uOD_xdv7p3WkrhRODauLCVGvSLQsSbJGUmr9Q,146956
@@ -12,13 +12,13 @@ cidc_api/models/files/details.py,sha256=sZkGM7iEV4-J6IDQCdiMV6KBDLbPxCOqUMaU3aY9
12
12
  cidc_api/models/files/facets.py,sha256=RZoe0FadRGJw8_-jzJQkc4dIVSuaYlunNrsopb2dYho,33325
13
13
  cidc_api/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  cidc_api/shared/auth.py,sha256=PHqmVGkqDjbmUofytVFwD_9ssgUomESl3fFtFHPwZYQ,9062
15
- cidc_api/shared/emails.py,sha256=HQIixEUsR8yyu7Iv8S81RjtvEQeGuzQHzBfGsWIfP7k,4961
16
- cidc_api/shared/file_handling.py,sha256=l4wiRkVJLL7QbCoODsLx-uki6Km8QoMmUlRVnUV9vkk,3894
15
+ cidc_api/shared/emails.py,sha256=8kNFEaSnKpY-GX_iE59QUhSp3c4_uzy3SpHYt2QjuqI,6121
16
+ cidc_api/shared/file_handling.py,sha256=4xkekdrzxWsfmfBtWpylyDMT98ICjQwx1meqqh1FAis,4103
17
17
  cidc_api/shared/gcloud_client.py,sha256=BaoYv-lWWLwdZvyRjCWCyAyZMXtqlT8IPJpw9XDODCY,37210
18
18
  cidc_api/shared/jose.py,sha256=-qzGzEDAlokEp9E7WtBtQkXyyfPWTYXlwYpCqVJWmqM,1830
19
19
  cidc_api/shared/rest_utils.py,sha256=RwR30WOUAYCxL7V-i2totEyeriG30GbBDvBcpLXhM9w,6594
20
- nci_cidc_api_modules-1.2.11.dist-info/licenses/LICENSE,sha256=pNYWVTHaYonnmJyplmeAp7tQAjosmDpAWjb34jjv7Xs,1102
21
- nci_cidc_api_modules-1.2.11.dist-info/METADATA,sha256=LtfTSAzY5wOMrSIrLC3fhLmfbTiLgiBftULBMS_2ftw,39539
22
- nci_cidc_api_modules-1.2.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- nci_cidc_api_modules-1.2.11.dist-info/top_level.txt,sha256=rNiRzL0lJGi5Q9tY9uSoMdTbJ-7u5c_D2E86KA94yRA,9
24
- nci_cidc_api_modules-1.2.11.dist-info/RECORD,,
20
+ nci_cidc_api_modules-1.2.13.dist-info/licenses/LICENSE,sha256=pNYWVTHaYonnmJyplmeAp7tQAjosmDpAWjb34jjv7Xs,1102
21
+ nci_cidc_api_modules-1.2.13.dist-info/METADATA,sha256=gRTTJ2KEYN1B9Ac0rim5nAPVRsQtw5NWr0E9KJhSIc0,39539
22
+ nci_cidc_api_modules-1.2.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ nci_cidc_api_modules-1.2.13.dist-info/top_level.txt,sha256=rNiRzL0lJGi5Q9tY9uSoMdTbJ-7u5c_D2E86KA94yRA,9
24
+ nci_cidc_api_modules-1.2.13.dist-info/RECORD,,