From 7834171c2a63c41c5a7a55abe954c938d76fbb5f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 23 Apr 2022 23:38:49 +0200 Subject: [PATCH 01/19] [FR] White labeling Fixes #2301 --- InvenTree/InvenTree/settings.py | 7 +++++++ InvenTree/config_template.yaml | 3 +++ InvenTree/part/templatetags/inventree_extras.py | 7 +++++++ InvenTree/templates/account/login.html | 14 ++++++-------- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e1c584362f..b96705d6dc 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -67,6 +67,13 @@ DEMO_MODE = _is_true(get_setting( CONFIG.get('demo', False) )) +# user interface customization values +CUSTOMIZE = get_setting( + 'INVENTREE_CUSTOMIZE', + CONFIG.get('customize', {}), + {} +) + DOCKER = _is_true(get_setting( 'INVENTREE_DOCKER', False diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 65dd20d3e8..862d062787 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -186,3 +186,6 @@ static_root: '/home/inventree/data/static' # KEYCLOAK_URL: 'https://keycloak.custom/auth' # KEYCLOAK_REALM: 'master' +# customize: +# login_message: | +# InvenTree demo instance - Click here for login details diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index dc93e00efa..2d0b0660d6 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -509,6 +509,13 @@ def mail_configured(): return bool(settings.EMAIL_HOST) +@register.simple_tag() +def inventree_customize(reference, *args, **kwargs): + """ Return customization values for the user interface """ + + return djangosettings.CUSTOMIZE.get(reference, '') + + class I18nStaticNode(StaticNode): """ custom StaticNode diff --git a/InvenTree/templates/account/login.html b/InvenTree/templates/account/login.html index 6e62560bfa..1a4df286bb 100644 --- a/InvenTree/templates/account/login.html +++ b/InvenTree/templates/account/login.html @@ -1,7 +1,7 @@ {% extends "account/base.html" %} {% load inventree_extras %} -{% load i18n account socialaccount crispy_forms_tags inventree_extras %} +{% load i18n account socialaccount crispy_forms_tags inventree_extras markdownify %} {% block head_title %}{% trans "Sign In" %}{% endblock %} @@ -10,6 +10,7 @@ {% settings_value 'LOGIN_ENABLE_REG' as enable_reg %} {% settings_value 'LOGIN_ENABLE_PWD_FORGOT' as enable_pwd_forgot %} {% settings_value 'LOGIN_ENABLE_SSO' as enable_sso %} +{% inventree_customize 'login_message' as login_message %} {% mail_configured as mail_conf %} {% inventree_demo_mode as demo %} @@ -35,19 +36,16 @@ for a account and sign in below:{% endblocktrans %}

{% endif %}
+ {% if login_message %} + {{ login_message|markdownify }} +
+ {% endif %}
{% if mail_conf and enable_pwd_forgot and not demo %} {% trans "Forgot Password?" %} {% endif %} - {% if demo %} -

-

- {% trans "InvenTree demo instance" %} - {% trans "Click here for login details" %} -
-

- {% endif %} {% if enable_sso %} From 54d8a4e8026eeb01f3a9b5df1c576e9dd4e838e2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 00:21:33 +0200 Subject: [PATCH 02/19] use server title instead of InvenTree --- InvenTree/company/templates/company/manufacturer_part.html | 3 ++- InvenTree/templates/403.html | 3 ++- InvenTree/templates/404.html | 3 ++- InvenTree/templates/500.html | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/InvenTree/company/templates/company/manufacturer_part.html b/InvenTree/company/templates/company/manufacturer_part.html index 84e8016a59..fb33128a77 100644 --- a/InvenTree/company/templates/company/manufacturer_part.html +++ b/InvenTree/company/templates/company/manufacturer_part.html @@ -1,9 +1,10 @@ {% extends "page_base.html" %} {% load static %} {% load i18n %} +{% load inventree_extras %} {% block page_title %} -InvenTree | {% trans "Manufacturer Part" %} +{% inventree_title %} | {% trans "Manufacturer Part" %} {% endblock %} {% block sidebar %} diff --git a/InvenTree/templates/403.html b/InvenTree/templates/403.html index 372bd9fe27..4ee8367d9c 100644 --- a/InvenTree/templates/403.html +++ b/InvenTree/templates/403.html @@ -1,8 +1,9 @@ {% extends "base.html" %} {% load i18n %} +{% load inventree_extras %} {% block page_title %} -InvenTree | {% trans "Permission Denied" %} +{% inventree_title %} | {% trans "Permission Denied" %} {% endblock %} {% block content %} diff --git a/InvenTree/templates/404.html b/InvenTree/templates/404.html index 3cb6464d99..aae55031f3 100644 --- a/InvenTree/templates/404.html +++ b/InvenTree/templates/404.html @@ -1,8 +1,9 @@ {% extends "base.html" %} {% load i18n %} +{% load inventree_extras %} {% block page_title %} -InvenTree | {% trans "Page Not Found" %} +{% inventree_title %} | {% trans "Page Not Found" %} {% endblock %} {% block content %} diff --git a/InvenTree/templates/500.html b/InvenTree/templates/500.html index 3fab6c0a17..f50a5ea6fe 100644 --- a/InvenTree/templates/500.html +++ b/InvenTree/templates/500.html @@ -1,8 +1,9 @@ {% extends "base.html" %} {% load i18n %} +{% load inventree_extras %} {% block page_title %} -InvenTree | {% trans "Internal Server Error" %} +{% inventree_title %} | {% trans "Internal Server Error" %} {% endblock %} {% block content %} @@ -11,7 +12,7 @@ InvenTree | {% trans "Internal Server Error" %}

{% trans "Internal Server Error" %}

- {% trans "The InvenTree server raised an internal error" %}
+ {% blocktrans %}The {{ inventree_title }} server raised an internal error{% endblocktrans %}
{% trans "Refer to the error log in the admin interface for further details" %}
From 9673d810145a44031ebb7efcab2c1f0f0cd8397f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 00:23:26 +0200 Subject: [PATCH 03/19] remove InvenTree name where not needed --- InvenTree/templates/InvenTree/settings/plugin.html | 2 +- InvenTree/templates/InvenTree/settings/plugin_settings.html | 2 +- InvenTree/templates/InvenTree/settings/user_display.html | 2 +- InvenTree/templates/account/base.html | 2 +- InvenTree/templates/base.html | 2 +- InvenTree/templates/skeleton.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/InvenTree/templates/InvenTree/settings/plugin.html b/InvenTree/templates/InvenTree/settings/plugin.html index 2366096b87..94a166c84a 100644 --- a/InvenTree/templates/InvenTree/settings/plugin.html +++ b/InvenTree/templates/InvenTree/settings/plugin.html @@ -13,7 +13,7 @@ {% block content %}
- {% trans "Changing the settings below require you to immediatly restart InvenTree. Do not change this while under active usage." %} + {% trans "Changing the settings below require you to immediatly restart the server. Do not change this while under active usage." %}
diff --git a/InvenTree/templates/InvenTree/settings/plugin_settings.html b/InvenTree/templates/InvenTree/settings/plugin_settings.html index 9c5fa2d7c0..79150ec879 100644 --- a/InvenTree/templates/InvenTree/settings/plugin_settings.html +++ b/InvenTree/templates/InvenTree/settings/plugin_settings.html @@ -85,7 +85,7 @@ {% if plugin.is_package %} {% trans "This plugin was installed as a package" %} {% else %} - {% trans "This plugin was found in a local InvenTree path" %} + {% trans "This plugin was found in a local server path" %} {% endif %} diff --git a/InvenTree/templates/InvenTree/settings/user_display.html b/InvenTree/templates/InvenTree/settings/user_display.html index f5e74b04c1..1f52c095ac 100644 --- a/InvenTree/templates/InvenTree/settings/user_display.html +++ b/InvenTree/templates/InvenTree/settings/user_display.html @@ -101,7 +101,7 @@

{% trans "Help the translation efforts!" %}

-

{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the InvenTree web application is community contributed via crowdin. Contributions are welcomed and encouraged.{% endblocktrans %}

+

{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the web application is community contributed via crowdin. Contributions are welcomed and encouraged.{% endblocktrans %}

diff --git a/InvenTree/templates/account/base.html b/InvenTree/templates/account/base.html index 6c54faac67..06c9485fb5 100644 --- a/InvenTree/templates/account/base.html +++ b/InvenTree/templates/account/base.html @@ -89,7 +89,7 @@ - + diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 0739b42b6e..0bca5cc0f1 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -166,7 +166,7 @@ - + diff --git a/InvenTree/templates/skeleton.html b/InvenTree/templates/skeleton.html index 9b78a9a329..1c4775372e 100644 --- a/InvenTree/templates/skeleton.html +++ b/InvenTree/templates/skeleton.html @@ -75,7 +75,7 @@ - + {% block body_scripts_inventree %} From ff9d8e7b6ba458d0499d2c4b8a0d0bb7823e6cb8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 00:28:27 +0200 Subject: [PATCH 04/19] use instance title in version string --- InvenTree/part/templatetags/inventree_extras.py | 7 ++++++- InvenTree/report/templates/report/inventree_po_report.html | 2 +- InvenTree/report/templates/report/inventree_so_report.html | 2 +- .../templates/report/inventree_test_report_base.html | 2 +- InvenTree/templates/email/email.html | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 2d0b0660d6..0400b54ebd 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -220,8 +220,13 @@ def python_version(*args, **kwargs): @register.simple_tag() -def inventree_version(*args, **kwargs): +def inventree_version(shortstring=False, *args, **kwargs): """ Return InvenTree version string """ + if shortstring: + return _("{title} v{version}".format( + title=version.inventreeInstanceTitle(), + version=version.inventreeVersion() + )) return version.inventreeVersion() diff --git a/InvenTree/report/templates/report/inventree_po_report.html b/InvenTree/report/templates/report/inventree_po_report.html index f999644c2e..d1cae75c3b 100644 --- a/InvenTree/report/templates/report/inventree_po_report.html +++ b/InvenTree/report/templates/report/inventree_po_report.html @@ -15,7 +15,7 @@ content: "v{{report_revision}} - {{ date.isoformat }}"; {% endblock %} {% block bottom_center %} -content: "InvenTree v{% inventree_version %}"; +content: "{% inventree_version shortstring=True %}"; {% endblock %} {% block style %} diff --git a/InvenTree/report/templates/report/inventree_so_report.html b/InvenTree/report/templates/report/inventree_so_report.html index 255f0c6a50..5cb4900719 100644 --- a/InvenTree/report/templates/report/inventree_so_report.html +++ b/InvenTree/report/templates/report/inventree_so_report.html @@ -16,7 +16,7 @@ content: "v{{report_revision}} - {{ date.isoformat }}"; {% endblock %} {% block bottom_center %} -content: "InvenTree v{% inventree_version %}"; +content: "{% inventree_version shortstring=True %}"; {% endblock %} {% block style %} diff --git a/InvenTree/report/templates/report/inventree_test_report_base.html b/InvenTree/report/templates/report/inventree_test_report_base.html index d702973c30..73ee55c680 100644 --- a/InvenTree/report/templates/report/inventree_test_report_base.html +++ b/InvenTree/report/templates/report/inventree_test_report_base.html @@ -14,7 +14,7 @@ content: "{{ date.isoformat }}"; {% endblock %} {% block bottom_center %} -content: "InvenTree v{% inventree_version %}"; +content: "{% inventree_version shortstring=True %}"; {% endblock %} {% block top_center %} diff --git a/InvenTree/templates/email/email.html b/InvenTree/templates/email/email.html index 97e9a40f37..0b3c944da4 100644 --- a/InvenTree/templates/email/email.html +++ b/InvenTree/templates/email/email.html @@ -32,7 +32,7 @@ {% block footer_prefix %} {% endblock %} -

{% trans "InvenTree version" %}: {% inventree_version %} - inventree.readthedocs.io

+

{% inventree_version shortstring=True %} - readthedocs.io

{% block footer_suffix %} {% endblock %} From 1127bf2497f95c9ad3937438d84cd1a621be7f67 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 01:02:41 +0200 Subject: [PATCH 05/19] make it possible to resitrict the about modal --- InvenTree/common/models.py | 7 +++++++ InvenTree/part/templatetags/inventree_extras.py | 8 ++++++++ InvenTree/templates/InvenTree/settings/global.html | 1 + InvenTree/templates/base.html | 3 ++- InvenTree/templates/navbar.html | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index bb7de56e99..d0ca4636a0 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -696,6 +696,13 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'default': False, }, + 'INVENTREE_RESTRICT_ABOUT': { + 'name': _('Restrict showing `about`'), + 'description': _('Show the `about` modal only to superusers'), + 'validator': bool, + 'default': False, + }, + 'INVENTREE_COMPANY_NAME': { 'name': _('Company name'), 'description': _('Internal company name'), diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 0400b54ebd..ad23487a83 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -166,6 +166,14 @@ def inventree_demo_mode(*args, **kwargs): return djangosettings.DEMO_MODE +@register.simple_tag() +def inventree_show_about(user, *args, **kwargs): + """ Return True if the about modal should be shown """ + if InvenTreeSetting.get_setting('INVENTREE_RESTRICT_ABOUT') and not user.is_superuser: + return False + return True + + @register.simple_tag() def inventree_docker_mode(*args, **kwargs): """ Return True if the server is running as a Docker image """ diff --git a/InvenTree/templates/InvenTree/settings/global.html b/InvenTree/templates/InvenTree/settings/global.html index 60ae84f001..4d36d59369 100644 --- a/InvenTree/templates/InvenTree/settings/global.html +++ b/InvenTree/templates/InvenTree/settings/global.html @@ -15,6 +15,7 @@ {% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE_TITLE" icon="fa-info-circle" %} + {% include "InvenTree/settings/setting.html" with key="INVENTREE_RESTRICT_ABOUT" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_BASE_URL" icon="fa-globe" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_COMPANY_NAME" icon="fa-building" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_DOWNLOAD_FROM_URL" icon="fa-cloud-download-alt" %} diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 0bca5cc0f1..0188ecefa5 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -7,6 +7,7 @@ {% settings_value "REPORT_ENABLE" as report_enabled %} {% settings_value "SERVER_RESTART_REQUIRED" as server_restart_required %} {% settings_value "LABEL_ENABLE" with user=user as labels_enabled %} +{% inventree_show_about user as show_about %} {% inventree_demo_mode as demo_mode %} @@ -130,7 +131,7 @@ {% include 'modals.html' %} - {% include 'about.html' %} + {% if show_about %}{% include 'about.html' %}{% endif %} {% include "notifications.html" %} {% include "search.html" %} diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index d687300eb4..3af7fe481f 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -7,6 +7,7 @@ {% settings_value 'STICKY_HEADER' user=request.user as sticky %} {% navigation_enabled as plugin_nav %} {% inventree_demo_mode as demo %} +{% inventree_show_about user as show_about %}