Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove authz #563

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions lib/beacon/authorization.ex

This file was deleted.

16 changes: 0 additions & 16 deletions lib/beacon/authorization/default_policy.ex

This file was deleted.

41 changes: 0 additions & 41 deletions lib/beacon/authorization/policy.ex

This file was deleted.

18 changes: 2 additions & 16 deletions lib/beacon/beacon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ defmodule Beacon do
* `Beacon.Lifecycle` - inject custom logic into Beacon lifecycle to change how pages are loaded an rendred, and more.
* `Beacon.Content` - manage content as layouts, pages, page variants, snippets, and more.
* `Beacon.MediaLibrary` - upload images, videos, and documents that can be used in your content.
* `Beacon.Authorization` - define permissions to limit access to content and features, also used on Beacon LiveAdmin.

Get started with [your first site](https://hexdocs.pm/beacon/your-first-site.html) and check out the guides for more information.

Expand Down Expand Up @@ -53,8 +52,7 @@ defmodule Beacon do
config :my_app, Beacon,
sites: [
[site: :my_site, endpoint: MyAppWeb.Endpoint]
],
authorization_source: MyApp.AuthorizationPolicy
]

# lib/my_app/application.ex
def start(_type, _args) do
Expand Down Expand Up @@ -87,22 +85,10 @@ defmodule Beacon do

:pg.start_link(:beacon_cluster)

authorization_source = Keyword.get(opts, :authorization_source)

children =
sites
|> Enum.map(fn site_config -> assign_authorization_source(site_config, authorization_source) end)
|> Enum.map(&site_child_spec/1)

children = Enum.map(sites, &site_child_spec/1)
Supervisor.init(children, strategy: :one_for_one)
end

defp assign_authorization_source(site_config, nil), do: site_config

defp assign_authorization_source(site_config, authorization_source) do
Keyword.put_new(site_config, :authorization_source, authorization_source)
end

defp site_child_spec(opts) do
config = Config.new(opts)
Supervisor.child_spec({Beacon.SiteSupervisor, config}, id: config.site)
Expand Down
14 changes: 2 additions & 12 deletions lib/beacon/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ defmodule Beacon.Config do
"""
@type skip_boot? :: boolean()

@typedoc """
A module that implements `Beacon.Authorization.Policy`, used to provide authorization rules.
"""
@type authorization_source :: module()

@typedoc """
A module that implements `Beacon.RuntimeCSS`.
"""
Expand Down Expand Up @@ -184,7 +179,6 @@ defmodule Beacon.Config do
router: router(),
repo: repo(),
skip_boot?: skip_boot?(),
authorization_source: authorization_source(),
css_compiler: css_compiler(),
tailwind_config: tailwind_config(),
live_socket_path: live_socket_path(),
Expand Down Expand Up @@ -218,7 +212,8 @@ defmodule Beacon.Config do
router: nil,
repo: nil,
skip_boot?: false,
authorization_source: Beacon.Authorization.DefaultPolicy,
# TODO: rename to `authorization_policy`, see https://github.com/BeaconCMS/beacon/pull/563
# authorization_source: Beacon.Authorization.DefaultPolicy,
css_compiler: Beacon.RuntimeCSS.TailwindCompiler,
tailwind_config: nil,
live_socket_path: "/live",
Expand Down Expand Up @@ -247,7 +242,6 @@ defmodule Beacon.Config do
| {:router, router()}
| {:repo, repo()}
| {:skip_boot?, skip_boot?()}
| {:authorization_source, authorization_source()}
| {:css_compiler, css_compiler()}
| {:tailwind_config, tailwind_config()}
| {:live_socket_path, live_socket_path()}
Expand Down Expand Up @@ -275,8 +269,6 @@ defmodule Beacon.Config do

* `:skip_boot?` - `t:skip_boot?/0` (optional). Defaults to `false`.

* `:authorization_source` - `t:authorization_source/0` (optional). Defaults to `Beacon.Authorization.DefaultPolicy`.

* `css_compiler` - `t:css_compiler/0` (optional). Defaults to `Beacon.RuntimeCSS.TailwindCompiler`.

* `:tailwind_config` - `t:tailwind_config/0` (optional). Defaults to `Path.join(Application.app_dir(:beacon, "priv"), "tailwind.config.js")`.
Expand Down Expand Up @@ -313,7 +305,6 @@ defmodule Beacon.Config do
endpoint: MyAppWeb.Endpoint,
router: MyAppWeb.Router,
repo: MyApp.Repo,
authorization_source: MyApp.MySiteAuthzPolicy,
tailwind_config: Path.join(Application.app_dir(:my_app, "priv"), "tailwind.config.js"),
template_formats: [
{:custom_format, "My Custom Format"}
Expand Down Expand Up @@ -342,7 +333,6 @@ defmodule Beacon.Config do
router: MyAppWeb.Router,
repo: MyApp.Repo,
skip_boot?: false,
authorization_source: MyApp.SiteAuthnPolicy,
css_compiler: Beacon.RuntimeCSS.TailwindCompiler,
tailwind_config: "/my_app/priv/tailwind.config.js",
live_socket_path: "/live",
Expand Down
12 changes: 0 additions & 12 deletions lib/errors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ defmodule Beacon.RuntimeError do
defexception message: "runtime error in Beacon", plug_status: 404
end

defmodule Beacon.AuthorizationError do
@moduledoc """
Raised when there is an error in the `get_agent/1` or `authorized?/3` callbacks of
a `Beacon.Authorization.Policy`.

If you're seeing this error, and have implemented a custom `Beacon.Authorization.Policy`,
check the logic in your policy module.
"""

defexception message: "error in Beacon.Authorization"
end

defmodule Beacon.ParserError do
@moduledoc """
Raised when Beacon's Markdown engine attempts to convert Markdown to HTML unsuccessfully.
Expand Down
5 changes: 0 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ defmodule Beacon.MixProject do
Beacon.RuntimeCSS.TailwindCompiler,
Beacon.Web.BeaconAssigns
],
"Authn and Authz": [
Beacon.Authorization,
Beacon.Authorization.Policy,
Beacon.Authorization.DefaultPolicy
],
Extensibility: [
Beacon.Config,
Beacon.Lifecycle,
Expand Down
18 changes: 0 additions & 18 deletions test/beacon/authorization/default_policy_test.exs

This file was deleted.

18 changes: 0 additions & 18 deletions test/beacon/authorization_test.exs

This file was deleted.

1 change: 0 additions & 1 deletion test/beacon/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defmodule Beacon.ConfigTest do
test "returns the site config" do
assert %Beacon.Config{
css_compiler: Beacon.RuntimeCSS.TailwindCompiler,
authorization_source: Beacon.BeaconTest.BeaconAuthorizationSource,
live_socket_path: "/custom_live",
safe_code_check: false,
site: :my_site,
Expand Down
3 changes: 1 addition & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ Supervisor.start_link(
]
]
]
],
authorization_source: Beacon.BeaconTest.BeaconAuthorizationSource},
]},
Beacon.BeaconTest.Endpoint
],
strategy: :one_for_one
Expand Down
Loading