mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Feature: app branding (#5357)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import status
|
||||
@@ -49,10 +50,34 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
||||
"rotate_pages_threshold": None,
|
||||
"max_image_pixels": None,
|
||||
"color_conversion_strategy": None,
|
||||
"app_title": None,
|
||||
"app_logo": None,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def test_api_get_ui_settings_with_config(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing config with app_title, app_logo specified
|
||||
WHEN:
|
||||
- API to retrieve uisettings is called
|
||||
THEN:
|
||||
- app_title and app_logo are included
|
||||
"""
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
config.app_title = "Fancy New Title"
|
||||
config.app_logo = "/logo/example.jpg"
|
||||
config.save()
|
||||
response = self.client.get("/api/ui_settings/", format="json")
|
||||
self.assertDictContainsSubset(
|
||||
{
|
||||
"app_title": config.app_title,
|
||||
"app_logo": config.app_logo,
|
||||
},
|
||||
response.data["settings"],
|
||||
)
|
||||
|
||||
def test_api_update_config(self):
|
||||
"""
|
||||
GIVEN:
|
||||
@@ -100,3 +125,37 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
self.assertEqual(config.user_args, None)
|
||||
self.assertEqual(config.language, None)
|
||||
|
||||
def test_api_replace_app_logo(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing config with app_logo specified
|
||||
WHEN:
|
||||
- API to replace app_logo is called
|
||||
THEN:
|
||||
- old app_logo file is deleted
|
||||
"""
|
||||
with open(
|
||||
os.path.join(os.path.dirname(__file__), "samples", "simple.jpg"),
|
||||
"rb",
|
||||
) as f:
|
||||
self.client.patch(
|
||||
f"{self.ENDPOINT}1/",
|
||||
{
|
||||
"app_logo": f,
|
||||
},
|
||||
)
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
old_logo = config.app_logo
|
||||
self.assertTrue(os.path.exists(old_logo.path))
|
||||
with open(
|
||||
os.path.join(os.path.dirname(__file__), "samples", "simple.png"),
|
||||
"rb",
|
||||
) as f:
|
||||
self.client.patch(
|
||||
f"{self.ENDPOINT}1/",
|
||||
{
|
||||
"app_logo": f,
|
||||
},
|
||||
)
|
||||
self.assertFalse(os.path.exists(old_logo.path))
|
||||
|
@@ -35,6 +35,8 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase):
|
||||
self.assertDictEqual(
|
||||
response.data["settings"],
|
||||
{
|
||||
"app_title": None,
|
||||
"app_logo": None,
|
||||
"update_checking": {
|
||||
"backend_setting": "default",
|
||||
},
|
||||
|
@@ -120,6 +120,7 @@ from documents.serialisers import WorkflowTriggerSerializer
|
||||
from documents.signals import document_updated
|
||||
from documents.tasks import consume_file
|
||||
from paperless import version
|
||||
from paperless.config import GeneralConfig
|
||||
from paperless.db import GnuPG
|
||||
from paperless.views import StandardPagination
|
||||
|
||||
@@ -1164,6 +1165,16 @@ class UiSettingsView(GenericAPIView):
|
||||
ui_settings["update_checking"] = {
|
||||
"backend_setting": settings.ENABLE_UPDATE_CHECK,
|
||||
}
|
||||
|
||||
general_config = GeneralConfig()
|
||||
|
||||
ui_settings["app_title"] = settings.APP_TITLE
|
||||
if general_config.app_title is not None and len(general_config.app_title) > 0:
|
||||
ui_settings["app_title"] = general_config.app_title
|
||||
ui_settings["app_logo"] = settings.APP_LOGO
|
||||
if general_config.app_logo is not None and len(general_config.app_logo) > 0:
|
||||
ui_settings["app_logo"] = general_config.app_logo
|
||||
|
||||
user_resp = {
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
|
Reference in New Issue
Block a user