Skip to content

Commit

Permalink
[admin] fix identity providers templates update
Browse files Browse the repository at this point in the history
  • Loading branch information
patatoid committed Jan 6, 2025
1 parent 8b263d4 commit 56d036b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
3 changes: 2 additions & 1 deletion apps/boruta_admin/assets/src/models/template.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class Template {
}

get serialized () {
const { content } = this
const { id, content } = this

return {
id,
content
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,62 @@ defmodule BorutaAdminWeb.IdentityProviderControllerTest do
} = json_response(conn, 200)["data"]
end

# NOTE the transaction sandbox avoids the test
@tag :skip
@tag authorized: ["identity-providers:manage:all"]
test "do not reset when updated twice with same content", %{
conn: conn,
identity_provider: %IdentityProvider{id: identity_provider_id}
} do
conn =
patch(
conn,
Routes.admin_identity_provider_template_path(
conn,
:update_template,
identity_provider_id,
"new_registration"
),
template: @update_template_attrs
)

assert %{"id" => template_id, "content" => "some updated content"} =
json_response(conn, 200)["data"]

conn =
patch(
conn,
Routes.admin_identity_provider_template_path(
conn,
:update_template,
identity_provider_id,
"new_registration"
),
template: Map.put(@update_template_attrs, :id, template_id)
)

assert %{"id" => template_id, "content" => "some updated content"} =
json_response(conn, 200)["data"]

conn =
get(
conn,
Routes.admin_identity_provider_template_path(
conn,
:template,
identity_provider_id,
"new_registration"
)
)

assert %{
"id" => ^template_id,
"content" => "some updated content",
"type" => "new_registration",
"identity_provider_id" => ^identity_provider_id
} = json_response(conn, 200)["data"]
end

@tag authorized: ["identity-providers:manage:all"]
test "renders errors when data is invalid", %{
conn: conn,
Expand Down Expand Up @@ -449,7 +505,7 @@ defmodule BorutaAdminWeb.IdentityProviderControllerTest do

assert %{
"id" => ^id,
"name" => "some updated name",
"name" => "some updated name"
} = json_response(conn, 200)["data"]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule BorutaIdentity.IdentityProviders do
alias BorutaIdentity.IdentityProviders.Template

def get_identity_provider_template!(identity_provider_id, type) do
with %IdentityProvider{} = identity_provider <-
with %IdentityProvider{} = identity_provider_with_templates <-
Repo.one(
from(idp in IdentityProvider,
left_join: t in assoc(idp, :templates),
Expand All @@ -120,8 +120,8 @@ defmodule BorutaIdentity.IdentityProviders do
preload: [backend: b, templates: t]
)
),
%Template{} = template <- IdentityProvider.template(identity_provider, type) do
%{template | layout: IdentityProvider.template(identity_provider, :layout)}
%Template{} = template <- IdentityProvider.template(identity_provider_with_templates, type) do
%{template | layout: IdentityProvider.template(identity_provider_with_templates, :layout)}
else
nil -> raise Ecto.NoResultsError, queryable: Template
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ defmodule BorutaIdentity.IdentityProviders.Template do
end

defp put_default(changeset) do
case fetch_change(changeset, :content) do
{:ok, content} when not is_nil(content) ->
case get_field(changeset, :content) do
content when not is_nil(content) ->
changeset

_ ->
Expand Down

0 comments on commit 56d036b

Please sign in to comment.