From 33075e7be598280df51b1bb4fa4e17860fcec5d1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 7 Jul 2025 17:03:35 -0700 Subject: [PATCH] improvements --- options/locale/locale_en-US.ini | 6 ++--- routers/web/org/setting.go | 2 +- .../org/settings/options_dangerzone.tmpl | 9 ++++--- web_src/js/features/org-settings.ts | 25 +++++++++++++++++++ web_src/js/index-domready.ts | 2 ++ 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 web_src/js/features/org-settings.ts diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 612e831dad..0f1b894393 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2843,11 +2843,11 @@ settings.visibility = Visibility settings.change_visibility = Change Visibility settings.invalid_visibility = The new visibility is not valid. settings.change_visibility_notices_1 = This operation CANNOT be undone. -settings.change_visibility_notices_2 = Some users will no longer be able to access the organization’s repositories. -settings.change_visibility_no_change = There has been no change in visibility. +settings.change_visibility_notices_2 = Non-members will lose access to the organization’s repositories if visibility is changed to private. +settings.change_visibility_no_change = You did not make any changes to visibility. settings.change_visibility_failed = Failed to change the visibility of %s due to an internal error. settings.change_visibility_success = The visibility of organization %s has been successfully changed. -settings.visibility_desc = Change the organization visibility +settings.visibility_desc = Change who can view the organization and its repositories. settings.visibility.public = Public settings.visibility.limited = Limited (Visible to authenticated users only) settings.visibility.limited_shortname = Limited diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 8d62c2edab..d2965c2c3e 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -233,7 +233,7 @@ func SettingsRenamePost(ctx *context.Context) { // SettingsChangeVisibilityPost response for change organization visibility func SettingsChangeVisibilityPost(ctx *context.Context) { - visibility := structs.VisibleType(ctx.FormInt("visibility")) + visibility := structs.VisibilityModes[ctx.FormString("visibility")] if !visibility.IsValid() { ctx.JSONError(ctx.Tr("org.settings.invalid_visibility")) return diff --git a/templates/org/settings/options_dangerzone.tmpl b/templates/org/settings/options_dangerzone.tmpl index c21cbbde4b..f761c4ea7e 100644 --- a/templates/org/settings/options_dangerzone.tmpl +++ b/templates/org/settings/options_dangerzone.tmpl @@ -48,25 +48,26 @@
{{.CsrfTokenHtml}} +
- +
- +
- +
- +
diff --git a/web_src/js/features/org-settings.ts b/web_src/js/features/org-settings.ts new file mode 100644 index 0000000000..4d20f55021 --- /dev/null +++ b/web_src/js/features/org-settings.ts @@ -0,0 +1,25 @@ +function initOrgVisibilityChange() { + const visibilityModal = document.querySelector('#change-visibility-org-modal'); + if (!visibilityModal) return; + + const visibilitySelect = visibilityModal.querySelectorAll("input[name='visibility']"); + if (!visibilitySelect) return; + + const currentValue = visibilityModal.querySelector('input[name="current_visibility"]').value; + + for (const radio of visibilitySelect) { + radio.addEventListener('change', () => { + const selectedValue = visibilityModal.querySelector("input[name='visibility']:checked").value; + const btn = visibilityModal.querySelector('#change-visibility-submit'); + if (selectedValue === currentValue) { + btn.setAttribute('disabled', ''); + } else { + btn.removeAttribute('disabled'); + } + }); + } +} + +export function initOrgSettings() { + initOrgVisibilityChange(); +} diff --git a/web_src/js/index-domready.ts b/web_src/js/index-domready.ts index 4d7ab98db0..476ba8d50d 100644 --- a/web_src/js/index-domready.ts +++ b/web_src/js/index-domready.ts @@ -33,6 +33,7 @@ import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/ import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts'; import {initRepoDiffView} from './features/repo-diff.ts'; import {initOrgTeam} from './features/org-team.ts'; +import {initOrgSettings} from './features/org-settings.ts'; import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts'; import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts'; import {initRepoEditor} from './features/repo-editor.ts'; @@ -120,6 +121,7 @@ const initPerformanceTracer = callInitFunctions([ initNotificationsTable, initOrgTeam, + initOrgSettings, initRepoActivityTopAuthorsChart, initRepoArchiveLinks,