Skip to content

Commit 0299b04

Browse files
authored
toil(front): add feature flag for pipeline rebuilds in the UI (#419)
## πŸ“ Description Add feature flag to control if we want to display rebuild pipeline button in the UI ## βœ… Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 027dba9 commit 0299b04

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

β€Žfront/lib/front_web/controllers/pipeline_controller.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ defmodule FrontWeb.PipelineController do
55
alias Front.Models.Pipeline
66
alias Front.Models.Switch
77
alias Front.WorkflowPage.PipelineStatus
8-
alias FrontWeb.Plugs.{FetchPermissions, PageAccess, PublicPageAccess, PutProjectAssigns}
8+
9+
alias FrontWeb.Plugs.{
10+
FeatureEnabled,
11+
FetchPermissions,
12+
PageAccess,
13+
PublicPageAccess,
14+
PutProjectAssigns
15+
}
916

1017
require Logger
1118

@@ -24,6 +31,11 @@ defmodule FrontWeb.PipelineController do
2431
plug(:assign_pipeline_without_blocks when action in [:status, :switch, :stop, :rebuild])
2532
plug(:preload_switch when action in [:show, :poll, :switch])
2633

34+
plug(
35+
FeatureEnabled,
36+
[:ui_partial_ppl_rebuild] when action in [:rebuild]
37+
)
38+
2739
def path(conn, params) do
2840
organization_id = conn.assigns.organization_id
2941
workflow_id = conn.assigns.workflow.id

β€Žfront/lib/front_web/templates/workflow/status/_interactive_pipeline.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<span class="gray mh2">&middot;</span>
2222
<%= link "Stop Pipeline", to: pipeline_stop_path(@conn, :stop, @workflow.id, @pipeline.id), class: "btn btn-secondary btn-tiny", pipeline_stop_button: "true" %>
2323
<% end %>
24-
<%= if @conn.assigns.permissions["project.job.rerun"] && FrontWeb.PipelineView.pipeline_rebuildable?(@pipeline) && !FrontWeb.PipelineView.anonymous?(@conn) do %>
24+
<%= if FeatureProvider.feature_enabled?(:ui_partial_ppl_rebuild, param: @conn.assigns[:organization_id]) && @conn.assigns.permissions["project.job.rerun"] && FrontWeb.PipelineView.pipeline_rebuildable?(@pipeline) && !FrontWeb.PipelineView.anonymous?(@conn) do %>
2525
<span class="gray mh2">&middot;</span>
2626
<%= link "Rebuild Pipeline", to: pipeline_rebuild_path(@conn, :rebuild, @workflow.id, @pipeline.id), class: "btn btn-secondary btn-tiny", pipeline_rebuild_button: "true", title: "Rerun only failed jobs in this pipeline" %>
2727
<% end %>

β€Žfront/test/front_web/controllers/pipeline_controller_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,38 @@ defmodule FrontWeb.PipelineControllerTest do
308308
assert conn.status == 404
309309
end
310310
end
311+
312+
describe "rebuild => with ui_partial_ppl_rebuild feature flag" do
313+
test "returns 404 when feature flag is disabled", %{
314+
conn: conn,
315+
workflow_id: workflow_id,
316+
pipeline_id: pipeline_id
317+
} do
318+
org = Support.Stubs.DB.first(:organizations)
319+
Support.Stubs.Feature.disable_feature(org.id, :ui_partial_ppl_rebuild)
320+
321+
conn =
322+
conn
323+
|> post("/workflows/#{workflow_id}/pipelines/#{pipeline_id}/rebuild")
324+
325+
assert conn.status == 404
326+
end
327+
328+
test "returns 200 when feature flag is enabled", %{
329+
conn: conn,
330+
workflow_id: workflow_id,
331+
pipeline_id: pipeline_id
332+
} do
333+
org = Support.Stubs.DB.first(:organizations)
334+
Support.Stubs.Feature.enable_feature(org.id, :ui_partial_ppl_rebuild)
335+
336+
conn =
337+
conn
338+
|> post("/workflows/#{workflow_id}/pipelines/#{pipeline_id}/rebuild")
339+
340+
assert conn.status == 200
341+
assert json_response(conn, 200)["message"] == "Pipeline rebuild initiated successfully."
342+
assert json_response(conn, 200)["pipeline_id"] != nil
343+
end
344+
end
311345
end

β€Žfront/test/support/stubs/feature.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ defmodule Support.Stubs.Feature do
137137
{"new_project_onboarding", state: :ENABLED, quantity: 1},
138138
{"open_id_connect_filter", state: :ENABLED, quantity: 1},
139139
{"wf_editor_via_jobs", state: :HIDDEN, quantity: 0},
140-
{"ui_reports", state: :ENABLED, quantity: 1}
140+
{"ui_reports", state: :ENABLED, quantity: 1},
141+
{"ui_partial_ppl_rebuild", state: :ENABLED, quantity: 1}
141142
]
142143
end
143144

0 commit comments

Comments
Β (0)