From 8d8e671a073d2775e61090cce356e74563ecce47 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 19 Nov 2019 09:59:13 +0900 Subject: [PATCH 1/3] Fix suspension check in fetchPost() Previously, this check would return a "user not found" error when retrieving a collection post by its post ID, e.g. /api/posts/abc123 instead of /api/collections/demo/posts/my-slug -- this happens particularly when `Announce`ing a post in the fediverse. This change fixes that. --- posts.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/posts.go b/posts.go index 6410735..4891a8e 100644 --- a/posts.go +++ b/posts.go @@ -1039,7 +1039,6 @@ func pinPost(app *App, w http.ResponseWriter, r *http.Request) error { func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { var collID int64 - var ownerID int64 var coll *Collection var err error vars := mux.Vars(r) @@ -1055,14 +1054,13 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { return err } collID = coll.ID - ownerID = coll.OwnerID } p, err := app.db.GetPost(vars["post"], collID) if err != nil { return err } - suspended, err := app.db.IsUserSuspended(ownerID) + suspended, err := app.db.IsUserSuspended(p.OwnerID.Int64) if err != nil { log.Error("fetch post: %v", err) return ErrInternalGeneral From c81927a69f04103873a55f220375c3dbe56ca621 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 26 Nov 2019 12:59:15 -0500 Subject: [PATCH 2/3] Fix empty hostname when fetching AS post via ID Previously, fetching ActivityStreams data about a post via /api/posts/ID, instead of /api/collections/ALIAS/posts/SLUG wouldn't include the instance's base URL. This fixes that. --- posts.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/posts.go b/posts.go index 4891a8e..9440ad8 100644 --- a/posts.go +++ b/posts.go @@ -1048,11 +1048,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { if err != nil { return err } - coll.hostName = app.cfg.App.Host - _, err = apiCheckCollectionPermissions(app, r, coll) - if err != nil { - return err - } collID = coll.ID } @@ -1060,12 +1055,26 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { if err != nil { return err } + if coll == nil && p.CollectionID.Valid { + // Collection post is getting fetched by post ID, not coll alias + post slug, so get coll info now. + coll, err = app.db.GetCollectionByID(p.CollectionID.Int64) + if err != nil { + return err + } + } + if coll != nil { + coll.hostName = app.cfg.App.Host + _, err = apiCheckCollectionPermissions(app, r, coll) + if err != nil { + return err + } + } + suspended, err := app.db.IsUserSuspended(p.OwnerID.Int64) if err != nil { log.Error("fetch post: %v", err) return ErrInternalGeneral } - if suspended { return ErrPostNotFound } @@ -1074,13 +1083,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { accept := r.Header.Get("Accept") if strings.Contains(accept, "application/activity+json") { - // Fetch information about the collection this belongs to - if coll == nil && p.CollectionID.Valid { - coll, err = app.db.GetCollectionByID(p.CollectionID.Int64) - if err != nil { - return err - } - } if coll == nil { // This is a draft post; 404 for now // TODO: return ActivityObject From 342c3cde89d44b20c3e4086ec1cc04bf9a3ebb61 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 26 Nov 2019 13:15:31 -0500 Subject: [PATCH 3/3] Bump version to 0.11.2 --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 018ce37..d71fb1e 100644 --- a/app.go +++ b/app.go @@ -56,7 +56,7 @@ var ( debugging bool // Software version can be set from git env using -ldflags - softwareVer = "0.11.1" + softwareVer = "0.11.2" // DEPRECATED VARS isSingleUser bool