From 61ca2f7a4ed1bfa5b5ae4da5b28ca3c546b1e141 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 28 Apr 2019 19:42:43 +0300 Subject: [PATCH] Fix `rights` in TwitterAPI's user entity being present only for Admins/Moderators In !1093 I reused `maybe_with_role` for `rights` object, however I missed that `maybe_with_role` is called only for admins/moderators. --- lib/pleroma/web/twitter_api/views/user_view.ex | 7 +------ test/web/twitter_api/views/user_view_test.exs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 39b3f21c0..ea015b8f0 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -116,12 +116,7 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do |> maybe_with_activation_status(user, for_user) } |> maybe_with_user_settings(user, for_user) - - data = - if(user.info.is_admin || user.info.is_moderator, - do: maybe_with_role(data, user, for_user), - else: data - ) + |> maybe_with_role(user, for_user) if assigns[:token] do Map.put(data, "token", token_string(assigns[:token])) diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 2f9b2af01..c99dbddeb 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -100,7 +100,9 @@ test "A user" do "pleroma" => %{ "confirmation_pending" => false, "tags" => [] - } + }, + "rights" => %{"admin" => false, "delete_others_notice" => false}, + "role" => "member" } assert represented == UserView.render("show.json", %{user: user}) @@ -151,7 +153,9 @@ test "A user for a given other follower", %{user: user} do "pleroma" => %{ "confirmation_pending" => false, "tags" => [] - } + }, + "rights" => %{"admin" => false, "delete_others_notice" => false}, + "role" => "member" } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -194,7 +198,9 @@ test "A user that follows you", %{user: user} do "pleroma" => %{ "confirmation_pending" => false, "tags" => [] - } + }, + "rights" => %{"admin" => false, "delete_others_notice" => false}, + "role" => "member" } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -274,7 +280,9 @@ test "A blocked user for the blocker" do "pleroma" => %{ "confirmation_pending" => false, "tags" => [] - } + }, + "rights" => %{"admin" => false, "delete_others_notice" => false}, + "role" => "member" } blocker = User.get_cached_by_id(blocker.id)