From 8d8e671a073d2775e61090cce356e74563ecce47 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 19 Nov 2019 09:59:13 +0900 Subject: [PATCH 01/12] 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 02/12] 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 44a670374224d277e7cf3d3b88c926e327773ba2 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 26 Nov 2019 13:14:52 -0500 Subject: [PATCH 03/12] Prevent failed requests on failed user silence check --- posts.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/posts.go b/posts.go index 6410735..189ea63 100644 --- a/posts.go +++ b/posts.go @@ -384,7 +384,6 @@ func handleViewPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(ownerID.Int64) if err != nil { log.Error("view post: %v", err) - return ErrInternalGeneral } // Check if post has been unpublished @@ -511,7 +510,6 @@ func newPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(userID) if err != nil { log.Error("new post: %v", err) - return ErrInternalGeneral } if suspended { return ErrUserSuspended @@ -685,7 +683,6 @@ func existingPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(userID) if err != nil { log.Error("existing post: %v", err) - return ErrInternalGeneral } if suspended { return ErrUserSuspended @@ -888,7 +885,6 @@ func addPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(ownerID) if err != nil { log.Error("add post: %v", err) - return ErrInternalGeneral } if suspended { return ErrUserSuspended @@ -991,7 +987,6 @@ func pinPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(userID) if err != nil { log.Error("pin post: %v", err) - return ErrInternalGeneral } if suspended { return ErrUserSuspended @@ -1065,7 +1060,6 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error { suspended, err := app.db.IsUserSuspended(ownerID) if err != nil { log.Error("fetch post: %v", err) - return ErrInternalGeneral } if suspended { @@ -1335,7 +1329,6 @@ func viewCollectionPost(app *App, w http.ResponseWriter, r *http.Request) error suspended, err := app.db.IsUserSuspended(c.OwnerID) if err != nil { log.Error("view collection post: %v", err) - return ErrInternalGeneral } // Check collection permissions From 342c3cde89d44b20c3e4086ec1cc04bf9a3ebb61 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 26 Nov 2019 13:15:31 -0500 Subject: [PATCH 04/12] 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 From d8f77585f50917cd8597af448b145dec00e6d24c Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sun, 1 Dec 2019 06:16:12 -0500 Subject: [PATCH 05/12] Suppress log when editing post or its metadata This adds the instance's Hostname to the collection data loaded when editing a collection post or its metadata. While not technically needed in this situation, it suppresses an alarming error log. Resolves #216 --- pad.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pad.go b/pad.go index 37d1c9b..3b0f1c2 100644 --- a/pad.go +++ b/pad.go @@ -92,6 +92,7 @@ func handleViewPad(app *App, w http.ResponseWriter, r *http.Request) error { if err != nil { return err } + appData.EditCollection.hostName = app.cfg.App.Host } else { // Editing a floating article appData.Post = getRawPost(app, action) @@ -161,6 +162,7 @@ func handleViewMeta(app *App, w http.ResponseWriter, r *http.Request) error { if err != nil { return err } + appData.EditCollection.hostName = app.cfg.App.Host } else { // Editing a floating article appData.Post = getRawPost(app, action) From acb8f5fe5d55cf728e6d38ae671a9f54b7e6b8f6 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 7 Dec 2019 09:06:31 -0500 Subject: [PATCH 06/12] Fix broken password-collection template Fixed "user-supsended" to "user-suspended" --- templates/password-collection.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/password-collection.tmpl b/templates/password-collection.tmpl index 73c4465..66a3bef 100644 --- a/templates/password-collection.tmpl +++ b/templates/password-collection.tmpl @@ -26,7 +26,7 @@ {{if .Suspended}} - {{template "user-supsended"}} + {{template "user-suspended"}} {{end}}

{{.DisplayTitle}}

From 0b701c5f7f36736127c809d71a1bb2b7d9ae495c Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 7 Dec 2019 09:08:37 -0500 Subject: [PATCH 07/12] Update "account silenced" alert on edit-meta Use "silenced" phrasing instead of "suspended" --- templates/edit-meta.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/edit-meta.tmpl b/templates/edit-meta.tmpl index 6707e68..49c7781 100644 --- a/templates/edit-meta.tmpl +++ b/templates/edit-meta.tmpl @@ -270,7 +270,7 @@