Skip to content

Commit

Permalink
Fix template preview sending invalid view requests
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Mar 8, 2020
1 parent ca032c8 commit ba87801
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions public.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,14 @@ func handleRegisterCampaignView(c echo.Context) error {
campUUID = c.Param("campUUID")
subUUID = c.Param("subUUID")
)
if _, err := app.queries.RegisterCampaignView.Exec(campUUID, subUUID); err != nil {
app.log.Printf("error registering campaign view: %s", err)

// Exclude dummy hits from template previews.
if campUUID != dummyUUID && subUUID != dummyUUID {
if _, err := app.queries.RegisterCampaignView.Exec(campUUID, subUUID); err != nil {
app.log.Printf("error registering campaign view: %s", err)
}
}

c.Response().Header().Set("Cache-Control", "no-cache")
return c.Blob(http.StatusOK, "image/png", pixelPNG)
}
Expand Down
6 changes: 5 additions & 1 deletion subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/lib/pq"
)

const (
dummyUUID = "00000000-0000-0000-0000-000000000000"
)

// subQueryReq is a "catch all" struct for reading various
// subscriber related requests.
type subQueryReq struct {
Expand Down Expand Up @@ -57,7 +61,7 @@ type subOptin struct {
var dummySubscriber = models.Subscriber{
Email: "[email protected]",
Name: "Dummy Subscriber",
UUID: "00000000-0000-0000-0000-000000000000",
UUID: dummyUUID,
}

// handleGetSubscriber handles the retrieval of a single subscriber by ID.
Expand Down
2 changes: 1 addition & 1 deletion templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func handlePreviewTemplate(c echo.Context) error {

// Compile the template.
camp := models.Campaign{
UUID: "00000000-0000-0000-0000-000000000000",
UUID: dummyUUID,
Name: "Dummy Campaign",
Subject: "Dummy Campaign Subject",
FromEmail: "[email protected]",
Expand Down

0 comments on commit ba87801

Please sign in to comment.