Commit 7557c0b6 authored by Alex Castaño's avatar Alex Castaño

Moving Object to ActivityStream.Object

parent 97dc2a0f
Pipeline #32272211 failed with stages
in 4 minutes and 13 seconds
......@@ -6,6 +6,7 @@
/uploads
/test/uploads
/.elixir_ls
doc
# Prevent committing custom emojis
/priv/static/emoji/custom/*
......
erlang 21.1
elixir 1.7.3-otp-21
# Alex' Thoughts 08/10/18
## Pleroma.Web.ActivityPub Outbox
Trying tests around ActivityPub, I was wrong about `get` actor's `Outbox`.
It returns correctly the outbox the ordered collection.
I mistakenly thought it returned the user profile instead.
However, I found the following comment:
```
# XXX: technically note_count is wrong for this, but it's better than nothing
```
In my case I found the `totalItems` was 0, when it should be 1.
Furthermore, it fetches the activities in the view.
This is a bad practice.
The view should only format the given arguments,
in this case, format to JSON.
The given argument is just an user.
It should receive the activities as well.
More importantly, the following is a fragment of ActivityPub spec:
>>>
The outbox stream contains activities the user has published, subject to the ability of the requestor to retrieve the activity (that is, the contents of the outbox are filtered by the permissions of the person reading it). If a user submits a request without Authorization the server should respond with all of the Public posts. This could potentially be all relevant objects published by the user, though the number of available items is left to the discretion of those implementing and deploying the server.
>>>
Upon fetching, the code is not considering the user who made the request.
It is going to receive the same information if you're the owner of the outbox
than an unauthorized user.
# Alex' Thoughts 05/10/18
## Pleroma.Web.ActivityPub
......
defmodule ActivityStream do
alias ActivityStream.{IRI, Object}
alias Pleroma.Repo
@doc """
Returns true if the given argument is a valid ActivityStream IRI,
otherwise, returns false.
## Examples
iex> ActivityStream.valid_iri?(nil)
false
iex> ActivityStream.valid_iri?("https://social.example/")
false
iex> ActivityStream.valid_iri?("https://social.example/alyssa/")
true
"""
@spec valid_iri?(String.t) :: boolean
def valid_iri?(iri), do: validate_iri(iri) == :ok
@doc """
Verifies the given argument is an ActivityStream valid IRI
and returns the reason if not.
## Examples
iex> ActivityStream.validate_iri(nil)
{:error, :not_string}
iex> ActivityStream.validate_iri("social.example")
{:error, :invalid_scheme}
iex> ActivityStream.validate_iri("https://")
{:error, :invalid_host}
iex> ActivityStream.validate_iri("https://social.example/")
{:error, :invalid_path}
iex> ActivityStream.validate_iri("https://social.example/alyssa")
:ok
"""
@spec validate_iri(String.t) :: :ok | {:error, :invalid_scheme} | {:error, :invalid_host} | {:error, :invalid_path} | {:error, :not_string}
def validate_iri(iri), do: IRI.validate(iri)
def is_local?(iri) do
true
end
@doc """
Returns an object given and ID.
Options:
* `:cache` when is `true`, it uses cache to try to get the object.
This is the first option.
Default value is `true`.
* `:database` when is `true`, it uses the database like second option get the object.
This is the second option, so it is only used when cache is disabled or it couldn't be found.
Default value is `true`.
* `:external` when is `true`, it makes a request to an external server to get the object.
This is the third option, so it is only used when the database is disabled or it couldn't be found.
Default value is `true`.
"""
@spec get_object(binary, map | Keyword.t) :: {:ok, Object.t} | {:error, :not_found} | {:error, :invalid_id}
def get_object(id, opts \\ %{cache: true, database: true, external: true})
def get_object(id, opts) do
end
def create_object(params) do
Object.changeset(%Object{}, params)
|> Repo.insert()
end
def update_object(%Object{} = object, params) do
Object.changeset(object, params)
|> Repo.update()
end
end
defmodule ActivityStream.IRI do
@moduledoc false
# This is not a full implementation of IRI protocol.
# In fact, it just uses the default URI Elixir implementation.
# The following part of the ActivityStream protocol has not been considered:
#
# > https://www.w3.org/TR/activitystreams-core/#urls
#
# > This specification uses IRIs [RFC3987].
# > Every URI [RFC3986] is also an IRI, so a URI may be used wherever an
# > IRI is named. There are two special considerations:
# > (1) when an IRI that is not also a URI is given for dereferencing,
# > it MUST be mapped to a URI using the steps in Section 3.1 of [RFC3987] and
# > (2) when an IRI is serving as an "id" value, it MUST NOT be so mapped.
# However, the following is checked:
#
# > Relative IRI (and URL) references SHOULD NOT be used within an Activity Streams 2.0
# > document due to the fact that many JSON parser implementations are not capable
# > of reliably preserving the base context necessary to properly resolve
# > relative references.
@spec validate(String.t()) ::
:ok
| {:error, :invalid_scheme}
| {:error, :invalid_host}
| {:error, :invalid_path}
| {:error, :not_string}
def validate(string) when is_binary(string) do
case URI.parse(string) do
%{scheme: scheme} when scheme not in ["http", "https"] -> {:error, :invalid_scheme}
%{host: nil} -> {:error, :invalid_host}
%{path: path} when path in [nil, "/"] -> {:error, :invalid_path}
_ -> :ok
end
end
def validate(_), do: {:error, :not_string}
end
defmodule Pleroma.Object do
defmodule ActivityStream.Object do
alias ActivityStream.Object
@type t :: %Object{data: map, inserted_at: Datetime.t(), updated_at: Datetime.t()}
# This should be Pleroma.ActivityStream.Object
#
# FIXME
# * It should not use Repo in this module
# * I'd move query functions to a new module Pleroma.ActivityStream.ObjectQueries
use Ecto.Schema
alias Pleroma.{Repo, Object}
alias Pleroma.{Repo}
alias ActivityStream.Object
import Ecto.{Query, Changeset}
schema "objects" do
......@@ -14,12 +17,8 @@ defmodule Pleroma.Object do
timestamps()
end
def create(data) do
Object.change(%Object{}, %{data: data})
|> Repo.insert()
end
def change(struct, params \\ %{}) do
def changeset(struct, params \\ %{}) do
params = %{data: params}
struct
|> cast(params, [:data])
|> validate_required([:data])
......@@ -61,9 +60,4 @@ defmodule Pleroma.Object do
end)
end
end
# What?
def context_mapping(context) do
Object.change(%Object{}, %{data: %{"id" => context}})
end
end
......@@ -12,7 +12,8 @@ defmodule Pleroma.User do
use Ecto.Schema
import Ecto.{Changeset, Query}
alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
alias Pleroma.{Repo, User, Web, Activity, Notification}
alias ActivityStream.Object
alias Comeonin.Pbkdf2
alias Pleroma.Web.{OStatus, Websub}
alias Pleroma.Web.ActivityPub.{Utils, ActivityPub}
......
defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
alias Pleroma.{Activity, Repo, Upload, User, Notification}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF}
alias Pleroma.Web.WebFinger
alias Pleroma.Web.Federator
......@@ -577,7 +578,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def upload(file) do
data = Upload.store(file, Application.get_env(:pleroma, :instance)[:dedupe_media])
Repo.insert(%Object{data: data})
ActivityStream.create_object(data)
end
def user_data_from_user_object(data) do
......
defmodule Pleroma.Web.ActivityPub.ActivityPubController do
use Pleroma.Web, :controller
alias Pleroma.{User, Object}
alias Pleroma.{User}
alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.Federator
......
defmodule Pleroma.Web.ActivityPub.Relay do
alias Pleroma.{User, Object, Activity}
alias Pleroma.{User, Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
require Logger
......
......@@ -3,7 +3,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
A module to handle coding from internal to wire ActivityPub and back.
"""
alias Pleroma.User
alias Pleroma.Object
alias ActivityStream.Object
alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.Web.ActivityPub.ActivityPub
......
defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.{Repo, Web, Object, Activity, User}
alias Pleroma.{Repo, Web, Activity, User}
alias ActivityStream.Object
alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Endpoint
alias Ecto.{Changeset, UUID}
......@@ -61,9 +62,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def create_context(context) do
context = context || generate_id("contexts")
changeset = Object.context_mapping(context)
case Repo.insert(changeset) do
%{"id" => context}
|> ActivityStream.create_object()
|> case do
{:ok, object} ->
object
......@@ -129,7 +130,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
"""
def insert_full_object(%{"object" => %{"type" => type} = object_data})
when is_map(object_data) and type in ["Article", "Note", "Video"] do
with {:ok, _} <- Object.create(object_data) do
with {:ok, _} <- ActivityStream.create_object(object_data) do
:ok
end
end
......
defmodule Pleroma.Web.CommonAPI do
alias Pleroma.{User, Repo, Activity, Object}
alias Pleroma.{User, Repo, Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Formatter
......
defmodule Pleroma.Web.CommonAPI.Utils do
alias Pleroma.{Repo, Object, Formatter, Activity}
alias Pleroma.{Repo, Formatter, Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Endpoint
alias Pleroma.User
......
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
use Pleroma.Web, :controller
alias Pleroma.{Repo, Object, Activity, User, Notification, Stats}
alias Pleroma.{Repo, Activity, User, Notification, Stats}
alias ActivityStream.Object
alias Pleroma.Web
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView, FilterView}
alias Pleroma.Web.ActivityPub.ActivityPub
......@@ -441,8 +442,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
description <- data["description"] do
new_data = %{object.data | "name" => description}
change = Object.change(object, %{data: new_data})
{:ok, media_obj} = Repo.update(change)
{:ok, media_obj} = ActivityStream.update_object(object, new_data)
data =
new_data
......@@ -461,8 +461,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
object.data
end
change = Object.change(object, %{data: objdata})
{:ok, object} = Repo.update(change)
{:ok, media_obj} = ActivityStream.update_object(object, objdata)
objdata =
objdata
......
defmodule Pleroma.Web.OStatus.ActivityRepresenter do
alias Pleroma.{Activity, User, Object}
alias Pleroma.{Activity, User}
alias ActivityStream.Object
alias Pleroma.Web.OStatus.UserRepresenter
require Logger
......
defmodule Pleroma.Web.OStatus.DeleteHandler do
require Logger
alias Pleroma.Web.XML
alias Pleroma.Object
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
def handle_delete(entry, _doc \\ nil) do
......
defmodule Pleroma.Web.OStatus.NoteHandler do
require Logger
alias Pleroma.Web.{XML, OStatus}
alias Pleroma.{Object, Activity}
alias Pleroma.{Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
......
......@@ -5,7 +5,8 @@ defmodule Pleroma.Web.OStatus do
import Pleroma.Web.XML
require Logger
alias Pleroma.{Repo, User, Web, Object, Activity}
alias Pleroma.{Repo, User, Web, Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.{WebFinger, Websub}
alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler}
......
defmodule Pleroma.Web.Streamer do
use GenServer
require Logger
alias Pleroma.{User, Notification, Activity, Object, Repo}
alias Pleroma.{User, Notification, Activity, Repo}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
def init(args) do
......
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.Object
alias ActivityStream.Object
def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
data = object.data
......
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
alias Pleroma.{UserInviteToken, User, Activity, Repo, Object}
alias Pleroma.{UserInviteToken, User, Activity, Repo}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.{OStatus, CommonAPI}
......@@ -247,9 +248,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
id
else
_e ->
changeset = Object.context_mapping(context)
case Repo.insert(changeset) do
%{"id" => context}
|> ActivityStream.create_object()
|> case do
{:ok, %{id: id}} ->
id
......
......@@ -7,7 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.Activity
alias Pleroma.Object
alias ActivityStream.Object
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Formatter
......
......@@ -5,7 +5,7 @@ defmodule Pleroma.Mixfile do
[
app: :pleroma,
version: "0.9.0",
elixir: "~> 1.4",
elixir: "~> 1.7.3",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
......@@ -51,6 +51,7 @@ defmodule Pleroma.Mixfile do
{:ex_machina, "~> 2.2", only: :test},
{:credo, "~> 0.9.3", only: [:dev, :test]},
{:mock, "~> 0.3.1", only: :test},
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:crypt,
git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"}
]
......
......@@ -11,10 +11,12 @@
"crypt": {:git, "https://github.com/msantos/crypt", "1f2b58927ab57e72910191a7ebaeff984382a1d3", [ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"]},
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "2.2.10", "e7366dc82f48f8dd78fcbf3ab50985ceeb11cb3dc93435147c6e13f2cda0992e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"eternal": {:hex, :eternal, "1.2.0", "e2a6b6ce3b8c248f7dc31451aefca57e3bdf0e48d73ae5043229380a67614c41", [:mix], [], "hexpm"},
"ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
"ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_machina": {:hex, :ex_machina, "2.2.0", "fec496331e04fc2db2a1a24fe317c12c0c4a50d2beb8ebb3531ed1f0d84be0ed", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
"gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.13.0", "24edc8cd2b28e1c652593833862435c80661834f6c9344e84b6a2255e7aeef03", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
......@@ -22,6 +24,8 @@
"httpoison": {:hex, :httpoison, "1.2.0", "2702ed3da5fd7a8130fc34b11965c8cfa21ade2f232c00b42d96d4967c39a3a3", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.2", "e21cb58a09f0228a9e0b95eaa1217f1bcfc31a1aaa6e1fdf2f53a33f7dbd9494", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"meck": {:hex, :meck, "0.8.9", "64c5c0bd8bcca3a180b44196265c8ed7594e16bcc845d0698ec6b4e577f48188", [:rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
......@@ -29,6 +33,7 @@
"mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"},
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "0.12.3", "6706a148809a29c306062862c803406e88f048277f6e85b68faf73291e820b84", [:mix], [], "hexpm"},
"phoenix": {:hex, :phoenix, "1.3.4", "aaa1b55e5523083a877bcbe9886d9ee180bf2c8754905323493c2ac325903dc5", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
......
defmodule ActivityStream.IRITest do
use ExUnit.Case, async: true
test "validate" do
assert ActivityStream.validate_id(nil) == {:error, :not_string}
assert ActivityStream.validate_id("social.example") == {:error, :invalid_scheme}
assert ActivityStream.validate_id("https://") == {:error, :invalid_host}
assert ActivityStream.validate_id("https://social.example/") == {:error, :invalid_path}
assert ActivityStream.validate_id("https://social.example/alyssa") == :ok
end
end
defmodule ActivityStreamTest do
use Pleroma.DataCase, async: true
doctest ActivityStream
alias Pleroma.Factory
describe "object" do
test "it ensures uniqueness of the id" do
object = Factory.insert(:note)
{:error, cs} = ActivityStream.create_object(%{id: object.data["id"]})
refute cs.valid?
end
end
end
this is a text file
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.{Repo, Object}
test "returns an object by it's AP id" do
object = insert(:note)
found_object = Object.get_by_ap_id(object.data["id"])
assert object == found_object
end
describe "generic changeset" do
test "it ensures uniqueness of the id" do
object = insert(:note)
cs = Object.change(%Object{}, %{data: %{id: object.data["id"]}})
assert cs.valid?
{:error, _result} = Repo.insert(cs)
end
end
end
......@@ -40,7 +40,7 @@ defmodule Pleroma.Factory do
}
}
%Pleroma.Object{
%ActivityStream.Object{
data: data
}
end
......@@ -48,8 +48,8 @@ defmodule Pleroma.Factory do
def direct_note_factory do
user2 = insert(:user)
%Pleroma.Object{data: data} = note_factory()
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
%ActivityStream.Object{data: data} = note_factory()
%ActivityStream.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
end
def direct_note_activity_factory do
......
......@@ -3,7 +3,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
alias Pleroma.{Activity, Object, User}
alias Pleroma.{Activity, User}
alias ActivityStream.Object
alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory
......
......@@ -2,7 +2,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.{User, Activity, Object}
alias Pleroma.{User, Activity}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
......@@ -65,9 +66,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
note_object = Object.get_by_ap_id(note.data["object"]["id"])
Repo.update!(
Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
)
new_data = Map.put(note_object.data, "external_url", "someurl")
ActivityStream.update_object(note_object, new_data)
user = User.get_cached_by_ap_id(answer.data["actor"])
......
......@@ -2,7 +2,8 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.{Repo, Activity, Object}
alias Pleroma.{Repo, Activity}
alias ActivityStream.Object
alias Pleroma.Web.OStatus
describe "deletions" do
......
......@@ -2,7 +2,8 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
alias Pleroma.{Object, Repo, User, Activity}
alias Pleroma.{Repo, User, Activity}
alias ActivityStream.Object
import Pleroma.Factory
import ExUnit.CaptureLog
......
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase
alias Pleroma.{User, Activity, Object}
alias Pleroma.{User, Activity}
alias ActivityStream.Object
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Builders.UserBuilder
......@@ -85,7 +86,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
content = HtmlSanitizeEx.strip_tags(content_html)
date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601()
{:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
{:ok, convo_object} = ActivityStream.create_object(%{"id" => "2hu"})
to = [
User.ap_followers(user),
......
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
use Pleroma.DataCase
alias Pleroma.Object
alias ActivityStream.Object
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
test "represent an image attachment" do
......
......@@ -2,7 +2,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
alias Pleroma.{Repo, Activity, User, Object, Notification}
alias Pleroma.{Repo, Activity, User, Notification}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
......
......@@ -2,7 +2,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
alias Pleroma.{Activity, User, Repo, UserInviteToken}
alias ActivityStream.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
......@@ -358,7 +359,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns an existing mapping for an existing object" do
{:ok, object} = Object.context_mapping("random context") |> Repo.insert()
{:ok, object} = ActivityStream.create_object(%{"id" => "random context"})
conversation_id = TwitterAPI.context_to_conversation_id("random context")
assert conversation_id == object.id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment