CommonValidations: Refactor same_domain?

This commit is contained in:
lain 2020-08-05 17:36:27 +02:00
parent 9c96fc052a
commit 3655175639

View file

@ -126,18 +126,21 @@ def validate_fields_match(cng, fields) do
end end
end end
def same_domain?(cng, field_one \\ :actor, field_two \\ :object) do def same_domain?(cng, fields \\ [:actor, :object]) do
actor_uri = unique_domains =
cng fields
|> get_field(field_one) |> Enum.map(fn field ->
|> URI.parse() %URI{host: host} =
cng
|> get_field(field)
|> URI.parse()
object_uri = host
cng end)
|> get_field(field_two) |> Enum.uniq()
|> URI.parse() |> Enum.count()
object_uri.host == actor_uri.host unique_domains == 1
end end
# This figures out if a user is able to create, delete or modify something # This figures out if a user is able to create, delete or modify something