diff --git a/models/forgefed/activity.go b/models/forgefed/activity.go index 32b375d8b3..cbec22fa23 100644 --- a/models/forgefed/activity.go +++ b/models/forgefed/activity.go @@ -21,7 +21,6 @@ type ForgeLike struct { func NewForgeLike(actorIRI, objectIRI string, startTime time.Time) (ForgeLike, error) { result := ForgeLike{} result.Type = ap.LikeType - // ToDo: Would validating the source by Actor.Type field make sense? result.Actor = ap.IRI(actorIRI) // Thats us, a User result.Object = ap.IRI(objectIRI) // Thats them, a Repository result.StartTime = startTime diff --git a/models/forgefed/federationhost_test.go b/models/forgefed/federationhost_test.go index 75ddfff9dd..844d8c3e1a 100644 --- a/models/forgefed/federationhost_test.go +++ b/models/forgefed/federationhost_test.go @@ -14,7 +14,7 @@ func Test_FederationHostValidation(t *testing.T) { sut := FederationHost{ HostFqdn: "host.do.main", NodeInfo: NodeInfo{ - Source: "forgejo", + SoftwareName: "forgejo", }, LatestActivity: time.Now(), } @@ -34,7 +34,7 @@ func Test_FederationHostValidation(t *testing.T) { sut = FederationHost{ HostFqdn: "host.do.main", NodeInfo: NodeInfo{ - Source: "forgejo", + SoftwareName: "forgejo", }, LatestActivity: time.Now().Add(1 * time.Hour), } @@ -45,7 +45,7 @@ func Test_FederationHostValidation(t *testing.T) { sut = FederationHost{ HostFqdn: "hOst.do.main", NodeInfo: NodeInfo{ - Source: "forgejo", + SoftwareName: "forgejo", }, LatestActivity: time.Now(), } diff --git a/models/forgefed/nodeinfo.go b/models/forgefed/nodeinfo.go index 3e64f02c34..73536b67ab 100644 --- a/models/forgefed/nodeinfo.go +++ b/models/forgefed/nodeinfo.go @@ -12,13 +12,14 @@ import ( "github.com/valyala/fastjson" ) +// ToDo: Search for full text SourceType and Source, also in .md files type ( - SourceType string + SoftwareNameType string ) const ( - ForgejoSourceType SourceType = "forgejo" - GiteaSourceType SourceType = "gitea" + ForgejoSourceType SoftwareNameType = "forgejo" + GiteaSourceType SoftwareNameType = "gitea" ) var KnownSourceTypes = []any{ @@ -97,7 +98,7 @@ func (id ActorID) AsWellKnownNodeInfoURI() string { // NodeInfo data type // swagger:model type NodeInfo struct { - Source SourceType + SoftwareName SoftwareNameType } func NodeInfoUnmarshalJSON(data []byte) (NodeInfo, error) { @@ -108,7 +109,7 @@ func NodeInfoUnmarshalJSON(data []byte) (NodeInfo, error) { } source := string(val.GetStringBytes("software", "name")) result := NodeInfo{} - result.Source = SourceType(source) + result.SoftwareName = SoftwareNameType(source) return result, nil } @@ -127,8 +128,8 @@ func NewNodeInfo(body []byte) (NodeInfo, error) { // Validate collects error strings in a slice and returns this func (node NodeInfo) Validate() []string { var result []string - result = append(result, validation.ValidateNotEmpty(string(node.Source), "source")...) - result = append(result, validation.ValidateOneOf(node.Source, KnownSourceTypes)...) + result = append(result, validation.ValidateNotEmpty(string(node.SoftwareName), "source")...) + result = append(result, validation.ValidateOneOf(node.SoftwareName, KnownSourceTypes)...) return result } diff --git a/models/forgefed/nodeinfo_test.go b/models/forgefed/nodeinfo_test.go index 04384fe4f3..ba1bd90be8 100644 --- a/models/forgefed/nodeinfo_test.go +++ b/models/forgefed/nodeinfo_test.go @@ -77,7 +77,7 @@ func Test_NewNodeInfoWellKnown(t *testing.T) { func Test_NewNodeInfo(t *testing.T) { sut, _ := NewNodeInfo([]byte(`{"version":"2.1","software":{"name":"gitea","version":"1.20.0+dev-2539-g5840cc6d3","repository":"https://github.com/go-gitea/gitea.git","homepage":"https://gitea.io/"},"protocols":["activitypub"],"services":{"inbound":[],"outbound":["rss2.0"]},"openRegistrations":true,"usage":{"users":{"total":13,"activeHalfyear":1,"activeMonth":1}},"metadata":{}}`)) - expected := NodeInfo{Source: "gitea"} + expected := NodeInfo{SoftwareName: "gitea"} if sut != expected { t.Errorf("expected was: %v but was: %v", expected, sut) } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 4d9a4f5fad..d04474e097 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -157,7 +157,7 @@ func Star(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - err := repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true) + err := repository.StarRepoAndSendLikeActivities(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(http.StatusInternalServerError, "StarRepo", err) return @@ -188,7 +188,7 @@ func Unstar(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - err := repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false) + err := repository.StarRepoAndSendLikeActivities(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false) if err != nil { ctx.Error(http.StatusInternalServerError, "StarRepo", err) return diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index b95b3f788c..3fa392b2fb 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -333,7 +333,7 @@ func ActionWatch(watch bool) func(ctx *context.Context) { func ActionStar(star bool) func(ctx *context.Context) { return func(ctx *context.Context) { - err := repo_service.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, star) + err := repo_service.StarRepoAndSendLikeActivities(ctx, *ctx.Doer, ctx.Repo.Repository.ID, star) if err != nil { ctx.ServerError(fmt.Sprintf("Action (star, %t)", star), err) return diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index 08e324b77b..26a34c7b0e 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -391,7 +391,7 @@ func SettingsPost(ctx *context.Context) { ctx.Flash.Info(ctx.Tr("repo.settings.federation_not_enabled")) return } - + // ToDo: Rename to followingRepos federationRepos := strings.TrimSpace(form.FederationRepos) federationRepos = strings.TrimSuffix(federationRepos, ";") diff --git a/services/federation/federation_service.go b/services/federation/federation_service.go index b43560915f..f7ceed044b 100644 --- a/services/federation/federation_service.go +++ b/services/federation/federation_service.go @@ -47,7 +47,7 @@ func ProcessLikeActivity(ctx context.Context, form any, repositoryID int64) (int if !activity.IsNewer(federationHost.LatestActivity) { return http.StatusNotAcceptable, "Activity out of order.", fmt.Errorf("Activity already processed") } - actorID, err := forgefed.NewPersonID(actorURI, string(federationHost.NodeInfo.Source)) + actorID, err := forgefed.NewPersonID(actorURI, string(federationHost.NodeInfo.SoftwareName)) if err != nil { return http.StatusNotAcceptable, "Invalid PersonID", err } @@ -221,7 +221,7 @@ func StoreFollowingRepoList(ctx context.Context, localRepoID int64, followingRep if err != nil { return http.StatusInternalServerError, "Wrong FederationHost", err } - followingRepoID, err := forgefed.NewRepositoryID(uri, string(federationHost.NodeInfo.Source)) + followingRepoID, err := forgefed.NewRepositoryID(uri, string(federationHost.NodeInfo.SoftwareName)) if err != nil { return http.StatusNotAcceptable, "Invalid federated repo", err } diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 25c70bf81a..8696abca30 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -113,7 +113,7 @@ type RepoSettingForm struct { RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` Description string `binding:"MaxSize(2048)"` Website string `binding:"ValidUrl;MaxSize(1024)"` - + // ToDo: Refactor in template and i18n labels to Following Repos FederationRepos string Interval string MirrorAddress string