Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aerosol committed Oct 2, 2023
1 parent aab791d commit 920b008
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/plausible_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule PlausibleWeb do
alias PlausibleWeb.Plugins.API.Views
alias PlausibleWeb.Plugins.API.Context

plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true)
plug(OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true, replace_params: false)

use OpenApiSpex.ControllerSpecs
end
Expand Down
4 changes: 2 additions & 2 deletions lib/plausible_web/plugins/api/context/shared_links.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule PlausibleWeb.Plugins.API.Context.SharedLinks do

alias Plausible.Repo

@spec get_shared_links(Plausible.Site.t(), Keyword.t()) :: {:ok, Paginator.Page.t()}
@spec get_shared_links(Plausible.Site.t(), map()) :: {:ok, Paginator.Page.t()}
def get_shared_links(site, params) do
query =
from l in Plausible.Site.SharedLink,
Expand All @@ -27,7 +27,7 @@ defmodule PlausibleWeb.Plugins.API.Context.SharedLinks do
get_by_name(site, name)
end

@spec get_or_create(Plausible.Site.t(), String.t(), String.t()) ::
@spec get_or_create(Plausible.Site.t(), String.t(), String.t() | nil) ::
{:ok, Plausible.Site.SharedLink.t()}
def get_or_create(site, name, password \\ nil) do
case get_by_name(site, name) do
Expand Down
10 changes: 8 additions & 2 deletions lib/plausible_web/plugins/api/controllers/shared_links.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinks do

@spec create(Plug.Conn.t(), map()) :: Plug.Conn.t()
def create(
%{body_params: %Schemas.SharedLink.CreateRequest{name: name, password: password}} = conn,
%{
private: %{
open_api_spex: %{
body_params: %Schemas.SharedLink.CreateRequest{name: name, password: password}
}
}
} = conn,
_params
) do
site = conn.assigns.authorized_site
Expand Down Expand Up @@ -83,7 +89,7 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinks do
)

@spec get(Plug.Conn.t(), map()) :: Plug.Conn.t()
def get(conn, %{id: id}) do
def get(%{private: %{open_api_spex: %{params: %{id: id}}}} = conn, _params) do
site = conn.assigns.authorized_site

case Context.SharedLinks.get(site, id) do
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/plugins/api/errors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule PlausibleWeb.Plugins.API.Errors do
|> error(:unauthorized, "Plugins API: unauthorized")
end

@spec internal_server_error(Conn.t()) :: Conn.t()
@spec internal_server_error(Plug.Conn.t()) :: Plug.Conn.t()
def internal_server_error(conn) do
contact_support_note =
if not Plausible.Release.selfhost?() do
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/plugins/api/views/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule PlausibleWeb.Plugins.API.Views.Error do
render("500.json", assigns)
end

@spec render(Phoenix.Template.name(), map) :: map | binary()
@spec render(String.t(), map) :: map | binary()
def render("400.json", _assigns) do
%{errors: [%{detail: "Bad request"}]}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinksTest do
assert resp.data.href =~ "http://localhost:8000/share/#{site.domain}?auth="

[location] = get_resp_header(conn, "location")
assert location == Routes.shared_links_url(base_uri(), :get, resp.data.id)

assert location ==
Routes.shared_links_url(base_uri(), :get, resp.data.id)

assert ^resp =
initial_conn
Expand Down

0 comments on commit 920b008

Please sign in to comment.