Allow expires_at in filter requests

Fixes #492
This commit is contained in:
FloatingGhost 2023-03-09 19:13:14 +00:00
parent 87d5e5b06a
commit 8a4437d2be
5 changed files with 44 additions and 1 deletions

View file

@ -225,6 +225,12 @@ defp update_request do
type: :integer,
description:
"Number of seconds from now the filter should expire. Otherwise, null for a filter that doesn't expire."
},
expires_at: %Schema{
nullable: true,
type: :string,
description:
"When the filter should no longer be applied. String (ISO 8601 Datetime), or null if the filter does not expire."
}
},
required: [:phrase, :context],

View file

@ -116,6 +116,8 @@ defp csp_string(conn) do
script_src = "script-src 'self' '#{nonce_tag}'"
script_src = if Mix.env() == :dev, do: [script_src, " 'unsafe-eval'"], else: script_src
report = if report_uri, do: ["report-uri ", report_uri, ";report-to csp-endpoint"]
insecure = if scheme == "https", do: "upgrade-insecure-requests"

View file

@ -19,6 +19,7 @@
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/js/features/getting_started.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/js/features/compose.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/js/features/home_timeline.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/js/features/public_timeline.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/js/features/notifications.js'>
<script crossorigin='anonymous' src="/packs/js/application.js"></script>

View file

@ -85,6 +85,40 @@ test "a filter with expires_in", %{conn: conn, user: user} do
assert Repo.aggregate(Filter, :count, :id) == 0
end
test "a filter with expires_at", %{conn: conn, user: user} do
response =
with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/filters", %{
"phrase" => "bad memes",
context: ["home"],
expires_at: "2017-03-17T17:19:58.000Z"
})
|> json_response_and_validate_schema(200)
end
assert response["irreversible"] == false
assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
filter = Filter.get(response["id"], user)
id = filter.id
assert_enqueued(
worker: PurgeExpiredFilter,
args: %{filter_id: filter.id}
)
assert {:ok, %{id: ^id}} =
perform_job(PurgeExpiredFilter, %{
filter_id: filter.id
})
assert Repo.aggregate(Filter, :count, :id) == 0
end
end
test "fetching a list of filters" do

View file

@ -729,7 +729,7 @@ test "redirects with oauth authorization, " <>
end
test "redirects with oauth authorization, " <>
"granting requested app-supported scopes to moderators" do
"granting requested app-supported scopes to moderators" do
app_scopes = ["read", "write", "admin", "secret_scope"]
app = insert(:oauth_app, scopes: app_scopes)
redirect_uri = OAuthController.default_redirect_uri(app)