mirror of
https://github.com/plausible/analytics.git
synced 2024-12-27 03:21:37 +03:00
f635f0a6d3
* Add shield hostname rules migration
* Add hostname rule schema
* Initialize hostname rules cache
* Extend Shields context with hostname related functions
* Instrument ingestion pipeline with hostname rule lookups
* Limit hostname suggestions by shield patterns
* Add LiveView for hostname rules management
* Test hostname cache
* Rename feature flag - should be separate from hostname filter
* Remove :shield_pages feature flag
* Update CHANGELOG
* Format
* Update lib/plausible/shield/hostname_rule.ex
Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
* Move tests from `lib/` 🤦
* Use plain `assign` where no short-circuit is necessary
* Fine tune the copy a little bit
* Prevent misplaced tests
* Treat a test with common sense
* Fixup another test that hasn't been really run before
* Make the form hint dynamic depending on rules count
---------
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.Hostnames do
|
|
@moduledoc """
|
|
LiveView for Hostnames 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(:hostname_rules_count, fn %{site: site} ->
|
|
Shields.count_hostname_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.HostnameRules}
|
|
current_user={@current_user}
|
|
hostname_rules_count={@hostname_rules_count}
|
|
site={@site}
|
|
id="hostname-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
|