aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.exs9
-rw-r--r--docs/Admin-API.md191
-rw-r--r--docs/Differences-in-MastodonAPI-Responses.md4
-rw-r--r--lib/pleroma/formatter.ex4
-rw-r--r--lib/pleroma/user.ex6
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex4
-rw-r--r--lib/pleroma/web/auth/authenticator.ex25
-rw-r--r--lib/pleroma/web/auth/pleroma_authenticator.ex28
-rw-r--r--lib/pleroma/web/common_api/utils.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex11
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/websocket_handler.ex38
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex17
-rw-r--r--lib/pleroma/web/twitter_api/representers/activity_representer.ex247
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex10
-rw-r--r--lib/pleroma/web/twitter_api/views/activity_view.ex4
-rw-r--r--lib/pleroma/web/twitter_api/views/user_view.ex7
-rw-r--r--lib/pleroma/web/web.ex6
-rw-r--r--mix.exs5
-rw-r--r--mix.lock10
-rw-r--r--priv/repo/migrations/20190301101154_add_default_tags_to_user.exs9
-rw-r--r--test/user_test.exs14
-rw-r--r--test/web/activity_pub/activity_pub_test.exs7
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs35
-rw-r--r--test/web/common_api/common_api_utils_test.exs18
-rw-r--r--test/web/mastodon_api/account_view_test.exs66
-rw-r--r--test/web/mastodon_api/status_view_test.exs16
-rw-r--r--test/web/oauth/oauth_controller_test.exs12
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs43
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs19
-rw-r--r--test/web/twitter_api/views/user_view_test.exs7
31 files changed, 461 insertions, 415 deletions
diff --git a/config/config.exs b/config/config.exs
index 7e4ac1100..a620e7451 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -93,10 +93,11 @@ config :pleroma, Pleroma.Web.Endpoint,
dispatch: [
{:_,
[
- {"/api/v1/streaming", Elixir.Pleroma.Web.MastodonAPI.WebsocketHandler, []},
- {"/socket/websocket", Phoenix.Endpoint.CowboyWebSocket,
- {nil, {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
- {:_, Plug.Adapters.Cowboy.Handler, {Pleroma.Web.Endpoint, []}}
+ {"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {"/websocket", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
]}
]
],
diff --git a/docs/Admin-API.md b/docs/Admin-API.md
index 016444d58..508981d38 100644
--- a/docs/Admin-API.md
+++ b/docs/Admin-API.md
@@ -1,108 +1,173 @@
# Admin API
+
Authentication is required and the user must be an admin.
+## `/api/pleroma/admin/users`
+
+### List users
+
+- Method `GET`
+- Response:
+
+```JSON
+[
+ {
+ "deactivated": bool,
+ "id": integer,
+ "nickname": string
+ },
+ ...
+]
+```
+
## `/api/pleroma/admin/user`
+
### Remove a user
-* Method `DELETE`
-* Params:
- * `nickname`
-* Response: User’s nickname
+
+- Method `DELETE`
+- Params:
+ - `nickname`
+- Response: User’s nickname
+
### Create a user
-* Method: `POST`
-* Params:
- * `nickname`
- * `email`
- * `password`
-* Response: User’s nickname
+
+- Method: `POST`
+- Params:
+ - `nickname`
+ - `email`
+ - `password`
+- Response: User’s nickname
+
+## `/api/pleroma/admin/users/:nickname/toggle_activation`
+
+### Toggle user activation
+
+- Method: `PATCH`
+- Params:
+ - `nickname`
+- Response: User’s object
+
+```JSON
+{
+ "deactivated": bool,
+ "id": integer,
+ "nickname": string
+}
+```
## `/api/pleroma/admin/users/tag`
+
### Tag a list of users
-* Method: `PUT`
-* Params:
- * `nickname`
- * `tags`
+
+- Method: `PUT`
+- Params:
+ - `nickname`
+ - `tags`
+
### Untag a list of users
-* Method: `DELETE`
-* Params:
- * `nickname`
- * `tags`
+
+- Method: `DELETE`
+- Params:
+ - `nickname`
+ - `tags`
## `/api/pleroma/admin/permission_group/:nickname`
+
### Get user user permission groups membership
-* Method: `GET`
-* Params: none
-* Response:
+
+- Method: `GET`
+- Params: none
+- Response:
+
```JSON
{
- "is_moderator": bool,
- "is_admin": bool
+ "is_moderator": bool,
+ "is_admin": bool
}
```
## `/api/pleroma/admin/permission_group/:nickname/:permission_group`
+
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
### Get user user permission groups membership
-* Method: `GET`
-* Params: none
-* Response:
+
+- Method: `GET`
+- Params: none
+- Response:
+
```JSON
{
- "is_moderator": bool,
- "is_admin": bool
+ "is_moderator": bool,
+ "is_admin": bool
}
```
+
### Add user in permission group
-* Method: `POST`
-* Params: none
-* Response:
- * On failure: ``{"error": "…"}``
- * On success: JSON of the ``user.info``
+
+- Method: `POST`
+- Params: none
+- Response:
+ - On failure: `{"error": "…"}`
+ - On success: JSON of the `user.info`
+
### Remove user from permission group
-* Method: `DELETE`
-* Params: none
-* Response:
- * On failure: ``{"error": "…"}``
- * On success: JSON of the ``user.info``
-* Note: An admin cannot revoke their own admin status.
+
+- Method: `DELETE`
+- Params: none
+- Response:
+ - On failure: `{"error": "…"}`
+ - On success: JSON of the `user.info`
+- Note: An admin cannot revoke their own admin status.
## `/api/pleroma/admin/activation_status/:nickname`
### Active or deactivate a user
-* Method: `PUT`
-* Params:
- * `nickname`
- * `status` BOOLEAN field, false value means deactivation.
+
+- Method: `PUT`
+- Params:
+ - `nickname`
+ - `status` BOOLEAN field, false value means deactivation.
## `/api/pleroma/admin/relay`
+
### Follow a Relay
-* Methods: `POST`
-* Params:
- * `relay_url`
-* Response:
- * On success: URL of the followed relay
+
+- Methods: `POST`
+- Params:
+ - `relay_url`
+- Response:
+ - On success: URL of the followed relay
+
### Unfollow a Relay
-* Methods: `DELETE`
-* Params:
- * `relay_url`
-* Response:
- * On success: URL of the unfollowed relay
+
+- Methods: `DELETE`
+- Params:
+ - `relay_url`
+- Response:
+ - On success: URL of the unfollowed relay
## `/api/pleroma/admin/invite_token`
+
### Get a account registeration invite token
-* Methods: `GET`
-* Params: none
-* Response: invite token (base64 string)
+
+- Methods: `GET`
+- Params: none
+- Response: invite token (base64 string)
## `/api/pleroma/admin/email_invite`
+
### Sends registration invite via email
-* Methods: `POST`
-* Params:
- * `email`
- * `name`, optionnal
+
+- Methods: `POST`
+- Params:
+ - `email`
+ - `name`, optionnal
## `/api/pleroma/admin/password_reset`
+
### Get a password reset token for a given nickname
-* Methods: `GET`
-* Params: none
-* Response: password reset token (base64 string)
+
+- Methods: `GET`
+- Params: none
+- Response: password reset token (base64 string)
diff --git a/docs/Differences-in-MastodonAPI-Responses.md b/docs/Differences-in-MastodonAPI-Responses.md
index f6a5b6461..3026e1173 100644
--- a/docs/Differences-in-MastodonAPI-Responses.md
+++ b/docs/Differences-in-MastodonAPI-Responses.md
@@ -9,3 +9,7 @@ Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mas
## Attachment cap
Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.
+
+## Timelines
+
+Adding the parameter `with_muted=true` to the timeline queries will also return activities by muted (not by blocked!) users.
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 51d08c5ee..048c032ed 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -91,6 +91,10 @@ defmodule Pleroma.Formatter do
def get_emoji(_), do: []
+ def html_escape({text, mentions, hashtags}, type) do
+ {html_escape(text, type), mentions, hashtags}
+ end
+
def html_escape(text, "text/html") do
HTML.filter_tags(text)
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 01d532ab3..d58274508 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -613,9 +613,10 @@ defmodule Pleroma.User do
),
where:
fragment(
- "? @> ?",
+ "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
a.data,
- ^%{"object" => user.ap_id}
+ a.data,
+ ^user.ap_id
)
)
end
@@ -960,6 +961,7 @@ defmodule Pleroma.User do
update_and_set_cache(cng)
end
+ def mutes?(nil, _), do: false
def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.info.mutes, ap_id)
def blocks?(user, %{ap_id: ap_id}) do
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index a61bfa4db..b81198629 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -626,6 +626,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_reblogs(query, _), do: query
+ defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
+
defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
mutes = info.mutes
@@ -850,7 +852,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
date =
NaiveDateTime.utc_now()
- |> Timex.format!("{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
+ |> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
signature =
Pleroma.Web.HTTPSignatures.sign(actor, %{
diff --git a/lib/pleroma/web/auth/authenticator.ex b/lib/pleroma/web/auth/authenticator.ex
new file mode 100644
index 000000000..82267c595
--- /dev/null
+++ b/lib/pleroma/web/auth/authenticator.ex
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Auth.Authenticator do
+ alias Pleroma.User
+
+ def implementation do
+ Pleroma.Config.get(
+ Pleroma.Web.Auth.Authenticator,
+ Pleroma.Web.Auth.PleromaAuthenticator
+ )
+ end
+
+ @callback get_user(Plug.Conn.t()) :: {:ok, User.t()} | {:error, any()}
+ def get_user(plug), do: implementation().get_user(plug)
+
+ @callback handle_error(Plug.Conn.t(), any()) :: any()
+ def handle_error(plug, error), do: implementation().handle_error(plug, error)
+
+ @callback auth_template() :: String.t() | nil
+ def auth_template do
+ implementation().auth_template() || Pleroma.Config.get(:auth_template, "show.html")
+ end
+end
diff --git a/lib/pleroma/web/auth/pleroma_authenticator.ex b/lib/pleroma/web/auth/pleroma_authenticator.ex
new file mode 100644
index 000000000..3cc19af01
--- /dev/null
+++ b/lib/pleroma/web/auth/pleroma_authenticator.ex
@@ -0,0 +1,28 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Auth.PleromaAuthenticator do
+ alias Pleroma.User
+ alias Comeonin.Pbkdf2
+
+ @behaviour Pleroma.Web.Auth.Authenticator
+
+ def get_user(%Plug.Conn{} = conn) do
+ %{"authorization" => %{"name" => name, "password" => password}} = conn.params
+
+ with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
+ {_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
+ {:ok, user}
+ else
+ error ->
+ {:error, error}
+ end
+ end
+
+ def handle_error(%Plug.Conn{} = _conn, error) do
+ error
+ end
+
+ def auth_template, do: nil
+end
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 20123854d..e4b9102c5 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -186,9 +186,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do
options = Keyword.put(options, :mentions_escape, true)
text
- |> Formatter.html_escape("text/html")
|> Formatter.linkify(options)
|> (fn {text, mentions, tags} -> {Earmark.as_html!(text), mentions, tags} end).()
+ |> Formatter.html_escape("text/html")
end
def make_note_data(
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 8fdefdebd..c32f27be2 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -32,7 +32,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
}
end
- def render("relationship.json", %{user: user, target: target}) do
+ def render("relationship.json", %{user: nil, target: _target}) do
+ %{}
+ end
+
+ def render("relationship.json", %{user: %User{} = user, target: %User{} = target}) do
follow_activity = Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, target)
requested =
@@ -85,6 +89,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
bio = HTML.filter_tags(user.bio, User.html_filter_policy(opts[:for]))
+ relationship = render("relationship.json", %{user: opts[:for], target: user})
+
%{
id: to_string(user.id),
username: username_from_nickname(user.nickname),
@@ -115,7 +121,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
confirmation_pending: user_info.confirmation_pending,
tags: user.tags,
is_moderator: user.info.is_moderator,
- is_admin: user.info.is_admin
+ is_admin: user.info.is_admin,
+ relationship: relationship
}
}
end
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index b90e4252a..3468c0e1c 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -168,7 +168,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
reblogged: present?(repeated),
favourited: present?(favorited),
bookmarked: present?(bookmarked),
- muted: CommonAPI.thread_muted?(user, activity),
+ muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
pinned: pinned?(activity, user),
sensitive: sensitive,
spoiler_text: object["summary"] || "",
diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex
index ea75070c4..8efe2efd5 100644
--- a/lib/pleroma/web/mastodon_api/websocket_handler.ex
+++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex
@@ -9,7 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
alias Pleroma.Repo
alias Pleroma.User
- @behaviour :cowboy_websocket_handler
+ @behaviour :cowboy_websocket
@streams [
"public",
@@ -26,37 +26,37 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
# Handled by periodic keepalive in Pleroma.Web.Streamer.
@timeout :infinity
- def init(_type, _req, _opts) do
- {:upgrade, :protocol, :cowboy_websocket}
- end
-
- def websocket_init(_type, req, _opts) do
- with {qs, req} <- :cowboy_req.qs(req),
- params <- :cow_qs.parse_qs(qs),
+ def init(%{qs: qs} = req, state) do
+ with params <- :cow_qs.parse_qs(qs),
access_token <- List.keyfind(params, "access_token", 0),
{_, stream} <- List.keyfind(params, "stream", 0),
{:ok, user} <- allow_request(stream, access_token),
topic when is_binary(topic) <- expand_topic(stream, params) do
- send(self(), :subscribe)
- {:ok, req, %{user: user, topic: topic}, @timeout}
+ {:cowboy_websocket, req, %{user: user, topic: topic}, %{idle_timeout: @timeout}}
else
{:error, code} ->
Logger.debug("#{__MODULE__} denied connection: #{inspect(code)} - #{inspect(req)}")
{:ok, req} = :cowboy_req.reply(code, req)
- {:shutdown, req}
+ {:ok, req, state}
error ->
Logger.debug("#{__MODULE__} denied connection: #{inspect(error)} - #{inspect(req)}")
- {:shutdown, req}
+ {:ok, req} = :cowboy_req.reply(400, req)
+ {:ok, req, state}
end
end
+ def websocket_init(state) do
+ send(self(), :subscribe)
+ {:ok, state}
+ end
+
# We never receive messages.
- def websocket_handle(_frame, req, state) do
- {:ok, req, state}
+ def websocket_handle(_frame, state) do
+ {:ok, state}
end
- def websocket_info(:subscribe, req, state) do
+ def websocket_info(:subscribe, state) do
Logger.debug(
"#{__MODULE__} accepted websocket connection for user #{
(state.user || %{id: "anonymous"}).id
@@ -64,14 +64,14 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
)
Pleroma.Web.Streamer.add_socket(state.topic, streamer_socket(state))
- {:ok, req, state}
+ {:ok, state}
end
- def websocket_info({:text, message}, req, state) do
- {:reply, {:text, message}, req, state}
+ def websocket_info({:text, message}, state) do
+ {:reply, {:text, message}, state}
end
- def websocket_terminate(reason, _req, state) do
+ def terminate(reason, _req, state) do
Logger.debug(
"#{__MODULE__} terminating websocket connection for user #{
(state.user || %{id: "anonymous"}).id
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 7c1a3adbd..36318d69b 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.OAuth.OAuthController do
use Pleroma.Web, :controller
+ alias Pleroma.Web.Auth.Authenticator
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.OAuth.App
@@ -24,27 +25,25 @@ defmodule Pleroma.Web.OAuth.OAuthController do
available_scopes = (app && app.scopes) || []
scopes = oauth_scopes(params, nil) || available_scopes
- render(conn, "show.html", %{
+ render(conn, Authenticator.auth_template(), %{
response_type: params["response_type"],
client_id: params["client_id"],
available_scopes: available_scopes,
scopes: scopes,
redirect_uri: params["redirect_uri"],
- state: params["state"]
+ state: params["state"],
+ params: params
})
end
def create_authorization(conn, %{
"authorization" =>
%{
- "name" => name,
- "password" => password,
"client_id" => client_id,
"redirect_uri" => redirect_uri
} = auth_params
}) do
- with %User{} = user <- User.get_by_nickname_or_email(name),
- true <- Pbkdf2.checkpw(password, user.password_hash),
+ with {_, {:ok, %User{} = user}} <- {:get_user, Authenticator.get_user(conn)},
%App{} = app <- Repo.get_by(App, client_id: client_id),
true <- redirect_uri in String.split(app.redirect_uris),
scopes <- oauth_scopes(auth_params, []),
@@ -53,9 +52,9 @@ defmodule Pleroma.Web.OAuth.OAuthController do
{:missing_scopes, false} <- {:missing_scopes, scopes == []},
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
{:ok, auth} <- Authorization.create_authorization(app, user, scopes) do
- # Special case: Local MastodonFE.
redirect_uri =
if redirect_uri == "." do
+ # Special case: Local MastodonFE
mastodon_api_url(conn, :login)
else
redirect_uri
@@ -97,7 +96,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|> authorize(auth_params)
error ->
- error
+ Authenticator.handle_error(conn, error)
end
end
@@ -114,7 +113,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
refresh_token: token.refresh_token,
created_at: DateTime.to_unix(inserted_at),
expires_in: 60 * 10,
- scope: Enum.join(token.scopes)
+ scope: Enum.join(token.scopes, " ")
}
json(conn, response)
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
index 192ab7334..55c612ddd 100644
--- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
@@ -6,247 +6,10 @@
# THIS MODULE IS DEPRECATED! DON'T USE IT!
# USE THE Pleroma.Web.TwitterAPI.Views.ActivityView MODULE!
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
- use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
- alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
- alias Pleroma.Activity
- alias Pleroma.Formatter
- alias Pleroma.HTML
- alias Pleroma.User
- alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.UserView
- alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.MastodonAPI.StatusView
-
- defp user_by_ap_id(user_list, ap_id) do
- Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end)
- end
-
- def to_map(
- %Activity{data: %{"type" => "Announce", "actor" => actor, "published" => created_at}} =
- activity,
- %{users: users, announced_activity: announced_activity} = opts
- ) do
- user = user_by_ap_id(users, actor)
- created_at = created_at |> Utils.date_to_asctime()
-
- text = "#{user.nickname} retweeted a status."
-
- announced_user = user_by_ap_id(users, announced_activity.data["actor"])
- retweeted_status = to_map(announced_activity, Map.merge(%{user: announced_user}, opts))
-
- %{
- "id" => activity.id,
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "statusnet_html" => text,
- "text" => text,
- "is_local" => activity.local,
- "is_post_verb" => false,
- "uri" => "tag:#{activity.data["id"]}:objectType=note",
- "created_at" => created_at,
- "retweeted_status" => retweeted_status,
- "statusnet_conversation_id" => conversation_id(announced_activity),
- "external_url" => activity.data["id"],
- "activity_type" => "repeat"
- }
- end
-
- def to_map(
- %Activity{data: %{"type" => "Like", "published" => created_at}} = activity,
- %{user: user, liked_activity: liked_activity} = opts
- ) do
- created_at = created_at |> Utils.date_to_asctime()
-
- text = "#{user.nickname} favorited a status."
-
- %{
- "id" => activity.id,
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "statusnet_html" => text,
- "text" => text,
- "is_local" => activity.local,
- "is_post_verb" => false,
- "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
- "created_at" => created_at,
- "in_reply_to_status_id" => liked_activity.id,
- "external_url" => activity.data["id"],
- "activity_type" => "like"
- }
- end
-
- def to_map(
- %Activity{data: %{"type" => "Follow", "object" => followed_id}} = activity,
- %{user: user} = opts
- ) do
- created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
- created_at = created_at |> Utils.date_to_asctime()
-
- followed = User.get_cached_by_ap_id(followed_id)
- text = "#{user.nickname} started following #{followed.nickname}"
-
- %{
- "id" => activity.id,
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "attentions" => [],
- "statusnet_html" => text,
- "text" => text,
- "is_local" => activity.local,
- "is_post_verb" => false,
- "created_at" => created_at,
- "in_reply_to_status_id" => nil,
- "external_url" => activity.data["id"],
- "activity_type" => "follow"
- }
- end
-
- # TODO:
- # Make this more proper. Just a placeholder to not break the frontend.
- def to_map(
- %Activity{
- data: %{"type" => "Undo", "published" => created_at, "object" => undid_activity}
- } = activity,
- %{user: user} = opts
- ) do
- created_at = created_at |> Utils.date_to_asctime()
-
- text = "#{user.nickname} undid the action at #{undid_activity["id"]}"
-
- %{
- "id" => activity.id,
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "attentions" => [],
- "statusnet_html" => text,
- "text" => text,
- "is_local" => activity.local,
- "is_post_verb" => false,
- "created_at" => created_at,
- "in_reply_to_status_id" => nil,
- "external_url" => activity.data["id"],
- "activity_type" => "undo"
- }
- end
-
- def to_map(
- %Activity{data: %{"type" => "Delete", "published" => created_at, "object" => _}} =
- activity,
- %{user: user} = opts
- ) do
- created_at = created_at |> Utils.date_to_asctime()
-
- %{
- "id" => activity.id,
- "uri" => activity.data["object"],
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "attentions" => [],
- "statusnet_html" => "deleted notice {{tag",
- "text" => "deleted notice {{tag",
- "is_local" => activity.local,
- "is_post_verb" => false,
- "created_at" => created_at,
- "in_reply_to_status_id" => nil,
- "external_url" => activity.data["id"],
- "activity_type" => "delete"
- }
- end
-
- def to_map(
- %Activity{data: %{"object" => %{"content" => _content} = object}} = activity,
- %{user: user} = opts
- ) do
- created_at = object["published"] |> Utils.date_to_asctime()
- like_count = object["like_count"] || 0
- announcement_count = object["announcement_count"] || 0
- favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
- repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
- pinned = activity.id in user.info.pinned_activities
-
- mentions = opts[:mentioned] || []
-
- attentions =
- []
- |> Utils.maybe_notify_to_recipients(activity)
- |> Utils.maybe_notify_mentioned_recipients(activity)
- |> Enum.map(fn ap_id -> Enum.find(mentions, fn user -> ap_id == user.ap_id end) end)
- |> Enum.filter(& &1)
- |> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
-
- conversation_id = conversation_id(activity)
-
- tags = activity.data["object"]["tag"] || []
- possibly_sensitive = activity.data["object"]["sensitive"] || Enum.member?(tags, "nsfw")
-
- tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
-
- {_summary, content} = ActivityView.render_content(object)
-
- html =
- HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
- |> Formatter.emojify(object["emoji"])
-
- attachments = object["attachment"] || []
-
- reply_parent = Activity.get_in_reply_to_activity(activity)
-
- reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
-
- summary = HTML.strip_tags(object["summary"])
-
- card =
- StatusView.render(
- "card.json",
- Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
- )
-
- %{
- "id" => activity.id,
- "uri" => activity.data["object"]["id"],
- "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
- "statusnet_html" => html,
- "text" => HTML.strip_tags(content),
- "is_local" => activity.local,
- "is_post_verb" => true,
- "created_at" => created_at,
- "in_reply_to_status_id" => object["inReplyToStatusId"],
- "in_reply_to_screen_name" => reply_user && reply_user.nickname,
- "in_reply_to_profileurl" => User.profile_url(reply_user),
- "in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id,
- "in_reply_to_user_id" => reply_user && reply_user.id,
- "statusnet_conversation_id" => conversation_id,
- "attachments" => attachments |> ObjectRepresenter.enum_to_list(opts),
- "attentions" => attentions,
- "fave_num" => like_count,
- "repeat_num" => announcement_count,
- "favorited" => to_boolean(favorited),
- "repeated" => to_boolean(repeated),
- "pinned" => pinned,
- "external_url" => object["external_url"] || object["id"],
- "tags" => tags,
- "activity_type" => "post",
- "possibly_sensitive" => possibly_sensitive,
- "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
- "summary" => summary,
- "summary_html" => summary |> Formatter.emojify(object["emoji"]),
- "card" => card
- }
- end
-
- def conversation_id(activity) do
- with context when not is_nil(context) <- activity.data["context"] do
- TwitterAPI.context_to_conversation_id(context)
- else
- _e -> nil
- end
- end
-
- defp to_boolean(false) do
- false
- end
-
- defp to_boolean(nil) do
- false
- end
-
- defp to_boolean(_) do
- true
+ def to_map(activity, opts) do
+ Pleroma.Web.TwitterAPI.ActivityView.render(
+ "activity.json",
+ Map.put(opts, :activity, activity)
+ )
end
end
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index efdd0bf43..ab6470d78 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -229,18 +229,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
end
end
- def get_by_id_or_nickname(id_or_nickname) do
- if !is_integer(id_or_nickname) && :error == Integer.parse(id_or_nickname) do
- Repo.get_by(User, nickname: id_or_nickname)
- else
- Repo.get(User, id_or_nickname)
- end
- end
-
def get_user(user \\ nil, params) do
case params do
%{"user_id" => user_id} ->
- case target = get_by_id_or_nickname(user_id) do
+ case target = User.get_cached_by_nickname_or_id(user_id) do
nil ->
{:error, "No user with such user_id"}
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 661022afa..02ca4ee42 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.TwitterAPI.ActivityView
@@ -309,7 +310,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
"visibility" => StatusView.get_visibility(object),
"summary" => summary,
"summary_html" => summary |> Formatter.emojify(object["emoji"]),
- "card" => card
+ "card" => card,
+ "muted" => CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user)
}
end
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index c5034cf36..22f33e0b5 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -132,6 +132,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"confirmation_pending" => user_info.confirmation_pending,
"tags" => user.tags
}
+ |> maybe_with_activation_status(user, for_user)
|> maybe_with_follow_request_count(user, for_user)
}
@@ -148,6 +149,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
+ defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
+ Map.put(data, "deactivated", user.info.deactivated)
+ end
+
+ defp maybe_with_activation_status(data, _, _), do: data
+
defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
id: id
}) do
diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex
index 853aa2a87..66813e4dd 100644
--- a/lib/pleroma/web/web.ex
+++ b/lib/pleroma/web/web.ex
@@ -26,6 +26,12 @@ defmodule Pleroma.Web do
import Plug.Conn
import Pleroma.Web.Gettext
import Pleroma.Web.Router.Helpers
+
+ plug(:set_put_layout)
+
+ defp set_put_layout(conn, _) do
+ put_layout(conn, Pleroma.Config.get(:app_layout, "app.html"))
+ end
end
end
diff --git a/mix.exs b/mix.exs
index 5392d94d1..0fe9c6ec3 100644
--- a/mix.exs
+++ b/mix.exs
@@ -55,9 +55,8 @@ defmodule Pleroma.Mixfile do
# Type `mix help deps` for examples and options.
defp deps do
[
- # Until Phoenix 1.4.1 is released
- {:phoenix, github: "phoenixframework/phoenix", branch: "v1.4"},
- {:plug_cowboy, "~> 1.0"},
+ {:phoenix, "~> 1.4.1"},
+ {:plug_cowboy, "~> 2.0"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 3.3"},
{:postgrex, ">= 0.13.5"},
diff --git a/mix.lock b/mix.lock
index 918702444..50e742fbd 100644
--- a/mix.lock
+++ b/mix.lock
@@ -9,8 +9,8 @@
"comeonin": {:hex, :comeonin, "4.1.1", "c7304fc29b45b897b34142a91122bc72757bc0c295e9e824999d5179ffc08416", [:mix], [{:argon2_elixir, "~> 1.2", [hex: :argon2_elixir, repo: "hexpm", optional: true]}, {:bcrypt_elixir, "~> 0.12.1 or ~> 1.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: true]}, {:pbkdf2_elixir, "~> 0.12", [hex: :pbkdf2_elixir, repo: "hexpm", optional: true]}], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"cors_plug": {:hex, :cors_plug, "1.5.2", "72df63c87e4f94112f458ce9d25800900cc88608c1078f0e4faddf20933eda6e", [:mix], [{:plug, "~> 1.3 or ~> 1.4 or ~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
- "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
- "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
+ "cowboy": {:hex, :cowboy, "2.6.1", "f2e06f757c337b3b311f9437e6e072b678fcd71545a7b2865bdaa154d078593f", [:rebar3], [{:cowlib, "~> 2.7.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
+ "cowlib": {:hex, :cowlib, "2.7.0", "3ef16e77562f9855a2605900cedb15c1462d76fb1be6a32fc3ae91973ee543d2", [:rebar3], [], "hexpm"},
"credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"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"},
@@ -45,17 +45,17 @@
"nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "0.12.3", "6706a148809a29c306062862c803406e88f048277f6e85b68faf73291e820b84", [:mix], [], "hexpm"},
- "phoenix": {:git, "https://github.com/phoenixframework/phoenix.git", "ea22dc50b574178a300ecd19253443960407df93", [branch: "v1.4"]},
+ "phoenix": {:hex, :phoenix, "1.4.1", "801f9d632808657f1f7c657c8bbe624caaf2ba91429123ebe3801598aea4c3d9", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
"phoenix_ecto": {:hex, :phoenix_ecto, "3.3.0", "702f6e164512853d29f9d20763493f2b3bcfcb44f118af2bc37bb95d0801b480", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.13.1", "fa8f034b5328e2dfa0e4131b5569379003f34bc1fafdaa84985b0b9d2f12e68b", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"},
"plug": {:hex, :plug, "1.7.2", "d7b7db7fbd755e8283b6c0a50be71ec0a3d67d9213d74422d9372effc8e87fd1", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
- "plug_cowboy": {:hex, :plug_cowboy, "1.0.0", "2e2a7d3409746d335f451218b8bb0858301c3de6d668c3052716c909936eb57a", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
+ "plug_cowboy": {:hex, :plug_cowboy, "2.0.1", "d798f8ee5acc86b7d42dbe4450b8b0dadf665ce588236eb0a751a132417a980e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
- "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
+ "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"swoosh": {:hex, :swoosh, "0.20.0", "9a6c13822c9815993c03b6f8fccc370fcffb3c158d9754f67b1fdee6b3a5d928", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.12", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
"syslog": {:git, "https://github.com/Vagabond/erlang-syslog.git", "4a6c6f2c996483e86c1320e9553f91d337bcb6aa", [tag: "1.0.5"]},
diff --git a/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs
new file mode 100644
index 000000000..faeb8f1c6
--- /dev/null
+++ b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddDefaultTagsToUser do
+ use Ecto.Migration
+
+ def up do
+ execute "UPDATE users SET tags = array[]::varchar[] where tags IS NULL"
+ end
+
+ def down, do: :noop
+end
diff --git a/test/user_test.exs b/test/user_test.exs
index 0b1c39ecf..cbe4693fc 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -50,6 +50,20 @@ defmodule Pleroma.UserTest do
assert expected_followers_collection == User.ap_followers(user)
end
+ test "returns all pending follow requests" do
+ unlocked = insert(:user)
+ locked = insert(:user, %{info: %{locked: true}})
+ follower = insert(:user)
+
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => unlocked.id})
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => locked.id})
+
+ assert {:ok, []} = User.get_follow_requests(unlocked)
+ assert {:ok, [activity]} = User.get_follow_requests(locked)
+
+ assert activity
+ end
+
test "follow_all follows mutliple users" do
user = insert(:user)
followed_zero = insert(:user)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 17f48797b..950ce17dd 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -299,6 +299,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_three)
refute Enum.member?(activities, activity_one)
+ # Calling with 'with_muted' will deliver muted activities, too.
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+
+ assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, activity_one)
+
{:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]})
activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 9fbaaba39..f6ae16844 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -330,4 +330,39 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert conn.status == 200
end
+
+ test "GET /api/pleroma/admin/users" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users")
+
+ assert json_response(conn, 200) == [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response(conn, 200) ==
+ %{
+ "deactivated" => !user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ end
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index dc7b4c229..684f2a23f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -104,6 +104,18 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
+
+ text = """
+ > cool quote
+
+ by someone
+ """
+
+ expected = "<blockquote><p>cool quote</p>\n</blockquote>\n<p>by someone</p>\n"
+
+ {output, [], []} = Utils.format_input(text, "text/markdown")
+
+ assert output == expected
end
test "works for text/markdown with mentions" do
@@ -113,11 +125,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "<p><strong>hello world</strong></p>\n<p><em>another <span class='h-card'><a data-user='#{
+ "<p><strong>hello world</strong></p>\n<p><em>another <span class=\"h-card\"><a data-user=\"#{
user.id
- }' class='u-url mention' href='http://foo.com/user__test'>@<span>user__test</span></a></span> and <span class='h-card'><a data-user='#{
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> and <span class=\"h-card\"><a data-user=\"#{
user.id
- }' class='u-url mention' href='http://foo.com/user__test'>@<span>user__test</span></a></span> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
{output, _, _} = Utils.format_input(text, "text/markdown")
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index f8cd68173..6be66ef63 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -63,7 +63,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
confirmation_pending: false,
tags: [],
is_admin: false,
- is_moderator: false
+ is_moderator: false,
+ relationship: %{}
}
}
@@ -106,7 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
confirmation_pending: false,
tags: [],
is_admin: false,
- is_moderator: false
+ is_moderator: false,
+ relationship: %{}
}
}
@@ -148,4 +150,64 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
end
+
+ test "represent an embedded relationship" do
+ user =
+ insert(:user, %{
+ info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
+ nickname: "shp@shitposter.club",
+ inserted_at: ~N[2017-08-15 15:47:06.597036]
+ })
+
+ other_user = insert(:user)
+
+ {:ok, other_user} = User.follow(other_user, user)
+ {:ok, other_user} = User.block(other_user, user)
+
+ expected = %{
+ id: to_string(user.id),
+ username: "shp",
+ acct: user.nickname,
+ display_name: user.name,
+ locked: false,
+ created_at: "2017-08-15T15:47:06.000Z",
+ followers_count: 3,
+ following_count: 0,
+ statuses_count: 5,
+ note: user.bio,
+ url: user.ap_id,
+ avatar: "http://localhost:4001/images/avi.png",
+ avatar_static: "http://localhost:4001/images/avi.png",
+ header: "http://localhost:4001/images/banner.png",
+ header_static: "http://localhost:4001/images/banner.png",
+ emojis: [],
+ fields: [],
+ bot: true,
+ source: %{
+ note: "",
+ privacy: "public",
+ sensitive: false
+ },
+ pleroma: %{
+ confirmation_pending: false,
+ tags: [],
+ is_admin: false,
+ is_moderator: false,
+ relationship: %{
+ id: to_string(user.id),
+ following: false,
+ followed_by: false,
+ blocking: true,
+ muting: false,
+ muting_notifications: false,
+ requested: false,
+ domain_blocking: false,
+ showing_reblogs: false,
+ endorsed: false
+ }
+ }
+ }
+
+ assert expected == AccountView.render("account.json", %{user: user, for: other_user})
+ end
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 3412a6be2..351dbf673 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -126,6 +126,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert status == expected
end
+ test "tells if the message is muted for some reason" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ status = StatusView.render("status.json", %{activity: activity})
+
+ assert status.muted == false
+
+ status = StatusView.render("status.json", %{activity: activity, for: user})
+
+ assert status.muted == true
+ end
+
test "a reply" do
note = insert(:note_activity)
user = insert(:user)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 53d83e6e8..ed94416ff 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -165,10 +165,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "issues a token for request with HTTP basic auth client credentials" do
user = insert(:user)
- app = insert(:oauth_app, scopes: ["scope1", "scope2"])
+ app = insert(:oauth_app, scopes: ["scope1", "scope2", "scope3"])
- {:ok, auth} = Authorization.create_authorization(app, user, ["scope2"])
- assert auth.scopes == ["scope2"]
+ {:ok, auth} = Authorization.create_authorization(app, user, ["scope1", "scope2"])
+ assert auth.scopes == ["scope1", "scope2"]
app_encoded =
(URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
@@ -183,11 +183,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"redirect_uri" => app.redirect_uris
})
- assert %{"access_token" => token} = json_response(conn, 200)
+ assert %{"access_token" => token, "scope" => scope} = json_response(conn, 200)
+
+ assert scope == "scope1 scope2"
token = Repo.get_by(Token, token: token)
assert token
- assert token.scopes == ["scope2"]
+ assert token.scopes == ["scope1", "scope2"]
end
test "rejects token exchange with invalid client credentials" do
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 365c7f659..0e554623c 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -13,36 +13,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
- test "an announce activity" do
- user = insert(:user)
- note_activity = insert(:note_activity)
- activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
-
- {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
- note_activity = Activity.get_by_ap_id(note_activity.data["id"])
-
- status =
- ActivityRepresenter.to_map(announce_activity, %{
- users: [user, activity_actor],
- announced_activity: note_activity,
- for: user
- })
-
- assert status["id"] == announce_activity.id
- assert status["user"] == UserView.render("show.json", %{user: user, for: user})
-
- retweeted_status =
- ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
-
- assert retweeted_status["repeated"] == true
- assert retweeted_status["id"] == note_activity.id
- assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
-
- assert status["retweeted_status"] == retweeted_status
- assert status["activity_type"] == "repeat"
- end
-
test "a like activity" do
user = insert(:user)
note_activity = insert(:note_activity)
@@ -168,6 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
"card" => nil,
+ "muted" => false,
"summary" => "2hu :2hu:",
"summary_html" =>
"2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" />"
@@ -180,18 +151,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}) == expected_status
end
- test "an undo for a follow" do
- follower = insert(:user)
- followed = insert(:user)
-
- {:ok, _follow} = ActivityPub.follow(follower, followed)
- {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
-
- map = ActivityRepresenter.to_map(unfollow, %{user: follower})
- assert map["is_post_verb"] == false
- assert map["activity_type"] == "undo"
- end
-
test "a delete activity" do
object = insert(:note)
user = User.get_by_ap_id(object.data["actor"])
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 4f854ecaa..0a5384f34 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -56,6 +56,22 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
assert result["user"]["id"] == user.id
end
+ test "tells if the message is muted for some reason" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ status = ActivityView.render("activity.json", %{activity: activity})
+
+ assert status["muted"] == false
+
+ status = ActivityView.render("activity.json", %{activity: activity, for: user})
+
+ assert status["muted"] == true
+ end
+
test "a create activity with a html status" do
text = """
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
@@ -149,7 +165,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
"visibility" => "direct",
- "card" => nil
+ "card" => nil,
+ "muted" => false
}
assert result == expected
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 95e52ca46..114f24a1c 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -239,6 +239,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
assert represented["role"] == nil
end
+ test "A regular user for the admin", %{user: user} do
+ admin = insert(:user, %{info: %{is_admin: true}})
+ represented = UserView.render("show.json", %{user: user, for: admin})
+
+ assert represented["pleroma"]["deactivated"] == false
+ end
+
test "A blocked user for the blocker" do
user = insert(:user)
blocker = insert(:user)