Added signing ability to submission details
This commit is contained in:
@@ -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'):
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -116,6 +116,12 @@
|
||||
<img height="300px" width="650px" src="data:image/jpeg;base64,{{ sub['export_map'] | safe }}">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% if signing_permission %}
|
||||
<button type="button" id="sign_btn">Sign Off</button>
|
||||
{% endif %}
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</body>
|
||||
<script>
|
||||
var backend;
|
||||
@@ -127,5 +133,8 @@
|
||||
backend.sample_details("{{ sample['Submitter ID'] }}");
|
||||
});
|
||||
{% endfor %}
|
||||
document.getElementById("sign_btn").addEventListener("click", function(){
|
||||
backend.sign_off("{{ sub['Plate Number'] }}");
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
|
||||
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user