Compare commits

...

3 commits

4 changed files with 38 additions and 5 deletions

View file

@ -272,7 +272,8 @@
local_bubble: [],
max_frontend_settings_json_chars: 100_000,
export_prometheus_metrics: true,
federated_timeline_available: true
federated_timeline_available: true,
local_timeline_available: true
config :pleroma, :welcome,
direct_message: [

View file

@ -63,6 +63,7 @@ To add configuration to your config file, you can copy it from the base config.
* `local_bubble`: Array of domains representing instances closely related to yours. Used to populate the `bubble` timeline. e.g `["example.com"]`, (default: `[]`)
* `languages`: List of Language Codes used by the instance. This is used to try and set a default language from the frontend. It will try and find the first match between the languages set here and the user's browser languages. It will default to the first language in this setting if there is no match.. (default `["en"]`)
* `export_prometheus_metrics`: Enable prometheus metrics, served at `/api/v1/akkoma/metrics`, requiring the `admin:metrics` oauth scope.
* `local_timeline_available`: Set to `false` to remove access to the local timeline for all users.
## :database
* `improved_hashtag_timeline`: Setting to force toggle / force disable improved hashtags timeline. `:enabled` forces hashtags to be fetched from `hashtags` table for hashtags timeline. `:disabled` forces object-embedded hashtags to be used (slower). Keep it `:auto` for automatic behaviour (it is auto-set to `:enabled` [unless overridden] when HashtagsTableMigrator completes).

View file

@ -122,8 +122,14 @@ def public(%{assigns: %{user: user}} = conn, params) do
local_only = params[:local]
timeline_type = if local_only, do: :local, else: :federated
timeline_enabled =
case timeline_type do
:local -> Config.get([:instance, :local_timeline_available], true)
:federated -> Config.get([:instance, :federated_timeline_available], true)
end
with {:enabled, true} <-
{:enabled, local_only || Config.get([:instance, :federated_timeline_available], true)},
{:enabled, timeline_enabled},
{:authenticated, true} <-
{:authenticated, !(is_nil(user) and restrict_unauthenticated?(timeline_type))} do
Logger.debug("TimelineController.public: fetching activities")
@ -152,9 +158,15 @@ def public(%{assigns: %{user: user}} = conn, params) do
)
else
{:enabled, false} ->
error_msg =
case timeline_type do
:local -> "Local timeline is disabled"
:federated -> "Federated timeline is disabled"
end
conn
|> put_status(404)
|> json(%{error: "Federated timeline is disabled"})
|> json(%{error: error_msg})
{:authenticated, false} ->
fail_on_bad_auth(conn)

View file

@ -409,7 +409,7 @@ test "should not return local-only posts for anonymous users" do
assert [] = result
end
test "should return 404 if disabled" do
test "should return 404 if federated timeline disabled" do
clear_config([:instance, :federated_timeline_available], false)
result =
@ -420,7 +420,26 @@ test "should return 404 if disabled" do
assert %{"error" => "Federated timeline is disabled"} = result
end
test "should not return 404 if local is specified" do
test "should not return 404 if local timeline disabled" do
clear_config([:instance, :local_timeline_available], false)
build_conn()
|> get("/api/v1/timelines/public")
|> json_response_and_validate_schema(200)
end
test "should return 404 if local is specified and local timeline disabled" do
clear_config([:instance, :local_timeline_available], false)
result =
build_conn()
|> get("/api/v1/timelines/public?local=true")
|> json_response_and_validate_schema(404)
assert %{"error" => "Local timeline is disabled"} = result
end
test "should not return 404 if local is specified and federated timeline disabled" do
clear_config([:instance, :federated_timeline_available], false)
build_conn()