From 8300d3fbded450a19806fb110108f5b61e928242 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 24 Nov 2023 09:55:47 +0100 Subject: [PATCH] Add ToDos from code review --- models/activitypub/actor.go | 9 +++++---- routers/api/v1/activitypub/repository.go | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/activitypub/actor.go b/models/activitypub/actor.go index 312edd3bdc..54f6d159f5 100644 --- a/models/activitypub/actor.go +++ b/models/activitypub/actor.go @@ -8,7 +8,7 @@ import ( ) type Validatable interface { // ToDo: What is the right package for this interface? - validate_is_not_nil() error + validate_is_not_nil() error // ToDo: We may want an IsValid and a ThrowIfInvalid method, that collects errors and throws them at RepositoryInbox level validate_is_not_empty() error Validate() error } @@ -21,6 +21,7 @@ type ActorID struct { port string // optional } +// ToDo: validate_is_not_empty maybe not as an extra method func (a ActorID) validate_is_not_empty(str string, field string) error { if str == "" { @@ -61,7 +62,7 @@ func (a ActorID) Validate() error { return err } - if !strings.Contains(a.path, "api/v1/activitypub/user-id") { + if !strings.Contains(a.path, "api/v1/activitypub/user-id") { // This needs to happen in dependence to the star source type. return fmt.Errorf("the Path to the API was invalid: %v", a.path) } @@ -80,8 +81,8 @@ func ParseActorID(actor string) (ActorID, error) { pathWithUserID := strings.Split(u.Path, "/") userId := pathWithUserID[len(pathWithUserID)-1] - return ActorID{ - schema: u.Scheme, + return ActorID{ // ToDo: maybe keep original input to validate against (maybe extra method) + schema: u.Scheme, // ToDo: Add source type field userId: userId, host: u.Host, path: u.Path, diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index ad3041f212..8b2b364b8b 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -86,9 +86,8 @@ func RepositoryInbox(ctx *context.APIContext) { log.Info("RepositoryInbox: Activity.Actor %v", opt.Actor) // assume actor is: "actor": "https://codeberg.org/api/v1/activitypub/user-id/12345" - NB: This might be actually the ID? Maybe check vocabulary. - // TODO: validate input in front of parsing. // parse actor - actor, err := activitypub.ParseActorID(opt.Actor.GetID().String()) + actor, err := activitypub.ParseActorID(opt.Actor.GetID().String()) // ToDo: somehow extract source from star activity // Is the actor IRI well formed? if err != nil {