Browse Source

Only show plate detection popup to users with control permission

The plate detection alert popup (shown when objects are detected on
build plate and print is paused) was visible to all users. Now it
only shows to users who have the printers:control permission.

- Added hasPermission('printers:control') check before showing alert
- When auth disabled: all users see it (backward compatible)
- When auth enabled: only users with printers:control permission see it

Addresses #244
maziggy 3 months ago
parent
commit
d950b48023
1 changed files with 6 additions and 1 deletions
  1. 6 1
      frontend/src/components/Layout.tsx

+ 6 - 1
frontend/src/components/Layout.tsx

@@ -313,8 +313,13 @@ export function Layout() {
   }, [location.pathname, isMobile]);
   }, [location.pathname, isMobile]);
 
 
   // Listen for plate detection warnings (objects on plate, print paused)
   // Listen for plate detection warnings (objects on plate, print paused)
+  // Only show to users with printers:control permission
   useEffect(() => {
   useEffect(() => {
     const handlePlateNotEmpty = (event: Event) => {
     const handlePlateNotEmpty = (event: Event) => {
+      // Only show alert to users who can control printers
+      if (!hasPermission('printers:control')) {
+        return;
+      }
       const detail = (event as CustomEvent).detail;
       const detail = (event as CustomEvent).detail;
       setPlateDetectionAlert({
       setPlateDetectionAlert({
         printer_id: detail.printer_id,
         printer_id: detail.printer_id,
@@ -324,7 +329,7 @@ export function Layout() {
     };
     };
     window.addEventListener('plate-not-empty', handlePlateNotEmpty);
     window.addEventListener('plate-not-empty', handlePlateNotEmpty);
     return () => window.removeEventListener('plate-not-empty', handlePlateNotEmpty);
     return () => window.removeEventListener('plate-not-empty', handlePlateNotEmpty);
-  }, []);
+  }, [hasPermission]);
 
 
   // Global keyboard shortcuts for navigation
   // Global keyboard shortcuts for navigation
   const handleKeyDown = useCallback((e: KeyboardEvent) => {
   const handleKeyDown = useCallback((e: KeyboardEvent) => {