mirror of
https://github.com/plausible/analytics.git
synced 2024-12-29 20:42:01 +03:00
518cdb3307
* Migration: add country rules * Add CountryRule schema * Implement CountryRule cache * Add country rules context interface * Start country rules cache * Lookup country rules on ingestion * Remove :shields feature flag from test helpers * Add nested sidebar menu for Shields * Fix typo * IP Rules: hide description on mobile view * Prepare SiteController to handle multiple shield types * Seed some country shield * Implement LV for country rules * Remove "YOU" indicator from country rules * Fix small build * Format * Update typespecs * Make docs link point at /countries * Fix flash on top of modal for Safari * Build the rule struct with site_id provided up-front * Clarify why we're messaging the ComboBox component * Re-open combobox suggestions after pressing Escape * Update changelog * Fix font size in country table cells * Pass `added_by` via rule add options * Display site's timezone timestamps in rule tooltips * Display formatted timestamps in site's timezone And simplify+test Timezone module; an input timestamp converted to UTC can never be ambiguous. * Remove no-op atom * Display the maximum number of rules when reached * Improve readability of remove button tests * Credo --------- Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
54 lines
1.2 KiB
Elixir
54 lines
1.2 KiB
Elixir
defmodule PlausibleWeb.Live.Shields.Countries do
|
|
@moduledoc """
|
|
LiveView for IP Addresses Shield
|
|
"""
|
|
use PlausibleWeb, :live_view
|
|
use Phoenix.HTML
|
|
|
|
alias Plausible.Shields
|
|
alias Plausible.Sites
|
|
|
|
def mount(
|
|
_params,
|
|
%{
|
|
"domain" => domain,
|
|
"current_user_id" => user_id
|
|
},
|
|
socket
|
|
) do
|
|
socket =
|
|
socket
|
|
|> assign_new(:site, fn ->
|
|
Sites.get_for_user!(user_id, domain, [:owner, :admin, :super_admin])
|
|
end)
|
|
|> assign_new(:country_rules_count, fn %{site: site} ->
|
|
Shields.count_country_rules(site)
|
|
end)
|
|
|> assign_new(:current_user, fn ->
|
|
Plausible.Repo.get(Plausible.Auth.User, user_id)
|
|
end)
|
|
|
|
{:ok, socket}
|
|
end
|
|
|
|
def render(assigns) do
|
|
~H"""
|
|
<div>
|
|
<.flash_messages flash={@flash} />
|
|
<.live_component
|
|
module={PlausibleWeb.Live.Shields.CountryRules}
|
|
current_user={@current_user}
|
|
country_rules_count={@country_rules_count}
|
|
site={@site}
|
|
id="country-rules-#{@current_user.id}"
|
|
/>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def handle_info({:flash, kind, message}, socket) do
|
|
socket = put_live_flash(socket, kind, message)
|
|
{:noreply, socket}
|
|
end
|
|
end
|