adding notify_email setting for trigger emails
authorAlex S <alex.strizhakov@gmail.com>
Wed, 10 Apr 2019 10:57:41 +0000 (17:57 +0700)
committerAlex S <alex.strizhakov@gmail.com>
Wed, 10 Apr 2019 10:57:41 +0000 (17:57 +0700)
12 files changed:
config/config.exs
config/test.exs
docs/config.md
lib/mix/tasks/pleroma/instance.ex
lib/mix/tasks/pleroma/sample_config.eex
lib/pleroma/emails/admin_email.ex
lib/pleroma/emails/user_email.ex
test/tasks/instance.exs [new file with mode: 0644]
test/web/admin_api/admin_api_controller_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/twitter_api/twitter_api_controller_test.exs
test/web/twitter_api/twitter_api_test.exs

index 3462a37f76b3a6fd3517a4de4c2fbfcd3cc08f11..9edec8dc37aa690ec19291f76ea7d59e3029ca48 100644 (file)
@@ -160,6 +160,7 @@ config :pleroma, :http,
 config :pleroma, :instance,
   name: "Pleroma",
   email: "example@example.com",
+  notify_email: "noreply@example.com",
   description: "A Pleroma instance, an alternative fediverse server",
   limit: 5_000,
   remote_limit: 100_000,
index 894fa8d3d3eb541f5770d54d2cb565ebb2a570dd..2c4beaade9bc36ad75958857df14c14351bea585 100644 (file)
@@ -23,6 +23,10 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "test/uploads"
 
 config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Test
 
+config :pleroma, :instance,
+  email: "admin@example.com",
+  notify_email: "noreply@example.com"
+
 # Configure your database
 config :pleroma, Pleroma.Repo,
   adapter: Ecto.Adapters.Postgres,
index b5ea587463c91657221bc2a2cd231ae6067816ea..7d3a482b39c7479662093c08ab3363b59023aa2b 100644 (file)
@@ -63,6 +63,7 @@ config :pleroma, Pleroma.Mailer,
 ## :instance
 * `name`: The instance’s name
 * `email`: Email used to reach an Administrator/Moderator of the instance
+* `notify_email`: Email used for notifications.
 * `description`: The instance’s description, can be seen in nodeinfo and ``/api/v1/instance``
 * `limit`: Posts character limit (CW/Subject included in the counter)
 * `remote_limit`: Hard character limit beyond which remote posts will be dropped.
@@ -427,7 +428,7 @@ Pleroma account will be created with the same name as the LDAP user name.
 
 Authentication / authorization settings.
 
-* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`. 
+* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`.
 * `oauth_consumer_template`: OAuth consumer mode authentication form template. By default it's `consumer.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/consumer.html.eex`.
 * `oauth_consumer_strategies`: the list of enabled OAuth consumer strategies; by default it's set by OAUTH_CONSUMER_STRATEGIES environment variable.
 
@@ -440,7 +441,7 @@ Note: each strategy is shipped as a separate dependency; in order to get the str
 e.g. `OAUTH_CONSUMER_STRATEGIES="twitter facebook google microsoft" mix deps.get`.
 The server should also be started with `OAUTH_CONSUMER_STRATEGIES="..." mix phx.server` in case you enable any strategies.
 
-Note: each strategy requires separate setup (on external provider side and Pleroma side). Below are the guidelines on setting up most popular strategies.  
+Note: each strategy requires separate setup (on external provider side and Pleroma side). Below are the guidelines on setting up most popular strategies.
 
 * For Twitter, [register an app](https://developer.twitter.com/en/apps), configure callback URL to https://<your_host>/oauth/twitter/callback
 
@@ -475,7 +476,7 @@ config :ueberauth, Ueberauth.Strategy.Google.OAuth,
 config :ueberauth, Ueberauth.Strategy.Microsoft.OAuth,
   client_id: System.get_env("MICROSOFT_CLIENT_ID"),
   client_secret: System.get_env("MICROSOFT_CLIENT_SECRET")
-  
+
 config :ueberauth, Ueberauth,
   providers: [
     microsoft: {Ueberauth.Strategy.Microsoft, [callback_params: []]}
index 8f8d86a1120c5b402ea31b72d0f0dfb0e5291bcb..6cee8d63035de9303effc164c1219fed4f17bc4c 100644 (file)
@@ -24,10 +24,12 @@ defmodule Mix.Tasks.Pleroma.Instance do
   - `--domain DOMAIN` - the domain of your instance
   - `--instance-name INSTANCE_NAME` - the name of your instance
   - `--admin-email ADMIN_EMAIL` - the email address of the instance admin
+  - `--notify-email NOTIFY_EMAIL` - email address for notifications
   - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use
   - `--dbname DBNAME` - the name of the database to use
   - `--dbuser DBUSER` - the user (aka role) to use for the database connection
   - `--dbpass DBPASS` - the password to use for the database connection
+  - `--indexable Y/N` - Allow/disallow indexing site by search engines
   """
 
   def run(["gen" | rest]) do
@@ -41,10 +43,12 @@ defmodule Mix.Tasks.Pleroma.Instance do
           domain: :string,
           instance_name: :string,
           admin_email: :string,
+          notify_email: :string,
           dbhost: :string,
           dbname: :string,
           dbuser: :string,
-          dbpass: :string
+          dbpass: :string,
+          indexable: :string
         ],
         aliases: [
           o: :output,
@@ -61,7 +65,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
     will_overwrite = Enum.filter(paths, &File.exists?/1)
     proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false)
 
-    unless not proceed? do
+    if proceed? do
       [domain, port | _] =
         String.split(
           Common.get_option(
@@ -81,6 +85,14 @@ defmodule Mix.Tasks.Pleroma.Instance do
 
       email = Common.get_option(options, :admin_email, "What is your admin email address?")
 
+      notify_email =
+        Common.get_option(
+          options,
+          :notify_email,
+          "What email address do you want to use for sending email notifications?",
+          email
+        )
+
       indexable =
         Common.get_option(
           options,
@@ -122,6 +134,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
           domain: domain,
           port: port,
           email: email,
+          notify_email: notify_email,
           name: name,
           dbhost: dbhost,
           dbname: dbname,
index 1c935c0d8a0da7bf239b8b1d8fa0c6fd828bed7e..52bd57cb7efae12da86e755e433fc1a15979145d 100644 (file)
@@ -13,6 +13,7 @@ config :pleroma, Pleroma.Web.Endpoint,
 config :pleroma, :instance,
   name: "<%= name %>",
   email: "<%= email %>",
+  notify_email: "<%= notify_email %>",
   limit: 5000,
   registrations_open: true,
   dedupe_media: false
@@ -75,4 +76,3 @@ config :web_push_encryption, :vapid_details,
 #  storage_url: "https://swift-endpoint.prodider.com/v1/AUTH_<tenant>/<container>",
 #  object_url: "https://cdn-endpoint.provider.com/<container>"
 #
-
index afefccec5e2b928149c6ad30c902a7d07dc1f3fa..59d571c2a6fd69a3eb3bf996efd72dbc65d6aade 100644 (file)
@@ -11,7 +11,7 @@ defmodule Pleroma.AdminEmail do
 
   defp instance_config, do: Pleroma.Config.get(:instance)
   defp instance_name, do: instance_config()[:name]
-  defp instance_email, do: instance_config()[:email]
+  defp instance_notify_email, do: instance_config()[:notify_email]
 
   defp user_url(user) do
     Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.nickname)
@@ -59,7 +59,7 @@ defmodule Pleroma.AdminEmail do
 
     new()
     |> to({to.name, to.email})
-    |> from({instance_name(), instance_email()})
+    |> from({instance_name(), instance_notify_email()})
     |> reply_to({reporter.name, reporter.email})
     |> subject("#{instance_name()} Report")
     |> html_body(html_body)
index a3a09e96cccebda630c8ee86b4c534789dc7e949..34dff782a45fffbf8a8ce8472695bf70a1aee288 100644 (file)
@@ -15,7 +15,7 @@ defmodule Pleroma.UserEmail do
   defp instance_name, do: instance_config()[:name]
 
   defp sender do
-    {instance_name(), instance_config()[:email]}
+    {instance_name(), instance_config()[:notify_email]}
   end
 
   defp recipient(email, nil), do: email
diff --git a/test/tasks/instance.exs b/test/tasks/instance.exs
new file mode 100644 (file)
index 0000000..6917a23
--- /dev/null
@@ -0,0 +1,62 @@
+defmodule Pleroma.InstanceTest do
+  use ExUnit.Case, async: true
+
+  setup do
+    File.mkdir_p!(tmp_path())
+    on_exit(fn -> File.rm_rf(tmp_path()) end)
+    :ok
+  end
+
+  defp tmp_path do
+    "/tmp/generated_files/"
+  end
+
+  test "running gen" do
+    mix_task = fn ->
+      Mix.Tasks.Pleroma.Instance.run([
+        "gen",
+        "--output",
+        tmp_path() <> "generated_config.exs",
+        "--output-psql",
+        tmp_path() <> "setup.psql",
+        "--domain",
+        "test.pleroma.social",
+        "--instance-name",
+        "Pleroma",
+        "--admin-email",
+        "admin@example.com",
+        "--notify-email",
+        "notify@example.com",
+        "--dbhost",
+        "dbhost",
+        "--dbname",
+        "dbname",
+        "--dbuser",
+        "dbuser",
+        "--dbpass",
+        "dbpass",
+        "--indexable",
+        "y"
+      ])
+    end
+
+    ExUnit.CaptureIO.capture_io(fn ->
+      mix_task.()
+    end)
+
+    generated_config = File.read!(tmp_path() <> "generated_config.exs")
+    assert generated_config =~ "host: \"test.pleroma.social\""
+    assert generated_config =~ "name: \"Pleroma\""
+    assert generated_config =~ "email: \"admin@example.com\""
+    assert generated_config =~ "notify_email: \"notify@example.com\""
+    assert generated_config =~ "hostname: \"dbhost\""
+    assert generated_config =~ "database: \"dbname\""
+    assert generated_config =~ "username: \"dbuser\""
+    assert generated_config =~ "password: \"dbpass\""
+    assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
+  end
+
+  defp generated_setup_psql do
+    ~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\n)
+  end
+end
index ca6bd0e9764caa4fee6d7a55899ba2dcbb82f86f..7b1f6d53ac8f50526d7118c7670dcd52a3577cca 100644 (file)
@@ -316,13 +316,21 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       assert token_record
       refute token_record.used
 
-      Swoosh.TestAssertions.assert_email_sent(
+      notify_email = Pleroma.Config.get([:instance, :notify_email])
+      instance_name = Pleroma.Config.get([:instance, :name])
+
+      email =
         Pleroma.UserEmail.user_invitation_email(
           user,
           token_record,
           recipient_email,
           recipient_name
         )
+
+      Swoosh.TestAssertions.assert_email_sent(
+        from: {instance_name, notify_email},
+        to: {recipient_name, recipient_email},
+        html_body: email.html_body
       )
     end
 
index e16862a48cc9c1f9a9f3e73df130082e92fd5812..24e258d66c4ae1ca87c2d64f573bdfe0f18813cf 100644 (file)
@@ -1910,13 +1910,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     conn = get(conn, "/api/v1/instance")
     assert result = json_response(conn, 200)
 
+    email = Pleroma.Config.get([:instance, :email])
     # Note: not checking for "max_toot_chars" since it's optional
     assert %{
              "uri" => _,
              "title" => _,
              "description" => _,
              "version" => _,
-             "email" => _,
+             "email" => from_config_email,
              "urls" => %{
                "streaming_api" => _
              },
@@ -1925,6 +1926,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
              "languages" => _,
              "registrations" => _
            } = result
+
+    assert email == from_config_email
   end
 
   test "get instance stats", %{conn: conn} do
index 72b7ea85eba8e001cde0a212aa8a73ca9f09d464..e7293e384bad926ba56b9fb8f3bd78defed94ee3 100644 (file)
@@ -22,8 +22,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Web.TwitterAPI.UserView
 
-  import Pleroma.Factory
   import Mock
+  import Pleroma.Factory
+  import Swoosh.TestAssertions
 
   @banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
 
@@ -1063,8 +1064,14 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     test "it sends an email to user", %{user: user} do
       token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
 
-      Swoosh.TestAssertions.assert_email_sent(
-        Pleroma.UserEmail.password_reset_email(user, token_record.token)
+      email = Pleroma.UserEmail.password_reset_email(user, token_record.token)
+      notify_email = Pleroma.Config.get([:instance, :notify_email])
+      instance_name = Pleroma.Config.get([:instance, :name])
+
+      assert_email_sent(
+        from: {instance_name, notify_email},
+        to: {user.name, user.email},
+        html_body: email.html_body
       )
     end
   end
@@ -1163,7 +1170,15 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       |> assign(:user, user)
       |> post("/api/account/resend_confirmation_email?email=#{user.email}")
 
-      Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+      email = Pleroma.UserEmail.account_confirmation_email(user)
+      notify_email = Pleroma.Config.get([:instance, :notify_email])
+      instance_name = Pleroma.Config.get([:instance, :name])
+
+      assert_email_sent(
+        from: {instance_name, notify_email},
+        to: {user.name, user.email},
+        html_body: email.html_body
+      )
     end
   end
 
index 6c00244deb70ff1a8ffa866c4a76c9ddee2e30a1..24e46408c248fff6e26267044f8d4cfd9c10e1e2 100644 (file)
@@ -321,7 +321,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
 
     assert user.info.confirmation_pending
 
-    Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+    email = Pleroma.UserEmail.account_confirmation_email(user)
+
+    notify_email = Pleroma.Config.get([:instance, :notify_email])
+    instance_name = Pleroma.Config.get([:instance, :name])
+
+    Swoosh.TestAssertions.assert_email_sent(
+      from: {instance_name, notify_email},
+      to: {user.name, user.email},
+      html_body: email.html_body
+    )
   end
 
   test "it registers a new user and parses mentions in the bio" do