From dc5549486fd85d2bbaba0ef155a41718b0a73e6b Mon Sep 17 00:00:00 2001 From: Landon Wark Date: Wed, 10 Apr 2024 11:01:08 -0500 Subject: [PATCH] Added signing ability to submission details --- CHANGELOG.md | 5 +++++ src/submissions/backend/validators/pydant.py | 14 -------------- .../frontend/widgets/submission_details.py | 12 ++++++++++-- .../templates/basicsubmission_details.html | 9 +++++++++ src/submissions/tools.py | 5 ++++- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de4c4a8..8250431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 202404.02 + +- Various bug fixes. +- Added ability to sign off on submission in submission details. + ## 202403.03 - Automated version construction. diff --git a/src/submissions/backend/validators/pydant.py b/src/submissions/backend/validators/pydant.py index 16a063f..e42d5a1 100644 --- a/src/submissions/backend/validators/pydant.py +++ b/src/submissions/backend/validators/pydant.py @@ -137,20 +137,6 @@ class PydReagent(BaseModel): # add end-of-life extension from reagent type to expiry date # NOTE: this will now be done only in the reporting phase to account for potential changes in end-of-life extensions return reagent, report - - # def toForm(self, parent:QWidget, extraction_kit:str) -> QComboBox: - # """ - # Converts this instance into a form widget - - # Args: - # parent (QWidget): Parent widget of the constructed object - # extraction_kit (str): Name of extraction kit used - - # Returns: - # QComboBox: Form object. - # """ - # from frontend.widgets.submission_widget import ReagentFormWidget - # return ReagentFormWidget(parent=parent, reagent=self, extraction_kit=extraction_kit) class PydSample(BaseModel, extra='allow'): diff --git a/src/submissions/frontend/widgets/submission_details.py b/src/submissions/frontend/widgets/submission_details.py index 680c8ac..29c278d 100644 --- a/src/submissions/frontend/widgets/submission_details.py +++ b/src/submissions/frontend/widgets/submission_details.py @@ -5,7 +5,7 @@ from PyQt6.QtWebChannel import QWebChannel from PyQt6.QtCore import Qt, pyqtSlot from backend.db.models import BasicSubmission, BasicSample -from tools import check_if_app +from tools import check_if_app, check_authorization, is_power_user from .functions import select_save_file from io import BytesIO from tempfile import TemporaryFile, TemporaryDirectory @@ -92,10 +92,18 @@ class SubmissionDetails(QDialog): logger.debug(f"Making platemap...") self.base_dict['platemap'] = submission.make_plate_map() self.base_dict, self.template = submission.get_details_template(base_dict=self.base_dict) - self.html = self.template.render(sub=self.base_dict) + self.html = self.template.render(sub=self.base_dict, signing_permission=is_power_user()) self.webview.setHtml(self.html) self.setWindowTitle(f"Submission Details - {submission.rsl_plate_num}") + @pyqtSlot(str) + def sign_off(self, submission:str|BasicSubmission): + logger.debug(f"Signing off on {submission}") + if isinstance(submission, str): + submission = BasicSubmission.query(rsl_number=submission) + submission.uploaded_by = getuser() + submission.save() + def export(self): """ Renders submission to html, then creates and saves .pdf file to user selected file. diff --git a/src/submissions/templates/basicsubmission_details.html b/src/submissions/templates/basicsubmission_details.html index 4917fd1..c07d256 100644 --- a/src/submissions/templates/basicsubmission_details.html +++ b/src/submissions/templates/basicsubmission_details.html @@ -116,6 +116,12 @@ {% endif %} {% endblock %} + {% if signing_permission %} + + {% endif %} +
+
+
diff --git a/src/submissions/tools.py b/src/submissions/tools.py index 9564f9e..619af5f 100644 --- a/src/submissions/tools.py +++ b/src/submissions/tools.py @@ -537,6 +537,9 @@ def rreplace(s, old, new): ctx = get_config(None) +def is_power_user() -> bool: + return getpass.getuser() in ctx.power_users + def check_authorization(func): """ Decorator to check if user is authorized to access function @@ -546,7 +549,7 @@ def check_authorization(func): """ def wrapper(*args, **kwargs): logger.debug(f"Checking authorization") - if getpass.getuser() in ctx.power_users: + if is_power_user(): return func(*args, **kwargs) else: logger.error(f"User {getpass.getuser()} is not authorized for this function.")