@@ -6,12 +6,13 @@ defmodule ValentineWeb.WorkspaceLive.Threat.Index do
6
6
7
7
@ impl true
8
8
def mount ( % { "workspace_id" => workspace_id } = _params , _session , socket ) do
9
- workspace = Composer . get_workspace! ( workspace_id )
9
+ workspace = Composer . get_workspace! ( workspace_id , [ :assumptions , :mitigations ] )
10
10
ValentineWeb.Endpoint . subscribe ( "workspace_" <> workspace . id )
11
11
12
12
{ :ok ,
13
13
socket
14
14
|> assign ( :workspace_id , workspace_id )
15
+ |> assign ( :workspace , workspace )
15
16
|> assign ( :filters , % { } )
16
17
|> assign ( :threats , Composer . list_threats_by_workspace ( workspace . id , % { } ) ) }
17
18
end
@@ -21,12 +22,26 @@ defmodule ValentineWeb.WorkspaceLive.Threat.Index do
21
22
{ :noreply , apply_action ( socket , socket . assigns . live_action , params ) }
22
23
end
23
24
25
+ defp apply_action ( socket , :assumptions , % { "id" => id } ) do
26
+ socket
27
+ |> assign ( :page_title , gettext ( "Link assumptions to threat" ) )
28
+ |> assign ( :assumptions , socket . assigns . workspace . assumptions )
29
+ |> assign ( :threat , Composer . get_threat! ( id , [ :assumptions ] ) )
30
+ end
31
+
24
32
defp apply_action ( socket , :index , % { "workspace_id" => workspace_id } = _params ) do
25
33
socket
26
34
|> assign ( :page_title , gettext ( "Listing threats" ) )
27
35
|> assign ( :workspace_id , workspace_id )
28
36
end
29
37
38
+ defp apply_action ( socket , :mitigations , % { "id" => id } ) do
39
+ socket
40
+ |> assign ( :page_title , gettext ( "Link mitigations to threat" ) )
41
+ |> assign ( :mitigations , socket . assigns . workspace . mitigations )
42
+ |> assign ( :threat , Composer . get_threat! ( id , [ :mitigations ] ) )
43
+ end
44
+
30
45
@ impl true
31
46
def handle_event ( "delete" , % { "id" => id } , socket ) do
32
47
case Composer . get_threat! ( id ) do
@@ -83,6 +98,19 @@ defmodule ValentineWeb.WorkspaceLive.Threat.Index do
83
98
}
84
99
end
85
100
101
+ @ impl true
102
+ def handle_info (
103
+ { _ , { :saved , _threat } } ,
104
+ socket
105
+ ) do
106
+ { :noreply ,
107
+ assign (
108
+ socket ,
109
+ :threats ,
110
+ Composer . list_threats_by_workspace ( socket . assigns . workspace_id , socket . assigns . filters )
111
+ ) }
112
+ end
113
+
86
114
@ impl true
87
115
def handle_info ( % { topic: "workspace_" <> workspace_id } , socket ) do
88
116
{ :noreply ,
0 commit comments