From 2f40a92647857616698a4199b399f61585186b84 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 14 Jun 2021 20:20:08 -0500 Subject: [PATCH] accepts_newsletter --> accepts_email_list --- lib/pleroma/user.ex | 10 +++++----- lib/pleroma/user/email_list.ex | 2 +- lib/pleroma/web/api_spec/operations/account_operation.ex | 4 ++-- .../web/mastodon_api/controllers/account_controller.ex | 2 +- lib/pleroma/web/mastodon_api/views/account_view.ex | 10 +++++----- lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- .../20210612185407_add_email_list_field_to_users.exs | 9 +++++++++ .../20210612185407_add_newsletter_field_to_users.exs | 9 --------- test/pleroma/user_test.exs | 14 +++++++------- .../mastodon_api/controllers/account_controller_test.exs | 8 ++++---- test/pleroma/web/mastodon_api/update_credentials_test.exs | 4 ++-- test/pleroma/web/mastodon_api/views/account_view_test.exs | 6 +++--- test/pleroma/web/twitter_api/twitter_api_test.exs | 6 +++--- 13 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 priv/repo/migrations/20210612185407_add_email_list_field_to_users.exs delete mode 100644 priv/repo/migrations/20210612185407_add_newsletter_field_to_users.exs diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 35910aaff..ef5639500 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -148,7 +148,7 @@ defmodule Pleroma.User do field(:accepts_chat_messages, :boolean, default: nil) field(:last_active_at, :naive_datetime) field(:disclose_client, :boolean, default: true) - field(:accepts_newsletter, :boolean, default: false) + field(:accepts_email_list, :boolean, default: false) embeds_one( :notification_settings, @@ -517,7 +517,7 @@ defmodule Pleroma.User do :actor_type, :accepts_chat_messages, :disclose_client, - :accepts_newsletter + :accepts_email_list ] ) |> unique_constraint(:nickname) @@ -681,7 +681,7 @@ defmodule Pleroma.User do :nickname, :email, :accepts_chat_messages, - :accepts_newsletter + :accepts_email_list ]) |> validate_required([:name, :nickname]) |> unique_constraint(:nickname) @@ -726,7 +726,7 @@ defmodule Pleroma.User do :emoji, :accepts_chat_messages, :registration_reason, - :accepts_newsletter + :accepts_email_list ]) |> validate_required([:name, :nickname, :password, :password_confirmation]) |> validate_confirmation(:password) @@ -1714,7 +1714,7 @@ defmodule Pleroma.User do raw_fields: [], is_discoverable: false, also_known_as: [], - accepts_newsletter: false + accepts_email_list: false }) end diff --git a/lib/pleroma/user/email_list.ex b/lib/pleroma/user/email_list.ex index f6e5ea619..70850941a 100644 --- a/lib/pleroma/user/email_list.ex +++ b/lib/pleroma/user/email_list.ex @@ -19,7 +19,7 @@ defmodule Pleroma.User.EmailList do is_active: true, is_approved: true, is_confirmed: true, - accepts_newsletter: true + accepts_email_list: true }) |> where([u], not is_nil(u.email)) end diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 0dec46139..ae34ca726 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -459,7 +459,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do nullable: true, description: "Invite token required when the registrations aren't public" }, - accepts_newsletter: %Schema{ + accepts_email_list: %Schema{ allOf: [BooleanLike], description: "Whether the user opts-in to receiving news and marketing updates from site admins. These should be presented to the user in order to allow them to consent before setting this parameter to TRUE." @@ -641,7 +641,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do "Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed." }, actor_type: ActorType, - accepts_newsletter: %Schema{ + accepts_email_list: %Schema{ allOf: [BooleanLike], description: "Whether the user opts-in to receiving news and marketing updates from site admins." diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index c7e21a0d2..e6f41757e 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do :allow_following_move, :also_known_as, :accepts_chat_messages, - :accepts_newsletter + :accepts_email_list ] |> Enum.reduce(%{}, fn key, acc -> Maps.put_if_present(acc, key, params[key], &{:ok, truthy_param?(&1)}) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index c3a0be006..fc1536440 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -292,7 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do |> maybe_put_allow_following_move(user, opts[:for]) |> maybe_put_unread_conversation_count(user, opts[:for]) |> maybe_put_unread_notification_count(user, opts[:for]) - |> maybe_put_accepts_newsletter(user, opts[:for]) + |> maybe_put_accepts_email_list(user, opts[:for]) end defp username_from_nickname(string) when is_binary(string) do @@ -404,15 +404,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do defp maybe_put_unread_notification_count(data, _, _), do: data - defp maybe_put_accepts_newsletter(data, %User{id: user_id}, %User{id: user_id} = user) do + defp maybe_put_accepts_email_list(data, %User{id: user_id}, %User{id: user_id} = user) do Kernel.put_in( data, - [:pleroma, :accepts_newsletter], - user.accepts_newsletter + [:pleroma, :accepts_email_list], + user.accepts_email_list ) end - defp maybe_put_accepts_newsletter(data, _, _), do: data + defp maybe_put_accepts_email_list(data, _, _), do: data defp image_url(%{"url" => [%{"href" => href} | _]}), do: href defp image_url(_), do: nil diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index f6250a313..132ecb610 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def register_user(params, opts \\ []) do params = params - |> Map.take([:email, :token, :password, :accepts_newsletter]) + |> Map.take([:email, :token, :password, :accepts_email_list]) |> Map.put(:bio, params |> Map.get(:bio, "") |> User.parse_bio()) |> Map.put(:nickname, params[:username]) |> Map.put(:name, Map.get(params, :fullname, params[:username])) diff --git a/priv/repo/migrations/20210612185407_add_email_list_field_to_users.exs b/priv/repo/migrations/20210612185407_add_email_list_field_to_users.exs new file mode 100644 index 000000000..e8da99f1f --- /dev/null +++ b/priv/repo/migrations/20210612185407_add_email_list_field_to_users.exs @@ -0,0 +1,9 @@ +defmodule Pleroma.Repo.Migrations.AddEmailListFieldToUsers do + use Ecto.Migration + + def change do + alter table(:users) do + add(:accepts_email_list, :boolean, default: false) + end + end +end diff --git a/priv/repo/migrations/20210612185407_add_newsletter_field_to_users.exs b/priv/repo/migrations/20210612185407_add_newsletter_field_to_users.exs deleted file mode 100644 index ee46a6076..000000000 --- a/priv/repo/migrations/20210612185407_add_newsletter_field_to_users.exs +++ /dev/null @@ -1,9 +0,0 @@ -defmodule Pleroma.Repo.Migrations.AddNewsletterFieldToUsers do - use Ecto.Migration - - def change do - alter table(:users) do - add(:accepts_newsletter, :boolean, default: false) - end - end -end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 2cfd54d52..5f008acb1 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -664,14 +664,14 @@ defmodule Pleroma.UserTest do assert user.is_confirmed end - test "it sets 'accepts_newsletter'" do - params = Map.put_new(@full_user_data, :accepts_newsletter, true) + test "it sets 'accepts_email_list'" do + params = Map.put_new(@full_user_data, :accepts_email_list, true) changeset = User.register_changeset(%User{}, params) assert changeset.valid? {:ok, user} = Repo.insert(changeset) - assert user.accepts_newsletter + assert user.accepts_email_list end end @@ -748,13 +748,13 @@ defmodule Pleroma.UserTest do end describe "update_changeset/2" do - test "it sets :accepts_newsletter" do + test "it sets :accepts_email_list" do changeset = - %User{accepts_newsletter: false} - |> User.update_changeset(%{accepts_newsletter: true}) + %User{accepts_email_list: false} + |> User.update_changeset(%{accepts_email_list: true}) assert changeset.valid? - assert %User{accepts_newsletter: true} = Ecto.Changeset.apply_changes(changeset) + assert %User{accepts_email_list: true} = Ecto.Changeset.apply_changes(changeset) end end diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index 3558394fd..9ddd5c935 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -1125,7 +1125,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do assert user assert user.is_confirmed assert user.is_approved - refute user.accepts_newsletter + refute user.accepts_email_list end test "registers but does not log in with :account_activation_required", %{conn: conn} do @@ -1357,7 +1357,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do assert json_response_and_validate_schema(res, 200) end - test "registration with accepts_newsletter", %{conn: conn, valid_params: valid_params} do + test "registration with accepts_email_list", %{conn: conn, valid_params: valid_params} do app_token = insert(:oauth_token, user: nil) conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token) @@ -1365,10 +1365,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do conn |> put_req_header("content-type", "application/json") |> Map.put(:remote_ip, {127, 0, 0, 9}) - |> post("/api/v1/accounts", Map.put(valid_params, :accepts_newsletter, true)) + |> post("/api/v1/accounts", Map.put(valid_params, :accepts_email_list, true)) assert json_response_and_validate_schema(res, 200) - assert %User{accepts_newsletter: true} = Repo.get_by(User, email: "lain@example.org") + assert %User{accepts_email_list: true} = Repo.get_by(User, email: "lain@example.org") end test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index 21917e282..fd2eadd1b 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -114,10 +114,10 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do end test "updates the user's newsletter preference", %{user: user, conn: conn} do - conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_newsletter: "true"}) + conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_email_list: "true"}) assert json_response_and_validate_schema(conn, 200) - assert %User{accepts_newsletter: true} = User.get_by_id(user.id) + assert %User{accepts_email_list: true} = User.get_by_id(user.id) end test "updates the user's allow_following_move", %{user: user, conn: conn} do diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index a0a4d1ac6..96cec6652 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -470,7 +470,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do end end - test "shows accepts_newsletter only to the account owner" do + test "shows accepts_email_list only to the account owner" do user = insert(:user) other_user = insert(:user) @@ -479,12 +479,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do assert AccountView.render( "show.json", %{user: user, for: other_user} - )[:pleroma][:accepts_newsletter] == nil + )[:pleroma][:accepts_email_list] == nil assert AccountView.render( "show.json", %{user: user, for: user} - )[:pleroma][:accepts_newsletter] == user.accepts_newsletter + )[:pleroma][:accepts_email_list] == user.accepts_email_list end describe "follow requests counter" do diff --git a/test/pleroma/web/twitter_api/twitter_api_test.exs b/test/pleroma/web/twitter_api/twitter_api_test.exs index 295a57d71..ac841b1f1 100644 --- a/test/pleroma/web/twitter_api/twitter_api_test.exs +++ b/test/pleroma/web/twitter_api/twitter_api_test.exs @@ -146,18 +146,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert user2.bio == expected_text end - test "it registers a new user with accepts_newsletter." do + test "it registers a new user with accepts_email_list." do data = %{ :username => "lain", :email => "lain@wired.jp", :fullname => "lain iwakura", :password => "bear", :confirm => "bear", - :accepts_newsletter => true + :accepts_email_list => true } {:ok, user} = TwitterAPI.register_user(data) - assert user.accepts_newsletter + assert user.accepts_email_list end describe "register with one time token" do