mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-19 06:20:48 +02:00
improvements
This commit is contained in:
parent
ddd1e6ca83
commit
ef7a98b505
@ -955,6 +955,16 @@ func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateUserColsWithNoAutotime update user according special columns
|
||||||
|
func UpdateUserColsWithNoAutotime(ctx context.Context, u *User, cols ...string) error {
|
||||||
|
if err := ValidateUser(u, cols...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := db.GetEngine(ctx).ID(u.ID).Cols(cols...).NoAutoTime().Update(u)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// GetInactiveUsers gets all inactive users
|
// GetInactiveUsers gets all inactive users
|
||||||
func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, error) {
|
func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, error) {
|
||||||
cond := builder.And(
|
cond := builder.And(
|
||||||
|
@ -39,6 +39,10 @@ func (vt VisibleType) IsPrivate() bool {
|
|||||||
return vt == VisibleTypePrivate
|
return vt == VisibleTypePrivate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vt VisibleType) IsValid() bool {
|
||||||
|
return vt.String() != ""
|
||||||
|
}
|
||||||
|
|
||||||
// VisibilityString provides the mode string of the visibility type (public, limited, private)
|
// VisibilityString provides the mode string of the visibility type (public, limited, private)
|
||||||
func (vt VisibleType) String() string {
|
func (vt VisibleType) String() string {
|
||||||
for k, v := range VisibilityModes {
|
for k, v := range VisibilityModes {
|
||||||
@ -56,3 +60,10 @@ func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
|
|||||||
}
|
}
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertStringToVisibleType(s string) VisibleType {
|
||||||
|
if vt, ok := VisibilityModes[s]; ok {
|
||||||
|
return vt
|
||||||
|
}
|
||||||
|
return VisibleType(-1) // Invalid type
|
||||||
|
}
|
||||||
|
@ -2826,6 +2826,14 @@ settings.location = Location
|
|||||||
settings.permission = Permissions
|
settings.permission = Permissions
|
||||||
settings.repoadminchangeteam = Repository admin can add and remove access for teams
|
settings.repoadminchangeteam = Repository admin can add and remove access for teams
|
||||||
settings.visibility = Visibility
|
settings.visibility = Visibility
|
||||||
|
settings.change_visibility = Change Visibility
|
||||||
|
settings.invalid_visibility = The new visibility is not valid.
|
||||||
|
settings.change_visibility_notices_1 = This operation <strong>CANNOT</strong> be undone.
|
||||||
|
settings.change_visibility_notices_2 = Some users will not visit the repositories of the orgniazation.
|
||||||
|
settings.change_visibility_no_change = The visibility is no change.
|
||||||
|
settings.change_visibility_failed = Change visibility of %s failed because of internal error
|
||||||
|
settings.change_visibility_success = Organization %s visibility has been changed successfully.
|
||||||
|
settings.visibility_desc = Changing the organisation visibility
|
||||||
settings.visibility.public = Public
|
settings.visibility.public = Public
|
||||||
settings.visibility.limited = Limited (Visible to authenticated users only)
|
settings.visibility.limited = Limited (Visible to authenticated users only)
|
||||||
settings.visibility.limited_shortname = Limited
|
settings.visibility.limited_shortname = Limited
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/optional"
|
"code.gitea.io/gitea/modules/optional"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/templates"
|
"code.gitea.io/gitea/modules/templates"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
@ -25,7 +26,6 @@ import (
|
|||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
org_service "code.gitea.io/gitea/services/org"
|
org_service "code.gitea.io/gitea/services/org"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
|
||||||
user_service "code.gitea.io/gitea/services/user"
|
user_service "code.gitea.io/gitea/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,38 +83,17 @@ func SettingsPost(ctx *context.Context) {
|
|||||||
Description: optional.Some(form.Description),
|
Description: optional.Some(form.Description),
|
||||||
Website: optional.Some(form.Website),
|
Website: optional.Some(form.Website),
|
||||||
Location: optional.Some(form.Location),
|
Location: optional.Some(form.Location),
|
||||||
Visibility: optional.Some(form.Visibility),
|
|
||||||
RepoAdminChangeTeamAccess: optional.Some(form.RepoAdminChangeTeamAccess),
|
RepoAdminChangeTeamAccess: optional.Some(form.RepoAdminChangeTeamAccess),
|
||||||
}
|
}
|
||||||
if ctx.Doer.IsAdmin {
|
if ctx.Doer.IsAdmin {
|
||||||
opts.MaxRepoCreation = optional.Some(form.MaxRepoCreation)
|
opts.MaxRepoCreation = optional.Some(form.MaxRepoCreation)
|
||||||
}
|
}
|
||||||
|
|
||||||
visibilityChanged := org.Visibility != form.Visibility
|
|
||||||
|
|
||||||
if err := user_service.UpdateUser(ctx, org.AsUser(), opts); err != nil {
|
if err := user_service.UpdateUser(ctx, org.AsUser(), opts); err != nil {
|
||||||
ctx.ServerError("UpdateUser", err)
|
ctx.ServerError("UpdateUser", err)
|
||||||
return
|
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)
|
log.Trace("Organization setting updated: %s", org.Name)
|
||||||
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
|
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
|
||||||
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
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.Flash.Success(ctx.Tr("org.settings.rename_success", oldOrgName, newOrgName))
|
||||||
ctx.JSONRedirect(setting.AppSubURL + "/org/" + url.PathEscape(newOrgName) + "/settings")
|
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"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Org.Organization.Visibility == visibility {
|
||||||
|
ctx.JSONError(ctx.Tr("org.settings.change_visibility_no_change"))
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
@ -966,6 +966,7 @@ func registerWebRoutes(m *web.Router) {
|
|||||||
|
|
||||||
m.Post("/rename", web.Bind(forms.RenameOrgForm{}), org.SettingsRenamePost)
|
m.Post("/rename", web.Bind(forms.RenameOrgForm{}), org.SettingsRenamePost)
|
||||||
m.Post("/delete", org.SettingsDeleteOrgPost)
|
m.Post("/delete", org.SettingsDeleteOrgPost)
|
||||||
|
m.Post("/visibility", org.SettingsChangeVisibilityPost)
|
||||||
|
|
||||||
m.Group("/packages", func() {
|
m.Group("/packages", func() {
|
||||||
m.Get("", org.Packages)
|
m.Get("", org.Packages)
|
||||||
|
@ -41,7 +41,6 @@ type UpdateOrgSettingForm struct {
|
|||||||
Description string `binding:"MaxSize(255)"`
|
Description string `binding:"MaxSize(255)"`
|
||||||
Website string `binding:"ValidUrl;MaxSize(255)"`
|
Website string `binding:"ValidUrl;MaxSize(255)"`
|
||||||
Location string `binding:"MaxSize(50)"`
|
Location string `binding:"MaxSize(50)"`
|
||||||
Visibility structs.VisibleType
|
|
||||||
MaxRepoCreation int
|
MaxRepoCreation int
|
||||||
RepoAdminChangeTeamAccess bool
|
RepoAdminChangeTeamAccess bool
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
secret_model "code.gitea.io/gitea/models/secret"
|
secret_model "code.gitea.io/gitea/models/secret"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/storage"
|
"code.gitea.io/gitea/modules/storage"
|
||||||
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
)
|
)
|
||||||
@ -102,3 +103,14 @@ func DeleteOrganization(ctx context.Context, org *org_model.Organization, purge
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChangeOrganizationVisibility(ctx context.Context, org *org_model.Organization, visibility structs.VisibleType) error {
|
||||||
|
if org.Visibility == visibility {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
org.Visibility = visibility
|
||||||
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
|
return user_model.UpdateUserColsWithNoAutotime(ctx, org.AsUser(), "visibility")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -29,29 +29,6 @@
|
|||||||
<input id="location" name="location" value="{{.Org.Location}}" maxlength="50">
|
<input id="location" name="location" value="{{.Org.Location}}" maxlength="50">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="divider"></div>
|
|
||||||
<div class="field" id="visibility_box">
|
|
||||||
<label for="visibility">{{ctx.Locale.Tr "org.settings.visibility"}}</label>
|
|
||||||
<div class="field">
|
|
||||||
<div class="ui radio checkbox">
|
|
||||||
<input class="enable-system-radio" name="visibility" type="radio" value="0" {{if eq .CurrentVisibility 0}}checked{{end}}>
|
|
||||||
<label>{{ctx.Locale.Tr "org.settings.visibility.public"}}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<div class="ui radio checkbox">
|
|
||||||
<input class="enable-system-radio" name="visibility" type="radio" value="1" {{if eq .CurrentVisibility 1}}checked{{end}}>
|
|
||||||
<label>{{ctx.Locale.Tr "org.settings.visibility.limited"}}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<div class="ui radio checkbox">
|
|
||||||
<input class="enable-system-radio" name="visibility" type="radio" value="2" {{if eq .CurrentVisibility 2}}checked{{end}}>
|
|
||||||
<label>{{ctx.Locale.Tr "org.settings.visibility.private"}}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field" id="permission_box">
|
<div class="field" id="permission_box">
|
||||||
<label>{{ctx.Locale.Tr "org.settings.permission"}}</label>
|
<label>{{ctx.Locale.Tr "org.settings.permission"}}</label>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
@ -3,6 +3,16 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<div class="ui attached error danger segment">
|
<div class="ui attached error danger segment">
|
||||||
<div class="flex-list">
|
<div class="flex-list">
|
||||||
|
<div class="flex-item tw-items-center">
|
||||||
|
<div class="flex-item-main">
|
||||||
|
<div class="flex-item-title">{{ctx.Locale.Tr "org.settings.visibility"}}</div>
|
||||||
|
<div class="flex-item-body">{{ctx.Locale.Tr "org.settings.visibility_desc"}}</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex-item-trailing">
|
||||||
|
<button class="ui basic red show-modal button" data-modal="#change-visibility-org-modal">{{ctx.Locale.Tr "org.settings.change_visibility"}}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex-item tw-items-center">
|
<div class="flex-item tw-items-center">
|
||||||
<div class="flex-item-main">
|
<div class="flex-item-main">
|
||||||
<div class="flex-item-title">{{ctx.Locale.Tr "org.settings.rename"}}</div>
|
<div class="flex-item-title">{{ctx.Locale.Tr "org.settings.rename"}}</div>
|
||||||
@ -25,6 +35,48 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="ui small modal" id="change-visibility-org-modal">
|
||||||
|
<div class="header">
|
||||||
|
{{ctx.Locale.Tr "org.settings.change_visibility"}}
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<ul class="ui warning message">
|
||||||
|
<li>{{ctx.Locale.Tr "org.settings.change_visibility_notices_1"}}</li>
|
||||||
|
<li>{{ctx.Locale.Tr "org.settings.change_visibility_notices_2"}}</li>
|
||||||
|
</ul>
|
||||||
|
<form class="ui form form-fetch-action" action="{{.Link}}/visibility" method="post">
|
||||||
|
{{.CsrfTokenHtml}}
|
||||||
|
|
||||||
|
<div class="field" id="visibility_box">
|
||||||
|
<label for="visibility">{{ctx.Locale.Tr "org.settings.visibility"}}</label>
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input class="enable-system-radio" name="visibility" type="radio" value="0" {{if eq .CurrentVisibility 0}}checked{{end}}>
|
||||||
|
<label>{{ctx.Locale.Tr "org.settings.visibility.public"}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input class="enable-system-radio" name="visibility" type="radio" value="1" {{if eq .CurrentVisibility 1}}checked{{end}}>
|
||||||
|
<label>{{ctx.Locale.Tr "org.settings.visibility.limited"}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input class="enable-system-radio" name="visibility" type="radio" value="2" {{if eq .CurrentVisibility 2}}checked{{end}}>
|
||||||
|
<label>{{ctx.Locale.Tr "org.settings.visibility.private"}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
|
<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
|
||||||
|
<button class="ui red button">{{ctx.Locale.Tr "org.settings.change_visibility"}}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="ui small modal" id="rename-org-modal">
|
<div class="ui small modal" id="rename-org-modal">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{ctx.Locale.Tr "org.settings.rename"}}
|
{{ctx.Locale.Tr "org.settings.rename"}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user