formatting
This commit is contained in:
parent
8ccd8e6586
commit
c6ef4a5dd3
|
@ -26,16 +26,18 @@ defmodule BallsPDS.Ecto.Schema.Agent do
|
|||
end
|
||||
|
||||
def get_by_acl(acl) when is_binary(acl) do
|
||||
query = from a in __MODULE__,
|
||||
where: a.acl == ^acl
|
||||
query =
|
||||
from(a in __MODULE__,
|
||||
where: a.acl == ^acl
|
||||
)
|
||||
|
||||
Repo.one(query)
|
||||
end
|
||||
|
||||
def get_or_create_by_acl(acl) when is_binary(acl) do
|
||||
with {:existing, nil} <- {:existing, get_by_acl(acl)},
|
||||
{:insert, {:ok, new}} <- {:insert, Repo.insert(%__MODULE__{acl: acl, disabled: false})} do
|
||||
{:ok, new}
|
||||
{:insert, {:ok, new}} <- {:insert, Repo.insert(%__MODULE__{acl: acl, disabled: false})} do
|
||||
{:ok, new}
|
||||
else
|
||||
{:existing, existing} -> {:ok, existing}
|
||||
{:insert, {:error, _} = error} -> error
|
||||
|
|
|
@ -51,16 +51,24 @@ defmodule BallsPDS.Ecto.Schema.CollectionObject do
|
|||
end
|
||||
|
||||
def delete_all(%Object{id: collection_id}, ids) when is_list(ids) do
|
||||
{object_ids, remote_ids} = ids |> Enum.map(&resolve_id/1) |> Enum.reduce({[], []}, fn
|
||||
nil, acc -> acc
|
||||
{object_ids, remote_ids} =
|
||||
ids
|
||||
|> Enum.map(&resolve_id/1)
|
||||
|> Enum.reduce({[], []}, fn
|
||||
nil, acc ->
|
||||
acc
|
||||
|
||||
object_id, {object_ids, remote_ids} when is_integer(object_id) -> {[object_id | object_ids], remote_ids}
|
||||
object_id, {object_ids, remote_ids} when is_integer(object_id) ->
|
||||
{[object_id | object_ids], remote_ids}
|
||||
|
||||
remote_id, {object_ids, remote_ids} when is_binary(remote_id) -> {object_ids, [remote_id | remote_ids]}
|
||||
end)
|
||||
remote_id, {object_ids, remote_ids} when is_binary(remote_id) ->
|
||||
{object_ids, [remote_id | remote_ids]}
|
||||
end)
|
||||
|
||||
from(co in __MODULE__,
|
||||
where: co.collection_id == ^collection_id and (co.object_id in ^object_ids or co.remote_id in ^remote_ids)
|
||||
where:
|
||||
co.collection_id == ^collection_id and
|
||||
(co.object_id in ^object_ids or co.remote_id in ^remote_ids)
|
||||
)
|
||||
|> Repo.delete_all()
|
||||
end
|
||||
|
|
|
@ -50,7 +50,8 @@ defmodule BallsPDS.Ecto.Schema.Object do
|
|||
defp validate_path(changeset, field) do
|
||||
validate_change(changeset, field, fn _, path ->
|
||||
case BallsPDS.Util.Util.is_valid_path?(path) do
|
||||
:ok -> []
|
||||
:ok ->
|
||||
[]
|
||||
|
||||
{:error, :invalid_char} ->
|
||||
[{field, "Invalid characters"}]
|
||||
|
|
|
@ -34,10 +34,10 @@ defmodule BallsPDS.JWT do
|
|||
with {:subject, {:ok, %{"sub" => subject}}} <- {:subject, JOSE.JWT.peek_payload(jwt)},
|
||||
{:kid, {:ok, %{"kid" => kid}}} <- {:kid, JOSE.JWT.peek_protected(jwt)} do
|
||||
{:ok, %{subject: subject, id: kid}}
|
||||
else
|
||||
{err, {:error, error}} ->
|
||||
Logger.error("extracting key info from JWT: #{err}: #{inspect(error)}")
|
||||
{:error, error}
|
||||
else
|
||||
{err, {:error, error}} ->
|
||||
Logger.error("extracting key info from JWT: #{err}: #{inspect(error)}")
|
||||
{:error, error}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -91,9 +91,11 @@ defmodule BallsPDS.Util.ACL do
|
|||
}
|
||||
}
|
||||
|
||||
graph = Enum.with_index(read_acls) |> Enum.map(fn {acl, i} ->
|
||||
make_read_authorization(path, acl, "#read_acl_#{i}")
|
||||
end)
|
||||
graph =
|
||||
Enum.with_index(read_acls)
|
||||
|> Enum.map(fn {acl, i} ->
|
||||
make_read_authorization(path, acl, "#read_acl_#{i}")
|
||||
end)
|
||||
|
||||
owner_read = %{
|
||||
"@id" => "#owner-read",
|
||||
|
|
|
@ -13,7 +13,7 @@ defmodule BallsPDS.Util.Util do
|
|||
{:trailing_or_no_starting_slash, Regex.match?(@starting_trailing_slashes_regex, path)},
|
||||
{:sequential_slashes, false} <-
|
||||
{:sequential_slashes, Regex.match?(@sequential_slashes_regex, path)},
|
||||
{:relative_path, false} <- {:relative_path, Regex.match?(@relative_path_regex, path)} do
|
||||
{:relative_path, false} <- {:relative_path, Regex.match?(@relative_path_regex, path)} do
|
||||
:ok
|
||||
else
|
||||
{error, _} -> {:error, error}
|
||||
|
|
|
@ -138,10 +138,12 @@ defmodule BallsPDS.WAC do
|
|||
end
|
||||
end
|
||||
|
||||
defp extract_key(controller, key = %{}, id) when is_binary(controller) and (is_binary(id) or is_nil(id)),
|
||||
do: extract_key(controller, [key], id)
|
||||
defp extract_key(controller, key = %{}, id)
|
||||
when is_binary(controller) and (is_binary(id) or is_nil(id)),
|
||||
do: extract_key(controller, [key], id)
|
||||
|
||||
defp extract_key(controller, keys, id) when is_list(keys) and is_binary(controller) and (is_binary(id) or is_nil(id)) do
|
||||
defp extract_key(controller, keys, id)
|
||||
when is_list(keys) and is_binary(controller) and (is_binary(id) or is_nil(id)) do
|
||||
Enum.reduce_while(keys, nil, fn
|
||||
%{"controller" => ^controller, "publicKeyMultibase" => multikey, "id" => key_id}, _
|
||||
when is_binary(multikey) and is_binary(key_id) ->
|
||||
|
@ -165,6 +167,7 @@ defmodule BallsPDS.WAC do
|
|||
# Match the entire key id or else check if it's just a fragment.
|
||||
defp match_id?(key_id, test_id) when is_binary(key_id) and is_binary(test_id),
|
||||
do: key_id == test_id || String.ends_with?(key_id, "#" <> test_id)
|
||||
|
||||
# If no test id is passed then match whatever was passed.
|
||||
defp match_id?(key_id, nil) when is_binary(key_id), do: true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue