diff --git a/models/repo/repo.go b/models/repo/repo.go index 6ab4af7990..3a4f878a7c 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -345,10 +345,10 @@ func (repo *Repository) APIURL() string { return setting.AppURL + "api/v1/repos/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name) } -// APAPIURL returns the activitypub repository API URL +// APActorID returns the activitypub repository API URL // TODO: At least camel case? // TODO: Mv federation related stuff to federated_repo -func (repo *Repository) APAPIURL() string { +func (repo *Repository) APActorID() string { // TODO: use spintf instead of concat - might mitigate injections return fmt.Sprintf("%vapi/v1/activitypub/repository-id/%v", setting.AppURL, url.PathEscape(fmt.Sprint(repo.ID))) } diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go index 7fa5f4fb68..a279478177 100644 --- a/models/repo/repo_test.go +++ b/models/repo/repo_test.go @@ -219,11 +219,11 @@ func TestComposeSSHCloneURL(t *testing.T) { assert.Equal(t, "ssh://git@[::1]:123/user/repo.git", repo_model.ComposeSSHCloneURL("user", "repo")) } -func TestAPAPIURL(t *testing.T) { +func TestAPActorID(t *testing.T) { repo := repo_model.Repository{ID: 1} - url := repo.APAPIURL() + url := repo.APActorID() expected := "https://try.gitea.io/api/v1/activitypub/repository-id/1" if url != expected { - t.Errorf("unexpected APAPIURL, expected: %q, actual: %q", expected, url) + t.Errorf("unexpected APActorID, expected: %q, actual: %q", expected, url) } } diff --git a/models/user/user.go b/models/user/user.go index d2ebb46da3..5844189e17 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -307,8 +307,8 @@ func (u *User) HTMLURL() string { return setting.AppURL + url.PathEscape(u.Name) } -// APAPIURL returns the IRI to the api endpoint of the user -func (u *User) APAPIURL() string { +// APActorID returns the IRI to the api endpoint of the user +func (u *User) APActorID() string { return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID))) } diff --git a/models/user/user_test.go b/models/user/user_test.go index 9efe9a9ef5..7457256017 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -108,12 +108,12 @@ func TestGetAllUsers(t *testing.T) { assert.False(t, found[user_model.UserTypeOrganization], users) } -func TestAPAPIURL(t *testing.T) { +func TestAPActorID(t *testing.T) { user := user_model.User{ID: 1} - url := user.APAPIURL() + url := user.APActorID() expected := "https://try.gitea.io/api/v1/activitypub/user-id/1" if url != expected { - t.Errorf("unexpected APAPIURL, expected: %q, actual: %q", expected, url) + t.Errorf("unexpected APActorID, expected: %q, actual: %q", expected, url) } } diff --git a/services/context/repo.go b/services/context/repo.go index 75b54664d9..e4cacbc53c 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -582,7 +582,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.Data["Title"] = owner.Name + "/" + repo.Name ctx.Data["Repository"] = repo - ctx.Data["RepositoryAPAPIURL"] = repo.APAPIURL() + ctx.Data["RepositoryAPActorID"] = repo.APActorID() ctx.Data["Owner"] = ctx.Repo.Repository.Owner ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner() ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin() diff --git a/services/federation/federation_service.go b/services/federation/federation_service.go index 94f1d78811..a7d9b6ef80 100644 --- a/services/federation/federation_service.go +++ b/services/federation/federation_service.go @@ -255,14 +255,14 @@ func SendLikeActivities(ctx context.Context, doer user.User, repoID int64) error for _, followingRepo := range followingRepos { log.Info("Found following repo: %v", followingRepo) target := followingRepo.URI - likeActivity, err := fm.NewForgeLike(doer.APAPIURL(), target, time.Now()) + likeActivity, err := fm.NewForgeLike(doer.APActorID(), target, time.Now()) if err != nil { return err } likeActivityList = append(likeActivityList, likeActivity) } - apclient, err := activitypub.NewClient(ctx, &doer, doer.APAPIURL()) + apclient, err := activitypub.NewClient(ctx, &doer, doer.APActorID()) if err != nil { return err } diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index b131e25f3e..f1adffcad2 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -73,7 +73,7 @@

{{ctx.Locale.Tr "repo.settings.federation_apapiurl"}}

-

{{.RepositoryAPAPIURL}}

+

{{.RepositoryAPActorID}}