aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-06-09 09:36:07 +0200
committerlain <lain@soykaf.club>2020-06-09 09:36:07 +0200
commit064c4f86f32b626a626fbc238f09434617f57a90 (patch)
tree0f36da23c31c76554659aab55da4dc5c64f4b307 /lib
parent40d5058cc4d8b235fa1ea7842c511f08df346c61 (diff)
parent674efb0ad2b34cbd4bbb32d414a2c8fa8719cc02 (diff)
downloadpleroma-064c4f86f32b626a626fbc238f09434617f57a90.tar.gz
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/following_relationship.ex6
-rw-r--r--lib/pleroma/user.ex8
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex6
-rw-r--r--lib/pleroma/web/admin_api/controllers/admin_api_controller.ex48
-rw-r--r--lib/pleroma/web/admin_api/controllers/relay_controller.ex67
-rw-r--r--lib/pleroma/web/api_spec/operations/admin/relay_operation.ex83
-rw-r--r--lib/pleroma/web/router.ex6
7 files changed, 171 insertions, 53 deletions
diff --git a/lib/pleroma/following_relationship.ex b/lib/pleroma/following_relationship.ex
index 3a3082e72..093b1f405 100644
--- a/lib/pleroma/following_relationship.ex
+++ b/lib/pleroma/following_relationship.ex
@@ -141,6 +141,12 @@ defmodule Pleroma.FollowingRelationship do
|> where([r], r.state == ^:follow_accept)
end
+ def outgoing_pending_follow_requests_query(%User{} = follower) do
+ __MODULE__
+ |> where([r], r.follower_id == ^follower.id)
+ |> where([r], r.state == ^:follow_pending)
+ end
+
def following(%User{} = user) do
following =
following_query(user)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 72ee2d58e..c5c74d132 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1489,6 +1489,8 @@ defmodule Pleroma.User do
delete_user_activities(user)
+ delete_outgoing_pending_follow_requests(user)
+
delete_or_deactivate(user)
end
@@ -1611,6 +1613,12 @@ defmodule Pleroma.User do
defp delete_activity(_activity, _user), do: "Doing nothing"
+ defp delete_outgoing_pending_follow_requests(user) do
+ user
+ |> FollowingRelationship.outgoing_pending_follow_requests_query()
+ |> Repo.delete_all()
+ end
+
def html_filter_policy(%User{no_rich_text: true}) do
Pleroma.HTML.Scrubber.TwitterText
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index d2347cdc9..985921aa0 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -222,9 +222,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
media_type =
cond do
- is_map(url) && is_binary(url["mediaType"]) -> url["mediaType"]
- is_binary(data["mediaType"]) -> data["mediaType"]
- is_binary(data["mimeType"]) -> data["mimeType"]
+ is_map(url) && MIME.valid?(url["mediaType"]) -> url["mediaType"]
+ MIME.valid?(data["mediaType"]) -> data["mediaType"]
+ MIME.valid?(data["mimeType"]) -> data["mimeType"]
true -> nil
end
diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
index edd3abc63..5cbf0dd4f 100644
--- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
@@ -16,7 +16,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Builder
alias Pleroma.Web.ActivityPub.Pipeline
- alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.AdminAPI
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.AdminAPI.ModerationLogView
@@ -59,7 +58,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
plug(
OAuthScopesPlug,
%{scopes: ["write:follows"], admin: true}
- when action in [:user_follow, :user_unfollow, :relay_follow, :relay_unfollow]
+ when action in [:user_follow, :user_unfollow]
)
plug(
@@ -74,7 +73,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
when action in [
:list_log,
:stats,
- :relay_list,
:need_reboot
]
)
@@ -491,50 +489,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
render_error(conn, :forbidden, "You can't revoke your own admin status.")
end
- def relay_list(conn, _params) do
- with {:ok, list} <- Relay.list() do
- json(conn, %{relays: list})
- else
- _ ->
- conn
- |> put_status(500)
- end
- end
-
- def relay_follow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do
- with {:ok, _message} <- Relay.follow(target) do
- ModerationLog.insert_log(%{
- action: "relay_follow",
- actor: admin,
- target: target
- })
-
- json(conn, target)
- else
- _ ->
- conn
- |> put_status(500)
- |> json(target)
- end
- end
-
- def relay_unfollow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do
- with {:ok, _message} <- Relay.unfollow(target) do
- ModerationLog.insert_log(%{
- action: "relay_unfollow",
- actor: admin,
- target: target
- })
-
- json(conn, target)
- else
- _ ->
- conn
- |> put_status(500)
- |> json(target)
- end
- end
-
@doc "Get a password reset token (base64 string) for given nickname"
def get_password_reset(conn, %{"nickname" => nickname}) do
(%User{local: true} = user) = User.get_cached_by_nickname(nickname)
diff --git a/lib/pleroma/web/admin_api/controllers/relay_controller.ex b/lib/pleroma/web/admin_api/controllers/relay_controller.ex
new file mode 100644
index 000000000..cf9f3a14b
--- /dev/null
+++ b/lib/pleroma/web/admin_api/controllers/relay_controller.ex
@@ -0,0 +1,67 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.AdminAPI.RelayController do
+ use Pleroma.Web, :controller
+
+ alias Pleroma.ModerationLog
+ alias Pleroma.Plugs.OAuthScopesPlug
+ alias Pleroma.Web.ActivityPub.Relay
+
+ require Logger
+
+ plug(Pleroma.Web.ApiSpec.CastAndValidate)
+
+ plug(
+ OAuthScopesPlug,
+ %{scopes: ["write:follows"], admin: true}
+ when action in [:follow, :unfollow]
+ )
+
+ plug(OAuthScopesPlug, %{scopes: ["read"], admin: true} when action == :index)
+
+ action_fallback(Pleroma.Web.AdminAPI.FallbackController)
+
+ defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.RelayOperation
+
+ def index(conn, _params) do
+ with {:ok, list} <- Relay.list() do
+ json(conn, %{relays: list})
+ end
+ end
+
+ def follow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
+ with {:ok, _message} <- Relay.follow(target) do
+ ModerationLog.insert_log(%{
+ action: "relay_follow",
+ actor: admin,
+ target: target
+ })
+
+ json(conn, target)
+ else
+ _ ->
+ conn
+ |> put_status(500)
+ |> json(target)
+ end
+ end
+
+ def unfollow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
+ with {:ok, _message} <- Relay.unfollow(target) do
+ ModerationLog.insert_log(%{
+ action: "relay_unfollow",
+ actor: admin,
+ target: target
+ })
+
+ json(conn, target)
+ else
+ _ ->
+ conn
+ |> put_status(500)
+ |> json(target)
+ end
+ end
+end
diff --git a/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex b/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex
new file mode 100644
index 000000000..7672cb467
--- /dev/null
+++ b/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex
@@ -0,0 +1,83 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
+ alias OpenApiSpex.Operation
+ alias OpenApiSpex.Schema
+
+ import Pleroma.Web.ApiSpec.Helpers
+
+ def open_api_operation(action) do
+ operation = String.to_existing_atom("#{action}_operation")
+ apply(__MODULE__, operation, [])
+ end
+
+ def index_operation do
+ %Operation{
+ tags: ["Admin", "Relays"],
+ summary: "List Relays",
+ operationId: "AdminAPI.RelayController.index",
+ security: [%{"oAuth" => ["read"]}],
+ responses: %{
+ 200 =>
+ Operation.response("Response", "application/json", %Schema{
+ type: :object,
+ properties: %{
+ relays: %Schema{
+ type: :array,
+ items: %Schema{type: :string},
+ example: ["lain.com", "mstdn.io"]
+ }
+ }
+ })
+ }
+ }
+ end
+
+ def follow_operation do
+ %Operation{
+ tags: ["Admin", "Relays"],
+ summary: "Follow a Relay",
+ operationId: "AdminAPI.RelayController.follow",
+ security: [%{"oAuth" => ["write:follows"]}],
+ requestBody:
+ request_body("Parameters", %Schema{
+ type: :object,
+ properties: %{
+ relay_url: %Schema{type: :string, format: :uri}
+ }
+ }),
+ responses: %{
+ 200 =>
+ Operation.response("Status", "application/json", %Schema{
+ type: :string,
+ example: "http://mastodon.example.org/users/admin"
+ })
+ }
+ }
+ end
+
+ def unfollow_operation do
+ %Operation{
+ tags: ["Admin", "Relays"],
+ summary: "Unfollow a Relay",
+ operationId: "AdminAPI.RelayController.unfollow",
+ security: [%{"oAuth" => ["write:follows"]}],
+ requestBody:
+ request_body("Parameters", %Schema{
+ type: :object,
+ properties: %{
+ relay_url: %Schema{type: :string, format: :uri}
+ }
+ }),
+ responses: %{
+ 200 =>
+ Operation.response("Status", "application/json", %Schema{
+ type: :string,
+ example: "http://mastodon.example.org/users/admin"
+ })
+ }
+ }
+ end
+end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index bc4f0b237..57570b672 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -160,9 +160,9 @@ defmodule Pleroma.Web.Router do
:right_delete_multiple
)
- get("/relay", AdminAPIController, :relay_list)
- post("/relay", AdminAPIController, :relay_follow)
- delete("/relay", AdminAPIController, :relay_unfollow)
+ get("/relay", RelayController, :index)
+ post("/relay", RelayController, :follow)
+ delete("/relay", RelayController, :unfollow)
post("/users/invite_token", InviteController, :create)
get("/users/invites", InviteController, :index)