mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-15 13:52:33 +00:00
set federatedRepoList into context
This commit is contained in:
parent
cf8a30efac
commit
d251fc2611
5 changed files with 13 additions and 15 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
<input type="hidden" name="action" value="federation">
|
||||
<div class="field {{if .Err_FederationRepos}}error{{end}}">
|
||||
<label for="federation_repos">{{ctx.Locale.Tr "repo.settings.federation_labelname_repo"}}</label>
|
||||
<input id="federation_repos" name="federation_repos" value="{{.FederationRepos}}" data-repo-name="{{.Repository.FederationRepos}}">
|
||||
<input id="federation_repos" name="federation_repos" value="{{.FederatedRepos}}">
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
|
||||
|
|
Loading…
Reference in a new issue