mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 12:54:53 -05:00
WIP Refactoring and solving (adding) ToDos
This commit is contained in:
parent
fb1d0df791
commit
71141a5ff3
9 changed files with 19 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, ";")
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue