From 8016bad8118d92f78c6001ab2aecffd5ab503643 Mon Sep 17 00:00:00 2001 From: mbrasil Date: Tue, 19 Mar 2024 16:14:57 +0000 Subject: [PATCH] feat: endpoint execute schedule permission [BACKLOG-40051] --- .../mantle/client/ui/PerspectiveManager.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/user-console/src/main/java/org/pentaho/mantle/client/ui/PerspectiveManager.java b/user-console/src/main/java/org/pentaho/mantle/client/ui/PerspectiveManager.java index d8da2b06bd..98b98fc614 100644 --- a/user-console/src/main/java/org/pentaho/mantle/client/ui/PerspectiveManager.java +++ b/user-console/src/main/java/org/pentaho/mantle/client/ui/PerspectiveManager.java @@ -112,22 +112,27 @@ private void init() { RequestBuilder builder = new RequestBuilder( RequestBuilder.GET, url ); builder.setHeader( CONTENT_TYPE, APPLICATION_JSON ); builder.setHeader( IF_MODIFIED_SINCE, IF_MODIFIED_SINCE_DATE ); - canSchedule = true; + canSchedule = false; try { builder.sendRequest( null, new RequestCallback() { @Override public void onError( Request request, Throwable throwable ) { - setupPerspectiveManager(); + canExecuteSchedules(); } @Override public void onResponseReceived( Request request, Response response ) { if ( response.getStatusCode() == 200 ) { canSchedule = "true".equals( response.getText() ); + + if ( canSchedule ) { + setupPerspectiveManager(); + return; + } } - setupPerspectiveManager(); + canExecuteSchedules(); } } ); } catch ( Exception ignored ) { @@ -135,6 +140,28 @@ public void onResponseReceived( Request request, Response response ) { } } + private void canExecuteSchedules() { + try { + final String url = MantleUtils.getSchedulerPluginContextURL() + "api/scheduler/canExecuteSchedules?ts=" + + System.currentTimeMillis(); //$NON-NLS-1$ + RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.GET, url ); + requestBuilder.setHeader( CONTENT_TYPE, APPLICATION_JSON ); + requestBuilder.setHeader( IF_MODIFIED_SINCE, IF_MODIFIED_SINCE_DATE ); + requestBuilder.sendRequest( null, new RequestCallback() { + public void onError( Request request, Throwable caught ) { + setupPerspectiveManager(); + } + + public void onResponseReceived( Request request, Response response ) { + canSchedule = "true".equalsIgnoreCase( response.getText() ); //$NON-NLS-1$ + setupPerspectiveManager(); + } + } ); + } catch ( RequestException ignored ) { + // ignore + } + } + private void setupPerspectiveManager() { final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/perspectives?ts=" + System.currentTimeMillis(); //$NON-NLS-1$