aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.formatter.exs3
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--installation/pleroma.nginx11
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex9
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex3
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex6
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex3
-rw-r--r--lib/pleroma/web/ostatus/activity_representer.ex9
-rw-r--r--lib/pleroma/web/twitter_api/views/notification_view.ex36
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex5
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs6
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs8
-rw-r--r--test/web/twitter_api/views/notification_view_test.exs22
13 files changed, 93 insertions, 36 deletions
diff --git a/.formatter.exs b/.formatter.exs
new file mode 100644
index 000000000..2bed17cc0
--- /dev/null
+++ b/.formatter.exs
@@ -0,0 +1,3 @@
+[
+ inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
+]
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4db167feb..35029c8f0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,4 @@
-image: elixir:1.5
+image: elixir:1.6.4
services:
- postgres:9.6.2
@@ -9,6 +9,7 @@ variables:
POSTGRES_PASSWORD: postgres
stages:
+ - lint
- test
before_script:
@@ -18,6 +19,11 @@ before_script:
- MIX_ENV=test mix ecto.create
- MIX_ENV=test mix ecto.migrate
+lint:
+ stage: lint
+ script:
+ - MIX_ENV=test mix format --check-formatted
+
unit-testing:
stage: test
script:
diff --git a/installation/pleroma.nginx b/installation/pleroma.nginx
index 61e40c508..895799a8e 100644
--- a/installation/pleroma.nginx
+++ b/installation/pleroma.nginx
@@ -4,7 +4,7 @@
# 1. Install your TLS certificate, possibly using Let's Encrypt.
# 2. Replace 'example.tld' with your instance's domain wherever it appears.
# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
-# in /etc/nginx/sites-enabled/ and restart nginx.
+# in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g
inactive=720m use_temp_path=off;
@@ -13,6 +13,15 @@ server {
listen 80;
server_name example.tld;
return 301 https://$server_name$request_uri;
+
+ # Uncomment this if you need to use the 'webroot' method with certbot. Make sure
+ # that you also create the .well-known/acme-challenge directory structure in pleroma/priv/static and
+ # that is is accessible by the webserver. You may need to load this file with the ssl
+ # server block commented out, run certbot to get the certificate, and then uncomment it.
+ #
+ # location ~ /\.well-known/acme-challenge {
+ # root <path to install>/pleroma/priv/static/;
+ # }
}
server {
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 00b9f74ff..2871a2544 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -146,7 +146,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = data
) do
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
+ {:ok, object} <-
+ get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
{:ok, activity, object} <- ActivityPub.like(actor, object, id, false) do
{:ok, activity}
else
@@ -158,7 +159,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data
) do
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
+ {:ok, object} <-
+ get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
{:ok, activity, object} <- ActivityPub.announce(actor, object, id, false) do
{:ok, activity}
else
@@ -209,7 +211,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
+ {:ok, object} <-
+ get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
{:ok, activity} <- ActivityPub.delete(object, false) do
{:ok, activity}
else
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 7a0762e9f..7b2bf8fa7 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -175,7 +175,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def update_element_in_object(property, element, object) do
with new_data <-
- object.data |> Map.put("#{property}_count", length(element))
+ object.data
+ |> Map.put("#{property}_count", length(element))
|> Map.put("#{property}s", element),
changeset <- Changeset.change(object, data: new_data),
{:ok, object} <- Repo.update(changeset),
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 10531ec15..c84c226e8 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -217,8 +217,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
activities = []
else
activities =
- ActivityPub.fetch_public_activities(params)
- |> Enum.reverse()
+ ActivityPub.fetch_public_activities(params)
+ |> Enum.reverse()
end
conn
@@ -521,7 +521,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
^query
),
limit: 20,
- order_by: [desc: :inserted_at]
+ order_by: [desc: :id]
)
statuses = Repo.all(q) ++ fetched
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 6297b7bae..11dc1806f 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -63,7 +63,8 @@ defmodule Pleroma.Web.OAuth.OAuthController do
client_secret: params["client_secret"]
),
fixed_token = fix_padding(params["code"]),
- %Authorization{} = auth <- Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
+ %Authorization{} = auth <-
+ Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
{:ok, token} <- Token.exchange_token(app, auth) do
response = %{
token_type: "Bearer",
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
index 2f28c456e..921a89bd0 100644
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ b/lib/pleroma/web/ostatus/activity_representer.ex
@@ -131,7 +131,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
h.(activity.data["object"]["content"] |> String.replace(~r/[\n\r]/, ""))},
{:published, h.(inserted_at)},
{:updated, h.(updated_at)},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
+ {:"ostatus:conversation", [ref: h.(activity.data["context"])],
+ h.(activity.data["context"])},
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
] ++
summary ++
@@ -162,7 +163,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
# For notes, federate the object id.
{:id, h.(activity.data["object"])}
]},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
+ {:"ostatus:conversation", [ref: h.(activity.data["context"])],
+ h.(activity.data["context"])},
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
{:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
{:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []}
@@ -193,7 +195,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
{:content, [type: 'html'], ['RT #{retweeted_activity.data["object"]["content"]}']},
{:published, h.(inserted_at)},
{:updated, h.(updated_at)},
- {:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
+ {:"ostatus:conversation", [ref: h.(activity.data["context"])],
+ h.(activity.data["context"])},
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
{:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
{:"activity:object", retweeted_xml}
diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex
index 4e1ba0b54..f41edea0b 100644
--- a/lib/pleroma/web/twitter_api/views/notification_view.ex
+++ b/lib/pleroma/web/twitter_api/views/notification_view.ex
@@ -23,16 +23,34 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do
end
def render("notification.json", %{notifications: notifications, for: user}) do
- render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user)
+ render_many(
+ notifications,
+ Pleroma.Web.TwitterAPI.NotificationView,
+ "notification.json",
+ for: user
+ )
end
- def render("notification.json", %{notification: %Notification{id: id, seen: seen, activity: activity, inserted_at: created_at}, for: user} = opts) do
- ntype = case activity.data["type"] do
- "Create" -> "mention"
- "Like" -> "like"
- "Announce" -> "repeat"
- "Follow" -> "follow"
- end
+ def render(
+ "notification.json",
+ %{
+ notification: %Notification{
+ id: id,
+ seen: seen,
+ activity: activity,
+ inserted_at: created_at
+ },
+ for: user
+ } = opts
+ ) do
+ ntype =
+ case activity.data["type"] do
+ "Create" -> "mention"
+ "Like" -> "like"
+ "Announce" -> "repeat"
+ "Follow" -> "follow"
+ end
+
from = get_user(activity.data["actor"], opts)
%{
@@ -40,7 +58,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do
"ntype" => ntype,
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
"from_profile" => UserView.render("show.json", %{user: from, for: user}),
- "is_seen" => (if seen, do: 1, else: 0),
+ "is_seen" => if(seen, do: 1, else: 0),
"created_at" => created_at |> Utils.format_naive_asctime()
}
end
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index e45c0ed8d..dc9ad2014 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -81,7 +81,10 @@ defmodule Pleroma.Web.WebFinger do
"href" => user.ap_id
},
%{"rel" => "salmon", "href" => OStatus.salmon_path(user)},
- %{"rel" => "magic-public-key", "href" => "data:application/magic-public-key,#{magic_key}"},
+ %{
+ "rel" => "magic-public-key",
+ "href" => "data:application/magic-public-key,#{magic_key}"
+ },
%{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
%{
"rel" => "http://ostatus.org/schema/1.0/subscribe",
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 060ebe9f1..3dab59746 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -102,7 +102,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = insert(:user)
data =
- File.read!("test/fixtures/mastodon-follow-activity.json") |> Poison.decode!()
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
|> Map.put("object", user.ap_id)
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -118,7 +119,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
data =
- File.read!("test/fixtures/mastodon-like.json") |> Poison.decode!()
+ File.read!("test/fixtures/mastodon-like.json")
+ |> Poison.decode!()
|> Map.put("object", activity.data["object"]["id"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 18a3243f5..406dace1c 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -270,10 +270,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 1
assert response ==
- NotificationView.render(
- "notification.json",
- %{notifications: Notification.for_user(current_user), for: current_user}
- )
+ NotificationView.render("notification.json", %{
+ notifications: Notification.for_user(current_user),
+ for: current_user
+ })
end
end
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index 33aaa89e1..e3b140657 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -36,14 +36,17 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"ntype" => "follow"
}
- assert represented == NotificationView.render("notification.json", %{notification: follow_notif, for: user})
+ assert represented ==
+ NotificationView.render("notification.json", %{notification: follow_notif, for: user})
end
test "A mention notification" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
+
[notification] = Notification.for_user(user)
represented = %{
@@ -55,7 +58,8 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"ntype" => "mention"
}
- assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ assert represented ==
+ NotificationView.render("notification.json", %{notification: notification, for: user})
end
test "A retweet notification" do
@@ -71,11 +75,13 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
"id" => notification.id,
"is_seen" => 0,
- "notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
+ "notice" =>
+ ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
"ntype" => "repeat"
}
- assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ assert represented ==
+ NotificationView.render("notification.json", %{notification: notification, for: user})
end
test "A like notification" do
@@ -91,10 +97,12 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
"from_profile" => UserView.render("show.json", %{user: liker, for: user}),
"id" => notification.id,
"is_seen" => 0,
- "notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
+ "notice" =>
+ ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
"ntype" => "like"
}
- assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ assert represented ==
+ NotificationView.render("notification.json", %{notification: notification, for: user})
end
end