[#923] Merge remote-tracking branch 'remotes/upstream/develop' into twitter_oauth
authorIvan Tashkinov <ivant.business@gmail.com>
Thu, 4 Apr 2019 20:43:08 +0000 (23:43 +0300)
committerIvan Tashkinov <ivant.business@gmail.com>
Thu, 4 Apr 2019 20:43:08 +0000 (23:43 +0300)
# Conflicts:
# mix.exs

1  2 
config/config.exs
lib/pleroma/user.ex
mix.exs
mix.lock

diff --combined config/config.exs
index 604290544485a6f349471a94f4c8e98a9b75a819,c143f79fc804136186e6c7da1a40b9b898a08613..9bc79f939cf49fd6e5e1a392f654d16efe469ea1
@@@ -118,6 -118,11 +118,11 @@@ config :logger, :ex_syslogger
    format: "$metadata[$level] $message",
    metadata: [:request_id]
  
+ config :quack,
+   level: :warn,
+   meta: [:all],
+   webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
  config :mime, :types, %{
    "application/xml" => ["xml"],
    "application/xrd+xml" => ["xrd+xml"],
@@@ -378,24 -383,6 +383,24 @@@ config :pleroma, :ldap
    base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
    uid: System.get_env("LDAP_UID") || "cn"
  
 +oauth_consumer_strategies = String.split(System.get_env("OAUTH_CONSUMER_STRATEGIES") || "")
 +
 +ueberauth_providers =
 +  for strategy <- oauth_consumer_strategies do
 +    strategy_module_name = "Elixir.Ueberauth.Strategy.#{String.capitalize(strategy)}"
 +    strategy_module = String.to_atom(strategy_module_name)
 +    {String.to_atom(strategy), {strategy_module, [callback_params: ["state"]]}}
 +  end
 +
 +config :ueberauth,
 +       Ueberauth,
 +       base_path: "/oauth",
 +       providers: ueberauth_providers
 +
 +config :pleroma, :auth,
 +  oauth_consumer_strategies: oauth_consumer_strategies,
 +  oauth_consumer_enabled: oauth_consumer_strategies != []
 +
  config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Sendmail
  
  # Import environment specific config. This must remain at the bottom
diff --combined lib/pleroma/user.ex
index cd1815b85fd1d8bdf96862ca10b49942d75315f7,5012aef77aa543be08d076e2db3be6a278a51e93..05f56c01e339677748f6685d6db10e68bab7b9b7
@@@ -13,7 -13,6 +13,7 @@@ defmodule Pleroma.User d
    alias Pleroma.Formatter
    alias Pleroma.Notification
    alias Pleroma.Object
 +  alias Pleroma.Registration
    alias Pleroma.Repo
    alias Pleroma.User
    alias Pleroma.Web
@@@ -56,7 -55,6 +56,7 @@@
      field(:bookmarks, {:array, :string}, default: [])
      field(:last_refreshed_at, :naive_datetime_usec)
      has_many(:notifications, Notification)
 +    has_many(:registrations, Registration)
      embeds_one(:info, Pleroma.User.Info)
  
      timestamps()
      changeset =
        struct
        |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
 -      |> validate_required([:email, :name, :nickname, :password, :password_confirmation])
 +      |> validate_required([:name, :nickname, :password, :password_confirmation])
        |> validate_confirmation(:password)
        |> unique_constraint(:email)
        |> unique_constraint(:nickname)
        |> validate_length(:name, min: 1, max: 100)
        |> put_change(:info, info_change)
  
 +    changeset =
 +      if opts[:external] do
 +        changeset
 +      else
 +        validate_required(changeset, [:email])
 +      end
 +
      if changeset.valid? do
        hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
        ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
        end
    end
  
 +  def get_by_email(email), do: Repo.get_by(User, email: email)
 +
    def get_by_nickname_or_email(nickname_or_email) do
 -    case user = Repo.get_by(User, nickname: nickname_or_email) do
 -      %User{} -> user
 -      nil -> Repo.get_by(User, email: nickname_or_email)
 -    end
 +    get_by_nickname(nickname_or_email) || get_by_email(nickname_or_email)
    end
  
    def get_cached_user_info(user) do
      # Remove all relationships
      {:ok, followers} = User.get_followers(user)
  
-     followers
-     |> Enum.each(fn follower -> User.unfollow(follower, user) end)
+     Enum.each(followers, fn follower -> User.unfollow(follower, user) end)
  
      {:ok, friends} = User.get_friends(user)
  
-     friends
-     |> Enum.each(fn followed -> User.unfollow(user, followed) end)
+     Enum.each(friends, fn followed -> User.unfollow(user, followed) end)
  
-     query =
-       from(a in Activity, where: a.actor == ^user.ap_id)
-       |> Activity.with_preloaded_object()
+     delete_user_activities(user)
+   end
  
-     Repo.all(query)
-     |> Enum.each(fn activity ->
-       case activity.data["type"] do
-         "Create" ->
-           ActivityPub.delete(Object.normalize(activity))
+   def delete_user_activities(%User{ap_id: ap_id} = user) do
+     Activity
+     |> where(actor: ^ap_id)
+     |> Activity.with_preloaded_object()
+     |> Repo.all()
+     |> Enum.each(fn
+       %{data: %{"type" => "Create"}} = activity ->
+         activity |> Object.normalize() |> ActivityPub.delete()
  
-         # TODO: Do something with likes, follows, repeats.
-         _ ->
-           "Doing nothing"
-       end
+       # TODO: Do something with likes, follows, repeats.
+       _ ->
+         "Doing nothing"
      end)
  
      {:ok, user}
diff --combined mix.exs
index 2b0d25b551ad00b0c30f438ac0defa1cec6a5aec,3a04e0060d96be00c5ff01734a0b2033d67d6252..30931821f13d09404fd07239bb8ce5da381a9b13
+++ b/mix.exs
@@@ -41,7 -41,7 +41,7 @@@ defmodule Pleroma.Mixfile d
    def application do
      [
        mod: {Pleroma.Application, []},
-       extra_applications: [:logger, :runtime_tools, :comeonin],
+       extra_applications: [:logger, :runtime_tools, :comeonin, :quack],
        included_applications: [:ex_syslogger]
      ]
    end
    #
    # Type `mix help deps` for examples and options.
    defp deps do
 +    oauth_strategies = String.split(System.get_env("OAUTH_CONSUMER_STRATEGIES") || "")
 +
 +    oauth_deps =
 +      for s <- oauth_strategies,
 +          do: {String.to_atom("ueberauth_#{s}"), ">= 0.0.0"}
 +
      [
        {:phoenix, "~> 1.4.1"},
        {:plug_cowboy, "~> 2.0"},
@@@ -77,7 -71,6 +77,7 @@@
        {:calendar, "~> 0.17.4"},
        {:cachex, "~> 3.0.2"},
        {:httpoison, "~> 1.2.0"},
 +      {:poison, "~> 3.0", override: true},
        {:tesla, "~> 1.2"},
        {:jason, "~> 1.0"},
        {:mogrify, "~> 0.6.1"},
        {:floki, "~> 0.20.0"},
        {:ex_syslogger, github: "slashmili/ex_syslogger", tag: "1.4.0"},
        {:timex, "~> 3.5"},
 +      {:ueberauth, "~> 0.4"},
        {:auto_linker,
         git: "https://git.pleroma.social/pleroma/auto_linker.git",
-        ref: "94193ca5f97c1f9fdf3d1469653e2d46fac34bcd"},
-       {:pleroma_job_queue, "~> 0.2.0"}
+        ref: "479dd343f4e563ff91215c8275f3b5c67e032850"},
+       {:pleroma_job_queue, "~> 0.2.0"},
+       {:quack, "~> 0.1.1"}
 -    ]
 +    ] ++ oauth_deps
    end
  
    # Aliases are shortcuts or tasks specific to the current project.
diff --combined mix.lock
index b0330b580e01777e4127fef102604c48f6f9b9c4,d84d11049a0cc10677de80a930a066dd79b746b0..eb1d1221e472ace9487c4c1aa260b645aa8aed66
+++ b/mix.lock
@@@ -1,10 -1,10 +1,10 @@@
  %{
-   "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "94193ca5f97c1f9fdf3d1469653e2d46fac34bcd", [ref: "94193ca5f97c1f9fdf3d1469653e2d46fac34bcd"]},
+   "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "479dd343f4e563ff91215c8275f3b5c67e032850", [ref: "479dd343f4e563ff91215c8275f3b5c67e032850"]},
    "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
    "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
    "cachex": {:hex, :cachex, "3.0.2", "1351caa4e26e29f7d7ec1d29b53d6013f0447630bbf382b4fb5d5bad0209f203", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"},
    "calendar": {:hex, :calendar, "0.17.4", "22c5e8d98a4db9494396e5727108dffb820ee0d18fed4b0aa8ab76e4f5bc32f1", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
 -  "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
 +  "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
    "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm"},
    "comeonin": {:hex, :comeonin, "4.1.1", "c7304fc29b45b897b34142a91122bc72757bc0c295e9e824999d5179ffc08416", [:mix], [{:argon2_elixir, "~> 1.2", [hex: :argon2_elixir, repo: "hexpm", optional: true]}, {:bcrypt_elixir, "~> 0.12.1 or ~> 1.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: true]}, {:pbkdf2_elixir, "~> 0.12", [hex: :pbkdf2_elixir, repo: "hexpm", optional: true]}], "hexpm"},
    "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
@@@ -27,7 -27,7 +27,7 @@@
    "floki": {:hex, :floki, "0.20.4", "be42ac911fece24b4c72f3b5846774b6e61b83fe685c2fc9d62093277fb3bc86", [:mix], [{:html_entities, "~> 0.4.0", [hex: :html_entities, repo: "hexpm", optional: false]}, {:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
    "gen_smtp": {:hex, :gen_smtp, "0.13.0", "11f08504c4bdd831dc520b8f84a1dce5ce624474a797394e7aafd3c29f5dcd25", [:rebar3], [], "hexpm"},
    "gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
 -  "hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
 +  "hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
    "html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm"},
    "html_sanitize_ex": {:hex, :html_sanitize_ex, "1.3.0", "f005ad692b717691203f940c686208aa3d8ffd9dd4bb3699240096a51fa9564e", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
    "httpoison": {:hex, :httpoison, "1.2.0", "2702ed3da5fd7a8130fc34b11965c8cfa21ade2f232c00b42d96d4967c39a3a3", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
@@@ -39,7 -39,7 +39,7 @@@
    "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
    "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
    "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
 -  "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
 +  "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
    "mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"},
    "mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
    "mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
@@@ -57,6 -57,7 +57,7 @@@
    "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
    "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
    "postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
+   "quack": {:hex, :quack, "0.1.1", "cca7b4da1a233757fdb44b3334fce80c94785b3ad5a602053b7a002b5a8967bf", [:mix], [{:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: false]}, {:tesla, "~> 1.2.0", [hex: :tesla, repo: "hexpm", optional: false]}], "hexpm"},
    "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
    "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
    "swoosh": {:hex, :swoosh, "0.20.0", "9a6c13822c9815993c03b6f8fccc370fcffb3c158d9754f67b1fdee6b3a5d928", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.12", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
@@@ -66,7 -67,6 +67,7 @@@
    "timex": {:hex, :timex, "3.5.0", "b0a23167da02d0fe4f1a4e104d1f929a00d348502b52432c05de875d0b9cffa5", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
    "trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
    "tzdata": {:hex, :tzdata, "0.5.17", "50793e3d85af49736701da1a040c415c97dc1caf6464112fd9bd18f425d3053b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
 +  "ueberauth": {:hex, :ueberauth, "0.6.1", "9e90d3337dddf38b1ca2753aca9b1e53d8a52b890191cdc55240247c89230412", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
    "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
    "unsafe": {:hex, :unsafe, "1.0.0", "7c21742cd05380c7875546b023481d3a26f52df8e5dfedcb9f958f322baae305", [:mix], [], "hexpm"},
    "web_push_encryption": {:hex, :web_push_encryption, "0.2.1", "d42cecf73420d9dc0053ba3299cc8c8d6ff2be2487d67ca2a57265868e4d9a98", [:mix], [{:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},