-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
979098b
commit 7e13bbe
Showing
126 changed files
with
1,315 additions
and
1,150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
erlang 25.0.4 | ||
erlang 25.3.2.7 | ||
elixir 1.14.0-otp-25 | ||
nodejs 18.19.0 |
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
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
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 |
---|---|---|
@@ -1,31 +1,11 @@ | ||
defmodule Frameworks.Concept.Branch do | ||
defmodule Factory do | ||
@type scope :: :self | :parent | ||
@type leaf :: struct() | ||
@callback name(leaf, scope) :: {:ok, binary()} | {:error, atom()} | ||
@callback hierarchy(leaf) :: {:ok, list()} | {:error, atom()} | ||
end | ||
defprotocol Frameworks.Concept.Branch do | ||
# FIXME: add possibility to resolve dependencies to leafs (siblings) | ||
|
||
require Logger | ||
@type scope :: :self | :parent | ||
|
||
def name(leaf, scope, default) when is_struct(leaf) and is_binary(default) do | ||
case factory().name(leaf, scope) do | ||
{:ok, name} -> | ||
name | ||
@spec name(t, scope) :: binary | ||
def name(_t, _scope) | ||
|
||
{:error, error} -> | ||
Logger.warn( | ||
"[Branch] Error while fetching name: #{inspect(error)} for leaf #{inspect(leaf)}" | ||
) | ||
|
||
default | ||
end | ||
end | ||
|
||
def hierarchy(leaf) when is_struct(leaf) do | ||
factory().hierarchy(leaf) | ||
end | ||
|
||
defp factory, do: Access.get(settings(), :factory, nil) | ||
defp settings, do: Application.fetch_env!(:core, :branch) | ||
@spec hierarchy(t) :: list | ||
def hierarchy(_t) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Frameworks.Concept.LiveHook do | ||
@type live_view_module :: atom() | ||
@type params :: map() | ||
@type session :: map() | ||
@type socket :: Phoenix.LiveView.Socket.t() | ||
|
||
@callback on_mount(live_view_module(), params(), session(), socket()) :: | ||
{:cont | :halt, socket()} | ||
|
||
defmacro __using__(_opts) do | ||
quote do | ||
@behaviour Frameworks.Concept.LiveHook | ||
|
||
import Phoenix.LiveView, | ||
only: [attach_hook: 4, connected?: 1, get_connect_params: 1, redirect: 2] | ||
|
||
import Phoenix.Component, only: [assign: 2] | ||
|
||
def optional_apply(socket, live_view_module, function) do | ||
Frameworks.Utility.Module.optional_apply(live_view_module, function, [socket], socket) | ||
end | ||
|
||
def optional_apply(socket, live_view_module, function, args) when is_list(args) do | ||
Frameworks.Utility.Module.optional_apply(live_view_module, function, args, socket) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Frameworks.Fabric.LiveHook do | ||
import Phoenix.Component, only: [assign: 2] | ||
|
||
def on_mount(_live_view_module, _params, _session, socket) do | ||
self = %Fabric.LiveView.RefModel{pid: self()} | ||
fabric = %Fabric.Model{parent: nil, self: self, children: nil} | ||
{:cont, socket |> assign(fabric: fabric)} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
defmodule Frameworks.GreenLight.LiveFeature do | ||
@callback get_authorization_context( | ||
Phoenix.LiveView.unsigned_params() | :not_mounted_at_router, | ||
session :: map, | ||
socket :: Phoenix.Socket.t() | ||
) :: integer | struct | ||
|
||
@optional_callbacks get_authorization_context: 3 | ||
|
||
defmacro __using__(_opts) do | ||
quote do | ||
@behaviour Frameworks.GreenLight.LiveFeature | ||
|
||
def mount(params, session, %{assigns: %{authorization_failed: true}} = socket) do | ||
{:ok, socket} | ||
end | ||
|
||
def render(%{authorization_failed: true}) do | ||
raise Frameworks.GreenLight.AccessDeniedError, "Authorization failed for #{__MODULE__}" | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Frameworks.GreenLight.LiveHook do | ||
@moduledoc """ | ||
Live Hook that enables automatic authorization checks. | ||
""" | ||
use Frameworks.Concept.LiveHook | ||
use CoreWeb, :verified_routes | ||
require Logger | ||
|
||
@impl true | ||
def on_mount(live_view_module, params, session, socket) do | ||
if access_allowed?(live_view_module, params, session, socket) do | ||
{:cont, socket} | ||
else | ||
{:halt, redirect(socket, to: ~p"/access_denied")} | ||
end | ||
end | ||
|
||
defp access_allowed?(live_view_module, params, session, socket) do | ||
user = Map.get(socket.assigns, :current_user) | ||
|
||
if function_exported?(live_view_module, :get_authorization_context, 3) do | ||
can_access? = | ||
auth_module().can_access?( | ||
user, | ||
live_view_module.get_authorization_context(params, session, socket) | ||
|> Core.Authorization.print_roles(), | ||
live_view_module | ||
) | ||
|
||
Logger.notice("User #{user.id} can_access? #{live_view_module}: #{can_access?}") | ||
can_access? | ||
else | ||
auth_module().can_access?(user, live_view_module) | ||
end | ||
end | ||
|
||
defp auth_module() do | ||
Application.get_env(:core, :greenlight_auth_module) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.