Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Fixes for vote listing issues

Matt Roberts277f323cb600
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 4c20a58f9..95ac14b99 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -214,6 +214,7 @@ func routes(r *web.Engine) *web.Engine {
publicApi.Get("/api/v1/posts/:number/comments", apiv1.ListComments())
publicApi.Get("/api/v1/posts/:number/comments/:id", apiv1.GetComment())
publicApi.Get("/api/v1/taggable-users", apiv1.ListTaggableUsers())
+ publicApi.Get("/api/v1/posts/:number/votes", apiv1.ListVotes())
}
// Operations used to manage the content of a site
@@ -248,7 +249,6 @@ func routes(r *web.Engine) *web.Engine {
staffApi.Use(middlewares.IsAuthorized(enum.RoleCollaborator, enum.RoleAdministrator))
staffApi.Get("/api/v1/users", apiv1.ListUsers())
- staffApi.Get("/api/v1/posts/:number/votes", apiv1.ListVotes())
staffApi.Post("/api/v1/invitations/send", apiv1.SendInvites())
staffApi.Post("/api/v1/invitations/sample", apiv1.SendSampleInvite())
diff --git a/app/handlers/apiv1/post.go b/app/handlers/apiv1/post.go
index 11fc0c283..058be7ffa 100644
--- a/app/handlers/apiv1/post.go
+++ b/app/handlers/apiv1/post.go
@@ -506,7 +506,8 @@ func ListVotes() web.HandlerFunc {
return c.Failure(err)
}
- listVotes := &query.ListPostVotes{PostID: getPost.Result.ID, IncludeEmail: true}
+ includeEmail := c.User() != nil && c.User().IsCollaborator()
+ listVotes := &query.ListPostVotes{PostID: getPost.Result.ID, IncludeEmail: includeEmail}
if err := bus.Dispatch(c, listVotes); err != nil {
return c.Failure(err)
}
diff --git a/public/components/PostDetails/PostDetails.tsx b/public/components/PostDetails/PostDetails.tsx
index 8749e2e47..4a7a5c43b 100644
--- a/public/components/PostDetails/PostDetails.tsx
+++ b/public/components/PostDetails/PostDetails.tsx
@@ -111,20 +111,20 @@ export const PostDetails: React.FC<PostDetailsProps> = (props) => {
setComments(commentsResult || [])
setTags(tagsResult || [])
- // Fetch votes and subscription status if authenticated
+ const votesResult = await actions.listVotes(props.postNumber)
+ // Limit votes to 24 to match SSR behavior
+ setVotes(votesResult.ok ? votesResult.data.slice(0, 24) : [])
+
+ // Fetch subscription status if authenticated
if (Fider.session.isAuthenticated) {
try {
- const votesResult = await actions.listVotes(props.postNumber)
- // Limit votes to 24 to match SSR behavior
- setVotes(votesResult.ok ? votesResult.data.slice(0, 24) : [])
-
const subResponse = await fetch(`/api/v1/posts/${props.postNumber}/subscription`)
if (subResponse.ok) {
const subData = await subResponse.json()
setSubscribed(subData.subscribed || false)
}
} catch (e) {
- // Ignore subscription and vote errors
+ // Ignore subscription errors
}
}
} catch (err) {