-
-
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
2c6e160
05e5d6c
d1f1cf8
a3d88b1
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 |
---|---|---|
|
@@ -2839,6 +2839,14 @@ settings.location = Location | |
settings.permission = Permissions | ||
settings.repoadminchangeteam = Repository admin can add and remove access for teams | ||
settings.visibility = Visibility | ||
settings.change_visibility = Change Visibility | ||
settings.invalid_visibility = The new visibility is not valid. | ||
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. Unused 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. |
||
settings.change_visibility_notices_1 = This operation <strong>CANNOT</strong> be undone. | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings.change_visibility_notices_2 = Some users will not visit the repositories of the orgniazation. | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings.change_visibility_no_change = The visibility is no change. | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings.change_visibility_failed = Change visibility of %s failed because of internal error | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings.change_visibility_success = Organization %s visibility has been changed successfully. | ||
settings.visibility_desc = Changing the organisation visibility | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings.visibility.public = Public | ||
settings.visibility.limited = Limited (Visible to authenticated users only) | ||
settings.visibility.limited_shortname = Limited | ||
|
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() { | ||
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.
You can just use 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. |
||
ctx.JSONError(ctx.Tr("org.settings.invalid_visibility")) | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
|
||
if ctx.Org.Organization.Visibility == visibility { | ||
ctx.JSONError(ctx.Tr("org.settings.change_visibility_no_change")) | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.