From f1f6ccf2a65904f68fb430a8a3fd62f1e320819a Mon Sep 17 00:00:00 2001 From: fescobar Date: Fri, 15 Jan 2021 13:39:19 +0000 Subject: [PATCH 1/2] #16-Support viewer endpoints public --- docker-compose-dev.yml | 1 + ui/.gitignore | 1 + ui/package.json | 4 +- ui/src/App.js | 45 ++++++- .../AllureDockerInfoDialog.js | 112 +++++++++++++++--- .../AllureDockerSigIn/AllureDockerSigIn.js | 26 +++- .../AllureDockerToolbar.js | 16 +++ .../AllureDockerBar/AllureDockerBar.js | 1 + .../AllureDockerMainContainer.js | 1 + ui/src/utility/user-actions.js | 13 +- 10 files changed, 189 insertions(+), 31 deletions(-) diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index fbfe720..f6e5092 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -27,6 +27,7 @@ services: SECURITY_VIEWER_USER: "view_user" SECURITY_VIEWER_PASS: "view_pass" SECURITY_ENABLED: 1 + MAKE_VIEWER_ENDPOINTS_PUBLIC: 0 #URL_PREFIX: /my-prefix #ACCESS_TOKEN_EXPIRES_IN_SECONDS: 10 #REFRESH_TOKEN_EXPIRES_IN_SECONDS: 10 diff --git a/ui/.gitignore b/ui/.gitignore index 9006a72..5fac5fc 100644 --- a/ui/.gitignore +++ b/ui/.gitignore @@ -19,3 +19,4 @@ package-lock.json /public/env-config.js /public/config.json +.eslintcache diff --git a/ui/package.json b/ui/package.json index 266e79f..f0c0792 100644 --- a/ui/package.json +++ b/ui/package.json @@ -7,12 +7,12 @@ "@material-ui/core": "4.11.0", "@material-ui/icons": "4.9.1", "@material-ui/lab": "4.0.0-alpha.56", - "axios": "0.19.2", + "axios": "0.21.1", "react": "16.13.1", "react-cookie": "4.0.3", "react-dom": "16.13.1", "react-router-dom": "5.2.0", - "react-scripts": "3.4.3" + "react-scripts": "4.0.1" }, "devDependencies": {}, "scripts": { diff --git a/ui/src/App.js b/ui/src/App.js index 49f70ad..292f88f 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -3,6 +3,7 @@ import "./App.css"; import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles"; import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom"; +import { setViewerRole } from "./utility/user-actions"; import AllureDockerSigIn from "./components/AllureDockerSigIn/AllureDockerSigIn"; import AllureDockerMainContainer from "./containers/AllureDockerMainContainer/AllureDockerMainContainer"; import AllureDockerReportFullView from "./components/AllureDockerReportFullView/AllureDockerReportFullView"; @@ -14,6 +15,7 @@ class App extends Component { state = { darkState: false, isLogoutNeeded: false, + isSignInAnOption: false, isLoginRequired: null, error: null, }; @@ -23,15 +25,33 @@ class App extends Component { this.recoverTheme(); } + isAdminEndpointAccessible = () => { + return axios + .post("/send-results") + .then((response) => { + return response.status !== 401; + }) + .catch((error) => { + return error.status !== 401; + }); + } + isLoginRequired = () => { this.setState({ error: null }); axios .get("/config") - .then((response) => { + .then(async (response) => { const isSecurityEnabled = response.data.data.security_enabled; let isLogoutNeeded = false; + let isSignInAnOption = false; if (isSecurityEnabled === 1) { isLogoutNeeded = true; + const isMakeViewerEndpointsPublic = response.data.data.make_viewer_endpoints_public; + if (isMakeViewerEndpointsPublic === 1 && !await this.isAdminEndpointAccessible()) { + setViewerRole(); + isLogoutNeeded = false; + isSignInAnOption = true; + } } else { localStorage.removeItem("expirationDate"); localStorage.removeItem("roles"); @@ -39,6 +59,7 @@ class App extends Component { this.setState({ isLoginRequired: false, isLogoutNeeded: isLogoutNeeded, + isSignInAnOption: isSignInAnOption }); }) .catch((error) => { @@ -90,13 +111,29 @@ class App extends Component { ( - + )} /> } /> ); } else { + let signInAnOption; + if (this.state.isSignInAnOption) { + signInAnOption = ( + + ( + + )} + /> + + ) + } else { + signInAnOption = ( } />) + } + switchRouter = ( )} /> @@ -118,6 +156,7 @@ class App extends Component { darkState={this.state.darkState} handleThemeChange={this.handleThemeChange} isLogoutNeeded={this.state.isLogoutNeeded} + isSignInAnOption={this.state.isSignInAnOption} /> )} /> @@ -126,7 +165,7 @@ class App extends Component { exact render={() => } /> - } /> + {signInAnOption} ); diff --git a/ui/src/components/AllureDockerInfoDialog/AllureDockerInfoDialog.js b/ui/src/components/AllureDockerInfoDialog/AllureDockerInfoDialog.js index b4292d8..dc79338 100644 --- a/ui/src/components/AllureDockerInfoDialog/AllureDockerInfoDialog.js +++ b/ui/src/components/AllureDockerInfoDialog/AllureDockerInfoDialog.js @@ -8,11 +8,35 @@ import DialogTitle from "@material-ui/core/DialogTitle"; import Link from "@material-ui/core/Link"; import Typography from "@material-ui/core/Typography"; +import localAxios from "axios"; + class AllureDockerInfoDialog extends Component { + state = { + version: null, + }; + + getConfig = () => { + const axios = localAxios.create(); + axios + .get(`${process.env.PUBLIC_URL}/config.json`) + .then((response) => { + this.setState({ version: response.data.version }); + }) + .catch((error) => { + this.setState({ version: 'NOT_FOUND' }); + }); + }; + handleCloseDialog = () => { this.props.handleCloseDialog(); }; + componentDidUpdate() { + if (!this.state.version) { + this.getConfig(); + } + } + render() { return ( - {"Frank Escobar --> "} - - LinkedIn - + Allure UI Version + + + {this.state.version} - {"Support --> "} + Support + + - Gitter + https://gitter.im/allure-docker-service/community - {"UI --> "} + UI + + - {"API --> "} + API + + - {"Examples --> "} + Examples + + + AUTHOR + + + + {"Frank Escobar"} + + + + LinkedIn + + + + + {isHomeAnOption} diff --git a/ui/src/components/AllureDockerToolbar/AllureDockerToolbar.js b/ui/src/components/AllureDockerToolbar/AllureDockerToolbar.js index 6522392..50b51ee 100644 --- a/ui/src/components/AllureDockerToolbar/AllureDockerToolbar.js +++ b/ui/src/components/AllureDockerToolbar/AllureDockerToolbar.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import clsx from "clsx"; import { fade, withStyles } from "@material-ui/core/styles"; +import AccountCircle from "@material-ui/icons/AccountCircle"; import AddCircle from "@material-ui/icons/AddCircle"; import Autocomplete from "@material-ui/lab/Autocomplete"; import Divider from "@material-ui/core/Divider"; @@ -152,6 +153,10 @@ class AllureDockerToolbar extends Component { redirectRoot(); }; + goToSignIn = () => { + this.props.history.push(`/signin`); + } + handleAPIErrorAlert = (error) => { this.props.setAPIAlert( "error", @@ -189,6 +194,15 @@ class AllureDockerToolbar extends Component { render() { const { classes } = this.props; + let isSignInAnOption = ""; + if (this.props.isSignInAnOption) { + isSignInAnOption = ( + + + + ); + } + let signOutButton = ""; if (this.props.isLogoutNeeded) { signOutButton = ( @@ -245,6 +259,8 @@ class AllureDockerToolbar extends Component { + {isSignInAnOption} + diff --git a/ui/src/containers/AllureDockerBar/AllureDockerBar.js b/ui/src/containers/AllureDockerBar/AllureDockerBar.js index da2a987..053bcb4 100644 --- a/ui/src/containers/AllureDockerBar/AllureDockerBar.js +++ b/ui/src/containers/AllureDockerBar/AllureDockerBar.js @@ -91,6 +91,7 @@ class AllureDockerBar extends Component { getProjects={this.props.getProjects} setAPIAlert={this.props.setAPIAlert} isLogoutNeeded={this.props.isLogoutNeeded} + isSignInAnOption={this.props.isSignInAnOption} /> diff --git a/ui/src/containers/AllureDockerMainContainer/AllureDockerMainContainer.js b/ui/src/containers/AllureDockerMainContainer/AllureDockerMainContainer.js index b7700d7..493fa84 100644 --- a/ui/src/containers/AllureDockerMainContainer/AllureDockerMainContainer.js +++ b/ui/src/containers/AllureDockerMainContainer/AllureDockerMainContainer.js @@ -120,6 +120,7 @@ class AllureDockerMainContainer extends Component { selectProject={this.selectProject} setAPIAlert={this.setAPIAlert} isLogoutNeeded={this.props.isLogoutNeeded} + isSignInAnOption={this.props.isSignInAnOption} >
{ if (!roles) { return true; } - return JSON.parse(roles).includes("admin"); + + try { + return JSON.parse(roles).includes("admin"); + } catch (ex) { + return false; + } }; export const setRoles = (roles) => { - if(roles) { + if (roles) { localStorage.setItem("roles", JSON.stringify(roles)); } }; + +export const setViewerRole = () => { + localStorage.setItem("roles", JSON.stringify(['viewer'])); +}; From 3ac48a23ade5f05d72fb3fc5f7a5ef4c23855062 Mon Sep 17 00:00:00 2001 From: fescobar Date: Fri, 15 Jan 2021 16:06:01 +0000 Subject: [PATCH 2/2] Updating buildx in GH Action --- .github/workflows/docker-publish.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 21fb6c2..c856c8b 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,4 +1,4 @@ -name: Allure Docker UI Workflow +name: Allure Docker Service UI Workflow on: push: @@ -14,7 +14,7 @@ env: DOCKER_IMAGE: frankescobar/allure-docker-service-ui jobs: - push: + build-release: runs-on: ubuntu-latest if: github.event_name == 'push' @@ -46,15 +46,14 @@ jobs: --build-arg VCS_REF=${GITHUB_SHA::8} \ ${TAGS} --file docker/Dockerfile . + - name: Setting up QEMU + uses: docker/setup-qemu-action@v1 + - name: Setting up Docker Buildx id: buildx - uses: crazy-max/ghaction-docker-buildx@v3 + uses: docker/setup-buildx-action@v1 with: - buildx-version: latest - qemu-version: latest - - - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} + version: latest - name: Docker Building run: | @@ -62,7 +61,7 @@ jobs: - name: DockerHub Login if: success() && startsWith(github.ref, 'refs/tags/v') - uses: crazy-max/ghaction-docker-login@v1 + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_PASS }}