%{
"type" => "Answer",
"actor" => user.ap_id,
+ "attributedTo" => user.ap_id,
"cc" => [object.data["actor"]],
"to" => [],
"name" => name,
field(:name, :string)
field(:inReplyTo, :string)
field(:attributedTo, ObjectValidators.ObjectID)
+
+ # TODO: Remove actor on objects
field(:actor, ObjectValidators.ObjectID)
end
def validate_data(data_cng) do
data_cng
|> validate_inclusion(:type, ["Answer"])
- |> validate_required([:id, :inReplyTo, :name])
+ |> validate_required([:id, :inReplyTo, :name, :attributedTo, :actor])
|> CommonValidations.validate_any_presence([:cc, :to])
- |> CommonValidations.validate_actor_presence()
+ |> CommonValidations.validate_fields_match([:actor, :attributedTo])
+ |> CommonValidations.validate_actor_is_active()
+ |> CommonValidations.validate_host_match()
end
end
end)
end
end
+
+ def validate_fields_match(cng, fields) do
+ unique_fields =
+ fields
+ |> Enum.map(fn field -> get_field(cng, field) end)
+ |> Enum.uniq()
+ |> Enum.count()
+
+ if unique_fields == 1 do
+ cng
+ else
+ fields
+ |> Enum.reduce(cng, fn field, cng ->
+ cng
+ |> add_error(field, "Fields #{inspect(fields)} aren't matching")
+ end)
+ end
+ end
end
end
def validate_actors_match(cng, meta) do
- object_actor = meta[:object_data]["actor"]
+ attributed_to = meta[:object_data]["attributedTo"] || meta[:object_data]["actor"]
cng
|> validate_change(:actor, fn :actor, actor ->
- if actor == object_actor do
+ if actor == attributed_to do
[]
else
- [{:actor, "Actor doesn't match with object actor"}]
+ [{:actor, "Actor doesn't match with object attributedTo"}]
end
end)
end
field(:type, :string)
field(:content, :string)
field(:context, :string)
+
+ # TODO: Remove actor on objects
field(:actor, ObjectValidators.ObjectID)
+
field(:attributedTo, ObjectValidators.ObjectID)
field(:summary, :string)
field(:published, ObjectValidators.DateTime)
def validate_data(data_cng) do
data_cng
|> validate_inclusion(:type, ["Question"])
- |> validate_required([:id, :actor, :type, :content, :context])
+ |> validate_required([:id, :actor, :attributedTo, :type, :content, :context])
|> CommonValidations.validate_any_presence([:cc, :to])
+ |> CommonValidations.validate_fields_match([:actor, :attributedTo])
|> CommonValidations.validate_actor_is_active()
|> CommonValidations.validate_any_presence([:oneOf, :anyOf])
|> CommonValidations.validate_host_match()
end
def fix_actor(%{"attributedTo" => actor} = object) do
- Map.put(object, "actor", Containment.get_actor(%{"actor" => actor}))
+ actor = Containment.get_actor(%{"actor" => actor})
+
+ # TODO: Remove actor field for Objects
+ object
+ |> Map.put("actor", actor)
+ |> Map.put("attributedTo", actor)
end
def fix_in_reply_to(object, options \\ [])