fix: [ritik/code-1773] Added Repository Setting for Public/Private Access

gitness-public-repo-testing
Ritik Kapoor 2024-05-07 17:30:45 +05:30 committed by Karan Saraswat
parent 71ea1947b2
commit ee8e744c1e
8 changed files with 84 additions and 49 deletions

View File

@ -48,7 +48,8 @@ const App: React.FC<AppProps> = React.memo(function App({
hooks,
customComponents,
currentUserProfileURL = '',
defaultSettingsURL = ''
defaultSettingsURL = '',
isPublicAccessEnabledOnResources = false
}: AppProps) {
const [strings, setStrings] = useState<LanguageRecord>()
const getRequestOptions = useCallback(
@ -90,7 +91,8 @@ const App: React.FC<AppProps> = React.memo(function App({
currentUser: defaultCurrentUser,
customComponents,
currentUserProfileURL,
defaultSettingsURL
defaultSettingsURL,
isPublicAccessEnabledOnResources
}}>
<IconoirProvider
iconProps={{

View File

@ -53,7 +53,8 @@ const AppContext = React.createContext<AppContextProps>({
},
currentUserProfileURL: '',
routingId: '',
defaultSettingsURL: ''
defaultSettingsURL: '',
isPublicAccessEnabledOnResources: false
})
export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(function AppContextProvider({

View File

@ -78,4 +78,5 @@ export interface AppProps {
currentUserProfileURL: string
defaultSettingsURL: string
isPublicAccessEnabledOnResources: boolean
}

View File

@ -50,6 +50,7 @@ ReactDOM.render(
currentUserProfileURL=""
routingId=""
defaultSettingsURL=""
isPublicAccessEnabledOnResources
/>,
document.getElementById('react-root')
)

View File

@ -179,6 +179,7 @@ export interface StringsMap {
confirmNewPassword: string
confirmPassRequired: string
confirmPassword: string
confirmRepoVisButton: string
confirmation: string
content: string
contents: string
@ -206,6 +207,7 @@ export interface StringsMap {
'createRepoModal.branchLabel': string
'createRepoModal.privateLabel': string
'createRepoModal.publicLabel': string
'createRepoModal.publicWarning': string
createRepoPerms: string
createSpace: string
createTag: string

View File

@ -122,6 +122,7 @@ createRepoModal:
branch: ' branch.'
publicLabel: Anyone with access to the Gitness environment can clone this repo.
privateLabel: You choose who can see and commit to this repository.
publicWarning: Please note that anyone with access to the Gitness environment can clone this repo.
validation:
repoNamePatternIsNotValid: "Name can only contain alphanumerics, '-', '_', '.', and '$'"
gitBranchNameInvalid: Branch name is invalid.
@ -893,7 +894,8 @@ enterGitlabPlaceholder: https://gitlab.com/
enterGithubPlaceholder: https://api.github.com/
enterBitbucketPlaceholder: https://bitbucket.org/
changeRepoVis: Change repository visibility
changeRepoVisContent: Are you sure you want to make this repository {repoVis}? {repoText}
changeRepoVisContent: Are you sure you want to make this repository {repoVis}?
confirmRepoVisButton: Yes, make the Repository {repoVis}
repoVisibility: Repository visibility
visibility: Visibility
attachText: Attach images & videos by dragging & dropping, selecting or pasting them.

View File

@ -65,8 +65,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
const { showError, showSuccess } = useToaster()
const space = useGetSpaceParam()
const { standalone } = useAppContext()
const { hooks } = useAppContext()
const { standalone, hooks, isPublicAccessEnabledOnResources } = useAppContext()
const { getString } = useStrings()
const currRepoVisibility = repoMetadata?.is_public === true ? RepoVisibility.PUBLIC : RepoVisibility.PRIVATE
@ -77,6 +76,11 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
path: `/api/v1/repos/${repoMetadata?.path}/+/`
})
const { mutate: changeVisibility } = useMutate({
verb: 'POST',
path: `/api/v1/repos/${repoMetadata?.path}/+/public-access`
})
const permEditResult = hooks?.usePermissionTranslate?.(
{
resource: {
@ -109,50 +113,71 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
return (
<Dialog
className={css.dialogContainer}
style={{ width: 610, maxHeight: '95vh', overflow: 'auto' }}
title={getString('changeRepoVis')}
style={{ width: 585, maxHeight: '95vh', overflow: 'auto' }}
title={<Text font={{ variation: FontVariation.H4 }}>{getString('changeRepoVis')}</Text>}
isOpen
onClose={hideModal}>
<Text>
<StringSubstitute
str={getString('changeRepoVisContent')}
vars={{
repoVis: <span className={css.text}>{repoVis}</span>,
repoText:
repoVis === RepoVisibility.PUBLIC
? getString('createRepoModal.publicLabel')
: getString('createRepoModal.privateLabel')
<Layout.Vertical spacing="xlarge">
<Text>
<StringSubstitute
str={getString('changeRepoVisContent')}
vars={{
repoVis: <span className={css.text}>{repoVis}</span>
}}
/>
</Text>
<Container
intent="warning"
background="yellow100"
border={{
color: 'orange500'
}}
/>
</Text>
<hr className={css.dividerContainer} />
<Layout.Horizontal className={css.buttonContainer}>
<Button
margin={{ right: 'medium' }}
type="submit"
text={getString('confirm')}
variation={ButtonVariation.PRIMARY}
onClick={() => {
mutate({ is_public: repoVis === RepoVisibility.PUBLIC ? true : false })
.then(() => {
showSuccess(getString('repoUpdate'))
hideModal()
refetch()
})
.catch(err => {
showError(getErrorMessage(err))
})
refetch()
}}
/>
<Button
text={getString('cancel')}
variation={ButtonVariation.TERTIARY}
onClick={() => {
hideModal()
}}
/>
</Layout.Horizontal>
margin={{ top: 'medium', bottom: 'medium' }}>
<Text
icon="warning-outline"
iconProps={{ size: 16, margin: { right: 'small' } }}
padding={{ left: 'large', right: 'large', top: 'small', bottom: 'small' }}
color={Color.WARNING}>
{repoVis === RepoVisibility.PUBLIC
? getString('createRepoModal.publicWarning')
: getString('createRepoModal.privateLabel')}
</Text>
</Container>
<Layout.Horizontal className={css.buttonContainer}>
<Button
margin={{ right: 'medium' }}
type="submit"
text={
<StringSubstitute
str={getString('confirmRepoVisButton')}
vars={{
repoVis: <span className={css.text}>{repoVis}</span>
}}
/>
}
variation={ButtonVariation.PRIMARY}
onClick={() => {
changeVisibility({ enable: repoVis === RepoVisibility.PUBLIC ? true : false })
.then(() => {
showSuccess(getString('repoUpdate'))
hideModal()
refetch()
})
.catch(err => {
showError(getErrorMessage(err))
})
refetch()
}}
/>
<Button
text={getString('cancel')}
variation={ButtonVariation.TERTIARY}
onClick={() => {
hideModal()
}}
/>
</Layout.Horizontal>
</Layout.Vertical>
</Dialog>
)
}
@ -315,7 +340,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
</Container>
</Layout.Horizontal>
</Container>
<Render when={enablePublicRepo}>
<Render when={enablePublicRepo && isPublicAccessEnabledOnResources}>
<Container padding="large" margin={{ bottom: 'medium' }} className={css.generalContainer}>
<Layout.Horizontal padding={{ bottom: 'medium' }}>
<Container className={css.label}>
@ -330,6 +355,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
onChange={evt => {
setRepoVis((evt.target as HTMLInputElement).value as RepoVisibility)
}}
{...permissionProps(permEditResult, standalone)}
className={css.radioContainer}
items={[
{
@ -391,6 +417,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => {
setRepoVis(formik.values.isPublic)
openModal()
}}
{...permissionProps(permEditResult, standalone)}
/>
) : null}
</Layout.Horizontal>

View File

@ -122,7 +122,6 @@
}
.dialogContainer {
padding-bottom: 27px !important;
:global(.bp3-dialog-header) {
margin-bottom: var(--spacing-medium) !important;