From 59385115aefc85d1f5d11b1544225c3f6dca7ede Mon Sep 17 00:00:00 2001 From: Shekar V Date: Fri, 15 Sep 2023 11:08:57 -0400 Subject: [PATCH 1/5] Refactored refresh dewartree view: - Hide proposals that the user doesnt belong to - Split long method into smaller methods --- config_params.py | 6 + gui/dewar_tree.py | 328 +++++++++++++++++++++++----------------------- 2 files changed, 171 insertions(+), 163 deletions(-) diff --git a/config_params.py b/config_params.py index 5a984c22..54f5e891 100644 --- a/config_params.py +++ b/config_params.py @@ -1,4 +1,5 @@ from enum import Enum +import os, grp # BlConfig parameter variable names @@ -109,3 +110,8 @@ class RasterStatus(Enum): } LSDC_SERVICE_USERS = ("lsdc-amx", "lsdc-fmx", "lsdc-nyx") +IS_STAFF = ( + True + if os.environ["STAFF_GROUP"] in [grp.getgrgid(g).gr_name for g in os.getgroups()] + else False +) diff --git a/gui/dewar_tree.py b/gui/dewar_tree.py index b0c05f9c..58bde972 100644 --- a/gui/dewar_tree.py +++ b/gui/dewar_tree.py @@ -1,23 +1,29 @@ import logging import typing - +import os, getpass from qtpy import QtCore, QtGui, QtWidgets from qtpy.QtCore import Qt - +import requests import daq_utils import db_lib -from config_params import DEWAR_SECTORS, PUCKS_PER_DEWAR_SECTOR, SAMPLE_TIMER_DELAY +from config_params import ( + DEWAR_SECTORS, + PUCKS_PER_DEWAR_SECTOR, + SAMPLE_TIMER_DELAY, + IS_STAFF, +) if typing.TYPE_CHECKING: from lsdcGui import ControlMain logger = logging.getLogger() -global sampleNameDict -sampleNameDict = {} +global sampleDict +sampleDict = {} global containerDict containerDict = {} +ICON = ":/trolltech/styles/commonstyle/images/file-16.png" class DewarTree(QtWidgets.QTreeView): @@ -33,6 +39,8 @@ def __init__(self, parent: "ControlMain"): # self.isExpanded = 1 self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.openMenu) + # Keeps track of whether the user is part of a proposal + self.proposal_membership = {} def openMenu(self, position): indexes = self.selectedIndexes() @@ -89,173 +97,174 @@ def keyPressEvent(self, event): def refreshTree(self): self.parent.dewarViewToggleCheckCB() + def set_mounted_sample(self, item): + # Formats the text of the item that is passed in as the mounted sample + item.setForeground(QtGui.QColor("red")) + font = QtGui.QFont() + font.setUnderline(True) + font.setItalic(True) + font.setOverline(True) + item.setFont(font) + def refreshTreeDewarView(self): - selectedIndex = None - mountedIndex = None - selectedSampleIndex = None puck = "" - collectionRunning = False self.model.clear() dewarContents = db_lib.getContainerByName( daq_utils.primaryDewarName, daq_utils.beamline )["content"] - for i in range(0, len(dewarContents)): # dewar contents is the list of puck IDs + for i, puck_id in enumerate( + dewarContents + ): # dewar contents is the list of puck IDs parentItem = self.model.invisibleRootItem() - if dewarContents[i] == "": - puck = "" - puckName = "" - else: - if dewarContents[i] not in containerDict: - puck = db_lib.getContainerByID(dewarContents[i]) - containerDict[dewarContents[i]] = puck - else: - puck = containerDict[dewarContents[i]] + puck = "" + puckName = "" + if puck_id: + puck = containerDict.get( + puck_id, + containerDict.setdefault(puck_id, db_lib.getContainerByID(puck_id)), + ) puckName = puck["name"] - index_s = "%d%s" % ( - (i) / self.pucksPerDewarSector + 1, - chr(((i) % self.pucksPerDewarSector) + ord("A")), - ) - item = QtGui.QStandardItem( - QtGui.QIcon(":/trolltech/styles/commonstyle/images/file-16.png"), - index_s + " " + puckName, - ) + sector, puck_pos = divmod(i, self.pucksPerDewarSector) + index_s = f"{sector+1}{chr(puck_pos + ord('A'))}" + item = QtGui.QStandardItem(QtGui.QIcon(ICON), f"{index_s} {puckName}") item.setData(puckName, 32) item.setData("container", 33) parentItem.appendRow(item) parentItem = item if puck != "" and puckName != "private": - puckContents = puck["content"] - puckSize = len(puckContents) - for j in range(0, len(puckContents)): # should be the list of samples - if puckContents[j] != "": - if puckContents[j] not in sampleNameDict: - sampleName = db_lib.getSampleNamebyID(puckContents[j]) - sampleNameDict[puckContents[j]] = sampleName - else: - sampleName = sampleNameDict[puckContents[j]] - position_s = str(j + 1) + "-" + sampleName - item = QtGui.QStandardItem( - QtGui.QIcon( - ":/trolltech/styles/commonstyle/images/file-16.png" - ), - position_s, - ) - item.setData( - puckContents[j], 32 - ) # just stuck sampleID there, but negate it to diff from reqID - item.setData("sample", 33) - if puckContents[j] == self.parent.mountedPin_pv.get(): - item.setForeground(QtGui.QColor("red")) - font = QtGui.QFont() - font.setItalic(True) - font.setOverline(True) - font.setUnderline(True) - item.setFont(font) - parentItem.appendRow(item) - if puckContents[j] == self.parent.mountedPin_pv.get(): - mountedIndex = self.model.indexFromItem(item) - if ( - puckContents[j] == self.parent.selectedSampleID - ): # looking for the selected item - logger.info("found " + str(self.parent.SelectedItemData)) - selectedSampleIndex = self.model.indexFromItem(item) - sampleRequestList = db_lib.getRequestsBySampleID( - puckContents[j] - ) - for k in range(len(sampleRequestList)): - if not ("protocol" in sampleRequestList[k]["request_obj"]): - continue - col_item = QtGui.QStandardItem( - QtGui.QIcon( - ":/trolltech/styles/commonstyle/images/file-16.png" - ), - sampleRequestList[k]["request_obj"]["file_prefix"] - + "_" - + sampleRequestList[k]["request_obj"]["protocol"], - ) - col_item.setData(sampleRequestList[k]["uid"], 32) - col_item.setData("request", 33) - col_item.setFlags( - Qt.ItemIsUserCheckable - | Qt.ItemIsEnabled - | Qt.ItemIsEditable - | Qt.ItemIsSelectable - ) - if sampleRequestList[k]["priority"] == 99999: - col_item.setCheckState(Qt.Checked) - col_item.setBackground(QtGui.QColor("green")) - selectedIndex = self.model.indexFromItem( - col_item - ) ##attempt to leave it on the request after collection - - collectionRunning = True - self.parent.refreshCollectionParams( - sampleRequestList[k], validate_hdf5=False - ) - elif sampleRequestList[k]["priority"] > 0: - col_item.setCheckState(Qt.Checked) - col_item.setBackground(QtGui.QColor("white")) - elif sampleRequestList[k]["priority"] < 0: - col_item.setCheckable(False) - col_item.setBackground(QtGui.QColor("cyan")) - else: - col_item.setCheckState(Qt.Unchecked) - col_item.setBackground(QtGui.QColor("white")) - item.appendRow(col_item) - if ( - sampleRequestList[k]["uid"] - == self.parent.SelectedItemData - ): # looking for the selected item, this is a request - selectedIndex = self.model.indexFromItem(col_item) - else: # this is an empty spot, no sample - position_s = str(j + 1) - item = QtGui.QStandardItem( - QtGui.QIcon( - ":/trolltech/styles/commonstyle/images/file-16.png" - ), - position_s, - ) - item.setData("", 32) - parentItem.appendRow(item) - self.setModel(self.model) - if selectedSampleIndex != None and collectionRunning == False: - self.setCurrentIndex(selectedSampleIndex) - if mountedIndex != None: - self.model.itemFromIndex(mountedIndex).setForeground( - QtGui.QColor("red") - ) - font = QtGui.QFont() - font.setUnderline(True) - font.setItalic(True) - font.setOverline(True) - self.model.itemFromIndex(mountedIndex).setFont(font) - self.parent.row_clicked(selectedSampleIndex) - elif selectedSampleIndex == None and collectionRunning == False: - if mountedIndex != None: - self.setCurrentIndex(mountedIndex) - self.model.itemFromIndex(mountedIndex).setForeground( - QtGui.QColor("red") - ) - font = QtGui.QFont() - font.setUnderline(True) - font.setItalic(True) - font.setOverline(True) - self.model.itemFromIndex(mountedIndex).setFont(font) - self.parent.row_clicked(mountedIndex) - else: - pass - if selectedIndex != None and collectionRunning == False: - self.setCurrentIndex(selectedIndex) - self.parent.row_clicked(selectedIndex) - if collectionRunning == True: - if mountedIndex != None: - self.setCurrentIndex(mountedIndex) + puckContents = puck.get("content", []) + self.add_samples_to_puck_tree(puckContents, parentItem) + self.setModel(self.model) if self.isExpanded: self.expandAll() else: self.collapseAll() self.scrollTo(self.currentIndex(), QtWidgets.QAbstractItemView.PositionAtCenter) + def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem): + # Method will attempt to add samples to the puck. If you don't belong to the proposal, + # it will not add samples and clear the puck information + selectedIndex = None + mountedIndex = None + selectedSampleIndex = None + collectionRunning = False + for j, sample_id in enumerate(puckContents): + if not sample_id: + # this is an empty spot, no sample + position_s = str(j + 1) + item = QtGui.QStandardItem(QtGui.QIcon(ICON), position_s) + item.setData("", 32) + parentItem.appendRow(item) + continue + + sample = sampleDict.get( + sample_id, + sampleDict.setdefault(sample_id, db_lib.getSampleByID(sample_id)), + ) + + if not self.is_proposal_member(sample["proposal"]) and not IS_STAFF: + # If the user is not part of the proposal or is not staff, don't fill tree + # Clear the puck information and don't make it selectable + parentItem.clearData() + parentItem.setText("") + current_flags = parentItem.flags() + parentItem.setFlags(current_flags & ~Qt.ItemFlag.ItemIsSelectable) # type: ignore + return + + position_s = f'{j+1}-{sample.get("name", "")}' + item = QtGui.QStandardItem( + QtGui.QIcon(ICON), + position_s, + ) + # just stuck sampleID there, but negate it to diff from reqID + item.setData(sample_id, 32) + item.setData("sample", 33) + if sample_id == self.parent.mountedPin_pv.get(): + self.set_mounted_sample(item) + parentItem.appendRow(item) + if sample_id == self.parent.mountedPin_pv.get(): + mountedIndex = self.model.indexFromItem(item) + # looking for the selected item + if sample_id == self.parent.selectedSampleID: + logger.info("found " + str(self.parent.SelectedItemData)) + selectedSampleIndex = self.model.indexFromItem(item) + sampleRequestList = db_lib.getRequestsBySampleID(sample_id) + for request in sampleRequestList: + if not ("protocol" in request["request_obj"]): + continue + col_item = self.create_request_item(request) + if request["priority"] == 99999: + selectedIndex = self.model.indexFromItem( + col_item + ) ##attempt to leave it on the request after collection + collectionRunning = True + item.appendRow(col_item) + if ( + request["uid"] == self.parent.SelectedItemData + ): # looking for the selected item, this is a request + selectedIndex = self.model.indexFromItem(col_item) + + current_index = None + if not collectionRunning: + if selectedSampleIndex: + current_index = selectedSampleIndex + elif mountedIndex: + current_index = mountedIndex + item = self.model.itemFromIndex(mountedIndex) + self.set_mounted_sample(item) + elif selectedIndex: + current_index = selectedIndex + elif collectionRunning and mountedIndex: + current_index = mountedIndex + + if current_index: + self.setCurrentIndex(current_index) + self.parent.row_clicked(current_index) + + def is_proposal_member(self, proposal) -> bool: + # Check if the user running LSDC is part of the sample's proposal + if proposal not in self.proposal_membership: + r = requests.get(f"{os.environ['NSLS_API_URL']}/proposal/{proposal}") + r.raise_for_status() + response = r.json() + if getpass.getuser() not in [ + user["username"] for user in response["users"] if "username" in user + ]: + self.proposal_membership[proposal] = False + else: + self.proposal_membership[proposal] = True + return self.proposal_membership[proposal] + + def create_request_item(self, request) -> QtGui.QStandardItem: + col_item = QtGui.QStandardItem( + QtGui.QIcon(ICON), + request["request_obj"]["file_prefix"] + + "_" + + request["request_obj"]["protocol"], + ) + col_item.setData(request["uid"], 32) + col_item.setData("request", 33) + col_item.setFlags( + Qt.ItemFlag.ItemIsUserCheckable # type:ignore + | Qt.ItemFlag.ItemIsEnabled + | Qt.ItemFlag.ItemIsEditable + | Qt.ItemFlag.ItemIsSelectable + ) + if request["priority"] == 99999: + col_item.setCheckState(Qt.CheckState.Checked) + col_item.setBackground(QtGui.QColor("green")) + self.parent.refreshCollectionParams(request, validate_hdf5=False) + elif request["priority"] > 0: + col_item.setCheckState(Qt.CheckState.Checked) + col_item.setBackground(QtGui.QColor("white")) + elif request["priority"] < 0: + col_item.setCheckable(False) + col_item.setBackground(QtGui.QColor("cyan")) + else: + col_item.setCheckState(Qt.CheckState.Unchecked) + col_item.setBackground(QtGui.QColor("white")) + return col_item + def refreshTreePriorityView( self, ): # "item" is a sample, "col_items" are requests which are children of samples. @@ -282,18 +291,13 @@ def refreshTreePriorityView( parentItem = self.model.invisibleRootItem() nodeString = str(db_lib.getSampleNamebyID(requestedSampleList[i])) item = QtGui.QStandardItem( - QtGui.QIcon(":/trolltech/styles/commonstyle/images/file-16.png"), + QtGui.QIcon(ICON), nodeString, ) item.setData(requestedSampleList[i], 32) item.setData("sample", 33) if requestedSampleList[i] == mountedPin: - item.setForeground(QtGui.QColor("red")) - font = QtGui.QFont() - font.setItalic(True) - font.setOverline(True) - font.setUnderline(True) - item.setFont(font) + self.set_mounted_sample(item) parentItem.appendRow(item) if requestedSampleList[i] == mountedPin: mountedIndex = self.model.indexFromItem(item) @@ -305,9 +309,7 @@ def refreshTreePriorityView( for k in range(len(self.orderedRequests)): if self.orderedRequests[k]["sample"] == requestedSampleList[i]: col_item = QtGui.QStandardItem( - QtGui.QIcon( - ":/trolltech/styles/commonstyle/images/file-16.png" - ), + QtGui.QIcon(ICON), self.orderedRequests[k]["request_obj"]["file_prefix"] + "_" + self.orderedRequests[k]["request_obj"]["protocol"], From fd7310a98332a5026d06192553744d0aae56e428 Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Tue, 19 Sep 2023 14:17:37 -0400 Subject: [PATCH 2/5] Minimum working example for showing puck info --- gui/control_main.py | 8 ++++--- gui/dewar_tree.py | 52 ++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 5bca9905..edd00918 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -201,7 +201,7 @@ def __init__(self): self.raddoseTimer.timeout.connect(self.spawnRaddoseThread) self.createSampleTab() - + self.userScreenDialog = UserScreenDialog(self) self.initCallbacks() if self.scannerType != "PI": self.motPos = { @@ -224,14 +224,13 @@ def __init__(self): if daq_utils.beamline == "nyx": # requires staffScreenDialog to be present self.staffScreenDialog.fastDPCheckBox.setDisabled(True) - self.dewarTree.refreshTreeDewarView() if self.mountedPin_pv.get() == "": mountedPin = db_lib.beamlineInfo(daq_utils.beamline, "mountedSample")[ "sampleID" ] self.mountedPin_pv.put(mountedPin) self.rasterExploreDialog = RasterExploreDialog() - self.userScreenDialog = UserScreenDialog(self) + self.detDistMotorEntry.getEntry().setText( self.detDistRBVLabel.getEntry().text() ) # this is to fix the current val being overwritten by reso @@ -241,6 +240,7 @@ def __init__(self): self.changeControlMasterCB(1) self.controlMasterCheckBox.setChecked(True) self.XRFInfoDict = self.parseXRFTable() # I don't like this + #self.dewarTree.refreshTreeDewarView() def setGuiValues(self, values): for item, value in values.items(): @@ -4624,6 +4624,8 @@ def row_clicked( self, index ): # I need "index" here? seems like I get it from selmod, but sometimes is passed selmod = self.dewarTree.selectionModel() + if not selmod: + return selection = selmod.selection() indexes = selection.indexes() if len(indexes) == 0: diff --git a/gui/dewar_tree.py b/gui/dewar_tree.py index 58bde972..d745e204 100644 --- a/gui/dewar_tree.py +++ b/gui/dewar_tree.py @@ -35,7 +35,7 @@ def __init__(self, parent: "ControlMain"): self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) self.setAnimated(True) self.model = QtGui.QStandardItemModel() - self.model.itemChanged.connect(self.queueSelectedSample) + # self.isExpanded = 1 self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.openMenu) @@ -112,10 +112,10 @@ def refreshTreeDewarView(self): dewarContents = db_lib.getContainerByName( daq_utils.primaryDewarName, daq_utils.beamline )["content"] + parentItem = self.model.invisibleRootItem() for i, puck_id in enumerate( dewarContents ): # dewar contents is the list of puck IDs - parentItem = self.model.invisibleRootItem() puck = "" puckName = "" if puck_id: @@ -130,18 +130,18 @@ def refreshTreeDewarView(self): item.setData(puckName, 32) item.setData("container", 33) parentItem.appendRow(item) - parentItem = item if puck != "" and puckName != "private": puckContents = puck.get("content", []) - self.add_samples_to_puck_tree(puckContents, parentItem) - self.setModel(self.model) + self.add_samples_to_puck_tree(puckContents, item, index_s) + self.setModel(self.model) + self.model.itemChanged.connect(self.queueSelectedSample) if self.isExpanded: self.expandAll() else: self.collapseAll() self.scrollTo(self.currentIndex(), QtWidgets.QAbstractItemView.PositionAtCenter) - def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem): + def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem, index_label): # Method will attempt to add samples to the puck. If you don't belong to the proposal, # it will not add samples and clear the puck information selectedIndex = None @@ -162,13 +162,19 @@ def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem sampleDict.setdefault(sample_id, db_lib.getSampleByID(sample_id)), ) - if not self.is_proposal_member(sample["proposal"]) and not IS_STAFF: + #if not IS_STAFF and not self.is_proposal_member(sample["proposalID"]): + if not self.is_proposal_member(sample["proposalID"]): # If the user is not part of the proposal or is not staff, don't fill tree # Clear the puck information and don't make it selectable - parentItem.clearData() - parentItem.setText("") + # parentItem.clearData() + parentItem.setText(index_label) current_flags = parentItem.flags() parentItem.setFlags(current_flags & ~Qt.ItemFlag.ItemIsSelectable) # type: ignore + position_s = f'{j+1}-{sample.get("name", "")}' + item = QtGui.QStandardItem( + QtGui.QIcon(ICON), + position_s, + ) return position_s = f'{j+1}-{sample.get("name", "")}' @@ -227,12 +233,13 @@ def is_proposal_member(self, proposal) -> bool: r = requests.get(f"{os.environ['NSLS_API_URL']}/proposal/{proposal}") r.raise_for_status() response = r.json() - if getpass.getuser() not in [ + if "users" in response and getpass.getuser() in [ user["username"] for user in response["users"] if "username" in user ]: - self.proposal_membership[proposal] = False - else: self.proposal_membership[proposal] = True + else: + logger.info(f"Users not found in response: {response}") + self.proposal_membership[proposal] = False return self.proposal_membership[proposal] def create_request_item(self, request) -> QtGui.QStandardItem: @@ -362,16 +369,17 @@ def refreshTreePriorityView( self.expandAll() def queueSelectedSample(self, item): - reqID = str(item.data(32)) - checkedSampleRequest = db_lib.getRequestByID(reqID) # line not needed??? - if item.checkState() == Qt.Checked: - db_lib.updatePriority(reqID, 5000) - else: - db_lib.updatePriority(reqID, 0) - item.setBackground(QtGui.QColor("white")) - self.parent.treeChanged_pv.put( - self.parent.processID - ) # the idea is touch the pv, but have this gui instance not refresh + if item.data(33) == "request": + reqID = str(item.data(32)) + checkedSampleRequest = db_lib.getRequestByID(reqID) # line not needed??? + if item.checkState() == Qt.Checked: + db_lib.updatePriority(reqID, 5000) + else: + db_lib.updatePriority(reqID, 0) + item.setBackground(QtGui.QColor("white")) + self.parent.treeChanged_pv.put( + self.parent.processID + ) # the idea is touch the pv, but have this gui instance not refresh def queueAllSelectedCB(self): selmod = self.selectionModel() From e0f74eea31204587dd4e83c93c247efde0c11157 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Mon, 2 Oct 2023 16:00:59 -0400 Subject: [PATCH 3/5] Added env variable healthcheck --- utils/healthcheck.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/healthcheck.py b/utils/healthcheck.py index 7a123b66..0c7ff891 100644 --- a/utils/healthcheck.py +++ b/utils/healthcheck.py @@ -168,6 +168,14 @@ def check_curr_visit_dir() -> bool: return True +@healthcheck(name="check environment variables", remediation="", fatal=True) +def check_env_variables() -> bool: + env_vars = ["STAFF_GROUP", "NSLS2_API_URL"] + missing_vars = [var for var in env_vars if var not in os.environ] + if missing_vars: + check_env_variables.remidiation = f"Environment variable(s) not found: {','.join(missing_vars)}" + return False + return True @healthcheck(name="existence of environment file", remediation="", fatal=True) def check_env_file() -> bool: From ed862b90c01f69649d422d2236120fbb364c9a03 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Mon, 2 Oct 2023 16:14:20 -0400 Subject: [PATCH 4/5] Checks if user is proposal member or staff --- gui/dewar_tree.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gui/dewar_tree.py b/gui/dewar_tree.py index d745e204..a8a4ab63 100644 --- a/gui/dewar_tree.py +++ b/gui/dewar_tree.py @@ -35,7 +35,7 @@ def __init__(self, parent: "ControlMain"): self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) self.setAnimated(True) self.model = QtGui.QStandardItemModel() - + # self.isExpanded = 1 self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.openMenu) @@ -141,7 +141,9 @@ def refreshTreeDewarView(self): self.collapseAll() self.scrollTo(self.currentIndex(), QtWidgets.QAbstractItemView.PositionAtCenter) - def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem, index_label): + def add_samples_to_puck_tree( + self, puckContents, parentItem: QtGui.QStandardItem, index_label + ): # Method will attempt to add samples to the puck. If you don't belong to the proposal, # it will not add samples and clear the puck information selectedIndex = None @@ -162,11 +164,9 @@ def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem sampleDict.setdefault(sample_id, db_lib.getSampleByID(sample_id)), ) - #if not IS_STAFF and not self.is_proposal_member(sample["proposalID"]): - if not self.is_proposal_member(sample["proposalID"]): - # If the user is not part of the proposal or is not staff, don't fill tree + if not IS_STAFF and not self.is_proposal_member(sample["proposalID"]): + # If the user is not part of the proposal and is not staff, don't fill tree # Clear the puck information and don't make it selectable - # parentItem.clearData() parentItem.setText(index_label) current_flags = parentItem.flags() parentItem.setFlags(current_flags & ~Qt.ItemFlag.ItemIsSelectable) # type: ignore @@ -227,20 +227,20 @@ def add_samples_to_puck_tree(self, puckContents, parentItem: QtGui.QStandardItem self.setCurrentIndex(current_index) self.parent.row_clicked(current_index) - def is_proposal_member(self, proposal) -> bool: + def is_proposal_member(self, proposal_id) -> bool: # Check if the user running LSDC is part of the sample's proposal - if proposal not in self.proposal_membership: - r = requests.get(f"{os.environ['NSLS_API_URL']}/proposal/{proposal}") + if proposal_id not in self.proposal_membership: + r = requests.get(f"{os.environ['NSLS2_API_URL']}/proposal/{proposal_id}") r.raise_for_status() response = r.json() - if "users" in response and getpass.getuser() in [ + if "users" in response and getpass.getuser() in [ user["username"] for user in response["users"] if "username" in user ]: - self.proposal_membership[proposal] = True + self.proposal_membership[proposal_id] = True else: logger.info(f"Users not found in response: {response}") - self.proposal_membership[proposal] = False - return self.proposal_membership[proposal] + self.proposal_membership[proposal_id] = False + return self.proposal_membership[proposal_id] def create_request_item(self, request) -> QtGui.QStandardItem: col_item = QtGui.QStandardItem( From 0c066321bd6c0ae1457f89f0bb3cd709fd659784 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Mon, 2 Oct 2023 16:19:47 -0400 Subject: [PATCH 5/5] Attempting to add proposal number to puck label --- gui/dewar_tree.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/dewar_tree.py b/gui/dewar_tree.py index a8a4ab63..355dbc53 100644 --- a/gui/dewar_tree.py +++ b/gui/dewar_tree.py @@ -177,6 +177,8 @@ def add_samples_to_puck_tree( ) return + parentItem.setText(f"{index_label} pass-{sample['proposalID']}") + position_s = f'{j+1}-{sample.get("name", "")}' item = QtGui.QStandardItem( QtGui.QIcon(ICON),