Skip to content

Commit

Permalink
[cuegui] Limit user actions on alien jobs (AcademySoftwareFoundation#…
Browse files Browse the repository at this point in the history
…1488)

**Rationale**
Users shouldn't be allowed by default to execute destructive actions on
jobs they don't own. For "superusers" there should be a simple way to
toggle this behavior off. This preference should be saved on the user
profile.

**Implementation details**
This feature checks user permissions before allowing a user to "eat,
kill, retry" jobs that they do not own.
The behavior can be overwritten at: "File -> Enable Job Interaction".
This gets saved to the config file and is disabled by
default.

---------

Co-authored-by: Roula O'Regan <[email protected]>
  • Loading branch information
DiegoTavares and roulaoregan-spi authored Aug 22, 2024
1 parent d48a45a commit 195a003
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 108 deletions.
40 changes: 39 additions & 1 deletion cuegui/cuegui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import os
import sys
import time
import yaml

from qtpy import QtCore
from qtpy import QtGui
Expand All @@ -48,6 +49,9 @@
class MainWindow(QtWidgets.QMainWindow):
"""The main window of the application. Multiple windows may exist."""

# Message to be displayed when a change requires an application restart
USER_CONFIRM_RESTART = "You must restart for this action to take effect, close window?: "

windows = []
windows_names = []
windows_titles = {}
Expand All @@ -70,6 +74,7 @@ def __init__(self, app_name, app_version, window_name, parent = None):
self.name = window_name
else:
self.name = self.windows_names[0]
self.__isEnabled = yaml.safe_load(self.app.settings.value("EnableJobInteraction", "False"))

# Provides a location for widgets to the right of the menu
menuLayout = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -206,6 +211,22 @@ def __createMenus(self):
self.windowMenu = self.menuBar().addMenu("&Window")
self.helpMenu = self.menuBar().addMenu("&Help")

if self.__isEnabled is False:
# Menu Bar: File -> Enable Job Interaction
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'),
'&Enable Job Interaction', self)
enableJobInteraction.setStatusTip('Enable Job Interaction')
enableJobInteraction.triggered.connect(self.__enableJobInteraction)
self.fileMenu.addAction(enableJobInteraction)
# allow user to disable the job interaction
else:
# Menu Bar: File -> Disable Job Interaction
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'),
'&Disable Job Interaction', self)
enableJobInteraction.setStatusTip('Disable Job Interaction')
enableJobInteraction.triggered.connect(self.__enableJobInteraction)
self.fileMenu.addAction(enableJobInteraction)

# Menu Bar: File -> Close Window
close = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'), '&Close Window', self)
close.setStatusTip('Close Window')
Expand Down Expand Up @@ -464,9 +485,26 @@ def __revertLayout(self):
result = QtWidgets.QMessageBox.question(
self,
"Restart required ",
"You must restart for this action to take effect, close window?: ",
MainWindow.USER_CONFIRM_RESTART,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)

if result == QtWidgets.QMessageBox.Yes:
self.settings.setValue("RevertLayout", True)
self.__windowCloseApplication()

def __enableJobInteraction(self):
""" Enable/Disable user job interaction """
result = QtWidgets.QMessageBox.question(
self,
"Job Interaction Settings ",
MainWindow.USER_CONFIRM_RESTART,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)

if result == QtWidgets.QMessageBox.Yes:
# currently not enabled, user wants to enable
if self.__isEnabled is False:
self.settings.setValue("EnableJobInteraction", 1)
self.__windowCloseApplication()
else:
self.settings.setValue("EnableJobInteraction", 0)
self.__windowCloseApplication()
Loading

0 comments on commit 195a003

Please sign in to comment.