Skip to content

Commit ea34e17

Browse files
committed
feat: profile and type on workspace
1 parent d9b914a commit ea34e17

File tree

7 files changed

+94
-7
lines changed

7 files changed

+94
-7
lines changed

valentine/lib/valentine/composer/workspace.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ defmodule Valentine.Composer.Workspace do
1111

1212
schema "workspaces" do
1313
field :name, :string
14+
field :cloud_profile, :string
15+
field :cloud_profile_type, :string
16+
field :url, :string
1417

1518
has_one :application_information, Valentine.Composer.ApplicationInformation,
1619
on_delete: :delete_all
@@ -29,7 +32,7 @@ defmodule Valentine.Composer.Workspace do
2932
@doc false
3033
def changeset(workspace, attrs) do
3134
workspace
32-
|> cast(attrs, [:name])
35+
|> cast(attrs, [:name, :cloud_profile, :cloud_profile_type, :url])
3336
|> validate_required([:name])
3437
end
3538
end

valentine/lib/valentine_web/live/workspace_live/form_component.ex

+46-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,49 @@ defmodule ValentineWeb.WorkspaceLive.FormComponent do
3939
label: gettext("Name")
4040
}
4141
}
42-
class="mt-2"
42+
class="my-2"
43+
is_full_width
44+
is_form_control
45+
/>
46+
47+
<.select
48+
form={f}
49+
name="cloud_profile"
50+
options={[
51+
[key: gettext("None selected"), value: "None selected"],
52+
[key: gettext("CCCS Low Profile for Cloud"), value: "CCCS Low Profile for Cloud"],
53+
[
54+
key: gettext("CCCS Medium Profile for Cloud"),
55+
value: "CCCS Medium Profile for Cloud"
56+
]
57+
]}
58+
selected={@changeset.changes[:cloud_profile] || @workspace.cloud_profile}
59+
is_form_control
60+
/>
61+
62+
<.select
63+
form={f}
64+
name="cloud_profile_type"
65+
options={[
66+
[key: gettext("None selected"), value: "None selected"],
67+
[key: gettext("CSP Full Stack"), value: "CSP Full Stack"],
68+
[key: gettext("CSP Stacked PaaS"), value: "CSP Stacked PaaS"],
69+
[key: gettext("CSP Stacked SaaS"), value: "CSP Stacked SaaS"],
70+
[key: gettext("Client IaaS / PaaS"), value: "Client IaaS / PaaS"],
71+
[key: gettext("Client SaaS"), value: "Client SaaS"]
72+
]}
73+
selected={@changeset.changes[:cloud_profile_type] || @workspace.cloud_profile_type}
74+
is_form_control
75+
/>
76+
77+
<.text_input
78+
form={f}
79+
field={:url}
80+
form_control={
81+
%{
82+
label: gettext("URL")
83+
}
84+
}
4385
is_full_width
4486
is_form_control
4587
/>
@@ -66,7 +108,9 @@ defmodule ValentineWeb.WorkspaceLive.FormComponent do
66108

67109
@impl true
68110
def handle_event("validate", %{"workspace" => workspace_params}, socket) do
69-
changeset = Composer.change_workspace(socket.assigns.workspace, workspace_params)
111+
changeset =
112+
Composer.change_workspace(socket.assigns.workspace, workspace_params)
113+
70114
{:noreply, assign(socket, :changeset, changeset)}
71115
end
72116

valentine/lib/valentine_web/live/workspace_live/show.html.heex

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<.box>
1717
<:header_title>{gettext("Details")}</:header_title>
1818
<:body>
19-
<span class="f3">{@workspace.name}</span>
19+
<div class="f3">{@workspace.name}</div>
20+
<div class="f5 mt-1">{gettext("Profile")}: {@workspace.cloud_profile}</div>
21+
<div class="f5 mt-1">{gettext("Type")}: {@workspace.cloud_profile_type}</div>
2022
<table class="summary">
2123
<tr>
2224
<td>{gettext("Total threats")}</td>

valentine/priv/repo/migrations/20241110232917_create_workspaces.exs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ defmodule Valentine.Repo.Migrations.CreateWorkspaces do
66
add :id, :uuid, primary_key: true, null: false
77
add :name, :string
88

9+
add :cloud_profile, :string
10+
add :cloud_profile_type, :string
11+
add :url, :string
12+
913
timestamps(type: :utc_datetime)
1014
end
1115
end

valentine/test/support/fixtures/composer_fixtures.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ defmodule Valentine.ComposerFixtures do
1919
{:ok, workspace} =
2020
attrs
2121
|> Enum.into(%{
22-
name: "some name"
22+
name: "some name",
23+
cloud_profile: "some cloud_profile",
24+
cloud_profile_type: "some cloud_profile_type",
25+
url: "some url"
2326
})
2427
|> Valentine.Composer.create_workspace()
2528

valentine/test/valentine/composer_test.exs

+19-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ defmodule Valentine.ComposerTest do
2121
end
2222

2323
test "create_workspace/1 with valid data creates a workspace" do
24-
valid_attrs = %{name: "some name"}
24+
valid_attrs = %{
25+
name: "some name",
26+
cloud_profile: "some cloud_profile",
27+
cloud_profile_type: "some cloud_profile_type",
28+
url: "some url"
29+
}
2530

2631
assert {:ok, %Workspace{} = workspace} = Composer.create_workspace(valid_attrs)
2732
assert workspace.name == "some name"
33+
assert workspace.cloud_profile == "some cloud_profile"
34+
assert workspace.cloud_profile_type == "some cloud_profile_type"
35+
assert workspace.url == "some url"
2836
end
2937

3038
test "create_workspace/1 with invalid data returns error changeset" do
@@ -33,10 +41,19 @@ defmodule Valentine.ComposerTest do
3341

3442
test "update_workspace/2 with valid data updates the workspace" do
3543
workspace = workspace_fixture()
36-
update_attrs = %{name: "some updated name"}
44+
45+
update_attrs = %{
46+
name: "some updated name",
47+
cloud_profile: "some updated cloud_profile",
48+
cloud_profile_type: "some updated cloud_profile_type",
49+
url: "some updated url"
50+
}
3751

3852
assert {:ok, %Workspace{} = workspace} = Composer.update_workspace(workspace, update_attrs)
3953
assert workspace.name == "some updated name"
54+
assert workspace.cloud_profile == "some updated cloud_profile"
55+
assert workspace.cloud_profile_type == "some updated cloud_profile_type"
56+
assert workspace.url == "some updated url"
4057
end
4158

4259
test "update_workspace/2 with invalid data returns error changeset" do

valentine/test/valentine_web/live/workspace/show_view_test.exs

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ defmodule ValentineWeb.WorkspaceLive.ShowViewTest do
2424
assert html =~ workspace.name
2525
end
2626

27+
test "display workspace cloud profile", %{conn: conn, workspace: workspace} do
28+
{:ok, _index_live, html} = live(conn, ~p"/workspaces/#{workspace.id}")
29+
30+
assert html =~ "Profile"
31+
assert html =~ workspace.cloud_profile
32+
end
33+
34+
test "display workspace cloud profile type", %{conn: conn, workspace: workspace} do
35+
{:ok, _index_live, html} = live(conn, ~p"/workspaces/#{workspace.id}")
36+
37+
assert html =~ "Type"
38+
assert html =~ workspace.cloud_profile_type
39+
end
40+
2741
test "display mitigation status", %{conn: conn, mitigation: mitigation} do
2842
{:ok, _index_live, html} = live(conn, ~p"/workspaces/#{mitigation.workspace_id}")
2943

0 commit comments

Comments
 (0)