Merge branch 'develop' into issue/1383
authorMaksim Pechnikov <parallel588@gmail.com>
Mon, 13 Jan 2020 09:41:07 +0000 (12:41 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Mon, 13 Jan 2020 09:41:07 +0000 (12:41 +0300)
1  2 
config/config.exs
config/description.exs
docs/configuration/cheatsheet.md
mix.exs
mix.lock
test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
test/web/twitter_api/util_controller_test.exs

index bbd8f7d781d4088229ab55d954e1b5d09c84975d,d41abf09099447de593135de309f35840fb9038d..8b8ecc833f71492c058d02ef9e605bdcd2fdf752
@@@ -51,9 -51,23 +51,9 @@@ config :pleroma, Pleroma.Repo
    telemetry_event: [Pleroma.Repo.Instrumenter],
    migration_lock: nil
  
 -scheduled_jobs =
 -  with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
 -       true <- digest_config[:active] do
 -    [{digest_config[:schedule], {Pleroma.Daemons.DigestEmailDaemon, :perform, []}}]
 -  else
 -    _ -> []
 -  end
 -
 -config :pleroma, Pleroma.Scheduler,
 -  global: true,
 -  overlap: true,
 -  timezone: :utc,
 -  jobs: scheduled_jobs
 -
  config :pleroma, Pleroma.Captcha,
    enabled: true,
-   seconds_valid: 60,
+   seconds_valid: 300,
    method: Pleroma.Captcha.Native
  
  config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.ch"
Simple merge
Simple merge
diff --cc mix.exs
Simple merge
diff --cc mix.lock
Simple merge
index 478631a12c642aebb35c4e3e7f7279b87cf41f75,9666a7f2e627c00c4dd67a17640524afa4de8277..6317d1b477351aa6284531d9c30ba9f64983698c
@@@ -9,12 -9,10 +9,13 @@@ defmodule Pleroma.Web.MastodonAPI.Sched
    alias Pleroma.ScheduledActivity
  
    import Pleroma.Factory
 +  import Ecto.Query
 +
 +  clear_config([ScheduledActivity, :enabled])
  
-   test "shows scheduled activities", %{conn: conn} do
-     user = insert(:user)
+   test "shows scheduled activities" do
+     %{user: user, conn: conn} = oauth_access(["read:statuses"])
      scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string()
      scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string()
      scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string()
      assert %{"error" => "Record not found"} = json_response(res_conn, 404)
    end
  
-   test "updates a scheduled activity", %{conn: conn} do
+   test "updates a scheduled activity" do
 +    Pleroma.Config.put([ScheduledActivity, :enabled], true)
-     user = insert(:user)
+     %{user: user, conn: conn} = oauth_access(["write:statuses"])
 -    scheduled_activity = insert(:scheduled_activity, user: user)
  
-     scheduled_at =
-       NaiveDateTime.add(
-         NaiveDateTime.utc_now(),
-         :timer.minutes(60),
-         :millisecond
-       )
 -    new_scheduled_at =
 -      NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
++    scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
 +
 +    {:ok, scheduled_activity} =
 +      ScheduledActivity.create(
 +        user,
 +        %{
 +          scheduled_at: scheduled_at,
 +          params: build(:note).data
 +        }
 +      )
 +
-     scheduled_activity_job =
-       Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
++    job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
 +
-     assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id}
++    assert job.args == %{"activity_id" => scheduled_activity.id}
++    assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(scheduled_at)
 +
-     assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) ==
-              to_datetime(scheduled_at)
-     new_scheduled_at =
-       NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
++    new_scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 120)
  
      res_conn =
-       conn
-       |> assign(:user, user)
-       |> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
+       put(conn, "/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
          scheduled_at: new_scheduled_at
        })
  
      assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200)
      assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at)
-     scheduled_activity_job = refresh_record(scheduled_activity_job)
++    job = refresh_record(job)
 +
-     assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) ==
-              to_datetime(new_scheduled_at)
++    assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(new_scheduled_at)
  
-     res_conn =
-       conn
-       |> assign(:user, user)
-       |> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
+     res_conn = put(conn, "/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
  
      assert %{"error" => "Record not found"} = json_response(res_conn, 404)
    end
  
-   test "deletes a scheduled activity", %{conn: conn} do
+   test "deletes a scheduled activity" do
 +    Pleroma.Config.put([ScheduledActivity, :enabled], true)
-     user = insert(:user)
+     %{user: user, conn: conn} = oauth_access(["write:statuses"])
 -    scheduled_activity = insert(:scheduled_activity, user: user)
++    scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
 +
 +    {:ok, scheduled_activity} =
 +      ScheduledActivity.create(
 +        user,
 +        %{
-           scheduled_at:
-             NaiveDateTime.add(
-               NaiveDateTime.utc_now(),
-               :timer.minutes(60),
-               :millisecond
-             ),
++          scheduled_at: scheduled_at,
 +          params: build(:note).data
 +        }
 +      )
 +
-     scheduled_activity_job =
-       Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
++    job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
 +
-     assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id}
++    assert job.args == %{"activity_id" => scheduled_activity.id}
  
      res_conn =
        conn
        |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
  
      assert %{} = json_response(res_conn, 200)
 -    assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
 +    refute Repo.get(ScheduledActivity, scheduled_activity.id)
-     refute Repo.get(Oban.Job, scheduled_activity_job.id)
++    refute Repo.get(Oban.Job, job.id)
  
      res_conn =
        conn
index 43299e147b3f5d9ec67035dda40215fd16457f33,8418fd071f26e7eece7ea04d7d48afaeff77427e..5d60c0d51865f1c94b3c29f051f4a48d2af96880
@@@ -6,11 -6,11 +6,9 @@@ defmodule Pleroma.Web.TwitterAPI.UtilCo
    use Pleroma.Web.ConnCase
    use Oban.Testing, repo: Pleroma.Repo
  
-   alias Pleroma.Repo
    alias Pleroma.Tests.ObanHelpers
    alias Pleroma.User
--  alias Pleroma.Web.CommonAPI
-   import ExUnit.CaptureLog
 -  import ExUnit.CaptureLog
    import Pleroma.Factory
    import Mock