From 881377cbe26b10efec40c321fe810f418a5dc125 Mon Sep 17 00:00:00 2001 From: Jamil Date: Wed, 24 Jul 2024 15:43:31 -0700 Subject: [PATCH] fix(ux): Redirect to policies/new after creating Resource (#5938) Fixes a UX issue somewhat introduced by https://github.com/firezone/firezone/pull/5870 where we changed behavior to make the redirect consistent with other CRUD operations. The behavior we had prior to https://github.com/firezone/firezone/pull/5870 was to redirect to Resource show, but feedback from customer (which makes sense) is that you almost _always_ create a Policy after creating a Resource, so this PR streamlines the hot path flow there. This has occurred to a couple users in Discord as well, so by taking them directly to policies/new it hopefully make clear the user needs to create a Policy after creating a Resource. This papercut occurred while customer was demo'ing Firezone to another potential customer. Fixes #5929 cc @jameswinegar --- .../lib/domain/policies/policy/changeset.ex | 2 +- .../web/lib/web/live/actors/components.ex | 28 ++----- elixir/apps/web/lib/web/live/actors/new.ex | 73 +++++++++++++++---- .../web/live/actors/service_accounts/new.ex | 8 +- .../actors/service_accounts/new_identity.ex | 25 ++++--- .../apps/web/lib/web/live/actors/users/new.ex | 8 +- .../lib/web/live/actors/users/new_identity.ex | 15 ++-- elixir/apps/web/lib/web/live/groups/new.ex | 19 +++-- elixir/apps/web/lib/web/live/policies/new.ex | 43 +++++++---- .../apps/web/lib/web/live/relay_groups/new.ex | 4 +- elixir/apps/web/lib/web/live/resources/new.ex | 13 ++-- .../live/settings/api_clients/components.ex | 20 +++-- .../web/live/settings/api_clients/index.ex | 8 +- .../lib/web/live/settings/api_clients/new.ex | 6 +- .../live/settings/api_clients/new_token.ex | 6 +- .../google_workspace/new.ex | 6 +- .../identity_providers/jumpcloud/new.ex | 6 +- .../identity_providers/microsoft_entra/new.ex | 6 +- .../live/settings/identity_providers/new.ex | 4 +- .../settings/identity_providers/okta/new.ex | 6 +- .../identity_providers/openid_connect/new.ex | 6 +- elixir/apps/web/lib/web/live/sites/new.ex | 14 +++- .../web/test/web/live/policies/new_test.exs | 43 +++++++++-- .../web/test/web/live/resources/new_test.exs | 11 ++- .../settings/api_clients/new_token_test.exs | 4 +- 25 files changed, 235 insertions(+), 149 deletions(-) diff --git a/elixir/apps/domain/lib/domain/policies/policy/changeset.ex b/elixir/apps/domain/lib/domain/policies/policy/changeset.ex index 1a879ab5b..a02599629 100644 --- a/elixir/apps/domain/lib/domain/policies/policy/changeset.ex +++ b/elixir/apps/domain/lib/domain/policies/policy/changeset.ex @@ -43,7 +43,7 @@ defmodule Domain.Policies.Policy.Changeset do |> unique_constraint( :base, name: :policies_account_id_resource_id_actor_group_id_index, - message: "Policy with Group and Resource already exists" + message: "Policy for the selected Group and Resource already exists" ) |> assoc_constraint(:resource) |> assoc_constraint(:actor_group) diff --git a/elixir/apps/web/lib/web/live/actors/components.ex b/elixir/apps/web/lib/web/live/actors/components.ex index 60d96b5af..4b10f4591 100644 --- a/elixir/apps/web/lib/web/live/actors/components.ex +++ b/elixir/apps/web/lib/web/live/actors/components.ex @@ -74,6 +74,11 @@ defmodule Web.Actors.Components do placeholder="Role" required /> +

+ Select Admin + to grant this user access to the admin portal. Otherwise, select User + to limit access to the Client apps only. +

""" end @@ -160,29 +165,6 @@ defmodule Web.Actors.Components do """ end - def option(assigns) do - ~H""" -
-
- - -
-

- <%= @description %> -

-
- """ - end - def next_step_path(:service_account, account) do ~p"/#{account}/actors/service_accounts/new" end diff --git a/elixir/apps/web/lib/web/live/actors/new.ex b/elixir/apps/web/lib/web/live/actors/new.ex index beeee1ef6..b005b8b2f 100644 --- a/elixir/apps/web/lib/web/live/actors/new.ex +++ b/elixir/apps/web/lib/web/live/actors/new.ex @@ -18,9 +18,7 @@ defmodule Web.Actors.New do <.breadcrumb path={~p"/#{@account}/actors/new"}>Add <.section> - <:title> - Add Actor - + <:title><%= @page_title %> <:content>

Choose type

@@ -29,22 +27,65 @@ defmodule Web.Actors.New do
Choose Actor Type - <.option - account={@account} - type={:user} - name="User" - description="Admin or regular user accounts can be used to sign in to Firezone and access private resources." - /> - <.option - account={@account} - type={:service_account} - name="Service Account" - description="Service accounts can be used for headless clients or to access Firezone APIs." - /> +
    +
  • + <.input + id="idp-option-user" + type="radio_button_group" + name="next" + value={next_step_path(:user, @account)} + checked={false} + required + /> + +
  • + +
  • + <.input + id="idp-option-service_account" + type="radio_button_group" + name="next" + value={next_step_path(:service_account, @account)} + checked={false} + required + /> + +
  • +
<.submit_button> - Next: Create Actor + Next: Actor Details diff --git a/elixir/apps/web/lib/web/live/actors/service_accounts/new.ex b/elixir/apps/web/lib/web/live/actors/service_accounts/new.ex index 59cc769d8..2dbf2047f 100644 --- a/elixir/apps/web/lib/web/live/actors/service_accounts/new.ex +++ b/elixir/apps/web/lib/web/live/actors/service_accounts/new.ex @@ -24,13 +24,11 @@ defmodule Web.Actors.ServiceAccounts.New do <.section> - <:title> - Create Actor - + <:title><%= @page_title %> <:content>

- Create a Service Account + Service Account details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}> @@ -38,7 +36,7 @@ defmodule Web.Actors.ServiceAccounts.New do <.actor_form form={@form} type={:service_account} subject={@subject} />
<.submit_button> - Create + Next: Create Token diff --git a/elixir/apps/web/lib/web/live/actors/service_accounts/new_identity.ex b/elixir/apps/web/lib/web/live/actors/service_accounts/new_identity.ex index f1d434712..039732ae8 100644 --- a/elixir/apps/web/lib/web/live/actors/service_accounts/new_identity.ex +++ b/elixir/apps/web/lib/web/live/actors/service_accounts/new_identity.ex @@ -1,6 +1,5 @@ defmodule Web.Actors.ServiceAccounts.NewIdentity do use Web, :live_view - import Web.Actors.Components alias Domain.{Auth, Actors, Tokens} def mount(%{"id" => id}, _session, socket) do @@ -41,12 +40,10 @@ defmodule Web.Actors.ServiceAccounts.NewIdentity do <.section> - <:title> - Create <%= actor_type(@actor.type) %> Token - + <:title><%= @page_title %> <:content>
-

Create a Token

+

Token details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}>
@@ -75,14 +72,20 @@ defmodule Web.Actors.ServiceAccounts.NewIdentity do
- Your API token (will be shown only once): + Your Service Account token +
+
+ <.code_block id="code-sample-docker" class="w-full mw-1/2 rounded" phx-no-format><%= @encoded_token %> +

+ Store this in a safe place. It won't be shown again. +

- <.code_block id="code-sample-docker" class="w-full mw-1/2 rounded" phx-no-format><%= @encoded_token %> - - <.button icon="hero-arrow-uturn-left" navigate={~p"/#{@account}/actors/#{@actor}"}> - Back to Actor - +
+ <.button icon="hero-arrow-uturn-left" navigate={~p"/#{@account}/actors/#{@actor}"}> + Back to Service Account + +
diff --git a/elixir/apps/web/lib/web/live/actors/users/new.ex b/elixir/apps/web/lib/web/live/actors/users/new.ex index 3f62b2f08..42e2222d3 100644 --- a/elixir/apps/web/lib/web/live/actors/users/new.ex +++ b/elixir/apps/web/lib/web/live/actors/users/new.ex @@ -24,19 +24,17 @@ defmodule Web.Actors.Users.New do <.section> - <:title> - Create Actor - + <:title><%= @page_title %> <:content>
-

Create a User

+

User details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}>
<.actor_form form={@form} type={:user} subject={@subject} />
<.submit_button> - Create + Next: Add an Identity
diff --git a/elixir/apps/web/lib/web/live/actors/users/new_identity.ex b/elixir/apps/web/lib/web/live/actors/users/new_identity.ex index 416f8d488..4a65db196 100644 --- a/elixir/apps/web/lib/web/live/actors/users/new_identity.ex +++ b/elixir/apps/web/lib/web/live/actors/users/new_identity.ex @@ -51,12 +51,10 @@ defmodule Web.Actors.Users.NewIdentity do <.section> - <:title> - Create <%= actor_type(@actor.type) %> Identity - + <:title><%= @page_title %> <:content>
-

Create an Identity

+

Identity details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}>
@@ -74,11 +72,18 @@ defmodule Web.Actors.Users.NewIdentity do placeholder="Provider" required /> +

+ Select the provider to use for signing in. +

<.provider_form :if={@provider} form={@form} provider={@provider} />
<.submit_button> - Save + <%= if @next_step == "edit_groups" do %> + Next: Select Group Memberships + <% else %> + Create Identity + <% end %>
diff --git a/elixir/apps/web/lib/web/live/groups/new.ex b/elixir/apps/web/lib/web/live/groups/new.ex index 08f5dabf1..9955c3285 100644 --- a/elixir/apps/web/lib/web/live/groups/new.ex +++ b/elixir/apps/web/lib/web/live/groups/new.ex @@ -21,25 +21,24 @@ defmodule Web.Groups.New do <.breadcrumb path={~p"/#{@account}/groups/new"}>Add <.section> - <:title> - Create Group - + <:title><%= @page_title %> <:content>
+

+ Group details +

<.form for={@form} phx-change={:change} phx-submit={:submit}> <.input type="hidden" field={@form[:type]} value="static" />
- <.input - label="Group name" - field={@form[:name]} - placeholder="Enter a name for this Group, e.g. Engineering" - required - /> + <.input label="Name" field={@form[:name]} placeholder="E.g. Engineering" required /> +

+ Enter a name for this Group. +

<.submit_button> - Save + Next: Select Members
diff --git a/elixir/apps/web/lib/web/live/policies/new.ex b/elixir/apps/web/lib/web/live/policies/new.ex index 68282b422..472aa216f 100644 --- a/elixir/apps/web/lib/web/live/policies/new.ex +++ b/elixir/apps/web/lib/web/live/policies/new.ex @@ -34,12 +34,10 @@ defmodule Web.Policies.New do <.breadcrumb path={~p"/#{@account}/policies/new"}>Add Policy <.section> - <:title> - Add Policy - + <:title><%= @page_title %> <:content>
-

Details

+

Policy details

- <.submit_button phx-disable-with="Creating Policy..." class="w-full"> - Create Policy - +
+ <.submit_button phx-disable-with="Creating Policy..." class="w-full"> + Create Policy + +
@@ -141,12 +141,29 @@ defmodule Web.Policies.New do Map.delete(params, "conditions") end - with {:ok, policy} <- Policies.create_policy(params, socket.assigns.subject) do - if site_id = socket.assigns.params["site_id"] do - {:noreply, - push_navigate(socket, to: ~p"/#{socket.assigns.account}/sites/#{site_id}?#resources")} - else - {:noreply, push_navigate(socket, to: ~p"/#{socket.assigns.account}/policies/#{policy}")} + with {:ok, _policy} <- Policies.create_policy(params, socket.assigns.subject) do + cond do + site_id = socket.assigns.params["site_id"] -> + # Created from Add Resource from Site + {:noreply, + push_navigate(socket, to: ~p"/#{socket.assigns.account}/sites/#{site_id}?#resources")} + + resource_id = socket.assigns.resource_id -> + # Created from Add Resource from Resources + {:noreply, + push_navigate(socket, to: ~p"/#{socket.assigns.account}/resources/#{resource_id}")} + + actor_group_id = socket.assigns.actor_group_id -> + # Created from Add Policy from Actor Group + {:noreply, + push_navigate(socket, to: ~p"/#{socket.assigns.account}/groups/#{actor_group_id}")} + + true -> + # Created from Add Policy from Policies + {:noreply, + socket + |> put_flash(:info, "Policy created successfully.") + |> push_navigate(to: ~p"/#{socket.assigns.account}/policies")} end else {:error, %Ecto.Changeset{} = changeset} -> diff --git a/elixir/apps/web/lib/web/live/relay_groups/new.ex b/elixir/apps/web/lib/web/live/relay_groups/new.ex index 876ff14b1..9972ffb70 100644 --- a/elixir/apps/web/lib/web/live/relay_groups/new.ex +++ b/elixir/apps/web/lib/web/live/relay_groups/new.ex @@ -26,9 +26,7 @@ defmodule Web.RelayGroups.New do <.breadcrumb path={~p"/#{@account}/relay_groups/new"}>Add <.section> - <:title> - Add Relay Instance Group - + <:title><%= @page_title %> <:content>
<.form for={@form} phx-change={:change} phx-submit={:submit}> diff --git a/elixir/apps/web/lib/web/live/resources/new.ex b/elixir/apps/web/lib/web/live/resources/new.ex index 0d7dc9eac..9662472d5 100644 --- a/elixir/apps/web/lib/web/live/resources/new.ex +++ b/elixir/apps/web/lib/web/live/resources/new.ex @@ -28,9 +28,7 @@ defmodule Web.Resources.New do <.breadcrumb path={~p"/#{@account}/resources/new"}>Add Resource <.section> - <:title> - Add Resource - + <:title><%= @page_title %> <:content>
@@ -236,11 +234,16 @@ defmodule Web.Resources.New do if site_id = socket.assigns.params["site_id"] do {:noreply, socket - |> push_navigate(to: ~p"/#{socket.assigns.account}/sites/#{site_id}")} + |> push_navigate( + to: + ~p"/#{socket.assigns.account}/policies/new?resource_id=#{resource}&site_id=#{site_id}" + )} else {:noreply, socket - |> push_navigate(to: ~p"/#{socket.assigns.account}/resources")} + |> push_navigate( + to: ~p"/#{socket.assigns.account}/policies/new?resource_id=#{resource}" + )} end {:error, changeset} -> diff --git a/elixir/apps/web/lib/web/live/settings/api_clients/components.ex b/elixir/apps/web/lib/web/live/settings/api_clients/components.ex index f042acc60..09798c37e 100644 --- a/elixir/apps/web/lib/web/live/settings/api_clients/components.ex +++ b/elixir/apps/web/lib/web/live/settings/api_clients/components.ex @@ -50,14 +50,24 @@ defmodule Web.Settings.ApiClients.Components do ~H"""
- Your API token (will be shown only once): + Your API Token:
- <.code_block id="code-api-token" class="w-full mw-1/2 rounded" phx-no-format><%= @encoded_token %> +
+ <.code_block id="code-api-token" class="w-full mw-1/2 rounded" phx-no-format><%= @encoded_token %> +

+ Store this in a safe place. It won't be shown again. +

+
- <.button icon="hero-arrow-uturn-left" navigate={~p"/#{@account}/settings/api_clients/#{@actor}"}> - Back to API Client - +
+ <.button + icon="hero-arrow-uturn-left" + navigate={~p"/#{@account}/settings/api_clients/#{@actor}"} + > + Back to API Client + +
""" end diff --git a/elixir/apps/web/lib/web/live/settings/api_clients/index.ex b/elixir/apps/web/lib/web/live/settings/api_clients/index.ex index 4f675b4f6..d964e71e3 100644 --- a/elixir/apps/web/lib/web/live/settings/api_clients/index.ex +++ b/elixir/apps/web/lib/web/live/settings/api_clients/index.ex @@ -54,9 +54,11 @@ defmodule Web.Settings.ApiClients.Index do <.section> <:title><%= @page_title %> <:help> - API Clients are used to manage Firezone configuration through a REST API. See the - REST API docs - for more info. + API Clients are used to manage Firezone configuration through a REST API. See our + <.link navigate="https://api.firezone.dev/swaggerui" class={link_style()}> + OpenAPI-powered docs + + for more information. <:action> diff --git a/elixir/apps/web/lib/web/live/settings/api_clients/new.ex b/elixir/apps/web/lib/web/live/settings/api_clients/new.ex index 586484ee7..d471dfbc8 100644 --- a/elixir/apps/web/lib/web/live/settings/api_clients/new.ex +++ b/elixir/apps/web/lib/web/live/settings/api_clients/new.ex @@ -12,7 +12,7 @@ defmodule Web.Settings.ApiClients.New do socket = assign(socket, form: to_form(changeset), - page_title: "New API Client" + page_title: "Add an API Client" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -30,7 +30,7 @@ defmodule Web.Settings.ApiClients.New do <:content>

- Create API Client + API Client details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}> @@ -38,7 +38,7 @@ defmodule Web.Settings.ApiClients.New do <.api_client_form form={@form} type={:api_client} subject={@subject} />
<.submit_button> - Create + Next: Add a token
diff --git a/elixir/apps/web/lib/web/live/settings/api_clients/new_token.ex b/elixir/apps/web/lib/web/live/settings/api_clients/new_token.ex index 8762d6ab0..1667a1cf8 100644 --- a/elixir/apps/web/lib/web/live/settings/api_clients/new_token.ex +++ b/elixir/apps/web/lib/web/live/settings/api_clients/new_token.ex @@ -16,7 +16,7 @@ defmodule Web.Settings.ApiClients.NewToken do actor: actor, encoded_token: nil, form: to_form(changeset), - page_title: "Create API Token" + page_title: "Add an API Token" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -42,14 +42,14 @@ defmodule Web.Settings.ApiClients.NewToken do <:content>
-

Create Token

+

API Token details

<.flash kind={:error} flash={@flash} /> <.form for={@form} phx-change={:change} phx-submit={:submit}>
<.api_token_form form={@form} />
<.submit_button> - Create + Create API Token
diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/google_workspace/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/google_workspace/new.ex index 23babb32f..9895aff5d 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/google_workspace/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/google_workspace/new.ex @@ -17,7 +17,7 @@ defmodule Web.Settings.IdentityProviders.GoogleWorkspace.New do assign(socket, id: id, form: to_form(changeset), - page_title: "New Identity Provider" + page_title: "New Identity Provider: Google Workspace" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -37,9 +37,7 @@ defmodule Web.Settings.IdentityProviders.GoogleWorkspace.New do <.section> - <:title> - Add a new Google Workspace Identity Provider - + <:title><%= @page_title %> <:help> For a more detailed guide on setting up Firezone with Google Workspace, please <.link href="https://www.firezone.dev/kb/authenticate/google" diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/jumpcloud/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/jumpcloud/new.ex index a7311ddb3..afaaf1a01 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/jumpcloud/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/jumpcloud/new.ex @@ -17,7 +17,7 @@ defmodule Web.Settings.IdentityProviders.JumpCloud.New do assign(socket, id: id, form: to_form(changeset), - page_title: "New Identity Provider" + page_title: "New Identity Provider: JumpCloud" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -37,9 +37,7 @@ defmodule Web.Settings.IdentityProviders.JumpCloud.New do <.section> - <:title> - Add a new JumpCloud Identity Provider - + <:title><%= @page_title %> <:help> For a more detailed guide on setting up Firezone with JumpCloud, please <.link href="https://www.firezone.dev/kb/authenticate/jumpcloud" diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/microsoft_entra/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/microsoft_entra/new.ex index 763039219..db94a3e8a 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/microsoft_entra/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/microsoft_entra/new.ex @@ -17,7 +17,7 @@ defmodule Web.Settings.IdentityProviders.MicrosoftEntra.New do assign(socket, id: id, form: to_form(changeset), - page_title: "New Identity Provider" + page_title: "New Identity Provider: Microsoft Entra" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -37,9 +37,7 @@ defmodule Web.Settings.IdentityProviders.MicrosoftEntra.New do <.section> - <:title> - Add a new Microsoft Entra ID Identity Provider - + <:title><%= @page_title %> <:help> For a more detailed guide on setting up Firezone with Microsoft Entra ID, please <.link href="https://www.firezone.dev/kb/authenticate/entra" diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/new.ex index 365e25df2..f48e6eb0c 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/new.ex @@ -33,9 +33,7 @@ defmodule Web.Settings.IdentityProviders.New do <.section> - <:title> - Add a new Identity Provider - + <:title><%= @page_title %> <:help> Set up SSO authentication using your own identity provider. Directory sync also available for certain providers.
Learn more about diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/okta/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/okta/new.ex index 5a0329c25..e6c6dcf34 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/okta/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/okta/new.ex @@ -17,7 +17,7 @@ defmodule Web.Settings.IdentityProviders.Okta.New do assign(socket, id: id, form: to_form(changeset), - page_title: "New Identity Provider" + page_title: "New Identity Provider: Okta" ) {:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]} @@ -37,9 +37,7 @@ defmodule Web.Settings.IdentityProviders.Okta.New do <.section> - <:title> - Add a new Okta Identity Provider - + <:title><%= @page_title %> <:help> For a more detailed guide on setting up Firezone with Okta, please <.link href="https://www.firezone.dev/kb/authenticate/okta" diff --git a/elixir/apps/web/lib/web/live/settings/identity_providers/openid_connect/new.ex b/elixir/apps/web/lib/web/live/settings/identity_providers/openid_connect/new.ex index 29144fe63..00b6c9b21 100644 --- a/elixir/apps/web/lib/web/live/settings/identity_providers/openid_connect/new.ex +++ b/elixir/apps/web/lib/web/live/settings/identity_providers/openid_connect/new.ex @@ -17,7 +17,7 @@ defmodule Web.Settings.IdentityProviders.OpenIDConnect.New do assign(socket, id: id, form: to_form(changeset), - page_title: "New Identity Provider", + page_title: "New Identity Provider: OpenID Connect", provider: params["provider"] ) @@ -38,9 +38,7 @@ defmodule Web.Settings.IdentityProviders.OpenIDConnect.New do <.section> - <:title> - Add a new OpenID Connect Identity Provider - + <:title><%= @page_title %> <:content> <.provider_form account={@account} id={@id} form={@form} show_sync_msg={!!@provider} /> diff --git a/elixir/apps/web/lib/web/live/sites/new.ex b/elixir/apps/web/lib/web/live/sites/new.ex index c79d52ce4..96ecf1325 100644 --- a/elixir/apps/web/lib/web/live/sites/new.ex +++ b/elixir/apps/web/lib/web/live/sites/new.ex @@ -16,15 +16,21 @@ defmodule Web.Sites.New do <.section> - <:title> - Add a new Site - + <:title><%= @page_title %> <:content> <.flash kind={:error} flash={@flash} />
+

+ Site details +

<.form for={@form} phx-change={:change} phx-submit={:submit}>
- <.input label="Name" field={@form[:name]} placeholder="Name of this Site" required /> +
+ <.input label="Name" field={@form[:name]} placeholder="Name of this Site" required /> +

+ Enter a name for this Site. +

+
<.submit_button> Create diff --git a/elixir/apps/web/test/web/live/policies/new_test.exs b/elixir/apps/web/test/web/live/policies/new_test.exs index a4f032a76..7102f5fea 100644 --- a/elixir/apps/web/test/web/live/policies/new_test.exs +++ b/elixir/apps/web/test/web/live/policies/new_test.exs @@ -210,11 +210,11 @@ defmodule Web.Live.Policies.NewTest do |> form("form", policy: attrs) |> render_submit() |> form_validation_errors() == %{ - "policy[base]" => ["Policy with Group and Resource already exists"] + "policy[base]" => ["Policy for the selected Group and Resource already exists"] } end - test "creates a new policy on valid attrs and redirects to policy page", %{ + test "creates a new policy on valid attrs and redirects to policies page", %{ account: account, identity: identity, conn: conn @@ -236,9 +236,10 @@ defmodule Web.Live.Policies.NewTest do |> form("form", policy: attrs) |> render_submit() - assert policy = Repo.get_by(Domain.Policies.Policy, attrs) + assert Repo.get_by(Domain.Policies.Policy, attrs) - assert assert_redirect(lv, ~p"/#{account}/policies/#{policy}") + flash = assert_redirect(lv, ~p"/#{account}/policies") + assert flash["info"] == "Policy created successfully." end test "creates a new policy with conditions", %{ @@ -301,7 +302,7 @@ defmodule Web.Live.Policies.NewTest do } ] - assert assert_redirect(lv, ~p"/#{account}/policies/#{policy}") + assert assert_redirect(lv, ~p"/#{account}/resources/#{resource}") end test "creates a new policy on valid attrs and pre-set resource_id", %{ @@ -327,7 +328,7 @@ defmodule Web.Live.Policies.NewTest do policy = Repo.get_by(Domain.Policies.Policy, attrs) assert policy.resource_id == resource.id - assert assert_redirect(lv, ~p"/#{account}/policies/#{policy}") + assert assert_redirect(lv, ~p"/#{account}/resources/#{resource}") end test "removes conditions in the backend when policy_conditions is false", %{ @@ -368,7 +369,35 @@ defmodule Web.Live.Policies.NewTest do assert policy.resource_id == resource.id assert policy.conditions == [] - assert assert_redirect(lv, ~p"/#{account}/policies/#{policy}") + assert_redirect(lv, ~p"/#{account}/resources/#{resource}") + end + + test "redirects back to actor group when a new policy is created with pre-set actor_group_id", + %{ + account: account, + identity: identity, + conn: conn + } do + group = Fixtures.Actors.create_group(account: account) + resource = Fixtures.Resources.create_resource(account: account) + + Fixtures.Gateways.create_group(account: account) + + attrs = %{actor_group_id: group.id} + + {:ok, lv, _html} = + conn + |> authorize_conn(identity) + |> live(~p"/#{account}/policies/new?actor_group_id=#{group}") + + assert lv + |> form("form", policy: attrs) + |> render_submit() + + policy = Repo.get_by(Domain.Policies.Policy, attrs) + assert policy.resource_id == resource.id + + assert assert_redirect(lv, ~p"/#{account}/groups/#{group}") end test "redirects back to site when a new policy is created with pre-set site_id", %{ diff --git a/elixir/apps/web/test/web/live/resources/new_test.exs b/elixir/apps/web/test/web/live/resources/new_test.exs index d5b1026d5..748f9d31c 100644 --- a/elixir/apps/web/test/web/live/resources/new_test.exs +++ b/elixir/apps/web/test/web/live/resources/new_test.exs @@ -407,7 +407,7 @@ defmodule Web.Live.Resources.NewTest do resource = Repo.get_by(Domain.Resources.Resource, %{name: attrs.name, address: attrs.address}) - flash = assert_redirect(lv, ~p"/#{account}/resources") + flash = assert_redirect(lv, ~p"/#{account}/policies/new?resource_id=#{resource}") assert flash["info"] == "Resource #{resource.name} created successfully." end @@ -449,7 +449,9 @@ defmodule Web.Live.Resources.NewTest do resource = Repo.get_by(Domain.Resources.Resource, %{name: attrs.name, address: attrs.address}) - flash = assert_redirect(lv, ~p"/#{account}/sites/#{group}") + flash = + assert_redirect(lv, ~p"/#{account}/policies/new?resource_id=#{resource}&site_id=#{group}") + assert flash["info"] == "Resource #{resource.name} created successfully." end @@ -516,7 +518,10 @@ defmodule Web.Live.Resources.NewTest do assert %{connections: [connection]} = Repo.preload(resource, :connections) assert connection.gateway_group_id == group.id - assert assert_redirect(lv, ~p"/#{account}/sites/#{group}") + assert assert_redirect( + lv, + ~p"/#{account}/policies/new?resource_id=#{resource}&site_id=#{group}" + ) end test "prevents saving resource if traffic filters set when traffic filters disabled", %{ diff --git a/elixir/apps/web/test/web/live/settings/api_clients/new_token_test.exs b/elixir/apps/web/test/web/live/settings/api_clients/new_token_test.exs index d2a3ab336..2d563bebd 100644 --- a/elixir/apps/web/test/web/live/settings/api_clients/new_token_test.exs +++ b/elixir/apps/web/test/web/live/settings/api_clients/new_token_test.exs @@ -137,7 +137,9 @@ defmodule Web.Live.Settings.ApiClient.NewTokenTest do |> form("form", token: attrs) |> render_submit() - assert html =~ "Your API token (will be shown only once)" + assert html =~ "Your API Token" + assert html =~ "Store this in a safe place." + assert html =~ "It won't be shown again." assert Floki.find(html, "code") |> element_to_text()