Merge pull request #384 from colin-axner/374-fix-silenced-post-accessibility

fix accessibility of silenced user posts
pull/452/head
Matt Baer 4 years ago committed by GitHub
commit ac7583eadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      admin.go
  2. 8
      posts.go
  3. 25
      read.go

@ -328,6 +328,9 @@ func handleAdminToggleUserStatus(app *App, u *User, w http.ResponseWriter, r *ht
err = app.db.SetUserStatus(user.ID, UserActive) err = app.db.SetUserStatus(user.ID, UserActive)
} else { } else {
err = app.db.SetUserStatus(user.ID, UserSilenced) err = app.db.SetUserStatus(user.ID, UserSilenced)
// reset the cache to removed silence user posts
updateTimelineCache(app.timeline, true)
} }
if err != nil { if err != nil {
log.Error("toggle user silenced: %v", err) log.Error("toggle user silenced: %v", err)

@ -1430,13 +1430,17 @@ Are you sure it was ever here?`,
return err return err
} }
} }
p.IsOwner = owner != nil && p.OwnerID.Valid && owner.ID == p.OwnerID.Int64
// Check if the authenticated user is the post owner
p.IsOwner = u != nil && u.ID == p.OwnerID.Int64
p.Collection = coll p.Collection = coll
p.IsTopLevel = app.cfg.App.SingleUser p.IsTopLevel = app.cfg.App.SingleUser
if !p.IsOwner && silenced { // Only allow a post owner or admin to view a post for silenced collections
if silenced && !p.IsOwner && (u == nil || !u.IsAdmin()) {
return ErrPostNotFound return ErrPostNotFound
} }
// Check if post has been unpublished // Check if post has been unpublished
if p.Content == "" && p.Title.String == "" { if p.Content == "" && p.Title.String == "" {
return impart.HTTPError{http.StatusGone, "Post was unpublished."} return impart.HTTPError{http.StatusGone, "Post was unpublished."}

@ -128,7 +128,7 @@ func (app *App) FetchPublicPosts() (interface{}, error) {
} }
func viewLocalTimelineAPI(app *App, w http.ResponseWriter, r *http.Request) error { func viewLocalTimelineAPI(app *App, w http.ResponseWriter, r *http.Request) error {
updateTimelineCache(app.timeline) updateTimelineCache(app.timeline, false)
skip, _ := strconv.Atoi(r.FormValue("skip")) skip, _ := strconv.Atoi(r.FormValue("skip"))
@ -156,13 +156,19 @@ func viewLocalTimeline(app *App, w http.ResponseWriter, r *http.Request) error {
return showLocalTimeline(app, w, r, page, vars["author"], vars["tag"]) return showLocalTimeline(app, w, r, page, vars["author"], vars["tag"])
} }
func updateTimelineCache(tl *localTimeline) { // updateTimelineCache will reset and update the cache if it is stale or
// Fetch posts if enough time has passed since last cache // the boolean passed in is true.
if tl.posts == nil || tl.m.Invalidate() { func updateTimelineCache(tl *localTimeline, reset bool) {
if reset {
tl.m.Reset()
}
// Fetch posts if the cache is empty, has been reset or enough time has
// passed since last cache.
if tl.posts == nil || reset || tl.m.Invalidate() {
log.Info("[READ] Updating post cache") log.Info("[READ] Updating post cache")
var err error
var postsInterfaces interface{} postsInterfaces, err := tl.m.Get()
postsInterfaces, err = tl.m.Get()
if err != nil { if err != nil {
log.Error("[READ] Unable to cache posts: %v", err) log.Error("[READ] Unable to cache posts: %v", err)
} else { } else {
@ -170,10 +176,11 @@ func updateTimelineCache(tl *localTimeline) {
tl.posts = &castPosts tl.posts = &castPosts
} }
} }
} }
func showLocalTimeline(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string) error { func showLocalTimeline(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string) error {
updateTimelineCache(app.timeline) updateTimelineCache(app.timeline, false)
pl := len(*(app.timeline.posts)) pl := len(*(app.timeline.posts))
ttlPages := int(math.Ceil(float64(pl) / float64(app.timeline.postsPerPage))) ttlPages := int(math.Ceil(float64(pl) / float64(app.timeline.postsPerPage)))
@ -286,7 +293,7 @@ func viewLocalTimelineFeed(app *App, w http.ResponseWriter, req *http.Request) e
return impart.HTTPError{http.StatusNotFound, "Page doesn't exist."} return impart.HTTPError{http.StatusNotFound, "Page doesn't exist."}
} }
updateTimelineCache(app.timeline) updateTimelineCache(app.timeline, false)
feed := &Feed{ feed := &Feed{
Title: app.cfg.App.SiteName + " Reader", Title: app.cfg.App.SiteName + " Reader",

Loading…
Cancel
Save