From 884e38bdab96f0e73fc0074c9ba502bc11928641 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 19 Mar 2024 15:25:52 +0100 Subject: [PATCH] WIP Implement proper saving of federated repo urls Added ToDos where relevant --- models/repo/repo.go | 2 +- routers/web/repo/setting/setting.go | 13 +++++++++++++ services/forms/repo_form.go | 8 +++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 3b20b2d9bd..da1a159f35 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -137,7 +137,7 @@ type Repository struct { DefaultBranch string WikiBranch string // TODO: Create own table out of this field - FederationRepos string + FederationRepos string `xorm:"TEXT"` NumWatches int NumStars int diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index e4105ae898..34dfb97684 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -188,7 +188,20 @@ func SettingsPost(ctx *context.Context) { case "federation": if !setting.Federation.Enabled { ctx.NotFound("", nil) + ctx.Flash.Info("Federation Not enabled") return + } else { + // ToDo: Proper string handling + log.Info("web/repo/setting.go:Federation was detected as enabled.") + // ToDo: Ability to delete repos + repo.FederationRepos = repo.FederationRepos + form.FederationRepos + if err := repo_service.UpdateRepository(ctx, repo, false); err != nil { + ctx.ServerError("UpdateRepository", err) + return + } + log.Info("Repos are: %v", repo.FederationRepos) + ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) + ctx.Redirect(repo.Link() + "/settings") } // TODO: Validate semicolon separation diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 7cc07532ef..851124ae7c 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -110,9 +110,11 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err // RepoSettingForm form for changing repository settings type RepoSettingForm struct { - RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` - Description string `binding:"MaxSize(2048)"` - Website string `binding:"ValidUrl;MaxSize(1024)"` + RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` + Description string `binding:"MaxSize(2048)"` + Website string `binding:"ValidUrl;MaxSize(1024)"` + // ToDo: Do we need validation at this point? + FederationRepos string Interval string MirrorAddress string MirrorUsername string