diff --git a/web/config/webpack.common.js b/web/config/webpack.common.js index d3fba8a8b..0569d97db 100644 --- a/web/config/webpack.common.js +++ b/web/config/webpack.common.js @@ -220,6 +220,13 @@ module.exports = { minify: false, templateParameters: {} }), + new HTMLWebpackPlugin({ + template: 'src/index_public.html', + filename: 'index_public.html', + favicon: 'src/favicon.svg', + minify: false, + templateParameters: {} + }), moduleFederationPlugin, new DefinePlugin({ 'process.env': '{}', // required for @blueprintjs/core diff --git a/web/dist.go b/web/dist.go index 0d0519438..8d0c7ee05 100644 --- a/web/dist.go +++ b/web/dist.go @@ -64,14 +64,16 @@ func Handler() http.HandlerFunc { r.URL.Path = "/" + basePath } - //nolint:revive,staticcheck if RenderPublicAccessFrom(r.Context()) && (r.URL.Path == "/" || r.URL.Path == "/index.html") { - // TODO: handle public access rendering + r.URL.Path = "./index_public.html" } // Disable caching and sniffing via HTTP headers for UI main entry resources - if r.URL.Path == "/" || r.URL.Path == remoteEntryJSFullPath || r.URL.Path == "/index.html" { + if r.URL.Path == "/" || + r.URL.Path == remoteEntryJSFullPath || + r.URL.Path == "/index.html" || + r.URL.Path == "/index_public.html" { w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0") w.Header().Set("pragma", "no-cache") w.Header().Set("X-Content-Type-Options", "nosniff") diff --git a/web/src/App.tsx b/web/src/App.tsx index 8c6e72e47..97349d440 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -50,7 +50,7 @@ const App: React.FC = React.memo(function App({ currentUserProfileURL = '', defaultSettingsURL = '', isPublicAccessEnabledOnResources = false, - isCurrentSessionPublic = false + isCurrentSessionPublic = !!window.publicAccessOnGitness }: AppProps) { const [strings, setStrings] = useState() const getRequestOptions = useCallback( diff --git a/web/src/AppContext.tsx b/web/src/AppContext.tsx index 1cbc163c2..4061108cc 100644 --- a/web/src/AppContext.tsx +++ b/web/src/AppContext.tsx @@ -55,7 +55,7 @@ const AppContext = React.createContext({ routingId: '', defaultSettingsURL: '', isPublicAccessEnabledOnResources: false, - isCurrentSessionPublic: false + isCurrentSessionPublic: !!window.publicAccessOnGitness }) export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(function AppContextProvider({ diff --git a/web/src/bootstrap.tsx b/web/src/bootstrap.tsx index 8b25b7c42..525a59e09 100644 --- a/web/src/bootstrap.tsx +++ b/web/src/bootstrap.tsx @@ -51,7 +51,7 @@ ReactDOM.render( routingId="" defaultSettingsURL="" isPublicAccessEnabledOnResources - isCurrentSessionPublic={false} + isCurrentSessionPublic={!!window.publicAccessOnGitness} />, document.getElementById('react-root') ) diff --git a/web/src/global.d.ts b/web/src/global.d.ts index 5381c3607..9d7521c0b 100644 --- a/web/src/global.d.ts +++ b/web/src/global.d.ts @@ -70,6 +70,7 @@ declare interface Window { STRIP_CDE_PREFIX?: boolean STRIP_CODE_PREFIX?: boolean Sanitizer: any + publicAccessOnGitness: boolean } declare const __ENABLE_CDN__: boolean diff --git a/web/src/index.html b/web/src/index.html index f4ff33ff4..3d4d33cb1 100644 --- a/web/src/index.html +++ b/web/src/index.html @@ -8,6 +8,9 @@ Gitness +
diff --git a/web/src/index_public.html b/web/src/index_public.html new file mode 100644 index 000000000..2de9b1936 --- /dev/null +++ b/web/src/index_public.html @@ -0,0 +1,18 @@ + + + + + + + + + + Gitness + + + +
+ + diff --git a/web/src/layouts/layout.module.scss b/web/src/layouts/layout.module.scss index 55a24d624..f4cd6ac6d 100644 --- a/web/src/layouts/layout.module.scss +++ b/web/src/layouts/layout.module.scss @@ -40,7 +40,7 @@ } } - .profile { + .navContainer { margin: 0 var(--spacing-medium); padding: var(--spacing-medium) 0; } diff --git a/web/src/layouts/layout.module.scss.d.ts b/web/src/layouts/layout.module.scss.d.ts index 3c360a28e..6676b20d5 100644 --- a/web/src/layouts/layout.module.scss.d.ts +++ b/web/src/layouts/layout.module.scss.d.ts @@ -20,5 +20,5 @@ export declare const content: string export declare const layout: string export declare const main: string export declare const menu: string -export declare const profile: string +export declare const navContainer: string export declare const userManagement: string diff --git a/web/src/layouts/layout.tsx b/web/src/layouts/layout.tsx index 494a880f8..a79586016 100644 --- a/web/src/layouts/layout.tsx +++ b/web/src/layouts/layout.tsx @@ -15,7 +15,8 @@ */ import React from 'react' -import { Avatar, Container, FlexExpander, Layout } from '@harnessio/uicore' +import { useHistory } from 'react-router-dom' +import { Avatar, Button, ButtonVariation, Container, FlexExpander, Layout } from '@harnessio/uicore' import { Render } from 'react-jsx-match' import { ProfileCircle } from 'iconoir-react' import { useAppContext } from 'AppContext' @@ -32,10 +33,9 @@ interface LayoutWithSideNavProps { } export const LayoutWithSideNav: React.FC = ({ title, children, menu = }) => { - const { routes } = useAppContext() - const { currentUser } = useAppContext() + const { routes, currentUser, isCurrentSessionPublic } = useAppContext() + const history = useHistory() const { getString } = useStrings() - useDocumentTitle(title) return ( @@ -60,7 +60,7 @@ export const LayoutWithSideNav: React.FC = ({ title, chi - + = ({ title, chi + + + + + + {children} diff --git a/web/src/layouts/menu/DefaultMenu.tsx b/web/src/layouts/menu/DefaultMenu.tsx index 81204ed92..0f73260d6 100644 --- a/web/src/layouts/menu/DefaultMenu.tsx +++ b/web/src/layouts/menu/DefaultMenu.tsx @@ -31,7 +31,7 @@ import css from './DefaultMenu.module.scss' export const DefaultMenu: React.FC = () => { const history = useHistory() - const { routes, standalone } = useAppContext() + const { routes, standalone, isCurrentSessionPublic } = useAppContext() const [selectedSpace, setSelectedSpace] = useState() const { repoMetadata, gitRef, commitRef } = useGetRepositoryMetadata() const { getString } = useStrings() @@ -58,17 +58,19 @@ export const DefaultMenu: React.FC = () => { return ( - { - setSelectedSpace(_selectedSpace) - if (_selectedSpace.path === '' && _selectedSpace.id === -1) { - setSelectedSpace(undefined) - } - if (isUserAction) { - history.push(routes.toCODERepositories({ space: _selectedSpace.path as string })) - } - }} - /> + + { + setSelectedSpace(_selectedSpace) + if (_selectedSpace.path === '' && _selectedSpace.id === -1) { + setSelectedSpace(undefined) + } + if (isUserAction) { + history.push(routes.toCODERepositories({ space: _selectedSpace.path as string })) + } + }} + /> +