Browse Source

Check permissions before showing abort/pause/delete context buttons

The user needs permissions to do these things, so don't show them if the user can't use them.

Contributes to issue CURA-9220.
Ghostkeeper 2 years ago
parent
commit
5eb340e3f0

+ 76 - 17
plugins/UM3NetworkPrinting/resources/qml/MonitorContextMenu.qml

@@ -62,40 +62,65 @@ Item
                     }
                 }
 
-                PrintJobContextMenuItem {
-                    onClicked: {
+                PrintJobContextMenuItem
+                {
+                    onClicked:
+                    {
                         deleteConfirmationDialog.visible = true;
                         popUp.close();
                     }
                     text: catalog.i18nc("@label", "Delete");
-                    visible: {
-                        if (!printJob) {
+                    visible:
+                    {
+                        if(!printJob)
+                        {
                             return false;
                         }
+                        if(printJob.isMine)
+                        {
+                            if(!OutputDevice.canWriteOwnPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            if(!OutputDevice.canWriteOthersPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
                         var states = ["queued", "error", "sent_to_printer"];
                         return states.indexOf(printJob.state) !== -1;
                     }
                 }
 
-                PrintJobContextMenuItem {
+                PrintJobContextMenuItem
+                {
                     enabled: visible && !(printJob.state == "pausing" || printJob.state == "resuming");
-                    onClicked: {
-                        if (printJob.state == "paused") {
+                    onClicked:
+                    {
+                        if (printJob.state == "paused")
+                        {
                             printJob.setState("resume");
                             popUp.close();
                             return;
                         }
-                        if (printJob.state == "printing") {
+                        if (printJob.state == "printing")
+                        {
                             printJob.setState("pause");
                             popUp.close();
                             return;
                         }
                     }
-                    text: {
-                        if (!printJob) {
+                    text:
+                    {
+                        if(!printJob)
+                        {
                             return "";
                         }
-                        switch(printJob.state) {
+                        switch(printJob.state)
+                        {
                             case "paused":
                                 return catalog.i18nc("@label", "Resume");
                             case "pausing":
@@ -106,26 +131,60 @@ Item
                                 catalog.i18nc("@label", "Pause");
                         }
                     }
-                    visible: {
-                        if (!printJob) {
+                    visible:
+                    {
+                        if(!printJob)
+                        {
                             return false;
                         }
+                        if(printJob.isMine)
+                        {
+                            if(!OutputDevice.canWriteOwnPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            if(!OutputDevice.canWriteOthersPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
                         var states = ["printing", "pausing", "paused", "resuming"];
                         return states.indexOf(printJob.state) !== -1;
                     }
                 }
 
-                PrintJobContextMenuItem {
+                PrintJobContextMenuItem
+                {
                     enabled: visible && printJob.state !== "aborting";
-                    onClicked: {
+                    onClicked:
+                    {
                         abortConfirmationDialog.visible = true;
                         popUp.close();
                     }
                     text: printJob && printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort");
-                    visible: {
-                        if (!printJob) {
+                    visible:
+                    {
+                        if (!printJob)
+                        {
                             return false;
                         }
+                        if(printJob.isMine)
+                        {
+                            if(!OutputDevice.canWriteOwnPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            if(!OutputDevice.canWriteOthersPrintJobs)
+                            {
+                                return false;
+                            }
+                        }
                         var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
                         return states.indexOf(printJob.state) !== -1;
                     }

+ 2 - 2
plugins/UM3NetworkPrinting/src/UltimakerNetworkedPrinterOutputDevice.py

@@ -204,14 +204,14 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
         Whether this user can change things about print jobs made by other
         people.
         """
-        return False
+        return True
 
     @pyqtProperty(bool, constant = True)
     def canWriteOwnPrintJobs(self) -> bool:
         """
         Whether this user can change things about print jobs made by themself.
         """
-        return False
+        return True
 
     @pyqtSlot(name="openPrintJobControlPanel")
     def openPrintJobControlPanel(self) -> None: