Show error when policy is created with no groups available (#2825)

This commit is contained in:
Andrew Dryga
2023-12-07 22:25:44 -05:00
committed by GitHub
parent ed3db22d01
commit 0eee8a7c26
11 changed files with 33 additions and 44 deletions

View File

@@ -121,17 +121,13 @@ defmodule Domain.Config do
end
def sign_up_enabled? do
feature_enabled?(:signups)
feature_enabled?(:sign_up)
end
def flow_activities_enabled? do
feature_enabled?(:flow_activities)
end
def todos_enabled? do
feature_enabled?(:todos)
end
def traffic_filters_enabled? do
feature_enabled?(:traffic_filters)
end

View File

@@ -626,11 +626,6 @@ defmodule Domain.Config.Definitions do
"""
defconfig(:feature_flow_activities_enabled, :boolean, default: false)
@doc """
Boolean flag to turn UI TODOs on/off.
"""
defconfig(:feature_todos_enabled, :boolean, default: false)
@doc """
Boolean flag to turn Resource traffic filters on/off.
"""

View File

@@ -14,12 +14,10 @@ defmodule Web.Clients.Show do
socket,
client: client,
flows: flows,
todos_enabled?: Config.todos_enabled?(),
flow_activities_enabled?: Config.flow_activities_enabled?()
)
{:ok, socket,
temporary_assigns: [flows: [], todos_enabled?: nil, flow_activities_enabled?: nil]}
{:ok, socket}
else
{:error, _reason} -> raise Web.LiveErrors.NotFoundError
end
@@ -77,10 +75,6 @@ defmodule Web.Clients.Show do
<.relative_datetime datetime={@client.last_seen_at} />
</:value>
</.vertical_table_row>
<.vertical_table_row :if={@todos_enabled?}>
<:label>Transfer</:label>
<:value>TODO</:value>
</.vertical_table_row>
<.vertical_table_row>
<:label>Last Seen Remote IP</:label>
<:value>

View File

@@ -37,7 +37,29 @@ defmodule Web.Policies.New do
<:content>
<div class="max-w-2xl px-4 py-8 mx-auto lg:py-16">
<h2 class="mb-4 text-xl font-bold text-neutral-900">Policy details</h2>
<.simple_form for={@form} phx-submit="submit" phx-change="validate">
<div
:if={@actor_groups == []}
class={[
"p-4 text-sm flash-error",
"text-red-800 bg-red-50"
]}
role="alert"
>
<p class="text-sm font-semibold leading-6">
<.icon name="hero-exclamation-circle-mini" class="h-4 w-4" />
You have no groups to create policies for. You can create a group <.link
navigate={~p"/#{@account}/groups/new"}
class={link_style()}
>here</.link>.
</p>
</div>
<.simple_form
:if={@actor_groups != []}
for={@form}
phx-submit="submit"
phx-change="validate"
>
<.base_error form={@form} field={:base} />
<.input
field={@form[:actor_group_id]}

View File

@@ -3,18 +3,10 @@ defmodule Web.Relays.Show do
alias Domain.{Relays, Config}
def mount(%{"id" => id}, _session, socket) do
with true <- Domain.Config.self_hosted_relays_enabled?(),
with true <- Config.self_hosted_relays_enabled?(),
{:ok, relay} <-
Relays.fetch_relay_by_id(id, socket.assigns.subject, preload: :group) do
:ok = Relays.subscribe_for_relays_presence_in_group(relay.group)
socket =
assign(
socket,
relay: relay,
todos_enabled?: Config.todos_enabled?()
)
{:ok, assign(socket, relay: relay)}
else
_other -> raise Web.LiveErrors.NotFoundError
@@ -104,10 +96,6 @@ defmodule Web.Relays.Show do
<%= @relay.last_seen_user_agent %>
</:value>
</.vertical_table_row>
<.vertical_table_row :if={@todos_enabled?}>
<:label>Deployment Method</:label>
<:value>TODO: Docker</:value>
</.vertical_table_row>
</.vertical_table>
</div>
</:content>

View File

@@ -4,11 +4,13 @@ defmodule Web.Live.Policies.NewTest do
setup do
account = Fixtures.Accounts.create_account()
actor = Fixtures.Actors.create_actor(type: :account_admin_user, account: account)
actor_group = Fixtures.Actors.create_group(account: account)
identity = Fixtures.Auth.create_identity(account: account, actor: actor)
%{
account: account,
actor: actor,
actor_group: actor_group,
identity: identity
}
end

View File

@@ -48,7 +48,6 @@ defmodule Web.Live.Relays.ShowTest do
assert html =~ "(deleted)"
refute html =~ "Danger Zone"
refute html =~ "Add"
refute html =~ "Delete"
refute html =~ "Edit"
end

View File

@@ -101,7 +101,7 @@ defmodule Web.Live.SignUpTest do
end
test "renders sign up disabled message", %{conn: conn} do
Domain.Config.feature_flag_override(:signups, false)
Domain.Config.feature_flag_override(:sign_up, false)
{:ok, _lv, html} = live(conn, ~p"/sign_up")

View File

@@ -73,9 +73,8 @@ config :domain, Domain.Instrumentation,
config :domain, :enabled_features,
traffic_filters: true,
signups: true,
sign_up: true,
flow_activities: true,
todos: true,
self_hosted_relays: true
config :domain, docker_registry: "us-east1-docker.pkg.dev/firezone-staging/firezone"

View File

@@ -67,10 +67,9 @@ if config_env() == :prod do
config :domain, :enabled_features,
traffic_filters: compile_config!(:feature_traffic_filters_enabled),
signups: compile_config!(:feature_sign_up_enabled),
sign_up: compile_config!(:feature_sign_up_enabled),
flow_activities: compile_config!(:feature_flow_activities_enabled),
todos: compile_config!(:feature_todos_enabled),
relay_admin: compile_config!(:feature_self_hosted_relays_enabled)
self_hosted_relays: compile_config!(:feature_self_hosted_relays_enabled)
config :domain, docker_registry: compile_config!(:docker_registry)

View File

@@ -431,14 +431,9 @@ locals {
value = true
},
{
name = "FEATURE_TODOS_ENABLED"
value = true
},
{
name = "FEATURE_RELAY_ADMIN_ENABLED"
name = "FEATURE_SELF_HOSTED_RELAYS_ENABLED"
value = true
}
]
}