accepts_newsletter --> accepts_email_list
This commit is contained in:
parent
9ec3865725
commit
2f40a92647
13 changed files with 43 additions and 43 deletions
|
@ -148,7 +148,7 @@ defmodule Pleroma.User do
|
||||||
field(:accepts_chat_messages, :boolean, default: nil)
|
field(:accepts_chat_messages, :boolean, default: nil)
|
||||||
field(:last_active_at, :naive_datetime)
|
field(:last_active_at, :naive_datetime)
|
||||||
field(:disclose_client, :boolean, default: true)
|
field(:disclose_client, :boolean, default: true)
|
||||||
field(:accepts_newsletter, :boolean, default: false)
|
field(:accepts_email_list, :boolean, default: false)
|
||||||
|
|
||||||
embeds_one(
|
embeds_one(
|
||||||
:notification_settings,
|
:notification_settings,
|
||||||
|
@ -517,7 +517,7 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
:actor_type,
|
:actor_type,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:disclose_client,
|
:disclose_client,
|
||||||
:accepts_newsletter
|
:accepts_email_list
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|
@ -681,7 +681,7 @@ def register_changeset_ldap(struct, params = %{password: password})
|
||||||
:nickname,
|
:nickname,
|
||||||
:email,
|
:email,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:accepts_newsletter
|
:accepts_email_list
|
||||||
])
|
])
|
||||||
|> validate_required([:name, :nickname])
|
|> validate_required([:name, :nickname])
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|
@ -726,7 +726,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||||
:emoji,
|
:emoji,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:registration_reason,
|
:registration_reason,
|
||||||
:accepts_newsletter
|
:accepts_email_list
|
||||||
])
|
])
|
||||||
|> validate_required([:name, :nickname, :password, :password_confirmation])
|
|> validate_required([:name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_confirmation(:password)
|
|> validate_confirmation(:password)
|
||||||
|
@ -1714,7 +1714,7 @@ def purge_user_changeset(user) do
|
||||||
raw_fields: [],
|
raw_fields: [],
|
||||||
is_discoverable: false,
|
is_discoverable: false,
|
||||||
also_known_as: [],
|
also_known_as: [],
|
||||||
accepts_newsletter: false
|
accepts_email_list: false
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ defp subscribers_query do
|
||||||
is_active: true,
|
is_active: true,
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
is_confirmed: true,
|
is_confirmed: true,
|
||||||
accepts_newsletter: true
|
accepts_email_list: true
|
||||||
})
|
})
|
||||||
|> where([u], not is_nil(u.email))
|
|> where([u], not is_nil(u.email))
|
||||||
end
|
end
|
||||||
|
|
|
@ -459,7 +459,7 @@ defp create_request do
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: "Invite token required when the registrations aren't public"
|
description: "Invite token required when the registrations aren't public"
|
||||||
},
|
},
|
||||||
accepts_newsletter: %Schema{
|
accepts_email_list: %Schema{
|
||||||
allOf: [BooleanLike],
|
allOf: [BooleanLike],
|
||||||
description:
|
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."
|
"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 @@ defp update_credentials_request do
|
||||||
"Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
|
"Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
|
||||||
},
|
},
|
||||||
actor_type: ActorType,
|
actor_type: ActorType,
|
||||||
accepts_newsletter: %Schema{
|
accepts_email_list: %Schema{
|
||||||
allOf: [BooleanLike],
|
allOf: [BooleanLike],
|
||||||
description:
|
description:
|
||||||
"Whether the user opts-in to receiving news and marketing updates from site admins."
|
"Whether the user opts-in to receiving news and marketing updates from site admins."
|
||||||
|
|
|
@ -186,7 +186,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
|
||||||
:allow_following_move,
|
:allow_following_move,
|
||||||
:also_known_as,
|
:also_known_as,
|
||||||
:accepts_chat_messages,
|
:accepts_chat_messages,
|
||||||
:accepts_newsletter
|
:accepts_email_list
|
||||||
]
|
]
|
||||||
|> Enum.reduce(%{}, fn key, acc ->
|
|> Enum.reduce(%{}, fn key, acc ->
|
||||||
Maps.put_if_present(acc, key, params[key], &{:ok, truthy_param?(&1)})
|
Maps.put_if_present(acc, key, params[key], &{:ok, truthy_param?(&1)})
|
||||||
|
|
|
@ -292,7 +292,7 @@ defp do_render("show.json", %{user: user} = opts) do
|
||||||
|> maybe_put_allow_following_move(user, opts[:for])
|
|> maybe_put_allow_following_move(user, opts[:for])
|
||||||
|> maybe_put_unread_conversation_count(user, opts[:for])
|
|> maybe_put_unread_conversation_count(user, opts[:for])
|
||||||
|> maybe_put_unread_notification_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
|
end
|
||||||
|
|
||||||
defp username_from_nickname(string) when is_binary(string) do
|
defp username_from_nickname(string) when is_binary(string) do
|
||||||
|
@ -404,15 +404,15 @@ defp maybe_put_unread_notification_count(data, %User{id: user_id}, %User{id: use
|
||||||
|
|
||||||
defp maybe_put_unread_notification_count(data, _, _), do: data
|
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(
|
Kernel.put_in(
|
||||||
data,
|
data,
|
||||||
[:pleroma, :accepts_newsletter],
|
[:pleroma, :accepts_email_list],
|
||||||
user.accepts_newsletter
|
user.accepts_email_list
|
||||||
)
|
)
|
||||||
end
|
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(%{"url" => [%{"href" => href} | _]}), do: href
|
||||||
defp image_url(_), do: nil
|
defp image_url(_), do: nil
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||||
def register_user(params, opts \\ []) do
|
def register_user(params, opts \\ []) do
|
||||||
params =
|
params =
|
||||||
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(:bio, params |> Map.get(:bio, "") |> User.parse_bio())
|
||||||
|> Map.put(:nickname, params[:username])
|
|> Map.put(:nickname, params[:username])
|
||||||
|> Map.put(:name, Map.get(params, :fullname, params[:username]))
|
|> Map.put(:name, Map.get(params, :fullname, params[:username]))
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
|
@ -664,14 +664,14 @@ test "it creates a confirmed user" do
|
||||||
assert user.is_confirmed
|
assert user.is_confirmed
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it sets 'accepts_newsletter'" do
|
test "it sets 'accepts_email_list'" do
|
||||||
params = Map.put_new(@full_user_data, :accepts_newsletter, true)
|
params = Map.put_new(@full_user_data, :accepts_email_list, true)
|
||||||
changeset = User.register_changeset(%User{}, params)
|
changeset = User.register_changeset(%User{}, params)
|
||||||
assert changeset.valid?
|
assert changeset.valid?
|
||||||
|
|
||||||
{:ok, user} = Repo.insert(changeset)
|
{:ok, user} = Repo.insert(changeset)
|
||||||
|
|
||||||
assert user.accepts_newsletter
|
assert user.accepts_email_list
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -748,13 +748,13 @@ test "it restricts length of registration reason" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "update_changeset/2" do
|
describe "update_changeset/2" do
|
||||||
test "it sets :accepts_newsletter" do
|
test "it sets :accepts_email_list" do
|
||||||
changeset =
|
changeset =
|
||||||
%User{accepts_newsletter: false}
|
%User{accepts_email_list: false}
|
||||||
|> User.update_changeset(%{accepts_newsletter: true})
|
|> User.update_changeset(%{accepts_email_list: true})
|
||||||
|
|
||||||
assert changeset.valid?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1125,7 +1125,7 @@ test "registers and logs in without :account_activation_required / :account_appr
|
||||||
assert user
|
assert user
|
||||||
assert user.is_confirmed
|
assert user.is_confirmed
|
||||||
assert user.is_approved
|
assert user.is_approved
|
||||||
refute user.accepts_newsletter
|
refute user.accepts_email_list
|
||||||
end
|
end
|
||||||
|
|
||||||
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
||||||
|
@ -1357,7 +1357,7 @@ test "allow registration with an empty email", %{conn: conn, valid_params: valid
|
||||||
assert json_response_and_validate_schema(res, 200)
|
assert json_response_and_validate_schema(res, 200)
|
||||||
end
|
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)
|
app_token = insert(:oauth_token, user: nil)
|
||||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||||
|
|
||||||
|
@ -1365,10 +1365,10 @@ test "registration with accepts_newsletter", %{conn: conn, valid_params: valid_p
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|> Map.put(:remote_ip, {127, 0, 0, 9})
|
|> 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 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
|
end
|
||||||
|
|
||||||
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
|
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
|
||||||
|
|
|
@ -114,10 +114,10 @@ test "updates the user's chat acceptance status", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates the user's newsletter preference", %{user: user, conn: conn} do
|
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 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
|
end
|
||||||
|
|
||||||
test "updates the user's allow_following_move", %{user: user, conn: conn} do
|
test "updates the user's allow_following_move", %{user: user, conn: conn} do
|
||||||
|
|
|
@ -470,7 +470,7 @@ test "shows unread_count only to the account owner" do
|
||||||
end
|
end
|
||||||
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)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
@ -479,12 +479,12 @@ test "shows accepts_newsletter only to the account owner" do
|
||||||
assert AccountView.render(
|
assert AccountView.render(
|
||||||
"show.json",
|
"show.json",
|
||||||
%{user: user, for: other_user}
|
%{user: user, for: other_user}
|
||||||
)[:pleroma][:accepts_newsletter] == nil
|
)[:pleroma][:accepts_email_list] == nil
|
||||||
|
|
||||||
assert AccountView.render(
|
assert AccountView.render(
|
||||||
"show.json",
|
"show.json",
|
||||||
%{user: user, for: user}
|
%{user: user, for: user}
|
||||||
)[:pleroma][:accepts_newsletter] == user.accepts_newsletter
|
)[:pleroma][:accepts_email_list] == user.accepts_email_list
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "follow requests counter" do
|
describe "follow requests counter" do
|
||||||
|
|
|
@ -146,18 +146,18 @@ test "it registers a new user and parses mentions in the bio" do
|
||||||
assert user2.bio == expected_text
|
assert user2.bio == expected_text
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it registers a new user with accepts_newsletter." do
|
test "it registers a new user with accepts_email_list." do
|
||||||
data = %{
|
data = %{
|
||||||
:username => "lain",
|
:username => "lain",
|
||||||
:email => "lain@wired.jp",
|
:email => "lain@wired.jp",
|
||||||
:fullname => "lain iwakura",
|
:fullname => "lain iwakura",
|
||||||
:password => "bear",
|
:password => "bear",
|
||||||
:confirm => "bear",
|
:confirm => "bear",
|
||||||
:accepts_newsletter => true
|
:accepts_email_list => true
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, user} = TwitterAPI.register_user(data)
|
{:ok, user} = TwitterAPI.register_user(data)
|
||||||
assert user.accepts_newsletter
|
assert user.accepts_email_list
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "register with one time token" do
|
describe "register with one time token" do
|
||||||
|
|
Loading…
Reference in a new issue