added support for gitness public repo (#2405)

* update: to primary btn for signin
* update index2 sign in btn to secondary
* update index2 to index_public and add sign in btn
* lint errors
* remove redundant code
* update isCurrentSessionPublic with gitness public session changes
* added support for gitness public repo
This commit is contained in:
Ritik Kapoor 2024-08-06 12:39:02 +00:00 committed by Harness
parent ce8b17bb93
commit b1f8f528da
12 changed files with 72 additions and 25 deletions

View File

@ -220,6 +220,13 @@ module.exports = {
minify: false, minify: false,
templateParameters: {} templateParameters: {}
}), }),
new HTMLWebpackPlugin({
template: 'src/index_public.html',
filename: 'index_public.html',
favicon: 'src/favicon.svg',
minify: false,
templateParameters: {}
}),
moduleFederationPlugin, moduleFederationPlugin,
new DefinePlugin({ new DefinePlugin({
'process.env': '{}', // required for @blueprintjs/core 'process.env': '{}', // required for @blueprintjs/core

View File

@ -64,14 +64,16 @@ func Handler() http.HandlerFunc {
r.URL.Path = "/" + basePath r.URL.Path = "/" + basePath
} }
//nolint:revive,staticcheck
if RenderPublicAccessFrom(r.Context()) && if RenderPublicAccessFrom(r.Context()) &&
(r.URL.Path == "/" || r.URL.Path == "/index.html") { (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 // 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("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
w.Header().Set("pragma", "no-cache") w.Header().Set("pragma", "no-cache")
w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Type-Options", "nosniff")

View File

@ -50,7 +50,7 @@ const App: React.FC<AppProps> = React.memo(function App({
currentUserProfileURL = '', currentUserProfileURL = '',
defaultSettingsURL = '', defaultSettingsURL = '',
isPublicAccessEnabledOnResources = false, isPublicAccessEnabledOnResources = false,
isCurrentSessionPublic = false isCurrentSessionPublic = !!window.publicAccessOnGitness
}: AppProps) { }: AppProps) {
const [strings, setStrings] = useState<LanguageRecord>() const [strings, setStrings] = useState<LanguageRecord>()
const getRequestOptions = useCallback( const getRequestOptions = useCallback(

View File

@ -55,7 +55,7 @@ const AppContext = React.createContext<AppContextProps>({
routingId: '', routingId: '',
defaultSettingsURL: '', defaultSettingsURL: '',
isPublicAccessEnabledOnResources: false, isPublicAccessEnabledOnResources: false,
isCurrentSessionPublic: false isCurrentSessionPublic: !!window.publicAccessOnGitness
}) })
export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(function AppContextProvider({ export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(function AppContextProvider({

View File

@ -51,7 +51,7 @@ ReactDOM.render(
routingId="" routingId=""
defaultSettingsURL="" defaultSettingsURL=""
isPublicAccessEnabledOnResources isPublicAccessEnabledOnResources
isCurrentSessionPublic={false} isCurrentSessionPublic={!!window.publicAccessOnGitness}
/>, />,
document.getElementById('react-root') document.getElementById('react-root')
) )

1
web/src/global.d.ts vendored
View File

@ -70,6 +70,7 @@ declare interface Window {
STRIP_CDE_PREFIX?: boolean STRIP_CDE_PREFIX?: boolean
STRIP_CODE_PREFIX?: boolean STRIP_CODE_PREFIX?: boolean
Sanitizer: any Sanitizer: any
publicAccessOnGitness: boolean
} }
declare const __ENABLE_CDN__: boolean declare const __ENABLE_CDN__: boolean

View File

@ -8,6 +8,9 @@
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;700&display=swap" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;700&display=swap" rel="stylesheet" />
<link rel="icon" href="favicon.svg" /> <link rel="icon" href="favicon.svg" />
<title>Gitness</title> <title>Gitness</title>
<script>
window.publicAccessOnGitness = false
</script>
</head> </head>
<body> <body>
<div id="react-root"></div> <div id="react-root"></div>

18
web/src/index_public.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Language" content="en" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;700&display=swap" rel="stylesheet" />
<link rel="icon" href="favicon.svg" />
<title>Gitness</title>
<script>
window.publicAccessOnGitness = true
</script>
</head>
<body>
<div id="react-root"></div>
</body>
</html>

View File

@ -40,7 +40,7 @@
} }
} }
.profile { .navContainer {
margin: 0 var(--spacing-medium); margin: 0 var(--spacing-medium);
padding: var(--spacing-medium) 0; padding: var(--spacing-medium) 0;
} }

View File

@ -20,5 +20,5 @@ export declare const content: string
export declare const layout: string export declare const layout: string
export declare const main: string export declare const main: string
export declare const menu: string export declare const menu: string
export declare const profile: string export declare const navContainer: string
export declare const userManagement: string export declare const userManagement: string

View File

@ -15,7 +15,8 @@
*/ */
import React from 'react' 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 { Render } from 'react-jsx-match'
import { ProfileCircle } from 'iconoir-react' import { ProfileCircle } from 'iconoir-react'
import { useAppContext } from 'AppContext' import { useAppContext } from 'AppContext'
@ -32,10 +33,9 @@ interface LayoutWithSideNavProps {
} }
export const LayoutWithSideNav: React.FC<LayoutWithSideNavProps> = ({ title, children, menu = <DefaultMenu /> }) => { export const LayoutWithSideNav: React.FC<LayoutWithSideNavProps> = ({ title, children, menu = <DefaultMenu /> }) => {
const { routes } = useAppContext() const { routes, currentUser, isCurrentSessionPublic } = useAppContext()
const { currentUser } = useAppContext() const history = useHistory()
const { getString } = useStrings() const { getString } = useStrings()
useDocumentTitle(title) useDocumentTitle(title)
return ( return (
@ -60,7 +60,7 @@ export const LayoutWithSideNav: React.FC<LayoutWithSideNavProps> = ({ title, chi
</Render> </Render>
<Render when={currentUser?.uid}> <Render when={currentUser?.uid}>
<Container className={css.profile}> <Container className={css.navContainer}>
<NavMenuItem <NavMenuItem
label={currentUser?.display_name || currentUser?.email} label={currentUser?.display_name || currentUser?.email}
to={routes.toCODEUserProfile()} to={routes.toCODEUserProfile()}
@ -69,6 +69,20 @@ export const LayoutWithSideNav: React.FC<LayoutWithSideNavProps> = ({ title, chi
</NavMenuItem> </NavMenuItem>
</Container> </Container>
</Render> </Render>
<Render when={isCurrentSessionPublic}>
<Container className={css.navContainer}>
<Button
onClick={() => history.push(routes.toSignIn())}
variation={ButtonVariation.PRIMARY}
intent="primary"
loading={false}
disabled={false}
width="100%">
{getString('signIn')}
</Button>
</Container>
</Render>
</Container> </Container>
<Container className={css.content}>{children}</Container> <Container className={css.content}>{children}</Container>

View File

@ -31,7 +31,7 @@ import css from './DefaultMenu.module.scss'
export const DefaultMenu: React.FC = () => { export const DefaultMenu: React.FC = () => {
const history = useHistory() const history = useHistory()
const { routes, standalone } = useAppContext() const { routes, standalone, isCurrentSessionPublic } = useAppContext()
const [selectedSpace, setSelectedSpace] = useState<SpaceSpaceOutput | undefined>() const [selectedSpace, setSelectedSpace] = useState<SpaceSpaceOutput | undefined>()
const { repoMetadata, gitRef, commitRef } = useGetRepositoryMetadata() const { repoMetadata, gitRef, commitRef } = useGetRepositoryMetadata()
const { getString } = useStrings() const { getString } = useStrings()
@ -58,17 +58,19 @@ export const DefaultMenu: React.FC = () => {
return ( return (
<Container className={css.main}> <Container className={css.main}>
<Layout.Vertical spacing="small"> <Layout.Vertical spacing="small">
<SpaceSelector <Render when={!isCurrentSessionPublic}>
onSelect={(_selectedSpace, isUserAction) => { <SpaceSelector
setSelectedSpace(_selectedSpace) onSelect={(_selectedSpace, isUserAction) => {
if (_selectedSpace.path === '' && _selectedSpace.id === -1) { setSelectedSpace(_selectedSpace)
setSelectedSpace(undefined) if (_selectedSpace.path === '' && _selectedSpace.id === -1) {
} setSelectedSpace(undefined)
if (isUserAction) { }
history.push(routes.toCODERepositories({ space: _selectedSpace.path as string })) if (isUserAction) {
} history.push(routes.toCODERepositories({ space: _selectedSpace.path as string }))
}} }
/> }}
/>
</Render>
<Render when={selectedSpace}> <Render when={selectedSpace}>
<NavMenuItem <NavMenuItem