From 7ad21b7d25608eec9703fdf1d2c575247d2b4f2c Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sat, 28 Apr 2018 06:24:44 +0200
Subject: [PATCH] Fix #186: moved high-level settings to database preferences

---
 .env.dev                            |  1 -
 api/tests/music/test_permissions.py |  2 +-
 changes/changelog.d/186.enhancement | 24 ++++++++++++++++++++++++
 docs/configuration.rst              |  2 ++
 docs/federation.rst                 |  5 ++---
 5 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 changes/changelog.d/186.enhancement

diff --git a/.env.dev b/.env.dev
index c0926250..d9e2dd3c 100644
--- a/.env.dev
+++ b/.env.dev
@@ -1,4 +1,3 @@
-API_AUTHENTICATION_REQUIRED=True
 RAVEN_ENABLED=false
 RAVEN_DSN=https://44332e9fdd3d42879c7d35bf8562c6a4:0062dc16a22b41679cd5765e5342f716@sentry.eliotberriot.com/5
 DJANGO_ALLOWED_HOSTS=.funkwhale.test,localhost,nginx,0.0.0.0,127.0.0.1
diff --git a/api/tests/music/test_permissions.py b/api/tests/music/test_permissions.py
index d36f3788..a5f0c410 100644
--- a/api/tests/music/test_permissions.py
+++ b/api/tests/music/test_permissions.py
@@ -13,7 +13,7 @@ def test_list_permission_no_protect(anonymous_user, api_request, settings):
 
 
 def test_list_permission_protect_anonymous(
-        anonymous_user, api_request, settings):
+        db, anonymous_user, api_request, settings):
     settings.PROTECT_AUDIO_FILES = True
     view = APIView.as_view()
     permission = permissions.Listen()
diff --git a/changes/changelog.d/186.enhancement b/changes/changelog.d/186.enhancement
new file mode 100644
index 00000000..36777c78
--- /dev/null
+++ b/changes/changelog.d/186.enhancement
@@ -0,0 +1,24 @@
+Store high-level settings (such as federation or auth-related ones) in database (#186)
+
+Changelog
+^^^^^^^^^
+Due to the work done in #186, the following environment variables have been
+deprecated:
+
+- FEDERATION_ENABLED
+- FEDERATION_COLLECTION_PAGE_SIZE
+- FEDERATION_MUSIC_NEEDS_APPROVAL
+- FEDERATION_ACTOR_FETCH_DELAY
+- PLAYLISTS_MAX_TRACKS
+- API_AUTHENTICATION_REQUIRED
+
+Configuration for this settings has been moved to database, as it will provide
+a better user-experience, by allowing you to edit these values on-the-fly,
+without restarting Funkwhale processes.
+
+You can leave those environment variables in your .env file for now, as the
+values will be used to populate the database entries. We'll make a proper
+announcement when the variables won't be used anymore.
+
+Please browse https://docs.funkwhale.audio/configuration.html#instance-settings
+for more information about instance configuration using the web interface.
diff --git a/docs/configuration.rst b/docs/configuration.rst
index c0de76f5..1c89feeb 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -18,6 +18,8 @@ and technical aspects of your instance, such as database credentials.
     on environment variables.
 
 
+.. _instance-settings:
+
 Instance settings
 -----------------
 
diff --git a/docs/federation.rst b/docs/federation.rst
index 5b030074..0f016ada 100644
--- a/docs/federation.rst
+++ b/docs/federation.rst
@@ -12,8 +12,7 @@ Managing federation
 
 Federation management is only available to instance admins and users
 who have the proper permissions. You can disable federation completely
-at the instance level by setting the FEDERATION_ENABLED environment variable
-to False.
+at the instance level by editing the ``federation__enabled`` :ref:`setting <instance-settings>`.
 
 On the front end, assuming you have the proper permission, you will see
 a "Federation" link in the sidebar.
@@ -52,6 +51,6 @@ each other instance asking for access to library. This is by design,
 to ensure your library is not shared publicly without your consent.
 
 However, if you're confident about federating publicly without manual approval,
-you can set the FEDERATION_MUSIC_NEEDS_APPROVAL environment variable to false.
+you can set the ``federation__music_needs_approval`` :ref:`setting <instance-settings>` to false.
 Follow requests will be accepted automatically and followers
 given access to your library without manual intervention.
-- 
GitLab