From d013b58e84f2c8213a5d26b1c3daf36e2f4807e5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:04:08 +0700 Subject: [PATCH 1/9] add `mix pleroma.user delete_activities NICKNAME` task --- lib/mix/tasks/pleroma/user.ex | 12 ++++++++++++ lib/pleroma/user.ex | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 037e44716..e232df14f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -304,6 +304,18 @@ def run(["invite"]) do end end + def run(["delete_activities", nickname]) do + Common.start_pleroma() + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + User.delete_user_activities(user) + Mix.shell().info("User #{nickname} deleted.") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + defp set_moderator(user, value) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 50e7e7ccd..2d0a8cde4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1083,6 +1083,12 @@ def delete(%User{} = user) do friends |> Enum.each(fn followed -> User.unfollow(user, followed) end) + delete_user_activities(user) + + {:ok, user} + end + + def delete_user_activities(user) do query = from(a in Activity, where: a.actor == ^user.ap_id) Repo.all(query) @@ -1096,8 +1102,6 @@ def delete(%User{} = user) do "Doing nothing" end end) - - {:ok, user} end def html_filter_policy(%User{info: %{no_rich_text: true}}) do From 16e598ec11cb9178b9fc53a1ec4b649d97c5f3b8 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:12:05 +0700 Subject: [PATCH 2/9] fix wording --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index e232df14f..ec06d908a 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -309,7 +309,7 @@ def run(["delete_activities", nickname]) do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} deleted.") + Mix.shell().info("User #{nickname} statuses deleted..") else _ -> Mix.shell().error("No local user #{nickname}") From 1d01e8e656c364b97b9ee36a6173a830d3f5f4fc Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Mon, 1 Apr 2019 22:12:02 +0545 Subject: [PATCH 3/9] [OStatus] adds status to pleroma instance if the url given is a status --- .../controllers/util_controller.ex | 46 +++++--- test/fixtures/httpoison_mock/emelie.json | 106 ++++++++++++++++++ .../httpoison_mock/status.emelie.json | 64 +++++++++++ test/support/http_request_mock.ex | 16 +++ test/web/twitter_api/util_controller_test.exs | 17 +++ 5 files changed, 233 insertions(+), 16 deletions(-) create mode 100644 test/fixtures/httpoison_mock/emelie.json create mode 100644 test/fixtures/httpoison_mock/status.emelie.json diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index faa733fec..7f301a518 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do require Logger alias Comeonin.Pbkdf2 + alias Pleroma.Activity alias Pleroma.Emoji alias Pleroma.Notification alias Pleroma.PasswordResetToken @@ -73,26 +74,39 @@ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profil end def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do - {err, followee} = OStatus.find_or_make_user(acct) - avatar = User.avatar_url(followee) - name = followee.nickname - id = followee.id + case is_status?(acct) do + true -> + {:ok, object} = ActivityPub.fetch_object_from_id(acct) + %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) + redirect(conn, to: "/notice/#{activity_id}") - if !!user do - conn - |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) - else - conn - |> render("follow_login.html", %{ - error: false, - acct: acct, - avatar: avatar, - name: name, - id: id - }) + false -> + {err, followee} = OStatus.find_or_make_user(acct) + avatar = User.avatar_url(followee) + name = followee.nickname + id = followee.id + + if !!user do + conn + |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) + else + conn + |> render("follow_login.html", %{ + error: false, + acct: acct, + avatar: avatar, + name: name, + id: id + }) + end end end + defp is_status?(acct) do + %URI{path: path} = URI.parse(acct) + Regex.match?(~r/\/users\/[^\/]+\/statuses\/([0-9]+)$/, path) + end + def do_remote_follow(conn, %{ "authorization" => %{"name" => username, "password" => password, "id" => id} }) do diff --git a/test/fixtures/httpoison_mock/emelie.json b/test/fixtures/httpoison_mock/emelie.json new file mode 100644 index 000000000..2e164ffdf --- /dev/null +++ b/test/fixtures/httpoison_mock/emelie.json @@ -0,0 +1,106 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "toot": "http://joinmastodon.org/ns#", + "featured": { + "@id": "toot:featured", + "@type": "@id" + }, + "alsoKnownAs": { + "@id": "as:alsoKnownAs", + "@type": "@id" + }, + "movedTo": { + "@id": "as:movedTo", + "@type": "@id" + }, + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji", + "IdentityProof": "toot:IdentityProof", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "https://mastodon.social/users/emelie", + "type": "Person", + "following": "https://mastodon.social/users/emelie/following", + "followers": "https://mastodon.social/users/emelie/followers", + "inbox": "https://mastodon.social/users/emelie/inbox", + "outbox": "https://mastodon.social/users/emelie/outbox", + "featured": "https://mastodon.social/users/emelie/collections/featured", + "preferredUsername": "emelie", + "name": "emelie 🎨", + "summary": "

23 / #Sweden / #Artist / #Equestrian / #GameDev

If I ain't spending time with my pets, I'm probably drawing. 🐴 🐱 🐰

", + "url": "https://mastodon.social/@emelie", + "manuallyApprovesFollowers": false, + "publicKey": { + "id": "https://mastodon.social/users/emelie#main-key", + "owner": "https://mastodon.social/users/emelie", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3CWs1oAJPE3ZJ9sj6Ut\n/Mu+mTE7MOijsQc8/6c73XVVuhIEomiozJIH7l8a7S1n5SYL4UuiwcubSOi7u1bb\nGpYnp5TYhN+Cxvq/P80V4/ncNIPSQzS49it7nSLeG5pA21lGPDA44huquES1un6p\n9gSmbTwngVX9oe4MYuUeh0Z7vijjU13Llz1cRq/ZgPQPgfz+2NJf+VeXnvyDZDYx\nZPVBBlrMl3VoGbu0M5L8SjY35559KCZ3woIvqRolcoHXfgvJMdPcJgSZVYxlCw3d\nA95q9jQcn6s87CPSUs7bmYEQCrDVn5m5NER5TzwBmP4cgJl9AaDVWQtRd4jFZNTx\nlQIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "tag": [ + { + "type": "Hashtag", + "href": "https://mastodon.social/explore/sweden", + "name": "#sweden" + }, + { + "type": "Hashtag", + "href": "https://mastodon.social/explore/gamedev", + "name": "#gamedev" + }, + { + "type": "Hashtag", + "href": "https://mastodon.social/explore/artist", + "name": "#artist" + }, + { + "type": "Hashtag", + "href": "https://mastodon.social/explore/equestrian", + "name": "#equestrian" + } + ], + "attachment": [ + { + "type": "PropertyValue", + "name": "Ko-fi", + "value": "https://ko-fi.com/emeliepng" + }, + { + "type": "PropertyValue", + "name": "Instagram", + "value": "https://www.instagram.com/emelie_png/" + }, + { + "type": "PropertyValue", + "name": "Carrd", + "value": "https://emelie.carrd.co/" + }, + { + "type": "PropertyValue", + "name": "Artstation", + "value": "https://emiri.artstation.com" + } + ], + "endpoints": { + "sharedInbox": "https://mastodon.social/inbox" + }, + "icon": { + "type": "Image", + "mediaType": "image/png", + "url": "https://files.mastodon.social/accounts/avatars/000/015/657/original/e7163f98280da1a4.png" + }, + "image": { + "type": "Image", + "mediaType": "image/png", + "url": "https://files.mastodon.social/accounts/headers/000/015/657/original/847f331f3dd9e38b.png" + } +} diff --git a/test/fixtures/httpoison_mock/status.emelie.json b/test/fixtures/httpoison_mock/status.emelie.json new file mode 100644 index 000000000..4aada0377 --- /dev/null +++ b/test/fixtures/httpoison_mock/status.emelie.json @@ -0,0 +1,64 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "https://mastodon.social/users/emelie/statuses/101849165031453009", + "type": "Note", + "summary": null, + "inReplyTo": null, + "published": "2019-04-01T05:02:05Z", + "url": "https://mastodon.social/@emelie/101849165031453009", + "attributedTo": "https://mastodon.social/users/emelie", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://mastodon.social/users/emelie/followers" + ], + "sensitive": false, + "atomUri": "https://mastodon.social/users/emelie/statuses/101849165031453009", + "inReplyToAtomUri": null, + "conversation": "tag:mastodon.social,2019-04-01:objectId=94350309:objectType=Conversation", + "content": "

You gotta take whatever bellyrubbing opportunity you can get before she changes her mind 🦁 #mastocats

", + "contentMap": { + "en": "

You gotta take whatever bellyrubbing opportunity you can get before she changes her mind 🦁 #mastocats

" + }, + "attachment": [ + { + "type": "Document", + "mediaType": "video/mp4", + "url": "https://files.mastodon.social/media_attachments/files/013/049/816/original/e7831178a5e0d6d4.mp4", + "name": null + } + ], + "tag": [ + { + "type": "Hashtag", + "href": "https://mastodon.social/tags/mastocats", + "name": "#mastocats" + } + ], + "replies": { + "id": "https://mastodon.social/users/emelie/statuses/101849165031453009/replies", + "type": "Collection", + "first": { + "type": "CollectionPage", + "partOf": "https://mastodon.social/users/emelie/statuses/101849165031453009/replies", + "items": [] + } + } +} diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 78e8efc9d..2148bd4e7 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -36,6 +36,22 @@ def get("https://osada.macgirvin.com/channel/mike", _, _, _) do }} end + def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/status.emelie.json") + }} + end + + def get("https://mastodon.social/users/emelie", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/emelie.json") + }} + end + def get( "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", _, diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 832fdc096..f4a3ce501 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -6,6 +6,11 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do alias Pleroma.Web.CommonAPI import Pleroma.Factory + setup do + Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + describe "POST /api/pleroma/follow_import" do test "it returns HTTP 200", %{conn: conn} do user1 = insert(:user) @@ -164,4 +169,16 @@ test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} d assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!() end end + + describe "GET /ostatus_subscribe?acct=...." do + test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do + conn = + get( + conn, + "/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009" + ) + + assert redirected_to(conn) =~ "/notice/" + end + end end From 6386c1c9c1ff971c784744922a479ae38e5fdbad Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Tue, 2 Apr 2019 10:26:09 +0545 Subject: [PATCH 4/9] fetch url for OStatus to know if it is a/c or status --- .../controllers/util_controller.ex | 6 +- test/fixtures/httpoison_mock/emelie.atom | 306 ++++++++++++++++++ test/fixtures/httpoison_mock/emelie.json | 106 ------ .../httpoison_mock/webfinger_emelie.json | 36 +++ test/support/http_request_mock.ex | 21 ++ test/web/twitter_api/util_controller_test.exs | 10 + 6 files changed, 377 insertions(+), 108 deletions(-) create mode 100644 test/fixtures/httpoison_mock/emelie.atom delete mode 100644 test/fixtures/httpoison_mock/emelie.json create mode 100644 test/fixtures/httpoison_mock/webfinger_emelie.json diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 7f301a518..2a1c73111 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -103,8 +103,10 @@ def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do end defp is_status?(acct) do - %URI{path: path} = URI.parse(acct) - Regex.match?(~r/\/users\/[^\/]+\/statuses\/([0-9]+)$/, path) + case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do + {:ok, %{"type" => "Note"}} -> true + _ -> false + end end def do_remote_follow(conn, %{ diff --git a/test/fixtures/httpoison_mock/emelie.atom b/test/fixtures/httpoison_mock/emelie.atom new file mode 100644 index 000000000..ddaa1c6ca --- /dev/null +++ b/test/fixtures/httpoison_mock/emelie.atom @@ -0,0 +1,306 @@ + + + https://mastodon.social/users/emelie.atom + emelie 🎨 + 23 / #Sweden / #Artist / #Equestrian / #GameDev + +If I ain't spending time with my pets, I'm probably drawing. 🐴 🐱 🐰 + 2019-02-04T20:22:19Z + https://files.mastodon.social/accounts/avatars/000/015/657/original/e7163f98280da1a4.png + + https://mastodon.social/users/emelie + http://activitystrea.ms/schema/1.0/person + https://mastodon.social/users/emelie + emelie + emelie@mastodon.social + <p>23 / <a href="https://mastodon.social/tags/sweden" class="mention hashtag" rel="tag">#<span>Sweden</span></a> / <a href="https://mastodon.social/tags/artist" class="mention hashtag" rel="tag">#<span>Artist</span></a> / <a href="https://mastodon.social/tags/equestrian" class="mention hashtag" rel="tag">#<span>Equestrian</span></a> / <a href="https://mastodon.social/tags/gamedev" class="mention hashtag" rel="tag">#<span>GameDev</span></a></p><p>If I ain&apos;t spending time with my pets, I&apos;m probably drawing. 🐴 🐱 🐰</p> + + + + emelie + emelie 🎨 + 23 / #Sweden / #Artist / #Equestrian / #GameDev + +If I ain't spending time with my pets, I'm probably drawing. 🐴 🐱 🐰 + public + + + + + + + https://mastodon.social/users/emelie/statuses/101850331907006641 + 2019-04-01T09:58:50Z + 2019-04-01T09:58:50Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>Me: I&apos;m going to make this vital change to my world building in the morning, no way I&apos;ll forget this, it&apos;s too big of a deal<br />Also me: forgets</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101849626603073336 + 2019-04-01T06:59:28Z + 2019-04-01T06:59:28Z + New status by emelie + http://activitystrea.ms/schema/1.0/comment + http://activitystrea.ms/schema/1.0/post + + <p><span class="h-card"><a href="https://mastodon.social/@Fergant" class="u-url mention">@<span>Fergant</span></a></span> Dom är i stort sett religiös skrift vid det här laget 👏👏</p><p>har dock bara läst svenska översättningen, kanske är dags att jag läser dom på engelska</p> + + + public + + + + + + + https://mastodon.social/users/emelie/statuses/101849580030237068 + 2019-04-01T06:47:37Z + 2019-04-01T06:47:37Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>What&apos;s you people&apos;s favourite fantasy books? Give me some hot tips 🌞</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101849550599949363 + 2019-04-01T06:40:08Z + 2019-04-01T06:40:08Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>Stick them legs out 💃 <a href="https://mastodon.social/tags/mastocats" class="mention hashtag" rel="tag">#<span>mastocats</span></a></p> + + + + public + + + + + + https://mastodon.social/users/emelie/statuses/101849191533152720 + 2019-04-01T05:08:49Z + 2019-04-01T05:08:49Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>long 🐱 <a href="https://mastodon.social/tags/mastocats" class="mention hashtag" rel="tag">#<span>mastocats</span></a></p> + + + + public + + + + + + https://mastodon.social/users/emelie/statuses/101849165031453009 + 2019-04-01T05:02:05Z + 2019-04-01T05:02:05Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>You gotta take whatever bellyrubbing opportunity you can get before she changes her mind 🦁 <a href="https://mastodon.social/tags/mastocats" class="mention hashtag" rel="tag">#<span>mastocats</span></a></p> + + + + public + + + + + + https://mastodon.social/users/emelie/statuses/101846512530748693 + 2019-03-31T17:47:31Z + 2019-03-31T17:47:31Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>Hello look at this boy having a decent haircut for once <a href="https://mastodon.social/tags/mastohorses" class="mention hashtag" rel="tag">#<span>mastohorses</span></a> <a href="https://mastodon.social/tags/equestrian" class="mention hashtag" rel="tag">#<span>equestrian</span></a></p> + + + + + public + + + + + + https://mastodon.social/users/emelie/statuses/101846181093805500 + 2019-03-31T16:23:14Z + 2019-03-31T16:23:14Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>Sorry did I disturb the who-is-the-longest-cat competition ? <a href="https://mastodon.social/tags/mastocats" class="mention hashtag" rel="tag">#<span>mastocats</span></a></p> + + + + public + + + + + + https://mastodon.social/users/emelie/statuses/101845897513133849 + 2019-03-31T15:11:07Z + 2019-03-31T15:11:07Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + more earthsea ramblings + <p>I&apos;m re-watching Tales from Earthsea for the first time since I read the books, and that Therru doesn&apos;t squash Cob like a spider, as Orm Embar did is a wasted opportunity tbh</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101841219051533307 + 2019-03-30T19:21:19Z + 2019-03-30T19:21:19Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>I gave my cats some mackerel and they ate it all in 0.3 seconds, and now they won&apos;t stop meowing for more, and I&apos;m tired plz shut up</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101839949762341381 + 2019-03-30T13:58:31Z + 2019-03-30T13:58:31Z + New status by emelie + http://activitystrea.ms/schema/1.0/comment + http://activitystrea.ms/schema/1.0/post + + <p>yet I&apos;m confused about this american dude with a gun, like the heck r ya doin in mah ghibli</p> + + public + + + + + + + https://mastodon.social/users/emelie/statuses/101839928677863590 + 2019-03-30T13:53:09Z + 2019-03-30T13:53:09Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>2 hours into Ni no Kuni 2 and I&apos;ve already sold my soul to this game</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101836329521599438 + 2019-03-29T22:37:51Z + 2019-03-29T22:37:51Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>Pippi Longstocking the original one-punch /man</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101835905282948341 + 2019-03-29T20:49:57Z + 2019-03-29T20:49:57Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>I&apos;ve had so much wine I thought I had a 3rd brother</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101835878059204660 + 2019-03-29T20:43:02Z + 2019-03-29T20:43:02Z + New status by emelie + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + <p>ååååhhh booi</p> + + public + + + + + + https://mastodon.social/users/emelie/statuses/101835848050598939 + 2019-03-29T20:35:24Z + 2019-03-29T20:35:24Z + New status by emelie + http://activitystrea.ms/schema/1.0/comment + http://activitystrea.ms/schema/1.0/post + + <p><span class="h-card"><a href="https://thraeryn.net/@thraeryn" class="u-url mention">@<span>thraeryn</span></a></span> if I spent 1 hour and a half watching this monstrosity, I need to</p> + + + public + + + + + + + https://mastodon.social/users/emelie/statuses/101835823138262290 + 2019-03-29T20:29:04Z + 2019-03-29T20:29:04Z + New status by emelie + http://activitystrea.ms/schema/1.0/comment + http://activitystrea.ms/schema/1.0/post + + medical, fluids mention + <p><span class="h-card"><a href="https://icosahedron.website/@Trev" class="u-url mention">@<span>Trev</span></a></span> *hugs* ✨</p> + + + public + + + + + + diff --git a/test/fixtures/httpoison_mock/emelie.json b/test/fixtures/httpoison_mock/emelie.json deleted file mode 100644 index 2e164ffdf..000000000 --- a/test/fixtures/httpoison_mock/emelie.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", - "toot": "http://joinmastodon.org/ns#", - "featured": { - "@id": "toot:featured", - "@type": "@id" - }, - "alsoKnownAs": { - "@id": "as:alsoKnownAs", - "@type": "@id" - }, - "movedTo": { - "@id": "as:movedTo", - "@type": "@id" - }, - "schema": "http://schema.org#", - "PropertyValue": "schema:PropertyValue", - "value": "schema:value", - "Hashtag": "as:Hashtag", - "Emoji": "toot:Emoji", - "IdentityProof": "toot:IdentityProof", - "focalPoint": { - "@container": "@list", - "@id": "toot:focalPoint" - } - } - ], - "id": "https://mastodon.social/users/emelie", - "type": "Person", - "following": "https://mastodon.social/users/emelie/following", - "followers": "https://mastodon.social/users/emelie/followers", - "inbox": "https://mastodon.social/users/emelie/inbox", - "outbox": "https://mastodon.social/users/emelie/outbox", - "featured": "https://mastodon.social/users/emelie/collections/featured", - "preferredUsername": "emelie", - "name": "emelie 🎨", - "summary": "

23 / #Sweden / #Artist / #Equestrian / #GameDev

If I ain't spending time with my pets, I'm probably drawing. 🐴 🐱 🐰

", - "url": "https://mastodon.social/@emelie", - "manuallyApprovesFollowers": false, - "publicKey": { - "id": "https://mastodon.social/users/emelie#main-key", - "owner": "https://mastodon.social/users/emelie", - "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3CWs1oAJPE3ZJ9sj6Ut\n/Mu+mTE7MOijsQc8/6c73XVVuhIEomiozJIH7l8a7S1n5SYL4UuiwcubSOi7u1bb\nGpYnp5TYhN+Cxvq/P80V4/ncNIPSQzS49it7nSLeG5pA21lGPDA44huquES1un6p\n9gSmbTwngVX9oe4MYuUeh0Z7vijjU13Llz1cRq/ZgPQPgfz+2NJf+VeXnvyDZDYx\nZPVBBlrMl3VoGbu0M5L8SjY35559KCZ3woIvqRolcoHXfgvJMdPcJgSZVYxlCw3d\nA95q9jQcn6s87CPSUs7bmYEQCrDVn5m5NER5TzwBmP4cgJl9AaDVWQtRd4jFZNTx\nlQIDAQAB\n-----END PUBLIC KEY-----\n" - }, - "tag": [ - { - "type": "Hashtag", - "href": "https://mastodon.social/explore/sweden", - "name": "#sweden" - }, - { - "type": "Hashtag", - "href": "https://mastodon.social/explore/gamedev", - "name": "#gamedev" - }, - { - "type": "Hashtag", - "href": "https://mastodon.social/explore/artist", - "name": "#artist" - }, - { - "type": "Hashtag", - "href": "https://mastodon.social/explore/equestrian", - "name": "#equestrian" - } - ], - "attachment": [ - { - "type": "PropertyValue", - "name": "Ko-fi", - "value": "https://ko-fi.com/emeliepng" - }, - { - "type": "PropertyValue", - "name": "Instagram", - "value": "https://www.instagram.com/emelie_png/" - }, - { - "type": "PropertyValue", - "name": "Carrd", - "value": "https://emelie.carrd.co/" - }, - { - "type": "PropertyValue", - "name": "Artstation", - "value": "https://emiri.artstation.com" - } - ], - "endpoints": { - "sharedInbox": "https://mastodon.social/inbox" - }, - "icon": { - "type": "Image", - "mediaType": "image/png", - "url": "https://files.mastodon.social/accounts/avatars/000/015/657/original/e7163f98280da1a4.png" - }, - "image": { - "type": "Image", - "mediaType": "image/png", - "url": "https://files.mastodon.social/accounts/headers/000/015/657/original/847f331f3dd9e38b.png" - } -} diff --git a/test/fixtures/httpoison_mock/webfinger_emelie.json b/test/fixtures/httpoison_mock/webfinger_emelie.json new file mode 100644 index 000000000..0b61cb618 --- /dev/null +++ b/test/fixtures/httpoison_mock/webfinger_emelie.json @@ -0,0 +1,36 @@ +{ + "aliases": [ + "https://mastodon.social/@emelie", + "https://mastodon.social/users/emelie" + ], + "links": [ + { + "href": "https://mastodon.social/@emelie", + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html" + }, + { + "href": "https://mastodon.social/users/emelie.atom", + "rel": "http://schemas.google.com/g/2010#updates-from", + "type": "application/atom+xml" + }, + { + "href": "https://mastodon.social/users/emelie", + "rel": "self", + "type": "application/activity+json" + }, + { + "href": "https://mastodon.social/api/salmon/15657", + "rel": "salmon" + }, + { + "href": "data:application/magic-public-key,RSA.u3CWs1oAJPE3ZJ9sj6Ut_Mu-mTE7MOijsQc8_6c73XVVuhIEomiozJIH7l8a7S1n5SYL4UuiwcubSOi7u1bbGpYnp5TYhN-Cxvq_P80V4_ncNIPSQzS49it7nSLeG5pA21lGPDA44huquES1un6p9gSmbTwngVX9oe4MYuUeh0Z7vijjU13Llz1cRq_ZgPQPgfz-2NJf-VeXnvyDZDYxZPVBBlrMl3VoGbu0M5L8SjY35559KCZ3woIvqRolcoHXfgvJMdPcJgSZVYxlCw3dA95q9jQcn6s87CPSUs7bmYEQCrDVn5m5NER5TzwBmP4cgJl9AaDVWQtRd4jFZNTxlQ==.AQAB", + "rel": "magic-public-key" + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": "https://mastodon.social/authorize_interaction?uri={uri}" + } + ], + "subject": "acct:emelie@mastodon.social" +} diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 2148bd4e7..d3b547d91 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -52,6 +52,27 @@ def get("https://mastodon.social/users/emelie", _, _, _) do }} end + def get( + "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie", + _, + _, + _ + ) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/webfinger_emelie.json") + }} + end + + def get("https://mastodon.social/users/emelie.atom", _, _, _) do + {:ok, + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/httpoison_mock/emelie.atom") + }} + end + def get( "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", _, diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index f4a3ce501..e4dd97d46 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -180,5 +180,15 @@ test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} assert redirected_to(conn) =~ "/notice/" end + + test "show follow account page if the `acct` is a account link", %{conn: conn} do + response = + get( + conn, + "/ostatus_subscribe?acct=https://mastodon.social/users/emelie" + ) + + assert html_response(response, 200) =~ "Log in to follow" + end end end From f20e8d28de97e154ec43120cb4fc07e2792e955a Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Tue, 2 Apr 2019 12:15:41 +0545 Subject: [PATCH 5/9] add support for all status type (ostatus) and replase case with if --- .../controllers/util_controller.ex | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 2a1c73111..b661c4363 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -74,38 +74,39 @@ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profil end def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do - case is_status?(acct) do - true -> - {:ok, object} = ActivityPub.fetch_object_from_id(acct) - %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) - redirect(conn, to: "/notice/#{activity_id}") + if is_status?(acct) do + {:ok, object} = ActivityPub.fetch_object_from_id(acct) + %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) + redirect(conn, to: "/notice/#{activity_id}") + else + {err, followee} = OStatus.find_or_make_user(acct) + avatar = User.avatar_url(followee) + name = followee.nickname + id = followee.id - false -> - {err, followee} = OStatus.find_or_make_user(acct) - avatar = User.avatar_url(followee) - name = followee.nickname - id = followee.id - - if !!user do - conn - |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) - else - conn - |> render("follow_login.html", %{ - error: false, - acct: acct, - avatar: avatar, - name: name, - id: id - }) - end + if !!user do + conn + |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) + else + conn + |> render("follow_login.html", %{ + error: false, + acct: acct, + avatar: avatar, + name: name, + id: id + }) + end end end defp is_status?(acct) do case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do - {:ok, %{"type" => "Note"}} -> true - _ -> false + {:ok, %{"type" => type}} when type in ["Article", "Note", "Video", "Page", "Question"] -> + true + + _ -> + false end end From a14742f495fac78f4dfd7ab02f4c3ae5c7c37c3b Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 16:30:11 +0700 Subject: [PATCH 6/9] add `user delete_activities` mix task --- lib/mix/tasks/pleroma/user.ex | 8 ++++++-- lib/pleroma/user.ex | 33 +++++++++++++++++---------------- test/tasks/user_test.exs | 10 ++++++++++ test/user_test.exs | 10 ++++++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 680422c19..62c9fceda 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -23,7 +23,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -33,6 +33,10 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user rm NICKNAME + ## Delete the user's activities. + + mix pleroma.user delete_activities NICKNAME + ## Deactivate or activate the user's account. mix pleroma.user toggle_activated NICKNAME @@ -309,7 +313,7 @@ def run(["delete_activities", nickname]) do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} statuses deleted..") + Mix.shell().info("User #{nickname} statuses deleted.") else _ -> Mix.shell().error("No local user #{nickname}") diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 18cf374dd..a180c1a8b 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1088,29 +1088,30 @@ def delete(%User{} = user) do # Remove all relationships {:ok, followers} = User.get_followers(user) - followers - |> Enum.each(fn follower -> User.unfollow(follower, user) end) + Enum.each(followers, fn follower -> User.unfollow(follower, user) end) {:ok, friends} = User.get_friends(user) - friends - |> Enum.each(fn followed -> User.unfollow(user, followed) end) + Enum.each(friends, fn followed -> User.unfollow(user, followed) end) - query = - from(a in Activity, where: a.actor == ^user.ap_id) - |> Activity.with_preloaded_object() + delete_user_activities(user) + end - Repo.all(query) - |> Enum.each(fn activity -> - case activity.data["type"] do - "Create" -> - ActivityPub.delete(Object.normalize(activity)) + def delete_user_activities(%User{ap_id: ap_id} = user) do + Activity + |> where(actor: ^ap_id) + |> Activity.with_preloaded_object() + |> Repo.all() + |> Enum.each(fn + %{data: %{"type" => "Create"}} = activity -> + activity |> Object.normalize() |> ActivityPub.delete() - # TODO: Do something with likes, follows, repeats. - _ -> - "Doing nothing" - end + # TODO: Do something with likes, follows, repeats. + _ -> + "Doing nothing" end) + + {:ok, user} end def html_filter_policy(%User{info: %{no_rich_text: true}}) do diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs index 7b814d171..1030bd555 100644 --- a/test/tasks/user_test.exs +++ b/test/tasks/user_test.exs @@ -248,4 +248,14 @@ test "invite token is generated" do assert message =~ "Generated" end end + + describe "running delete_activities" do + test "activities are deleted" do + %{nickname: nickname} = insert(:user) + + assert :ok == Mix.Tasks.Pleroma.User.run(["delete_activities", nickname]) + assert_received {:mix_shell, :info, [message]} + assert message == "User #{nickname} statuses deleted." + end + end end diff --git a/test/user_test.exs b/test/user_test.exs index 8cf2ba6ab..a6fd35ede 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -792,6 +792,16 @@ test ".deactivate can de-activate then re-activate a user" do assert false == user.info.deactivated end + test ".delete_user_activities deletes all create activities" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"}) + {:ok, _} = User.delete_user_activities(user) + + # TODO: Remove favorites, repeats, delete activities. + refute Activity.get_by_id(activity.id) + end + test ".delete deactivates a user, all follow relationships and all create activities" do user = insert(:user) followed = insert(:user) From 88d3cb44c3adc234ee828a8b50bc0c3857eb85a9 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 17:47:02 +0700 Subject: [PATCH 7/9] replace `Repo.get_by(User, nickname: nickname)` with `User.get_by_nickname(nickname)` --- lib/pleroma/plugs/user_fetcher_plug.ex | 22 ++----------------- .../mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 9 +++----- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index 5a77f6833..4089aa958 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -3,9 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserFetcherPlug do - alias Pleroma.Repo alias Pleroma.User - import Plug.Conn def init(options) do @@ -14,26 +12,10 @@ def init(options) do def call(conn, _options) do with %{auth_credentials: %{username: username}} <- conn.assigns, - {:ok, %User{} = user} <- user_fetcher(username) do - conn - |> assign(:auth_user, user) + %User{} = user <- User.get_by_nickname_or_email(username) do + assign(conn, :auth_user, user) else _ -> conn end end - - defp user_fetcher(username_or_email) do - { - :ok, - cond do - # First, try logging in as if it was a name - user = Repo.get_by(User, %{nickname: username_or_email}) -> - user - - # If we get nil, we try using it as an email - user = Repo.get_by(User, %{email: username_or_email}) -> - user - end - } - end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index da96d1674..ffd544644 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -755,7 +755,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do end def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do - with %User{} = followed <- Repo.get_by(User, nickname: uri), + with %User{} = followed <- User.get_by_nickname(uri), {:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do conn |> put_view(AccountView) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index d0e58e71b..9b081a316 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -227,12 +227,9 @@ def get_user(user \\ nil, params) do end %{"screen_name" => nickname} -> - case target = Repo.get_by(User, nickname: nickname) do - nil -> - {:error, "No user with such screen_name"} - - _ -> - {:ok, target} + case User.get_by_nickname(nickname) do + nil -> {:error, "No user with such screen_name"} + target -> {:ok, target} end _ -> From 9a59c26619bada93e238f52e9432a93e54c04b5e Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 17:47:52 +0700 Subject: [PATCH 8/9] replace `Repo.get_by(User, ap_id: ap_id)` with `User.get_by_ap_id(ap_id)` --- test/web/activity_pub/activity_pub_test.exs | 4 ++-- test/web/mastodon_api/status_view_test.exs | 2 +- test/web/salmon/salmon_test.exs | 2 +- test/web/twitter_api/twitter_api_controller_test.exs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 7969c8035..46b4cf7b6 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -638,8 +638,8 @@ test "works with base64 encoded images" do describe "fetch the latest Follow" do test "fetches the latest Follow activity" do %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) - follower = Repo.get_by(User, ap_id: activity.data["actor"]) - followed = Repo.get_by(User, ap_id: activity.data["object"]) + follower = User.get_by_ap_id(activity.data["actor"]) + followed = User.get_by_ap_id(activity.data["object"]) assert activity == Utils.fetch_latest_follow(follower, followed) end diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index e1c9b2c8f..8db92ac16 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -175,7 +175,7 @@ test "contains mentions" do status = StatusView.render("status.json", %{activity: activity}) - actor = Repo.get_by(User, ap_id: activity.actor) + actor = User.get_by_ap_id(activity.actor) assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end) diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs index 265e1abbd..35503259b 100644 --- a/test/web/salmon/salmon_test.exs +++ b/test/web/salmon/salmon_test.exs @@ -99,7 +99,7 @@ test "it pushes an activity to remote accounts it's addressed to" do } {:ok, activity} = Repo.insert(%Activity{data: activity_data, recipients: activity_data["to"]}) - user = Repo.get_by(User, ap_id: activity.data["actor"]) + user = User.get_by_ap_id(activity.data["actor"]) {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user) poster = fn url, _data, _headers -> diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index dffd401f7..405f0cfae 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -955,7 +955,7 @@ test "with credentials", %{conn: conn, user: current_user} do |> post(request_path) activity = Activity.get_by_id(note_activity.id) - activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"]) + activity_user = User.get_by_ap_id(note_activity.data["actor"]) assert json_response(response, 200) == ActivityView.render("activity.json", %{ @@ -993,7 +993,7 @@ test "with credentials", %{conn: conn, user: current_user} do |> post(request_path) activity = Activity.get_by_id(note_activity.id) - activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"]) + activity_user = User.get_by_ap_id(note_activity.data["actor"]) assert json_response(response, 200) == ActivityView.render("activity.json", %{ From 20c619f85f7ccd69469eb9977b6f2805edd18525 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 17:58:32 +0700 Subject: [PATCH 9/9] replace `Repo.get_by(User, nickname: nickname)` with `User.get_by_nickname(nickname)` in tests --- test/web/twitter_api/twitter_api_controller_test.exs | 2 +- test/web/twitter_api/twitter_api_test.exs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 405f0cfae..72b7ea85e 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1021,7 +1021,7 @@ test "it creates a new user", %{conn: conn} do user = json_response(conn, 200) - fetched_user = Repo.get_by(User, nickname: "lain") + fetched_user = User.get_by_nickname("lain") assert user == UserView.render("show.json", %{user: fetched_user}) end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index b823bfd68..6c00244de 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -275,7 +275,7 @@ test "it registers a new user and returns the user." do {:ok, user} = TwitterAPI.register_user(data) - fetched_user = Repo.get_by(User, nickname: "lain") + fetched_user = User.get_by_nickname("lain") assert UserView.render("show.json", %{user: user}) == UserView.render("show.json", %{user: fetched_user}) @@ -293,7 +293,7 @@ test "it registers a new user with empty string in bio and returns the user." do {:ok, user} = TwitterAPI.register_user(data) - fetched_user = Repo.get_by(User, nickname: "lain") + fetched_user = User.get_by_nickname("lain") assert UserView.render("show.json", %{user: user}) == UserView.render("show.json", %{user: fetched_user}) @@ -369,7 +369,7 @@ test "it registers a new user via invite token and returns the user." do {:ok, user} = TwitterAPI.register_user(data) - fetched_user = Repo.get_by(User, nickname: "vinny") + fetched_user = User.get_by_nickname("vinny") token = Repo.get_by(UserInviteToken, token: token.token) assert token.used == true @@ -393,7 +393,7 @@ test "it returns an error if invalid token submitted" do {:error, msg} = TwitterAPI.register_user(data) assert msg == "Invalid token" - refute Repo.get_by(User, nickname: "GrimReaper") + refute User.get_by_nickname("GrimReaper") end @moduletag skip: "needs 'registrations_open: false' in config" @@ -414,7 +414,7 @@ test "it returns an error if expired token submitted" do {:error, msg} = TwitterAPI.register_user(data) assert msg == "Expired token" - refute Repo.get_by(User, nickname: "GrimReaper") + refute User.get_by_nickname("GrimReaper") end test "it returns the error on registration problems" do @@ -429,7 +429,7 @@ test "it returns the error on registration problems" do {:error, error_object} = TwitterAPI.register_user(data) assert is_binary(error_object[:error]) - refute Repo.get_by(User, nickname: "lain") + refute User.get_by_nickname("lain") end test "it assigns an integer conversation_id" do