mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-05-17 01:02:38 +00:00
41 lines
878 B
Elixir
41 lines
878 B
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.GeneratorValidator do
|
|
use Ecto.Schema
|
|
|
|
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
|
|
|
import Ecto.Changeset
|
|
|
|
@primary_key false
|
|
embedded_schema do
|
|
field(:type, :string)
|
|
field(:name, :string)
|
|
field(:url, ObjectValidators.BareUri)
|
|
end
|
|
|
|
def cast_and_validate(data, _meta \\ []) do
|
|
data
|
|
|> cast_data()
|
|
|> validate_data()
|
|
end
|
|
|
|
def cast_data(data) do
|
|
%__MODULE__{}
|
|
|> changeset(data)
|
|
end
|
|
|
|
def changeset(struct, data) do
|
|
struct
|
|
|> cast(data, __schema__(:fields))
|
|
end
|
|
|
|
defp validate_data(cng) do
|
|
cng
|
|
|> validate_inclusion(:type, ~w[Application])
|
|
|> validate_required([:name, :url])
|
|
end
|
|
end
|