Skip to content

Commit c230729

Browse files
author
Matthew Peck
committed
supported forced installs through the REST api
1 parent 0bfa2b8 commit c230729

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

test/controllers/v1/bundles_controller_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ defmodule Cog.V1.BundlesControllerTest do
134134
"version has already been taken"] = json_response(conn, 409)["errors"]
135135
end
136136

137+
test "force enables installation of an already installed version", %{authed: requestor} do
138+
config = config(:map)
139+
{:ok, _orig_version3} = Bundles.install(%{"name" => config["name"], "version" => config["version"], "config_file" => config})
140+
141+
conn = api_request(requestor, :post, "/v1/bundles", body: %{"bundle" => %{"config" => config, "force" => true}})
142+
assert response(conn, 201)
143+
end
144+
137145
test "fails to install with semantically invalid config", %{authed: requestor} do
138146
# The config includes rules that mention permissions; if we remove
139147
# those permissions, installation should fail

web/controllers/v1/bundles_controller.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ defmodule Cog.V1.BundlesController do
7676

7777
defp install_bundle(params) do
7878
with {:ok, config} <- parse_config(params),
79+
{:ok, install_type} <- install_type(params),
7980
{:ok, valid_config, warnings} <- validate_config(config),
8081
{:ok, params} <- merge_config(params, valid_config),
81-
{:ok, bundle} <- Repository.Bundles.install(params) do
82+
{:ok, bundle} <- Repository.Bundles.install(install_type, params) do
8283
{:ok, bundle, warnings}
8384
end
8485
end
@@ -92,6 +93,11 @@ defmodule Cog.V1.BundlesController do
9293
defp parse_config(_),
9394
do: {:error, :no_config}
9495

96+
defp install_type(%{"force" => true}),
97+
do: {:ok, :force}
98+
defp install_type(_),
99+
do: {:ok, :normal}
100+
95101
# If we have a file, check to see if the filename has the correct extension
96102
defp validate_file_format(%Plug.Upload{filename: filename}) do
97103
if Config.config_extension?(filename) do

0 commit comments

Comments
 (0)