[#1304]. Post-merge fixes. Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into 1304-user-info-deprecation

# Conflicts:
#	CHANGELOG.md
#	lib/pleroma/notification.ex
#	lib/pleroma/user.ex
#	lib/pleroma/user/info.ex
#	lib/pleroma/web/admin_api/admin_api_controller.ex
#	lib/pleroma/web/ostatus/handlers/follow_handler.ex
#	lib/pleroma/web/ostatus/ostatus.ex
#	lib/pleroma/web/salmon/salmon.ex
#	lib/pleroma/web/websub/websub.ex
#	test/web/admin_api/admin_api_controller_test.exs
#	test/web/federator_test.exs
#	test/web/mastodon_api/controllers/conversation_controller_test.exs
#	test/web/ostatus/ostatus_controller_test.exs
#	test/web/ostatus/ostatus_test.exs
#	test/web/salmon/salmon_test.exs
#	test/web/websub/websub_test.exs
This commit is contained in:
Ivan Tashkinov 2019-10-20 22:29:56 +03:00
parent c6fdfbc4f1
commit ee04fbc35a
7 changed files with 20 additions and 53 deletions

View File

@ -180,7 +180,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
- `nicknames`: nicknames array - `nicknames`: nicknames array
- Response: - Response:
- On failure: `{"error": "…"}` - On failure: `{"error": "…"}`
- On success: JSON of the `user.info` - On success: JSON of the user
## DEPRECATED `DELETE /api/pleroma/admin/users/:nickname/permission_group/:permission_group` ## DEPRECATED `DELETE /api/pleroma/admin/users/:nickname/permission_group/:permission_group`
@ -200,7 +200,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
- `nicknames`: nicknames array - `nicknames`: nicknames array
- Response: - Response:
- On failure: `{"error": "…"}` - On failure: `{"error": "…"}`
- On success: JSON of the `user.info` - On success: JSON of the user
- Note: An admin cannot revoke their own admin status. - Note: An admin cannot revoke their own admin status.
## `PATCH /api/pleroma/admin/users/activate` ## `PATCH /api/pleroma/admin/users/activate`

View File

@ -89,9 +89,6 @@ defmodule Pleroma.User do
field(:settings, :map, default: nil) field(:settings, :map, default: nil)
field(:magic_key, :string, default: nil) field(:magic_key, :string, default: nil)
field(:uri, :string, default: nil) field(:uri, :string, default: nil)
field(:topic, :string, default: nil)
field(:hub, :string, default: nil)
field(:salmon, :string, default: nil)
field(:hide_followers_count, :boolean, default: false) field(:hide_followers_count, :boolean, default: false)
field(:hide_follows_count, :boolean, default: false) field(:hide_follows_count, :boolean, default: false)
field(:hide_followers, :boolean, default: false) field(:hide_followers, :boolean, default: false)
@ -250,9 +247,6 @@ defmodule Pleroma.User do
:settings, :settings,
:magic_key, :magic_key,
:uri, :uri,
:topic,
:hub,
:salmon,
:hide_followers_count, :hide_followers_count,
:hide_follows_count, :hide_follows_count,
:hide_followers, :hide_followers,
@ -317,9 +311,6 @@ defmodule Pleroma.User do
:locked, :locked,
:magic_key, :magic_key,
:uri, :uri,
:hub,
:topic,
:salmon,
:hide_followers, :hide_followers,
:hide_follows, :hide_follows,
:hide_followers_count, :hide_followers_count,
@ -1453,7 +1444,7 @@ defmodule Pleroma.User do
{:ok, key} {:ok, key}
end end
def public_key_from_info(_), do: {:error, "not found key"} def public_key(_), do: {:error, "not found key"}
def get_public_key_for_ap_id(ap_id) do def get_public_key_for_ap_id(ap_id) do
with {:ok, %User{} = user} <- get_or_fetch_by_ap_id(ap_id), with {:ok, %User{} = user} <- get_or_fetch_by_ap_id(ap_id),

View File

@ -51,8 +51,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
:tag_users, :tag_users,
:untag_users, :untag_users,
:right_add, :right_add,
:right_delete, :right_delete
:set_activation_status
] ]
) )
@ -364,11 +363,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
"nicknames" => nicknames "nicknames" => nicknames
}) })
when permission_group in ["moderator", "admin"] do when permission_group in ["moderator", "admin"] do
info = Map.put(%{}, "is_" <> permission_group, true) update = %{:"is_#{permission_group}" => true}
users = nicknames |> Enum.map(&User.get_cached_by_nickname/1) users = nicknames |> Enum.map(&User.get_cached_by_nickname/1)
User.update_info(users, &User.Info.admin_api_update(&1, info)) for u <- users, do: User.admin_api_update(u, update)
ModerationLog.insert_log(%{ ModerationLog.insert_log(%{
action: "grant", action: "grant",
@ -377,7 +376,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group permission: permission_group
}) })
json(conn, info) json(conn, update)
end end
def right_add_multiple(conn, _) do def right_add_multiple(conn, _) do
@ -429,11 +428,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
) )
when permission_group in ["moderator", "admin"] do when permission_group in ["moderator", "admin"] do
with false <- Enum.member?(nicknames, admin_nickname) do with false <- Enum.member?(nicknames, admin_nickname) do
info = Map.put(%{}, "is_" <> permission_group, false) update = %{:"is_#{permission_group}" => false}
users = nicknames |> Enum.map(&User.get_cached_by_nickname/1) users = nicknames |> Enum.map(&User.get_cached_by_nickname/1)
User.update_info(users, &User.Info.admin_api_update(&1, info)) for u <- users, do: User.admin_api_update(u, update)
ModerationLog.insert_log(%{ ModerationLog.insert_log(%{
action: "revoke", action: "revoke",
@ -442,7 +441,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
permission: permission_group permission: permission_group
}) })
json(conn, info) json(conn, update)
else else
_ -> render_error(conn, :forbidden, "You can't revoke your own admin/moderator status.") _ -> render_error(conn, :forbidden, "You can't revoke your own admin/moderator status.")
end end
@ -481,25 +480,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
render_error(conn, :forbidden, "You can't revoke your own admin status.") render_error(conn, :forbidden, "You can't revoke your own admin status.")
end end
def set_activation_status(%{assigns: %{user: admin}} = conn, %{
"nickname" => nickname,
"status" => status
}) do
with {:ok, status} <- Ecto.Type.cast(:boolean, status),
%User{} = user <- User.get_cached_by_nickname(nickname),
{:ok, _} <- User.deactivate(user, !status) do
action = if(user.deactivated, do: "activate", else: "deactivate")
ModerationLog.insert_log(%{
actor: admin,
subject: user,
action: action
})
json_response(conn, :no_content, "")
end
end
def relay_list(conn, _params) do def relay_list(conn, _params) do
with {:ok, list} <- Relay.list() do with {:ok, list} <- Relay.list() do
json(conn, %{relays: list}) json(conn, %{relays: list})
@ -507,6 +487,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
_ -> _ ->
conn conn
|> put_status(500) |> put_status(500)
end
end
def relay_follow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do def relay_follow(%{assigns: %{user: admin}} = conn, %{"relay_url" => target}) do
with {:ok, _message} <- Relay.follow(target) do with {:ok, _message} <- Relay.follow(target) do

View File

@ -28,9 +28,6 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoaddsToUsers do
:settings, :settings,
:magic_key, :magic_key,
:uri, :uri,
:topic,
:hub,
:salmon,
:hide_followers_count, :hide_followers_count,
:hide_follows_count, :hide_follows_count,
:hide_followers, :hide_followers,
@ -121,9 +118,6 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoaddsToUsers do
add(:settings, :map, default: nil) add(:settings, :map, default: nil)
add(:magic_key, :text, default: nil) add(:magic_key, :text, default: nil)
add(:uri, :text, default: nil) add(:uri, :text, default: nil)
add(:topic, :text, default: nil)
add(:hub, :text, default: nil)
add(:salmon, :text, default: nil)
add(:hide_followers_count, :boolean, default: false, null: false) add(:hide_followers_count, :boolean, default: false, null: false)
add(:hide_follows_count, :boolean, default: false, null: false) add(:hide_follows_count, :boolean, default: false, null: false)
add(:hide_followers, :boolean, default: false, null: false) add(:hide_followers, :boolean, default: false, null: false)

View File

@ -36,8 +36,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
[%{read: true}] = Participation.for_user(user) [%{read: true}] = Participation.for_user(user)
[%{read: false} = participation] = Participation.for_user(other_user) [%{read: false} = participation] = Participation.for_user(other_user)
assert User.get_cached_by_id(user.id).info.unread_conversation_count == 0 assert User.get_cached_by_id(user.id).unread_conversation_count == 0
assert User.get_cached_by_id(other_user.id).info.unread_conversation_count == 1 assert User.get_cached_by_id(other_user.id).unread_conversation_count == 1
{:ok, _} = {:ok, _} =
CommonAPI.post(other_user, %{ CommonAPI.post(other_user, %{
@ -52,8 +52,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
[%{read: false}] = Participation.for_user(user) [%{read: false}] = Participation.for_user(user)
[%{read: true}] = Participation.for_user(other_user) [%{read: true}] = Participation.for_user(other_user)
assert User.get_cached_by_id(user.id).info.unread_conversation_count == 1 assert User.get_cached_by_id(user.id).unread_conversation_count == 1
assert User.get_cached_by_id(other_user.id).info.unread_conversation_count == 0 assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
end end
test "for a new conversation, it sets the recipents of the participation" do test "for a new conversation, it sets the recipents of the participation" do

View File

@ -95,8 +95,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
"visibility" => "direct" "visibility" => "direct"
}) })
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 0 assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 1 assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
[%{"id" => direct_conversation_id, "unread" => true}] = [%{"id" => direct_conversation_id, "unread" => true}] =
conn conn

View File

@ -108,7 +108,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
[participation2, participation1] = Participation.for_user(other_user) [participation2, participation1] = Participation.for_user(other_user)
assert Participation.get(participation2.id).read == false assert Participation.get(participation2.id).read == false
assert Participation.get(participation1.id).read == false assert Participation.get(participation1.id).read == false
assert User.get_cached_by_id(other_user.id).info.unread_conversation_count == 2 assert User.get_cached_by_id(other_user.id).unread_conversation_count == 2
[%{"unread" => false}, %{"unread" => false}] = [%{"unread" => false}, %{"unread" => false}] =
conn conn
@ -119,7 +119,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
[participation2, participation1] = Participation.for_user(other_user) [participation2, participation1] = Participation.for_user(other_user)
assert Participation.get(participation2.id).read == true assert Participation.get(participation2.id).read == true
assert Participation.get(participation1.id).read == true assert Participation.get(participation1.id).read == true
assert User.get_cached_by_id(other_user.id).info.unread_conversation_count == 0 assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
end end
describe "POST /api/v1/pleroma/notifications/read" do describe "POST /api/v1/pleroma/notifications/read" do