UI related changed for ENABLE_SIZE_LIMIT & REPO_SIZE_LIMIT options

This commit is contained in:
truecode112
2023-05-15 17:06:39 +00:00
committed by DmitryFrolovTri
parent a22b73866a
commit 66c476e5de
7 changed files with 98 additions and 1 deletions
+8 -1
View File
@@ -138,7 +138,14 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
// FileSize calculates the file size and generate user-friendly string.
func FileSize(s int64) string {
return humanize.IBytes(uint64(s))
return humanize.Bytes(uint64(s))
}
// Get FileSize bytes value from String.
func GetFileSize(s string) (int64, error) {
v, err := humanize.ParseBytes(s)
iv := int64(v)
return iv, err
}
// EllipsisString returns a truncated short string,
+20
View File
@@ -7,6 +7,7 @@ import (
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
"code.gitea.io/gitea/modules/log"
@@ -265,12 +266,31 @@ var (
RepoArchive = struct {
Storage
}{}
EnableSizeLimit = true
RepoSizeLimit int64 = 0
)
func SaveGlobalRepositorySetting(enable_size_limit bool, repo_size_limit int64) {
EnableSizeLimit = enable_size_limit
RepoSizeLimit = repo_size_limit
sec := CfgProvider.Section("repository")
if EnableSizeLimit {
sec.Key("ENABLE_SIZE_LIMIT").SetValue("true")
} else {
sec.Key("ENABLE_SIZE_LIMIT").SetValue("false")
}
sec.Key("REPO_SIZE_LIMIT").SetValue(strconv.FormatInt(RepoSizeLimit, 10))
}
func loadRepositoryFrom(rootCfg ConfigProvider) {
var err error
// Determine and create root git repository path.
sec := rootCfg.Section("repository")
EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool()
RepoSizeLimit = sec.Key("REPO_SIZE_LIMIT").MustInt64(0)
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
+36
View File
@@ -17,7 +17,9 @@ import (
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/web/explore"
"code.gitea.io/gitea/services/forms"
repo_service "code.gitea.io/gitea/services/repository"
)
@@ -31,6 +33,9 @@ func Repos(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.repositories")
ctx.Data["PageIsAdminRepositories"] = true
ctx.Data["EnableSizeLimit"] = setting.EnableSizeLimit
ctx.Data["RepoSizeLimit"] = base.FileSize(setting.RepoSizeLimit)
explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{
Private: true,
PageSize: setting.UI.Admin.RepoPagingNum,
@@ -39,6 +44,37 @@ func Repos(ctx *context.Context) {
})
}
func UpdateRepoPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.UpdateGlobalRepoFrom)
ctx.Data["Title"] = ctx.Tr("admin.repositories")
ctx.Data["PageIsAdminRepositories"] = true
repo_size_limit, err := base.GetFileSize(form.RepoSizeLimit)
ctx.Data["EnableSizeLimit"] = form.EnableSizeLimit
ctx.Data["RepoSizeLimit"] = form.RepoSizeLimit
if err != nil {
ctx.Data["Err_Repo_Size_Limit"] = true
explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{
Private: true,
PageSize: setting.UI.Admin.RepoPagingNum,
TplName: tplRepos,
OnlyShowRelevant: false,
})
return
}
setting.SaveGlobalRepositorySetting(form.EnableSizeLimit, repo_size_limit)
ctx.Flash.Success(ctx.Tr("admin.config.repository_setting_success"))
ctx.Data["RepoSizeLimit"] = base.FileSize(setting.RepoSizeLimit)
ctx.Flash.Success(ctx.Tr("admin.config.repository_setting_success"))
ctx.Redirect(setting.AppSubURL + "/admin/repos")
}
// DeleteRepo delete one repository
func DeleteRepo(ctx *context.Context) {
repo, err := repo_model.GetRepositoryByID(ctx, ctx.FormInt64("id"))
+5
View File
@@ -141,6 +141,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant))
ctx.Data["Page"] = pager
if ctx.Data["Err_Repo_Size_Limit"] != nil {
ctx.RenderWithErr(ctx.Tr("admin.config.invalid_repo_size"), opts.TplName, nil)
return
}
ctx.HTML(http.StatusOK, opts.TplName)
}
+2
View File
@@ -580,6 +580,8 @@ func registerRoutes(m *web.Route) {
m.Get("", admin.Repos)
m.Combo("/unadopted").Get(admin.UnadoptedRepos).Post(admin.AdoptOrDeleteRepository)
m.Post("/delete", admin.DeleteRepo)
m.Post("", web.Bind(forms.UpdateGlobalRepoFrom{}), admin.UpdateRepoPost)
})
m.Group("/packages", func() {
+6
View File
@@ -28,6 +28,12 @@ import (
// |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
// \/ \/ \/ \/ \/ \/ \/
// UpdateGlobalRepoFrom for updating global repository setting
type UpdateGlobalRepoFrom struct {
RepoSizeLimit string
EnableSizeLimit bool
}
// CreateRepoForm form for creating repository
type CreateRepoForm struct {
UID int64 `binding:"Required"`
+21
View File
@@ -1,5 +1,26 @@
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin")}}
<div class="admin-setting-content">
<h4 class="ui top attached header">
{{.locale.Tr "admin.config.repository_config"}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div class="inline field">
<label>{{.locale.Tr "admin.config.enable_size_limit"}}</label>
<div class="ui checkbox">
<input name="enable_size_limit" type="checkbox" {{if .EnableSizeLimit}}checked{{end}}>
</div>
</div>
<div class="inline field {{if .Err_Repo_Size_Limit}}error{{end}}">
<label for="repo_size_limit">{{.locale.Tr "admin.config.repo_size_limit"}}</label>
<input id="repo_size_limit" name="repo_size_limit" value="{{.RepoSizeLimit}}">
</div>
<div class="field">
<button class="ui green button">{{$.locale.Tr "repo.settings.update_settings"}}</button>
</div>
</form>
</div>
<h4 class="ui top attached header">
{{.locale.Tr "admin.repos.repo_manage_panel"}} ({{.locale.Tr "admin.total" .Total}})
<div class="ui right">