From 8b4c2f0e79c24d73d184b0f0827b7b92fda0a8c3 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Mon, 7 Oct 2019 18:05:56 +0530 Subject: [PATCH 1/2] Redirect logged-out user within the loading screen in APPM UI --- .../react-app/src/App.js | 31 +++++++++++++--- .../components/new-release/AddReleaseForm.js | 7 ++-- .../react-app/src/App.js | 36 ++++++++++++++++--- .../react-app/src/js/Utils.js | 3 +- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js index 484fe6be6c5..801f875404d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js @@ -24,7 +24,7 @@ import { Redirect, Switch, } from 'react-router-dom'; import axios from "axios"; -import {Layout, Spin, Result} from "antd"; +import {Layout, Spin, Result, notification} from "antd"; import ConfigContext from "./context/ConfigContext"; const {Content} = Layout; @@ -68,9 +68,7 @@ class App extends React.Component { window.location.origin + "/publisher/public/conf/config.json", ).then(res => { const config = res.data; - - this.getAndroidEnterpriseToken(config); - + this.checkUserLoggedIn(config); }).catch((error) => { this.setState({ loading: false, @@ -99,6 +97,31 @@ class App extends React.Component { }); }; + checkUserLoggedIn = (config) => { + axios.get( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.publisher + "/applications/categories" + ).then(res => { + this.getAndroidEnterpriseToken(config); + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + const redirectUrl = encodeURI(window.location.href); + const pageURL = window.location.pathname; + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if(lastURLSegment!=="login"){ + window.location.href = window.location.origin + `/publisher/login?redirect=${redirectUrl}`; + }else{ + this.getAndroidEnterpriseToken(config); + } + } else { + this.setState({ + loading: false, + error: true + }) + } + }); + }; + render() { const {loading, error} = this.state; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-release/AddReleaseForm.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-release/AddReleaseForm.js index c3c7abbb1fa..200cf9e7411 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-release/AddReleaseForm.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/new-release/AddReleaseForm.js @@ -106,8 +106,6 @@ class AddNewReleaseFormComponent extends React.Component { loading: true }); const {price, isSharedWithAllTenants, icon, screenshots, releaseDescription, releaseType, binaryFile} = values; - - const data = new FormData(); //add release data @@ -115,7 +113,7 @@ class AddNewReleaseFormComponent extends React.Component { description: releaseDescription, price: (price === undefined) ? 0 : parseInt(price), isSharedWithAllTenants, - metaData: "string", + metaData: "[]", releaseType: releaseType, supportedOsVersions: `${this.lowerOsVersion}-${this.upperOsVersion}` }; @@ -132,7 +130,8 @@ class AddNewReleaseFormComponent extends React.Component { data.append("applicationRelease", blob); - const url = window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/" + deviceType + "/ent-app/" + appId; + const url = window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.publisher + "/applications/" + deviceType + "/ent-app/" + appId; axios.post( url, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js index 5d8747417f5..4fc452939e2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js @@ -67,16 +67,44 @@ class App extends React.Component { axios.get( window.location.origin + "/store/public/conf/config.json", ).then(res => { - console.log(res); + const config = res.data; + this.checkUserLoggedIn(config); + }).catch((error) => { this.setState({ loading: false, - config: res.data + error: true }) - }).catch((error) => { + }); + } + + checkUserLoggedIn = (config) => { + axios.get( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.publisher + "/applications/categories" + ).then(res => { this.setState({ loading: false, - error: true + config: config }) + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + const redirectUrl = encodeURI(window.location.href); + const pageURL = window.location.pathname; + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if(lastURLSegment!=="login"){ + window.location.href = window.location.origin + `/store/login?redirect=${redirectUrl}`; + }else{ + this.setState({ + loading: false, + config: config + }) + } + } else { + this.setState({ + loading: false, + error: true + }) + } }); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js index 9bb8c4a521e..d99d02dde93 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js @@ -21,7 +21,8 @@ import {notification} from "antd"; export const handleApiError = (error, message) => { console.log(error); if (error.hasOwnProperty("response") && error.response.status === 401) { - window.location.href = window.location.origin + '/store/login'; + const redirectUrl = encodeURI(window.location.href); + window.location.href = window.location.origin + `/store/login?redirect=${redirectUrl}`; } else { notification["error"]({ message: "There was a problem", From 97beaeb63b38438893eccaeb2bd091810e38f6ee Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Mon, 7 Oct 2019 18:06:35 +0530 Subject: [PATCH 2/2] Add missing scopes to application-mgt.xml --- .../main/resources/conf/application-mgt.xml | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 140468aa061..6a6cfead86d 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -162,6 +162,100 @@ perm:android-work:customer perm:android-work:admin perm:application-command:modify + perm:sign-csr + perm:admin:devices:view + perm:admin:topics:view + perm:roles:add + perm:roles:add-users + perm:roles:update + perm:roles:permissions + perm:roles:details + perm:roles:view + perm:roles:create-combined-role + perm:roles:delete + perm:dashboard:vulnerabilities + perm:dashboard:non-compliant-count + perm:dashboard:non-compliant + perm:dashboard:by-groups + perm:dashboard:device-counts + perm:dashboard:feature-non-compliant + perm:dashboard:count-overview + perm:dashboard:filtered-count + perm:dashboard:details + perm:get-activity + perm:devices:delete + perm:devices:applications + perm:devices:effective-policy + perm:devices:compliance-data + perm:devices:features + perm:devices:operations + perm:devices:search + perm:devices:details + perm:devices:update + perm:devices:view + perm:view-configuration + perm:manage-configuration + perm:policies:remove + perm:policies:priorities + perm:policies:deactivate + perm:policies:get-policy-details + perm:policies:manage + perm:policies:activate + perm:policies:update + perm:policies:changes + perm:policies:get-details + perm:users:add + perm:users:details + perm:users:count + perm:users:delete + perm:users:roles + perm:users:user-details + perm:users:credentials + perm:users:search + perm:users:is-exist + perm:users:update + perm:users:send-invitation + perm:admin-users:view + perm:admin:devices:update-enrollment + perm:groups:devices + perm:groups:update + perm:groups:add + perm:groups:device + perm:groups:devices-count + perm:groups:remove + perm:groups:groups + perm:groups:groups-view + perm:groups:share + perm:groups:count + perm:groups:roles + perm:groups:devices-remove + perm:groups:devices-add + perm:groups:assign + perm:device-types:configs + perm:device-types:features + perm:device-types:types + perm:applications:install + perm:applications:uninstall + perm:admin-groups:count + perm:admin-groups:view + perm:notifications:mark-checked + perm:notifications:view + perm:admin:certificates:delete + perm:admin:certificates:details + perm:admin:certificates:view + perm:admin:certificates:add + perm:admin:certificates:verify + perm:admin + perm:devicetype:deployment + perm:device-types:events + perm:device-types:events:view + perm:admin:device-type + perm:admin:device-type:view + perm:admin:device-type:configs + perm:device:enroll + perm:geo-service:analytics-view + perm:geo-service:alerts-manage + appm:rea app-mgt