diff --git a/docs/docs/settings/error_codes.md b/docs/docs/settings/error_codes.md index 092b05de96..ad5035e72a 100644 --- a/docs/docs/settings/error_codes.md +++ b/docs/docs/settings/error_codes.md @@ -50,6 +50,25 @@ This might be caused by an addition or removal of models to the code base or cha The settings for SITE_URL and ALLOWED_HOSTS do not match the host used to access the server. This might lead to issues with CSRF protection, CORS and other security features. The settings must be adjusted. +#### INVE-E9 +**Transition handler error - Backend** +An error occurred while discovering or executing a transition handler. This likely indicates a faulty or incompatible plugin. +This error is raised by a plugin with the `TransitionMixin` and can be debugged by looking into the logs for more information. + +#### INVE-E10 +**Plugin cannot be uninstalled or deactivated - Backend** +A plugin cannot be uninstalled if it is mandatory, a sample or a built-in plugin. Mandatory plugins can not be deactivated. + +This is to prevent accidental removal of essential system or compliance functionality. If you want to remove/deactivate a mandatory plugin, you need to remove it from the `INVENTREE_PLUGINS_MANDATORY` [setting](../start/config.md#plugin-options). Sample and built-in plugins can not be uninstalled at all but might be deactivated. + +See [Mandatory Plugins](../plugins/index.md#mandatory-plugins) for more information. + +#### INVE-E11 +**Plugin cannot override final method - Backend** +A plugin is not allowed to override a *final method* from the `InvenTreePlugin` class. + +This is a security measure to prevent plugins from changing the core functionality of InvenTree. The code of the plugin must be changed to not override functions that are marked as *final*. + ### INVE-W (InvenTree Warning) Warnings - These are non-critical errors which should be addressed when possible. @@ -144,5 +163,11 @@ To enable registration, the email settings must be configured correctly. See [e ### INVE-I (InvenTree Information) Information — These are not errors but information messages. They might point out potential issues or just provide information. +#### INVE-I1 +**Setting overridden - Backend** +Overriding a global setting with a different value than the current one. + +See [Override global settings](../settings/global.md#override-global-settings) for more information. + ### INVE-M (InvenTree Miscellaneous) Miscellaneous — These are information messages that might be used to mark debug information or other messages helpful for the InvenTree team to understand behaviour. diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index ae7f13dc1b..f82c673442 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -1438,7 +1438,9 @@ if SITE_URL: GLOBAL_SETTINGS_OVERRIDES['INVENTREE_BASE_URL'] = SITE_URL if len(GLOBAL_SETTINGS_OVERRIDES) > 0: - logger.info('Global settings overrides: %s', str(GLOBAL_SETTINGS_OVERRIDES)) + logger.info( + 'INVE-I1: Global settings overrides: %s', str(GLOBAL_SETTINGS_OVERRIDES) + ) for key in GLOBAL_SETTINGS_OVERRIDES: # Set the global setting logger.debug('- Override value for %s = ********', key) diff --git a/src/backend/InvenTree/common/apps.py b/src/backend/InvenTree/common/apps.py index 9a6e9856f6..021e6ccad4 100644 --- a/src/backend/InvenTree/common/apps.py +++ b/src/backend/InvenTree/common/apps.py @@ -56,7 +56,9 @@ class CommonConfig(AppConfig): if current_value != value: logger.info( - 'Overriding global setting: %s = %s', value, current_value + 'INVE-I1: Overriding global setting: %s = %s', + value, + current_value, ) set_global_setting(key, value, None, create=True) diff --git a/src/backend/InvenTree/generic/states/transition.py b/src/backend/InvenTree/generic/states/transition.py index 2a2b450d39..0c4c6e9089 100644 --- a/src/backend/InvenTree/generic/states/transition.py +++ b/src/backend/InvenTree/generic/states/transition.py @@ -107,14 +107,16 @@ class StateTransitionMixin: if type(handlers) is not list: logger.error( - 'Plugin %s returned invalid type for transition handlers', + 'INVE-E9: Plugin %s returned invalid type for transition handlers', plugin.slug, ) continue for handler in handlers: if not isinstance(handler, TransitionMethod): - logger.error('Invalid transition handler type: %s', handler) + logger.error( + 'INVE-E9: Invalid transition handler type: %s', handler + ) continue # Call the transition method diff --git a/src/backend/InvenTree/plugin/base/integration/TransitionMixin.py b/src/backend/InvenTree/plugin/base/integration/TransitionMixin.py index 19bc9da176..7b4a9d6981 100644 --- a/src/backend/InvenTree/plugin/base/integration/TransitionMixin.py +++ b/src/backend/InvenTree/plugin/base/integration/TransitionMixin.py @@ -48,14 +48,14 @@ class TransitionMixin: if not isinstance(handlers, list): raise TypeError( - 'TRANSITION_HANDLERS must be a list of TransitionMethod instances' + 'INVE-E9: TRANSITION_HANDLERS must be a list of TransitionMethod instances' ) handler_methods = [] for handler in handlers: if not isinstance(handler, TransitionMethod): - logger.error('Invalid transition handler type: %s', handler) + logger.error('INVE-E9: Invalid transition handler type: %s', handler) continue handler_methods.append(handler) diff --git a/src/backend/InvenTree/plugin/installer.py b/src/backend/InvenTree/plugin/installer.py index ef27b91f78..cc1624eeb8 100644 --- a/src/backend/InvenTree/plugin/installer.py +++ b/src/backend/InvenTree/plugin/installer.py @@ -341,17 +341,20 @@ def uninstall_plugin(cfg: plugin.models.PluginConfig, user=None, delete_config=T _('Plugin cannot be uninstalled as it is currently active') ) - if cfg.is_mandatory(): - raise ValidationError(_('Plugin cannot be uninstalled as it is mandatory')) + if cfg.is_mandatory(): # pragma: no cover + # This is only an additional check, as mandatory plugins cannot be deactivated + raise ValidationError( + 'INVE-E10' + _('Plugin cannot be uninstalled as it is mandatory') + ) if cfg.is_sample(): raise ValidationError( - _('Plugin cannot be uninstalled as it is a sample plugin') + 'INVE-E10' + _('Plugin cannot be uninstalled as it is a sample plugin') ) if cfg.is_builtin(): raise ValidationError( - _('Plugin cannot be uninstalled as it is a built-in plugin') + 'INVE-E10' + _('Plugin cannot be uninstalled as it is a built-in plugin') ) if not cfg.is_installed(): diff --git a/src/backend/InvenTree/plugin/plugin.py b/src/backend/InvenTree/plugin/plugin.py index 1de7946af0..df1e47c9a6 100644 --- a/src/backend/InvenTree/plugin/plugin.py +++ b/src/backend/InvenTree/plugin/plugin.py @@ -332,7 +332,8 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase): for name in child_methods: if name in final_methods: raise TypeError( - f"Plugin '{cls.__name__}' cannot override final method '{name}' from InvenTreePlugin." + 'INVE-E11: ' + + f"Plugin '{cls.__name__}' cannot override final method '{name}' from InvenTreePlugin." ) return super().__init_subclass__() diff --git a/src/backend/InvenTree/plugin/serializers.py b/src/backend/InvenTree/plugin/serializers.py index 813aebbaab..88fc9f7746 100644 --- a/src/backend/InvenTree/plugin/serializers.py +++ b/src/backend/InvenTree/plugin/serializers.py @@ -239,7 +239,9 @@ class PluginActivateSerializer(serializers.Serializer): active = validated_data.get('active', True) if not active and instance.is_mandatory(): - raise ValidationError(_('Mandatory plugin cannot be deactivated')) + raise ValidationError( + 'INVE-E10: ' + _('Mandatory plugin cannot be deactivated') + ) instance.activate(active) return instance