[#923] Merge remote-tracking branch 'remotes/upstream/develop' into twitter_oauth
authorIvan Tashkinov <ivant.business@gmail.com>
Mon, 8 Apr 2019 09:20:26 +0000 (12:20 +0300)
committerIvan Tashkinov <ivant.business@gmail.com>
Mon, 8 Apr 2019 09:20:26 +0000 (12:20 +0300)
# Conflicts:
# docs/config.md
# test/support/factory.ex

1  2 
config/config.exs
docs/config.md
lib/pleroma/web/endpoint.ex
lib/pleroma/web/oauth/oauth_controller.ex
lib/pleroma/web/router.ex
mix.exs
mix.lock
test/support/factory.ex
test/web/oauth/oauth_controller_test.exs

index 05b164273a42f3c43f3e2a3954e8c212803dc1dd,8a977ece5d5089a60ff33b8c2956dea3555a0e03..a9539526d5383ddf4f692e663c35148b7d4088b4
@@@ -383,24 -389,15 +389,31 @@@ 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
 +
  config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Sendmail
  
+ config :prometheus, Pleroma.Web.Endpoint.MetricsExporter, path: "/api/pleroma/app_metrics"
+ config :pleroma, Pleroma.ScheduledActivity,
+   daily_user_limit: 25,
+   total_user_limit: 300,
+   enabled: true
  # Import environment specific config. This must remain at the bottom
  # of this file so it overrides the configuration defined above.
  import_config "#{Mix.env()}.exs"
diff --cc docs/config.md
index 686f1f36b063ac99e74a3f91f53fafa58b0e3e93,ba0759e87c8468a1e3aaf3092bfc5f285b32be36..ed9b91363fd1ef8b29d01ac5158f67ac2b623d58
@@@ -390,11 -391,6 +391,17 @@@ config :auto_linker
    ]
  ```
  
++## Pleroma.ScheduledActivity
++
++* `daily_user_limit`: the number of scheduled activities a user is allowed to create in a single day (Default: `25`)
++* `total_user_limit`: the number of scheduled activities a user is allowed to create in total (Default: `300`)
++* `enabled`: whether scheduled activities are sent to the job queue to be executed
++
 +## Pleroma.Web.Auth.Authenticator
 +
 +* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
 +* `Pleroma.Web.Auth.LDAPAuthenticator`: LDAP authentication
 +
  ## :ldap
  
  Use LDAP for user authentication.  When a user logs in to the Pleroma
index 085f23159603861fdbd0e9b633c231a76abe3b16,6d9528c862fd63a52456c4b2824c4b0053344c91..1633477c365dd8aa2649b515d6a55d3a507ecc08
@@@ -76,10 -65,31 +76,30 @@@ defmodule Pleroma.Web.Endpoint d
      key: cookie_name,
      signing_salt: {Pleroma.Config, :get, [[__MODULE__, :signing_salt], "CqaoopA2"]},
      http_only: true,
 -    secure:
 -      Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:secure_cookie_flag),
 -    extra: "SameSite=Strict"
 +    secure: secure_cookies,
 +    extra: same_site
    )
  
+   # Note: the plug and its configuration is compile-time this can't be upstreamed yet
+   if proxies = Pleroma.Config.get([__MODULE__, :reverse_proxies]) do
+     plug(RemoteIp, proxies: proxies)
+   end
+   defmodule Instrumenter do
+     use Prometheus.PhoenixInstrumenter
+   end
+   defmodule PipelineInstrumenter do
+     use Prometheus.PlugPipelineInstrumenter
+   end
+   defmodule MetricsExporter do
+     use Prometheus.PlugExporter
+   end
+   plug(PipelineInstrumenter)
+   plug(MetricsExporter)
    plug(Pleroma.Web.Router)
  
    @doc """
index 108303eb25b3fe09c90f874347bc2206dd86a1b3,aac8f97fcc427d86abaa222cf3965fdae62439e4..bee7084ad39f058c41f0125c88690115688dcea3
@@@ -151,9 -149,10 +151,10 @@@ defmodule Pleroma.Web.OAuth.OAuthContro
          conn,
          %{"grant_type" => "password"} = params
        ) do
 -    with {_, {:ok, %User{} = user}} <- {:get_user, Authenticator.get_user(conn)},
 +    with {_, {:ok, %User{} = user}} <- {:get_user, Authenticator.get_user(conn, params)},
           %App{} = app <- get_app_from_request(conn, params),
           {:auth_active, true} <- {:auth_active, User.auth_active?(user)},
+          {:user_active, true} <- {:user_active, !user.info.deactivated},
           scopes <- oauth_scopes(params, app.scopes),
           [] <- scopes -- app.scopes,
           true <- Enum.any?(scopes),
Simple merge
diff --cc mix.exs
index 30931821f13d09404fd07239bb8ce5da381a9b13,ec0865c4fe25be16415deb556db7bfe5413b1b77..26a03b70bfa7683d637905bfc88650899a199a8d
+++ b/mix.exs
@@@ -103,8 -95,15 +103,15 @@@ defmodule Pleroma.Mixfile d
         git: "https://git.pleroma.social/pleroma/auto_linker.git",
         ref: "479dd343f4e563ff91215c8275f3b5c67e032850"},
        {:pleroma_job_queue, "~> 0.2.0"},
+       {:telemetry, "~> 0.3"},
+       {:prometheus_ex, "~> 3.0"},
+       {:prometheus_plugs, "~> 1.1"},
+       {:prometheus_phoenix, "~> 1.2"},
+       {:prometheus_ecto, "~> 1.4"},
+       {:prometheus_process_collector, "~> 1.4"},
+       {:recon, github: "ferd/recon", tag: "2.4.0"},
        {:quack, "~> 0.1.1"}
 -    ]
 +    ] ++ oauth_deps
    end
  
    # Aliases are shortcuts or tasks specific to the current project.
diff --cc mix.lock
Simple merge
index 67953931b0a88344a961ade8c85aa0bd1783188d,608f8d46b0554ef7d461f8789026aa9825c6a363..ea59912cfbab3ef755afd7f2dc0ba21501765c04
@@@ -258,19 -268,11 +268,27 @@@ defmodule Pleroma.Factory d
      }
    end
  
+   def scheduled_activity_factory do
+     %Pleroma.ScheduledActivity{
+       user: build(:user),
+       scheduled_at: NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(60), :millisecond),
+       params: build(:note) |> Map.from_struct() |> Map.get(:data)
+     }
+   end
++
 +  def registration_factory do
 +    user = insert(:user)
 +
 +    %Pleroma.Registration{
 +      user: user,
 +      provider: "twitter",
 +      uid: "171799000",
 +      info: %{
 +        "name" => "John Doe",
 +        "email" => "john@doe.com",
 +        "nickname" => "johndoe",
 +        "description" => "My bio"
 +      }
 +    }
 +  end
  end