Skip to content

Commit

Permalink
remove unnecessary argument
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco committed Jan 22, 2025
1 parent e05c30d commit eab1af6
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions lib/realtime/tenants/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,20 @@ defmodule Realtime.Tenants.Authorization do
@doc """
Runs validations based on RLS policies to set policies for read policies a given connection (either Phoenix.Socket or Plug.Conn).
"""
@spec get_read_authorizations(Socket.t() | Conn.t(), pid(), __MODULE__.t(), Policies.t()) ::
@spec get_read_authorizations(Socket.t() | Conn.t(), pid(), __MODULE__.t()) ::
{:ok, Socket.t() | Conn.t()} | {:error, any()}
def get_read_authorizations(socket, db_conn, authorization_context, policies \\ %Policies{})

def get_read_authorizations(%Socket{} = socket, db_conn, authorization_context, policies) do
policies = Map.get(socket.assigns, :policies) || policies
def get_read_authorizations(%Socket{} = socket, db_conn, authorization_context) do
policies = Map.get(socket.assigns, :policies) || %Policies{}

with {:ok, %Policies{} = policies} <-
get_read_policies_for_connection(db_conn, authorization_context, policies) do
{:ok, Socket.assign(socket, :policies, policies)}
end
end

def get_read_authorizations(%Conn{} = conn, db_conn, authorization_context, policies) do
policies = Map.get(conn.assigns, :policies, policies)
def get_read_authorizations(%Conn{} = conn, db_conn, authorization_context) do
policies = Map.get(conn.assigns, :policies) || %Policies{}

case get_read_policies_for_connection(db_conn, authorization_context, policies) do
{:ok, %Policies{} = policies} -> {:ok, Conn.assign(conn, :policies, policies)}
Expand All @@ -78,40 +77,33 @@ defmodule Realtime.Tenants.Authorization do
@doc """
Runs validations based on RLS policies to set policies for read policies a given connection (either Phoenix.Socket or Conn).
"""
@spec get_write_authorizations(
Socket.t() | Conn.t() | pid(),
pid(),
__MODULE__.t(),
Policies.t()
) :: {:ok, Socket.t() | Conn.t() | Policies.t()} | {:error, any()}
def get_write_authorizations(socket, db_conn, authorization_context, policies \\ %Policies{})
@spec get_write_authorizations(Socket.t() | Conn.t() | pid(), pid(), __MODULE__.t()) ::
{:ok, Socket.t() | Conn.t() | Policies.t()} | {:error, any()}

def get_write_authorizations(
%Socket{} = socket,
db_conn,
authorization_context,
policies
authorization_context
) do
policies = Map.get(socket.assigns, :policies) || policies
policies = Map.get(socket.assigns, :policies) || %Policies{}

case get_write_policies_for_connection(db_conn, authorization_context, policies) do
{:ok, %Policies{} = policies} -> {:ok, Socket.assign(socket, :policies, policies)}
{:error, error} -> {:error, error}
end
end

def get_write_authorizations(%Conn{} = conn, db_conn, authorization_context, policies) do
policies = Map.get(conn.assigns, :policies) || policies
def get_write_authorizations(%Conn{} = conn, db_conn, authorization_context) do
policies = Map.get(conn.assigns, :policies) || %Policies{}

case get_write_policies_for_connection(db_conn, authorization_context, policies) do
{:ok, %Policies{} = policies} -> {:ok, Conn.assign(conn, :policies, policies)}
{:error, error} -> {:error, error}
end
end

def get_write_authorizations(db_conn, db_conn, authorization_context, policies)
when is_pid(db_conn) do
case get_write_policies_for_connection(db_conn, authorization_context, policies) do
def get_write_authorizations(db_conn, db_conn, authorization_context) when is_pid(db_conn) do
case get_write_policies_for_connection(db_conn, authorization_context, %Policies{}) do
{:ok, %Policies{} = policies} -> {:ok, policies}
{:error, error} -> {:error, error}
end
Expand Down

0 comments on commit eab1af6

Please sign in to comment.