mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Email history enhancements (#10109)
* Improve formatting for <ConfigValueList> - Only used for email settings currently * API updates: - Allow delete operations of email record - Allow bulk delete operations of email record * Table updates: - Improved table rendering - Allow delete ops * Display timestamp in email table * Add setting to control email cleanup interval * Add scheduled task to delete old emails * Bump API version
This commit is contained in:
		| @@ -1,12 +1,15 @@ | ||||
| """InvenTree API version information.""" | ||||
|  | ||||
| # InvenTree API version | ||||
| INVENTREE_API_VERSION = 376 | ||||
| INVENTREE_API_VERSION = 377 | ||||
|  | ||||
| """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" | ||||
|  | ||||
| INVENTREE_API_TEXT = """ | ||||
|  | ||||
| v377 -> 2025-08-01 : https://github.com/inventree/InvenTree/pull/10109 | ||||
|     - Allow email records to be deleted via the API | ||||
|  | ||||
| v376 -> 2025-08-01 : https://github.com/inventree/InvenTree/pull/10108 | ||||
|     - Fix search fields for ReturnOrderLineItem API list endpoint | ||||
|  | ||||
|   | ||||
| @@ -466,6 +466,26 @@ def delete_old_notifications(): | ||||
|         ) | ||||
|  | ||||
|  | ||||
| @tracer.start_as_current_span('delete_old_emails') | ||||
| @scheduled_task(ScheduledTask.DAILY) | ||||
| def delete_old_emails(): | ||||
|     """Delete old email messages.""" | ||||
|     try: | ||||
|         from common.models import EmailMessage | ||||
|  | ||||
|         days = get_global_setting('INVENTREE_DELETE_EMAIL_DAYS', 30) | ||||
|         threshold = timezone.now() - timedelta(days=days) | ||||
|  | ||||
|         emails = EmailMessage.objects.filter(timestamp__lte=threshold) | ||||
|  | ||||
|         if emails.count() > 0: | ||||
|             logger.info('Deleted %s old email messages', emails.count()) | ||||
|             emails.delete() | ||||
|  | ||||
|     except AppRegistryNotReady: | ||||
|         logger.info("Could not perform 'delete_old_emails' - App registry not ready") | ||||
|  | ||||
|  | ||||
| @tracer.start_as_current_span('check_for_updates') | ||||
| @scheduled_task(ScheduledTask.DAILY) | ||||
| def check_for_updates(): | ||||
|   | ||||
| @@ -43,6 +43,7 @@ from InvenTree.mixins import ( | ||||
|     ListAPI, | ||||
|     ListCreateAPI, | ||||
|     RetrieveAPI, | ||||
|     RetrieveDestroyAPI, | ||||
|     RetrieveUpdateAPI, | ||||
|     RetrieveUpdateDestroyAPI, | ||||
| ) | ||||
| @@ -842,7 +843,7 @@ class EmailMessageMixin: | ||||
|     permission_classes = [IsSuperuserOrSuperScope] | ||||
|  | ||||
|  | ||||
| class EmailMessageList(EmailMessageMixin, ListAPI): | ||||
| class EmailMessageList(EmailMessageMixin, BulkDeleteMixin, ListAPI): | ||||
|     """List view for email objects.""" | ||||
|  | ||||
|     filter_backends = SEARCH_ORDER_FILTER | ||||
| @@ -865,7 +866,7 @@ class EmailMessageList(EmailMessageMixin, ListAPI): | ||||
|     ] | ||||
|  | ||||
|  | ||||
| class EmailMessageDetail(EmailMessageMixin, RetrieveAPI): | ||||
| class EmailMessageDetail(EmailMessageMixin, RetrieveDestroyAPI): | ||||
|     """Detail view for an email object.""" | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -331,6 +331,15 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = { | ||||
|         'units': _('days'), | ||||
|         'validator': [int, MinValueValidator(7)], | ||||
|     }, | ||||
|     'INVENTREE_DELETE_EMAIL_DAYS': { | ||||
|         'name': _('Email Deletion Interval'), | ||||
|         'description': _( | ||||
|             'Email messages will be deleted after specified number of days' | ||||
|         ), | ||||
|         'default': 30, | ||||
|         'units': _('days'), | ||||
|         'validator': [int, MinValueValidator(7)], | ||||
|     }, | ||||
|     'BARCODE_ENABLE': { | ||||
|         'name': _('Barcode Support'), | ||||
|         'description': _('Enable barcode scanner support in the web interface'), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user