Skip to content

Commit dd79417

Browse files
author
Matthew Peck
committed
supported forced installs through the REST api
1 parent efe28be commit dd79417

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
@@ -136,6 +136,14 @@ defmodule Cog.V1.BundlesControllerTest do
136136
"version has already been taken"] = json_response(conn, 409)["errors"]
137137
end
138138

139+
test "force enables installation of an already installed version", %{authed: requestor} do
140+
config = config(:map)
141+
{:ok, _orig_version3} = Bundles.install(%{"name" => config["name"], "version" => config["version"], "config_file" => config})
142+
143+
conn = api_request(requestor, :post, "/v1/bundles", body: %{"bundle" => %{"config" => config, "force_install" => true}})
144+
assert response(conn, 201)
145+
end
146+
139147
test "fails to install with semantically invalid config", %{authed: requestor} do
140148
# The config includes rules that mention permissions; if we remove
141149
# 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
@@ -64,9 +64,10 @@ defmodule Cog.V1.BundlesController do
6464

6565
defp install_bundle(params) do
6666
with {:ok, config} <- parse_config(params),
67+
{:ok, install_type} <- install_type(params),
6768
{:ok, valid_config, warnings} <- validate_config(config),
6869
{:ok, params} <- merge_config(params, valid_config),
69-
{:ok, bundle} <- Repository.Bundles.install(params) do
70+
{:ok, bundle} <- Repository.Bundles.install(install_type, params) do
7071
{:ok, bundle, warnings}
7172
end
7273
end
@@ -80,6 +81,11 @@ defmodule Cog.V1.BundlesController do
8081
defp parse_config(_),
8182
do: {:error, :no_config}
8283

84+
defp install_type(%{"force_install" => true}),
85+
do: {:ok, :force}
86+
defp install_type(_),
87+
do: {:ok, :normal}
88+
8389
# If we have a file, check to see if the filename has the correct extension
8490
defp validate_file_format(%Plug.Upload{filename: filename}) do
8591
if Config.config_extension?(filename) do

0 commit comments

Comments
 (0)