-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Move organization's visibility change to danger zone. #34814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
ef7a98b
475f40d
2785ae5
59e91b9
22cdf7e
0d0db1c
c2694d8
e9ba6fe
4db1324
fe350ae
33075e7
d6de786
ecc5b72
6dac5a4
8599143
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"code.gitea.io/gitea/modules/optional" | ||
repo_module "code.gitea.io/gitea/modules/repository" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/templates" | ||
"code.gitea.io/gitea/modules/util" | ||
"code.gitea.io/gitea/modules/web" | ||
|
@@ -25,7 +26,6 @@ import ( | |
"code.gitea.io/gitea/services/context" | ||
"code.gitea.io/gitea/services/forms" | ||
org_service "code.gitea.io/gitea/services/org" | ||
repo_service "code.gitea.io/gitea/services/repository" | ||
user_service "code.gitea.io/gitea/services/user" | ||
) | ||
|
||
|
@@ -83,38 +83,17 @@ func SettingsPost(ctx *context.Context) { | |
Description: optional.Some(form.Description), | ||
Website: optional.Some(form.Website), | ||
Location: optional.Some(form.Location), | ||
Visibility: optional.Some(form.Visibility), | ||
RepoAdminChangeTeamAccess: optional.Some(form.RepoAdminChangeTeamAccess), | ||
} | ||
if ctx.Doer.IsAdmin { | ||
opts.MaxRepoCreation = optional.Some(form.MaxRepoCreation) | ||
} | ||
|
||
visibilityChanged := org.Visibility != form.Visibility | ||
|
||
if err := user_service.UpdateUser(ctx, org.AsUser(), opts); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
|
||
// update forks visibility | ||
if visibilityChanged { | ||
repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{ | ||
Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}, | ||
}) | ||
if err != nil { | ||
ctx.ServerError("GetRepositories", err) | ||
return | ||
} | ||
for _, repo := range repos { | ||
repo.OwnerName = org.Name | ||
if err := repo_service.UpdateRepository(ctx, repo, true); err != nil { | ||
ctx.ServerError("UpdateRepository", err) | ||
return | ||
} | ||
} | ||
} | ||
|
||
log.Trace("Organization setting updated: %s", org.Name) | ||
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success")) | ||
ctx.Redirect(ctx.Org.OrgLink + "/settings") | ||
|
@@ -251,3 +230,26 @@ func SettingsRenamePost(ctx *context.Context) { | |
ctx.Flash.Success(ctx.Tr("org.settings.rename_success", oldOrgName, newOrgName)) | ||
ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(newOrgName) + "/settings") | ||
} | ||
|
||
// SettingsChangeVisibilityPost response for change organization visibility | ||
func SettingsChangeVisibilityPost(ctx *context.Context) { | ||
visibility := structs.VisibleType(ctx.FormInt("visibility")) | ||
if !visibility.IsValid() { | ||
ctx.JSONError(ctx.Tr("org.settings.invalid_visibility")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End users would never see such error message, so please re-use the existing |
||
return | ||
} | ||
|
||
if ctx.Org.Organization.Visibility == visibility { | ||
ctx.JSONError(ctx.Tr("org.settings.change_visibility_no_change")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be an "error". It can just flash a info or success message. And there can be a general message that "You did not make any changes" |
||
return | ||
} | ||
|
||
if err := org_service.ChangeOrganizationVisibility(ctx, ctx.Org.Organization, visibility); err != nil { | ||
log.Error("ChangeOrganizationVisibility: %v", err) | ||
ctx.JSONError(util.Iif(ctx.Doer.IsAdmin, err.Error(), string(ctx.Tr("org.settings.change_visibility_failed", ctx.Org.Organization.Name)))) | ||
return | ||
} | ||
|
||
ctx.Flash.Success(ctx.Tr("org.settings.change_visibility_success", ctx.Org.Organization.Name)) | ||
ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(ctx.Org.Organization.Name) + "/settings") | ||
} |
Uh oh!
There was an error while loading. Please reload this page.