Update routers to hide and show api's docs

pull/2376/head
saneery 5 years ago
parent b717c37c0b
commit 9a76297651
  1. 21
      apps/block_scout_web/lib/block_scout_web/api_router.ex
  2. 46
      apps/block_scout_web/lib/block_scout_web/router.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex
  4. 204
      apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex
  5. 5
      apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex
  6. 3
      apps/block_scout_web/lib/block_scout_web/web_router.ex
  7. 6
      apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs
  8. 2
      apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs

@ -5,7 +5,6 @@ defmodule BlockScoutWeb.ApiRouter do
use BlockScoutWeb, :router
alias BlockScoutWeb.API.RPC
alias BlockScoutWeb.Plug.GraphQL
pipeline :api do
plug(:accepts, ["json"])
@ -19,8 +18,6 @@ defmodule BlockScoutWeb.ApiRouter do
scope "/", BlockScoutWeb.API.V1 do
get("/supply", SupplyController, :supply)
get("/health", HealthController, :health)
post("/decompiled_smart_contract", DecompiledSmartContractController, :create)
post("/verified_smart_contracts", VerifiedSmartContractController, :create)
@ -38,24 +35,6 @@ defmodule BlockScoutWeb.ApiRouter do
end
end
# Needs to be 200 to support the schema introspection for graphiql
@max_complexity 200
forward("/graphql", Absinthe.Plug,
schema: BlockScoutWeb.Schema,
analyze_complexity: true,
max_complexity: @max_complexity
)
forward("/graphiql", Absinthe.Plug.GraphiQL,
schema: BlockScoutWeb.Schema,
interface: :advanced,
default_query: GraphQL.default_query(),
socket: BlockScoutWeb.UserSocket,
analyze_complexity: true,
max_complexity: @max_complexity
)
# For backward compatibility. Should be removed
scope "/", BlockScoutWeb.API.RPC do
pipe_through(:api)

@ -2,6 +2,10 @@ defmodule BlockScoutWeb.Router do
use BlockScoutWeb, :router
alias BlockScoutWeb.Plug.GraphQL
alias BlockScoutWeb.{ApiRouter, WebRouter}
forward("/wobserver", Wobserver.Web.Router)
forward("/admin", BlockScoutWeb.AdminRouter)
pipeline :browser do
plug(:accepts, ["html"])
@ -11,13 +15,24 @@ defmodule BlockScoutWeb.Router do
plug(BlockScoutWeb.CSPHeader)
end
forward("/wobserver", Wobserver.Web.Router)
forward("/admin", BlockScoutWeb.AdminRouter)
pipeline :api do
plug(:accepts, ["json"])
end
scope "/", BlockScoutWeb.API.V1, as: :api_v1 do
pipe_through(:api)
get("/api/v1/health", HealthController, :health)
end
if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do
forward("/api", BlockScoutWeb.ApiRouter)
scope "/verify_smart_contract" do
pipe_through(:api)
post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create)
end
if Application.get_env(:block_scout_web, ApiRouter)[:enabled] do
forward("/api", ApiRouter)
# For backward compatibility. Should be removed
# Needs to be 200 to support the schema introspection for graphiql
@max_complexity 200
@ -35,9 +50,28 @@ defmodule BlockScoutWeb.Router do
analyze_complexity: true,
max_complexity: @max_complexity
)
else
scope "/", BlockScoutWeb do
pipe_through(:browser)
get("/api_docs", PageNotFoundController, :index)
get("/eth_rpc_api_docs", PageNotFoundController, :index)
end
end
if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do
scope "/", BlockScoutWeb do
pipe_through(:browser)
get("/api_docs", APIDocsController, :index)
get("/eth_rpc_api_docs", APIDocsController, :eth_rpc)
end
if Application.get_env(:block_scout_web, WebRouter)[:enabled] do
forward("/", BlockScoutWeb.WebRouter)
else
scope "/", BlockScoutWeb do
pipe_through(:browser)
forward("/", APIDocsController, :index)
end
end
end

@ -9,7 +9,7 @@
<h1 class="smart-contract-title"><%= gettext "New Smart Contract Verification" %></h1>
<%= form_for @changeset,
api_v1_address_contract_verification_path(@conn, :create),
address_contract_verification_path(@conn, :create),
[],
fn f -> %>

@ -8,79 +8,83 @@
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link topnav-nav-link dropdown-toggle" href="#" id="navbarBlocksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_block_icon.html" %>
</span>
<%= gettext("Blocks") %>
</a>
<div class="dropdown-menu" aria-labelledby="navbarBlocksDropdown">
<%= link to: block_path(@conn, :index), class: "dropdown-item #{tab_status("blocks", @conn.request_path)}" do %>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %>
<li class="nav-item dropdown">
<a class="nav-link topnav-nav-link dropdown-toggle" href="#" id="navbarBlocksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_block_icon.html" %>
</span>
<%= gettext("Blocks") %>
</a>
<div class="dropdown-menu" aria-labelledby="navbarBlocksDropdown">
<%= link to: block_path(@conn, :index), class: "dropdown-item #{tab_status("blocks", @conn.request_path)}" do %>
<%= gettext("Blocks") %>
<% end %>
<%= link to: uncle_path(@conn, :uncle), class: "dropdown-item #{tab_status("uncles", @conn.request_path)}" do %>
<%= gettext("Uncles") %>
<% end %>
<%= link to: reorg_path(@conn, :reorg), class: "dropdown-item #{tab_status("reorgs", @conn.request_path)}" do %>
<%= gettext("Forked Blocks (Reorgs)") %>
<% end %>
</div>
</li>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarTransactionsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_transaction_icon.html" %>
</span>
<%= gettext("Transactions") %>
</a>
<div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown">
<%= link(
gettext("Validated"),
class: "dropdown-item #{tab_status("txs", @conn.request_path)}",
to: transaction_path(@conn, :index)
) %>
<%= link(
gettext("Pending"),
class: "dropdown-item #{tab_status("pending_transactions", @conn.request_path)}",
"data-test": "pending_transactions_link",
to: pending_transaction_path(@conn, :index)
) %>
</div>
</li>
<li class="nav-item">
<%= link to: address_path(@conn, :index), class: "nav-link topnav-nav-link #{tab_status("accounts", @conn.request_path)}" do %>
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_accounts_icon.html" %>
</span>
<%= gettext("Accounts") %>
<% end %>
<%= link to: uncle_path(@conn, :uncle), class: "dropdown-item #{tab_status("uncles", @conn.request_path)}" do %>
<%= gettext("Uncles") %>
<% end %>
<%= link to: reorg_path(@conn, :reorg), class: "dropdown-item #{tab_status("reorgs", @conn.request_path)}" do %>
<%= gettext("Forked Blocks (Reorgs)") %>
<% end %>
</div>
</li>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarTransactionsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_transaction_icon.html" %>
</span>
<%= gettext("Transactions") %>
</a>
<div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown">
<%= link(
gettext("Validated"),
class: "dropdown-item #{tab_status("txs", @conn.request_path)}",
to: transaction_path(@conn, :index)
) %>
<%= link(
gettext("Pending"),
class: "dropdown-item #{tab_status("pending_transactions", @conn.request_path)}",
"data-test": "pending_transactions_link",
to: pending_transaction_path(@conn, :index)
) %>
</div>
</li>
<li class="nav-item">
<%= link to: address_path(@conn, :index), class: "nav-link topnav-nav-link #{tab_status("accounts", @conn.request_path)}" do %>
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_accounts_icon.html" %>
</span>
<%= gettext("Accounts") %>
<% end %>
</li>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarAPIsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_api_icon.html" %>
</span>
<%= gettext("APIs") %>
</a>
<div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown">
<%= link(
gettext("GraphQL"),
class: "dropdown-item #{tab_status("graphiql", @conn.request_path)}",
to: "/graphiql"
) %>
<%= link(
gettext("RPC"),
class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}",
to: api_docs_path(@conn, :index)
) %>
<%= link(
gettext("Eth RPC"),
class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}",
to: api_docs_path(@conn, :eth_rpc)
) %>
</div>
</li>
</li>
<% end %>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do %>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarAPIsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
<%= render BlockScoutWeb.IconsView, "_api_icon.html" %>
</span>
<%= gettext("APIs") %>
</a>
<div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown">
<%= link(
gettext("GraphQL"),
class: "dropdown-item #{tab_status("graphiql", @conn.request_path)}",
to: "/graphiql"
) %>
<%= link(
gettext("RPC"),
class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}",
to: api_docs_path(@conn, :index)
) %>
<%= link(
gettext("Eth RPC"),
class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}",
to: api_docs_path(@conn, :eth_rpc)
) %>
</div>
</li>
<% end %>
<li class="nav-item dropdown nav-item-networks">
<a class="nav-link topnav-nav-link dropdown-toggle active-icon js-show-network-selector <%= if dropdown_nets() == [], do: "disabled" %>" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
@ -91,34 +95,36 @@
</li>
</ul>
<!-- Search navbar -->
<div class="search-form d-lg-flex d-inline-block">
<%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %>
<div class="input-group" title='<%= gettext("Search by address, token symbol name, transaction hash, or block number") %>'>
<%= awesomplete(f, :q,
[
class: "form-control me auto",
placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"),
"aria-describedby": "search-icon",
"aria-label": gettext("Search"),
"data-test": "search_input"
],
[ url: "#{chain_path(@conn, :token_autocomplete)}?q=",
limit: 0,
minChars: 2,
value: "contract_address_hash",
label: "contract_address_hash",
descrSearch: true,
descr: "symbol"
]) %>
<div class="input-group-append">
<button class="input-group-text" id="search-icon">
<%= render BlockScoutWeb.IconsView, "_search_icon.html" %>
</button>
</div>
</div>
<button class="btn btn-outline-success my-2 my-sm-0 sr-only hidden" type="submit"><%= gettext "Search" %></button>
<% end %>
</div>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %>
<div class="search-form d-lg-flex d-inline-block">
<%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %>
<div class="input-group" title='<%= gettext("Search by address, token symbol name, transaction hash, or block number") %>'>
<%= awesomplete(f, :q,
[
class: "form-control me auto",
placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"),
"aria-describedby": "search-icon",
"aria-label": gettext("Search"),
"data-test": "search_input"
],
[ url: "#{chain_path(@conn, :token_autocomplete)}?q=",
limit: 0,
minChars: 2,
value: "contract_address_hash",
label: "contract_address_hash",
descrSearch: true,
descr: "symbol"
]) %>
<div class="input-group-append">
<button class="input-group-text" id="search-icon">
<%= render BlockScoutWeb.IconsView, "_search_icon.html" %>
</button>
</div>
</div>
<button class="btn btn-outline-success my-2 my-sm-0 sr-only hidden" type="submit"><%= gettext "Search" %></button>
<% end %>
</div>
<% end %>
</div>
</div>
</nav>

@ -1,8 +1,3 @@
defmodule BlockScoutWeb.AddressContractVerificationView do
use BlockScoutWeb, :view
alias BlockScoutWeb.ApiRouter.Helpers
def api_v1_address_contract_verification_path(conn, action) do
"/api" <> Helpers.api_v1_address_contract_verification_path(conn, action)
end
end

@ -199,9 +199,6 @@ defmodule BlockScoutWeb.WebRouter do
get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks)
get("/api_docs", APIDocsController, :index)
get("/eth_rpc_api_docs", APIDocsController, :eth_rpc)
get("/:page", PageNotFoundController, :index)
end
end

@ -1,8 +1,6 @@
defmodule BlockScoutWeb.API.V1.HealthControllerTest do
use BlockScoutWeb.ConnCase
alias BlockScoutWeb.ApiRouter.Helpers
describe "GET last_block_status/0" do
test "returns error when there are no blocks in db", %{conn: conn} do
request = get(conn, api_v1_health_path(conn, :health))
@ -49,8 +47,4 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do
} = Poison.decode!(request.resp_body)
end
end
def api_v1_health_path(conn, action) do
"/api" <> Helpers.api_v1_health_path(conn, action)
end
end

@ -1,7 +1,7 @@
defmodule BlockScoutWeb.APIDocsControllerTest do
use BlockScoutWeb.ConnCase
import BlockScoutWeb.WebRouter.Helpers, only: [api_docs_path: 2]
import BlockScoutWeb.Router.Helpers, only: [api_docs_path: 2]
describe "GET index/2" do
test "renders documentation tiles for each API module#action", %{conn: conn} do

Loading…
Cancel
Save