defmodule PlausibleWeb.Live.Plugins.API.Settings do @moduledoc """ LiveView allowing listing, creating and revoking Plugins API tokens. """ use Phoenix.LiveView use Phoenix.HTML alias Plausible.Sites alias Plausible.Plugins.API.Tokens def mount( _params, %{"domain" => domain, "current_user_id" => user_id} = session, socket ) do socket = socket |> assign_new(:site, fn -> Sites.get_for_user!(user_id, domain, [:owner, :admin, :super_admin]) end) |> assign_new(:displayed_tokens, fn %{site: site} -> Tokens.list(site) end) {:ok, assign(socket, domain: domain, add_token?: not is_nil(session["new_token"]), token_description: String.capitalize(session["new_token"] || ""), current_user_id: user_id )} end def render(assigns) do ~H""" <.live_component id="embedded_liveview_flash" module={PlausibleWeb.Live.Flash} flash={@flash} /> <%= if @add_token? do %> <%= live_render( @socket, PlausibleWeb.Live.Plugins.API.TokenForm, id: "token-form", session: %{ "current_user_id" => @current_user_id, "domain" => @domain, "token_description" => @token_description, "rendered_by" => self() } ) %> <% end %>
Description | Hint | Last used | Revoke |
---|---|---|---|
<%= token.description %> | **********<%= token.hint %> | <%= Plausible.Plugins.API.Token.last_used_humanize(token) %> |