Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-22 09:54:24 +01:00

use new table to populate settings

This commit is contained in:
Michael Jerger 2024-03-25 09:15:32 +01:00
parent a9d18e5327
commit 828e7a76f6
3 changed files with 16 additions and 39 deletions

View file

@ -6,7 +6,6 @@ package repo
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/validation" "code.gitea.io/gitea/modules/validation"
@ -16,43 +15,12 @@ func init() {
db.RegisterModel(new(FederatedRepo)) db.RegisterModel(new(FederatedRepo))
} }
// TODO: do we need this? func FindFederatedRepoByRepoID(ctx context.Context, repoId int64) ([]*FederatedRepo, error) {
func GetFederatedRepo(ctx context.Context, ID int64) (*FederatedRepo, error) { maxFederatedRepos := 10
repo := new(FederatedRepo) sess := db.GetEngine(ctx).Where("repo_id=?", repoId)
has, err := db.GetEngine(ctx).Where("id=?", ID).Get(repo) sess = sess.Limit(maxFederatedRepos, 0)
if err != nil { federatedRepoList := make([]*FederatedRepo, 0, maxFederatedRepos)
return nil, err return federatedRepoList, sess.Find(&federatedRepoList)
} else if !has {
return nil, fmt.Errorf("FederationInfo record %v does not exist", ID)
}
if res, err := validation.IsValid(repo); !res {
return nil, fmt.Errorf("FederationInfo is not valid: %v", err)
}
return repo, nil
}
// TODO: do we need this?
func FindFederatedRepoByFQDN(ctx context.Context, fqdn string) (*FederatedRepo, error) {
repo := new(FederatedRepo)
has, err := db.GetEngine(ctx).Where("host_fqdn=?", strings.ToLower(fqdn)).Get(repo)
if err != nil {
return nil, err
} else if !has {
return nil, nil
}
if res, err := validation.IsValid(repo); !res {
return nil, fmt.Errorf("FederationInfo is not valid: %v", err)
}
return repo, nil
}
// TODO: do we need this?
func CreateFederatedRepo(ctx context.Context, repo *FederatedRepo) error {
if res, err := validation.IsValid(repo); !res {
return fmt.Errorf("FederationInfo is not valid: %v", err)
}
_, err := db.GetEngine(ctx).Insert(repo)
return err
} }
func UpdateFederatedRepo(ctx context.Context, localRepoId int64, federatedRepoList []*FederatedRepo) error { func UpdateFederatedRepo(ctx context.Context, localRepoId int64, federatedRepoList []*FederatedRepo) error {

View file

@ -380,6 +380,15 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
ctx.Data["HasAccess"] = true ctx.Data["HasAccess"] = true
ctx.Data["Permission"] = &ctx.Repo.Permission ctx.Data["Permission"] = &ctx.Repo.Permission
federatedRepo, err := repo_model.FindFederatedRepoByRepoID(ctx, repo.ID)
if err == nil {
// TODO: concat string to semicolon sperated list here
ctx.Data["FederatedRepos"] = federatedRepo
} else if err != repo_model.ErrMirrorNotExist {
ctx.ServerError("FindFederatedRepoByRepoID", err)
return
}
if repo.IsMirror { if repo.IsMirror {
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
if err == nil { if err == nil {

View file

@ -73,7 +73,7 @@
<input type="hidden" name="action" value="federation"> <input type="hidden" name="action" value="federation">
<div class="field {{if .Err_FederationRepos}}error{{end}}"> <div class="field {{if .Err_FederationRepos}}error{{end}}">
<label for="federation_repos">{{ctx.Locale.Tr "repo.settings.federation_labelname_repo"}}</label> <label for="federation_repos">{{ctx.Locale.Tr "repo.settings.federation_labelname_repo"}}</label>
<input id="federation_repos" name="federation_repos" value="{{.Repository.FederationRepos}}" data-repo-name="{{.Repository.FederationRepos}}"> <input id="federation_repos" name="federation_repos" value="{{.FederationRepos}}" data-repo-name="{{.Repository.FederationRepos}}">
</div> </div>
<div class="field"> <div class="field">
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button> <button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>