-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Beacon install integration test * Test data_source, mixfile, seeds * Credo * Fixes * Bump tailwind version * Idempotence tests * Update template * Resolve compile warnings * Schema * Context functions * Migration * Update docs * Inject in mix task * Test * Error pages backend * Minor fixes * Fix typespec * Unique index * Add test for create error * Use error layout * Small doc fixes * Validate error status codes * Switch error pages to module recompilation * CI fixes * Fix test fixtures * render * test render/1 * publish default layouts * Improve test fixture * Test custom error page * PubSub * Still not working * render error page with root layout compile a function for each part of the layout tree: root, layout, and page where root takes the content of page+layout * fix layout path * pass @conn to root_layout * test ErrorHTML * Check render and layout for my_component * fix tests and cleanup * add logger when error page render fails * use Phoenix.HTML.Engine * add tests rendering my_component * remove support for components in error pages It's possible to load those but requires injecting the LivePage env, which is risky because a server error may happen due to internals or even due to the components used in the pages, causing an endless loop. So for now we won't load components due to the risk they impose but we can revisit this if needed or if we find a safer approach. * broadcast error_page_updated event only on update_error_page/2 * fix dialyzer * fix dialyzer 2 * compile error page content and reload css --------- Co-authored-by: Leandro Pereira <leandro@leandro.io>
- Loading branch information
Showing
21 changed files
with
732 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
defmodule Beacon.Content.ErrorPage do | ||
@moduledoc """ | ||
Stores a template which can be rendered for error responses. | ||
An ErrorPage contains four main fields: | ||
* `:status` - the status code for which this ErrorPage is to be used | ||
* `:template` - the template to be rendered | ||
* `:site` - the Beacon site which should use this page | ||
* `:layout_id` - the ID of the Beacon Layout which is used for rendering | ||
> #### Do not create or edit ErrorPages manually {: .warning} | ||
> | ||
> Use the public functions in `Beacon.Content` instead. | ||
> The functions in that module guarantee that all dependencies | ||
> are created correctly and all processes are updated. | ||
> Manipulating data manually will most likely result | ||
> in inconsistent behavior and crashes. | ||
""" | ||
use Beacon.Schema | ||
|
||
import Beacon.Utils, only: [list_to_typespec: 1] | ||
import Ecto.Changeset | ||
|
||
# We can use Range.to_list/1 here when we upgrade to Elixir 1.15 | ||
@valid_error_statuses Enum.to_list(400..418) ++ | ||
Enum.to_list(421..426) ++ | ||
[428, 429, 431, 451] ++ | ||
Enum.to_list(500..508) ++ | ||
[510, 511] | ||
|
||
@type t :: %__MODULE__{ | ||
id: Ecto.UUID.t(), | ||
site: Beacon.Types.Site.t(), | ||
status: error_status(), | ||
template: binary(), | ||
layout_id: Ecto.UUID.t(), | ||
layout: Beacon.Content.Layout.t(), | ||
inserted_at: DateTime.t(), | ||
updated_at: DateTime.t() | ||
} | ||
|
||
@type error_status :: unquote(list_to_typespec(@valid_error_statuses)) | ||
|
||
schema "beacon_error_pages" do | ||
field :site, Beacon.Types.Site | ||
field :status, :integer | ||
field :template, :string | ||
|
||
belongs_to :layout, Beacon.Content.Layout | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(%__MODULE__{} = error_page, attrs) do | ||
fields = ~w(status template site layout_id)a | ||
|
||
error_page | ||
|> cast(attrs, fields) | ||
|> validate_required(fields) | ||
|> unique_constraint([:status, :site]) | ||
|> validate_inclusion(:status, @valid_error_statuses) | ||
end | ||
|
||
def valid_statuses, do: @valid_error_statuses | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.