mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
Unlock editing synced users (#1991)
This commit is contained in:
@@ -317,7 +317,6 @@ defmodule Domain.Actors do
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: when actor is synced we should not allow changing the name
|
||||
def actor_synced?(%Actor{last_synced_at: nil}), do: false
|
||||
def actor_synced?(%Actor{}), do: true
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ defmodule Web.Actors.Components do
|
||||
end
|
||||
|
||||
attr :type, :atom, required: true
|
||||
attr :actor, :any, default: %{memberships: [], last_synced_at: nil}, required: false
|
||||
attr :actor, :any, default: %Actors.Actor{memberships: [], last_synced_at: nil}, required: false
|
||||
attr :groups, :any, required: true
|
||||
attr :form, :any, required: true
|
||||
attr :subject, :any, required: true
|
||||
@@ -53,7 +53,7 @@ defmodule Web.Actors.Components do
|
||||
~H"""
|
||||
<div>
|
||||
<.input
|
||||
:if={is_nil(@actor.last_synced_at)}
|
||||
:if={not Actors.actor_synced?(@actor)}
|
||||
label="Name"
|
||||
field={@form[:name]}
|
||||
placeholder="Full Name"
|
||||
@@ -76,7 +76,7 @@ defmodule Web.Actors.Components do
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div :if={@groups != []}>
|
||||
<.input
|
||||
type="select"
|
||||
multiple={true}
|
||||
|
||||
@@ -108,11 +108,7 @@ defmodule Web.Actors.Show do
|
||||
Viewing <%= actor_type(@actor.type) %> <span class="font-bold"><%= @actor.name %></span>
|
||||
</:title>
|
||||
|
||||
<:action
|
||||
:if={not Actors.actor_synced?(@actor)}
|
||||
navigate={~p"/#{@account}/actors/#{@actor}/edit"}
|
||||
icon="hero-pencil"
|
||||
>
|
||||
<:action navigate={~p"/#{@account}/actors/#{@actor}/edit"} icon="hero-pencil">
|
||||
Edit <%= actor_type(@actor.type) %>
|
||||
</:action>
|
||||
|
||||
|
||||
@@ -74,11 +74,39 @@ defmodule Web.Live.Actors.EditTest do
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[name]",
|
||||
"actor[type]"
|
||||
]
|
||||
|
||||
Fixtures.Actors.create_group(account: account)
|
||||
|
||||
{:ok, lv, _html} =
|
||||
conn
|
||||
|> authorize_conn(identity)
|
||||
|> live(~p"/#{account}/actors/#{actor}/edit")
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[memberships][]",
|
||||
"actor[name]",
|
||||
"actor[type]"
|
||||
]
|
||||
|
||||
Fixtures.Actors.update(actor, last_synced_at: DateTime.utc_now())
|
||||
|
||||
{:ok, lv, _html} =
|
||||
conn
|
||||
|> authorize_conn(identity)
|
||||
|> live(~p"/#{account}/actors/#{actor}/edit")
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[memberships][]",
|
||||
"actor[type]"
|
||||
]
|
||||
end
|
||||
|
||||
test "renders changeset errors on input change", %{
|
||||
@@ -184,7 +212,7 @@ defmodule Web.Live.Actors.EditTest do
|
||||
describe "service account" do
|
||||
setup do
|
||||
account = Fixtures.Accounts.create_account()
|
||||
actor = Fixtures.Actors.create_actor(type: :account_admin_user, account: account)
|
||||
actor = Fixtures.Actors.create_actor(type: :service_account, account: account)
|
||||
|
||||
identity =
|
||||
Fixtures.Auth.create_identity(
|
||||
@@ -259,10 +287,22 @@ defmodule Web.Live.Actors.EditTest do
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[name]"
|
||||
]
|
||||
|
||||
Fixtures.Actors.create_group(account: account)
|
||||
|
||||
{:ok, lv, _html} =
|
||||
conn
|
||||
|> authorize_conn(identity)
|
||||
|> live(~p"/#{account}/actors/#{actor}/edit")
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[memberships][]",
|
||||
"actor[name]",
|
||||
"actor[type]"
|
||||
"actor[name]"
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -74,6 +74,19 @@ defmodule Web.Live.Actors.ServiceAccount.NewTest do
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[name]"
|
||||
]
|
||||
|
||||
Fixtures.Actors.create_group(account: account)
|
||||
|
||||
{:ok, lv, _html} =
|
||||
conn
|
||||
|> authorize_conn(identity)
|
||||
|> live(~p"/#{account}/actors/service_accounts/new")
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[memberships][]",
|
||||
"actor[name]"
|
||||
|
||||
@@ -58,6 +58,20 @@ defmodule Web.Live.Actors.User.NewTest do
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[name]",
|
||||
"actor[type]"
|
||||
]
|
||||
|
||||
Fixtures.Actors.create_group(account: account)
|
||||
|
||||
{:ok, lv, _html} =
|
||||
conn
|
||||
|> authorize_conn(identity)
|
||||
|> live(~p"/#{account}/actors/users/new")
|
||||
|
||||
form = form(lv, "form")
|
||||
|
||||
assert find_inputs(form) == [
|
||||
"actor[memberships][]",
|
||||
"actor[name]",
|
||||
|
||||
Reference in New Issue
Block a user