From d251fc261168a2e7ceffde77cb763c9c0727a4c0 Mon Sep 17 00:00:00 2001 From: Clemens Date: Tue, 26 Mar 2024 08:28:22 +0100 Subject: [PATCH] set federatedRepoList into context --- models/repo/federated_repo.go | 7 ++++--- models/repo/federated_repo_test.go | 2 ++ modules/context/repo.go | 7 +++++-- modules/forgefed/federation_service.go | 10 +--------- templates/repo/settings/options.tmpl | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/models/repo/federated_repo.go b/models/repo/federated_repo.go index fb2952d04b..10f1db9ce2 100644 --- a/models/repo/federated_repo.go +++ b/models/repo/federated_repo.go @@ -13,15 +13,15 @@ type FederatedRepo struct { RepoID int64 `xorm:"NOT NULL"` ExternalID string `xorm:"TEXT UNIQUE(federation_repo_mapping) NOT NULL"` FederationHostID int64 `xorm:"UNIQUE(federation_repo_mapping) NOT NULL"` - Schema string - Port string + Uri string } -func NewFederatedRepo(repoID int64, externalID string, federationHostID int64) (FederatedRepo, error) { +func NewFederatedRepo(repoID int64, externalID string, federationHostID int64, uri string) (FederatedRepo, error) { result := FederatedRepo{ RepoID: repoID, ExternalID: externalID, FederationHostID: federationHostID, + Uri: uri, } if valid, err := validation.IsValid(result); !valid { return FederatedRepo{}, err @@ -34,5 +34,6 @@ func (user FederatedRepo) Validate() []string { result = append(result, validation.ValidateNotEmpty(user.RepoID, "UserID")...) result = append(result, validation.ValidateNotEmpty(user.ExternalID, "ExternalID")...) result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...) + result = append(result, validation.ValidateNotEmpty(user.Uri, "Uri")...) return result } diff --git a/models/repo/federated_repo_test.go b/models/repo/federated_repo_test.go index 075061044a..c23a74817a 100644 --- a/models/repo/federated_repo_test.go +++ b/models/repo/federated_repo_test.go @@ -14,6 +14,7 @@ func Test_FederatedRepoValidation(t *testing.T) { RepoID: 12, ExternalID: "12", FederationHostID: 1, + Uri: "http://localhost:3000/api/v1/activitypub/repo-id/1", } if res, err := validation.IsValid(sut); !res { t.Errorf("sut should be valid but was %q", err) @@ -22,6 +23,7 @@ func Test_FederatedRepoValidation(t *testing.T) { sut = FederatedRepo{ ExternalID: "12", FederationHostID: 1, + Uri: "http://localhost:3000/api/v1/activitypub/repo-id/1", } if res, _ := validation.IsValid(sut); res { t.Errorf("sut should be invalid") diff --git a/modules/context/repo.go b/modules/context/repo.go index deb7f3d92e..6a8d1fe036 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -383,8 +383,11 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) { federatedRepoList, err := repo_model.FindFederatedReposByRepoID(ctx, repo.ID) if err == nil { federatedRepoString := "" - for _, federatedRepo := range federatedRepoList { - + for idx, federatedRepo := range federatedRepoList { + if idx > 0 { + federatedRepoString += ";" + } + federatedRepoString += (*federatedRepo).Uri } ctx.Data["FederatedRepos"] = federatedRepoString } else if err != repo_model.ErrMirrorNotExist { diff --git a/modules/forgefed/federation_service.go b/modules/forgefed/federation_service.go index 5e443a768e..ee63ed013d 100644 --- a/modules/forgefed/federation_service.go +++ b/modules/forgefed/federation_service.go @@ -223,7 +223,7 @@ func StoreFederatedRepoList(ctx context.Context, localRepoId int64, federatedRep if err != nil { return http.StatusNotAcceptable, "Invalid federated repo", err } - federatedRepo, err := repo.NewFederatedRepo(localRepoId, federatedRepoID.ID, federationHost.ID) + federatedRepo, err := repo.NewFederatedRepo(localRepoId, federatedRepoID.ID, federationHost.ID, uri) if err != nil { return http.StatusNotAcceptable, "Invalid federated repo", err } @@ -234,11 +234,3 @@ func StoreFederatedRepoList(ctx context.Context, localRepoId int64, federatedRep return 0, "", nil } - -func FederatedRepoUrl(ctx context.Context, federatedRepo repo.FederatedRepo) (string, error) { - federationHost, err := forgefed.GetFederationHost(ctx, federatedRepo.FederationHostID) - if err != nil { - return "", err - } - return federationHost.HostFqdn -} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index b6a4f6a88f..861a50c92e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -73,7 +73,7 @@
- +