Merge branch 'admin-api-account-view-namespace' into 'develop'
authorkaniini <nenolod@gmail.com>
Thu, 14 Mar 2019 02:01:10 +0000 (02:01 +0000)
committerkaniini <nenolod@gmail.com>
Thu, 14 Mar 2019 02:01:10 +0000 (02:01 +0000)
MastodonAPI.Admin.AccountView → AdminAPI.AccountView

See merge request pleroma/pleroma!930

lib/pleroma/web/admin_api/views/account_view.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

index c022fb07d2879b752b8a9b2a54b83e3b61f5d980..4d6f921efc7ed032d1d230f0cdfa2abe6dc43fc6 100644 (file)
@@ -21,7 +21,9 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
       "id" => user.id,
       "nickname" => user.nickname,
       "deactivated" => user.info.deactivated,
-      "roles" => Info.roles(user.info)
+      "local" => user.local,
+      "roles" => Info.roles(user.info),
+      "tags" => user.tags || []
     }
   end
 end
index 12b3d308ce31a3a33d0eaeba77b0a894c2cc7329..de0759fb09279995aa4f0c051586409cb8a716d9 100644 (file)
@@ -27,6 +27,42 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
+  def unfollow(follower, unfollowed) do
+    with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
+         {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
+      {:ok, follower}
+    end
+  end
+
+  def accept_follow_request(follower, followed) do
+    with {:ok, follower} <- User.maybe_follow(follower, followed),
+         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
+         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
+         {:ok, _activity} <-
+           ActivityPub.accept(%{
+             to: [follower.ap_id],
+             actor: followed,
+             object: follow_activity.data["id"],
+             type: "Accept"
+           }) do
+      {:ok, follower}
+    end
+  end
+
+  def reject_follow_request(follower, followed) do
+    with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
+         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
+         {:ok, _activity} <-
+           ActivityPub.reject(%{
+             to: [follower.ap_id],
+             actor: followed,
+             object: follow_activity.data["id"],
+             type: "Reject"
+           }) do
+      {:ok, follower}
+    end
+  end
+
   def delete(activity_id, user) do
     with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
          %Object{} = object <- Object.normalize(object_id),
index 88e0249a60672bdd0613d85ff51c3dc21559b816..e578f707e0a081073a94483bb82109840b623cbf 100644 (file)
@@ -15,7 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   alias Pleroma.User
   alias Pleroma.Web
   alias Pleroma.Web.ActivityPub.ActivityPub
-  alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.MastodonAPI.AccountView
@@ -697,16 +696,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
     with %User{} = follower <- Repo.get(User, id),
-         {:ok, follower} <- User.maybe_follow(follower, followed),
-         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
-         {:ok, _activity} <-
-           ActivityPub.accept(%{
-             to: [follower.ap_id],
-             actor: followed,
-             object: follow_activity.data["id"],
-             type: "Accept"
-           }) do
+         {:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
       conn
       |> put_view(AccountView)
       |> render("relationship.json", %{user: followed, target: follower})
@@ -720,15 +710,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
     with %User{} = follower <- Repo.get(User, id),
-         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
-         {:ok, _activity} <-
-           ActivityPub.reject(%{
-             to: [follower.ap_id],
-             actor: followed,
-             object: follow_activity.data["id"],
-             type: "Reject"
-           }) do
+         {:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
       conn
       |> put_view(AccountView)
       |> render("relationship.json", %{user: followed, target: follower})
@@ -770,8 +752,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
     with %User{} = followed <- Repo.get(User, id),
-         {:ok, _activity} <- ActivityPub.unfollow(follower, followed),
-         {:ok, follower, _} <- User.unfollow(follower, followed) do
+         {:ok, follower} <- CommonAPI.unfollow(follower, followed) do
       conn
       |> put_view(AccountView)
       |> render("relationship.json", %{user: follower, target: followed})
@@ -1129,7 +1110,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
           compose: %{
             me: "#{user.id}",
             default_privacy: user.info.default_scope,
-            default_sensitive: false
+            default_sensitive: false,
+            allow_content_types: Config.get([:instance, :allowed_post_formats])
           },
           media_attachments: %{
             accept_content_types: [
index a22e765c7ed1d7f0c8aa5c83261f1492d59aa77a..d57100491d155638a66eb8a1b652d2107545891a 100644 (file)
@@ -35,11 +35,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
 
   def unfollow(%User{} = follower, params) do
     with {:ok, %User{} = unfollowed} <- get_user(params),
-         {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
-         {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
+         {:ok, follower} <- CommonAPI.unfollow(follower, unfollowed) do
       {:ok, follower, unfollowed}
-    else
-      err -> err
     end
   end
 
index 8221b2324c2a2fcb7acfe244d798a81474b985a6..6ea0b110ba7f74a82ee19906c22d97a409649109 100644 (file)
@@ -14,7 +14,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   alias Pleroma.Repo
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
-  alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.OAuth.Token
@@ -588,16 +587,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   def approve_friend_request(conn, %{"user_id" => uid} = _params) do
     with followed <- conn.assigns[:user],
          %User{} = follower <- Repo.get(User, uid),
-         {:ok, follower} <- User.maybe_follow(follower, followed),
-         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
-         {:ok, _activity} <-
-           ActivityPub.accept(%{
-             to: [follower.ap_id],
-             actor: followed,
-             object: follow_activity.data["id"],
-             type: "Accept"
-           }) do
+         {:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
       conn
       |> put_view(UserView)
       |> render("show.json", %{user: follower, for: followed})
@@ -609,15 +599,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
   def deny_friend_request(conn, %{"user_id" => uid} = _params) do
     with followed <- conn.assigns[:user],
          %User{} = follower <- Repo.get(User, uid),
-         %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
-         {:ok, _activity} <-
-           ActivityPub.reject(%{
-             to: [follower.ap_id],
-             actor: followed,
-             object: follow_activity.data["id"],
-             type: "Reject"
-           }) do
+         {:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
       conn
       |> put_view(UserView)
       |> render("show.json", %{user: follower, for: followed})
index 0470a439bef958b5a541ddc0e8d43a1ba46dcd10..e50f0edde1e4a98e34651c3a6d18dc435988560f 100644 (file)
@@ -334,7 +334,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
   describe "GET /api/pleroma/admin/users" do
     test "renders users array for the first page" do
       admin = insert(:user, info: %{is_admin: true})
-      user = insert(:user)
+      user = insert(:user, local: false, tags: ["foo", "bar"])
 
       conn =
         build_conn()
@@ -349,13 +349,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => admin.info.deactivated,
                    "id" => admin.id,
                    "nickname" => admin.nickname,
-                   "roles" => %{"admin" => true, "moderator" => false}
+                   "roles" => %{"admin" => true, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  },
                  %{
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
                    "nickname" => user.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => false,
+                   "tags" => ["foo", "bar"]
                  }
                ]
              }
@@ -394,7 +398,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
                    "nickname" => user.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  }
                ]
              }
@@ -418,7 +424,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
                    "nickname" => user.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  }
                ]
              }
@@ -436,7 +444,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => user2.info.deactivated,
                    "id" => user2.id,
                    "nickname" => user2.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  }
                ]
              }
@@ -461,7 +471,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
                    "nickname" => user.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  }
                ]
              }
@@ -486,13 +498,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "deactivated" => admin.info.deactivated,
                    "id" => admin.id,
                    "nickname" => admin.nickname,
-                   "roles" => %{"admin" => true, "moderator" => false}
+                   "roles" => %{"admin" => true, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  },
                  %{
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
                    "nickname" => user.nickname,
-                   "roles" => %{"admin" => false, "moderator" => false}
+                   "roles" => %{"admin" => false, "moderator" => false},
+                   "local" => true,
+                   "tags" => []
                  }
                ]
              }
@@ -513,7 +529,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                "deactivated" => !user.info.deactivated,
                "id" => user.id,
                "nickname" => user.nickname,
-               "roles" => %{"admin" => false, "moderator" => false}
+               "roles" => %{"admin" => false, "moderator" => false},
+               "local" => true,
+               "tags" => []
              }
   end
 end