From ee8e744c1ef45948632e75934837986b349d6227 Mon Sep 17 00:00:00 2001 From: Ritik Kapoor Date: Tue, 7 May 2024 17:30:45 +0530 Subject: [PATCH] fix: [ritik/code-1773] Added Repository Setting for Public/Private Access --- web/src/App.tsx | 6 +- web/src/AppContext.tsx | 3 +- web/src/AppProps.ts | 1 + web/src/bootstrap.tsx | 1 + web/src/framework/strings/stringTypes.ts | 2 + web/src/i18n/strings.en.yaml | 4 +- .../GeneralSettingsContent.tsx | 115 +++++++++++------- .../RepositorySettings.module.scss | 1 - 8 files changed, 84 insertions(+), 49 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index effac21cb..098b8ab2d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -48,7 +48,8 @@ const App: React.FC = React.memo(function App({ hooks, customComponents, currentUserProfileURL = '', - defaultSettingsURL = '' + defaultSettingsURL = '', + isPublicAccessEnabledOnResources = false }: AppProps) { const [strings, setStrings] = useState() const getRequestOptions = useCallback( @@ -90,7 +91,8 @@ const App: React.FC = React.memo(function App({ currentUser: defaultCurrentUser, customComponents, currentUserProfileURL, - defaultSettingsURL + defaultSettingsURL, + isPublicAccessEnabledOnResources }}> ({ }, currentUserProfileURL: '', routingId: '', - defaultSettingsURL: '' + defaultSettingsURL: '', + isPublicAccessEnabledOnResources: false }) export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(function AppContextProvider({ diff --git a/web/src/AppProps.ts b/web/src/AppProps.ts index c4ae2d687..905f6c83d 100644 --- a/web/src/AppProps.ts +++ b/web/src/AppProps.ts @@ -78,4 +78,5 @@ export interface AppProps { currentUserProfileURL: string defaultSettingsURL: string + isPublicAccessEnabledOnResources: boolean } diff --git a/web/src/bootstrap.tsx b/web/src/bootstrap.tsx index a712f307c..3ed96d8c9 100644 --- a/web/src/bootstrap.tsx +++ b/web/src/bootstrap.tsx @@ -50,6 +50,7 @@ ReactDOM.render( currentUserProfileURL="" routingId="" defaultSettingsURL="" + isPublicAccessEnabledOnResources />, document.getElementById('react-root') ) diff --git a/web/src/framework/strings/stringTypes.ts b/web/src/framework/strings/stringTypes.ts index 4b114ff30..38ea9c649 100644 --- a/web/src/framework/strings/stringTypes.ts +++ b/web/src/framework/strings/stringTypes.ts @@ -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 diff --git a/web/src/i18n/strings.en.yaml b/web/src/i18n/strings.en.yaml index d9bd67c9a..ae03fe347 100644 --- a/web/src/i18n/strings.en.yaml +++ b/web/src/i18n/strings.en.yaml @@ -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. diff --git a/web/src/pages/RepositorySettings/GeneralSettingsContent/GeneralSettingsContent.tsx b/web/src/pages/RepositorySettings/GeneralSettingsContent/GeneralSettingsContent.tsx index 1b149ba08..fa0e03f84 100644 --- a/web/src/pages/RepositorySettings/GeneralSettingsContent/GeneralSettingsContent.tsx +++ b/web/src/pages/RepositorySettings/GeneralSettingsContent/GeneralSettingsContent.tsx @@ -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 ( {getString('changeRepoVis')}} isOpen onClose={hideModal}> - - {repoVis}, - repoText: - repoVis === RepoVisibility.PUBLIC - ? getString('createRepoModal.publicLabel') - : getString('createRepoModal.privateLabel') + + + {repoVis} + }} + /> + + - -
- -
) } @@ -315,7 +340,7 @@ const GeneralSettingsContent = (props: GeneralSettingsProps) => { - + @@ -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} diff --git a/web/src/pages/RepositorySettings/RepositorySettings.module.scss b/web/src/pages/RepositorySettings/RepositorySettings.module.scss index 4b25b2eab..640880926 100644 --- a/web/src/pages/RepositorySettings/RepositorySettings.module.scss +++ b/web/src/pages/RepositorySettings/RepositorySettings.module.scss @@ -122,7 +122,6 @@ } .dialogContainer { - padding-bottom: 27px !important; :global(.bp3-dialog-header) { margin-bottom: var(--spacing-medium) !important;