Skip to content

Commit

Permalink
Fix shared link download link (#884)
Browse files Browse the repository at this point in the history
* Fix shared link download link

* Add test and changelog entry

* Format
  • Loading branch information
ukutaht committed Mar 31, 2021
1 parent f988f2e commit bc35d5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- Capitalized date/time selection keybinds not working plausible/analytics#709
- Invisible text on Google Search Console settings page in dark mode plausible/analytics#759
- Disable analytics tracking when running Cypress tests
- CSV reports can be downloaded via shared links plausible/analytics#884

## [1.2] - 2021-01-26

Expand Down
1 change: 1 addition & 0 deletions assets/js/dashboard/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function serializeQuery(query, extraQuery=[]) {
if (query.from) { queryObj.from = formatISO(query.from) }
if (query.to) { queryObj.to = formatISO(query.to) }
if (query.filters) { queryObj.filters = serializeFilters(query.filters) }
if (SHARED_LINK_AUTH) { queryObj.auth = SHARED_LINK_AUTH }
Object.assign(queryObj, ...extraQuery)

return '?' + serialize(queryObj)
Expand Down
4 changes: 2 additions & 2 deletions lib/plausible_web/plugs/authorize_stats_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule PlausibleWeb.AuthorizeStatsPlug do

def call(conn, _opts) do
site = Repo.get_by(Plausible.Site, domain: conn.params["domain"])
shared_link_auth = get_req_header(conn, "x-shared-link-auth") |> List.first()
# SHOULD GENERATE A NEW PHOENIX TOKEN WHEN MOUNTING THE STATS
shared_link_auth = conn.params["auth"]

shared_link_record =
shared_link_auth && Repo.get_by(Plausible.Site.SharedLink, slug: shared_link_auth)

Expand Down
13 changes: 13 additions & 0 deletions test/plausible_web/controllers/stats_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ defmodule PlausibleWeb.StatsControllerTest do
end
end

describe "GET /:website/visitors.csv - via shared link" do
test "exports graph as csv", %{conn: conn} do
site = insert(:site, domain: "test-site.com")
link = insert(:shared_link, site: site)

today = Timex.today() |> Timex.format!("{ISOdate}")

conn = get(conn, "/" <> site.domain <> "/visitors.csv?auth=#{link.slug}")
assert response(conn, 200) =~ "Date,Visitors"
assert response(conn, 200) =~ "#{today},3"
end
end

describe "GET /share/:slug" do
test "prompts a password for a password-protected link", %{conn: conn} do
site = insert(:site)
Expand Down

0 comments on commit bc35d5a

Please sign in to comment.