Browse Source

User: Add settings store to Info, AccountView

This is to provide a generic frontend settings storage mechanism for all kinds
of frontends.
tags/v1.1.4
lain 5 years ago
parent
commit
eb2963bc43
3 changed files with 26 additions and 0 deletions
  1. +1
    -0
      lib/pleroma/user/info.ex
  2. +10
    -0
      lib/pleroma/web/mastodon_api/views/account_view.ex
  3. +15
    -0
      test/web/mastodon_api/account_view_test.exs

+ 1
- 0
lib/pleroma/user/info.ex View File

@@ -45,6 +45,7 @@ defmodule Pleroma.User.Info do
field(:flavour, :string, default: nil)
field(:mascot, :map, default: nil)
field(:emoji, {:array, :map}, default: [])
field(:pleroma_settings_store, :map, default: %{})

field(:notification_settings, :map,
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}


+ 10
- 0
lib/pleroma/web/mastodon_api/views/account_view.ex View File

@@ -130,6 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|> maybe_put_role(user, opts[:for])
|> maybe_put_settings(user, opts[:for], user_info)
|> maybe_put_notification_settings(user, opts[:for])
|> maybe_put_settings_store(user, opts[:for], opts)
end

defp username_from_nickname(string) when is_binary(string) do
@@ -152,6 +153,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do

defp maybe_put_settings(data, _, _, _), do: data

defp maybe_put_settings_store(data, %User{info: info, id: id}, %User{id: id}, %{
with_pleroma_settings: true
}) do
data
|> Kernel.put_in([:pleroma, :settings], info.pleroma_settings_store)
end

defp maybe_put_settings_store(data, _, _, _), do: data

defp maybe_put_role(data, %User{info: %{show_role: true}} = user, _) do
data
|> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin)


+ 15
- 0
test/web/mastodon_api/account_view_test.exs View File

@@ -239,4 +239,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do

assert expected == AccountView.render("account.json", %{user: user, for: other_user})
end

test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})

result =
AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})

assert result.pleroma.settings == %{:fe => "test"}

result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
assert result.pleroma[:settings] == nil

result = AccountView.render("account.json", %{user: user, for: user})
assert result.pleroma[:settings] == nil
end
end

Loading…
Cancel
Save