Skip to content

Commit

Permalink
fix error when voting on your poll
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 5, 2024
1 parent 9d90743 commit 4d5591f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
16 changes: 11 additions & 5 deletions front/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (h *Handler) post(w text.Writer, r *Request, oldNote *ap.Object, inReplyTo
Tag: tags,
}

anyRecipient := false

if inReplyTo != nil {
note.InReplyTo = inReplyTo.ID

Expand All @@ -164,16 +166,20 @@ func (h *Handler) post(w text.Writer, r *Request, oldNote *ap.Object, inReplyTo
note.To = ap.Audience{}
note.To.Add(inReplyTo.AttributedTo)
note.CC = ap.Audience{}

// allow users to vote on their own polls
anyRecipient = true
}
}
}
}

anyRecipient := false
for actorID := range note.To.Keys() {
if actorID != r.User.ID {
anyRecipient = true
break
if !anyRecipient {
for actorID := range note.To.Keys() {
if actorID != r.User.ID {
anyRecipient = true
break
}
}
}
if !anyRecipient {
Expand Down
30 changes: 30 additions & 0 deletions test/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,33 @@ func TestPoll_LocalVoteVisibilityPublic(t *testing.T) {
assert.NotContains(view, "bob")
assert.NotContains(view, "carol")
}

func TestPoll_LocalSelfVote(t *testing.T) {
server := newTestServer()
defer server.Shutdown()

assert := assert.New(t)

say := server.Handle("/users/say?%5bPOLL%20So%2c%20polls%20on%20Station%20are%20pretty%20cool%2c%20right%3f%5d%20Nope%20%7c%20Hell%20yeah%21%20%7c%20I%20couldn%27t%20care%20less", server.Alice)
assert.Regexp(`^30 /users/view/\S+\r\n$`, say)

server.cfg.PostThrottleUnit = 0
reply := server.Handle(fmt.Sprintf("/users/reply/%s?Hell%%20yeah%%21", say[15:len(say)-2]), server.Alice)
assert.Regexp(`^30 /users/view/\S+\r\n$`, reply)

reply = server.Handle(fmt.Sprintf("/users/reply/%s?I%%20couldn%%27t%%20care%%20less", say[15:len(say)-2]), server.Bob)
assert.Regexp(`^30 /users/view/\S+\r\n$`, reply)

poller := outbox.Poller{
Domain: domain,
DB: server.db,
}
assert.NoError(poller.Run(context.Background()))

view := server.Handle("/view/"+say[15:len(say)-2], nil)
assert.Contains(view, "So, polls on Station are pretty cool, right?")
assert.NotContains(view, "Vote")
assert.Contains(strings.Split(view, "\n"), "0 Nope")
assert.Contains(strings.Split(view, "\n"), "1 ████████ Hell yeah!")
assert.Contains(strings.Split(view, "\n"), "1 ████████ I couldn't care less")
}

0 comments on commit 4d5591f

Please sign in to comment.