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,
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

View File

@ -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")

View File

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

View File

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

View File

@ -51,7 +51,7 @@ ReactDOM.render(
routingId=""
defaultSettingsURL=""
isPublicAccessEnabledOnResources
isCurrentSessionPublic={false}
isCurrentSessionPublic={!!window.publicAccessOnGitness}
/>,
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_CODE_PREFIX?: boolean
Sanitizer: any
publicAccessOnGitness: 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 rel="icon" href="favicon.svg" />
<title>Gitness</title>
<script>
window.publicAccessOnGitness = false
</script>
</head>
<body>
<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);
padding: var(--spacing-medium) 0;
}

View File

@ -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

View File

@ -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<LayoutWithSideNavProps> = ({ title, children, menu = <DefaultMenu /> }) => {
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<LayoutWithSideNavProps> = ({ title, chi
</Render>
<Render when={currentUser?.uid}>
<Container className={css.profile}>
<Container className={css.navContainer}>
<NavMenuItem
label={currentUser?.display_name || currentUser?.email}
to={routes.toCODEUserProfile()}
@ -69,6 +69,20 @@ export const LayoutWithSideNav: React.FC<LayoutWithSideNavProps> = ({ title, chi
</NavMenuItem>
</Container>
</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 className={css.content}>{children}</Container>

View File

@ -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<SpaceSpaceOutput | undefined>()
const { repoMetadata, gitRef, commitRef } = useGetRepositoryMetadata()
const { getString } = useStrings()
@ -58,6 +58,7 @@ export const DefaultMenu: React.FC = () => {
return (
<Container className={css.main}>
<Layout.Vertical spacing="small">
<Render when={!isCurrentSessionPublic}>
<SpaceSelector
onSelect={(_selectedSpace, isUserAction) => {
setSelectedSpace(_selectedSpace)
@ -69,6 +70,7 @@ export const DefaultMenu: React.FC = () => {
}
}}
/>
</Render>
<Render when={selectedSpace}>
<NavMenuItem