2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue2279

This commit is contained in:
Matthias
2022-02-12 00:51:15 +01:00
103 changed files with 27416 additions and 23821 deletions

View File

@ -67,7 +67,6 @@ class WebhookView(CsrfExemptMixin, APIView):
message,
)
# return results
data = self.webhook.get_return(payload, headers, request)
return HttpResponse(data)

View File

@ -9,8 +9,6 @@ import os
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError
# from company.models import ManufacturerPart, SupplierPart
class FileManager:
""" Class for managing an uploaded file """

View File

@ -354,7 +354,7 @@ class BaseInvenTreeSetting(models.Model):
setting.value = str(value)
setting.save()
key = models.CharField(max_length=50, blank=False, unique=False, help_text=_('Settings key (must be unique - case insensitive'))
key = models.CharField(max_length=50, blank=False, unique=False, help_text=_('Settings key (must be unique - case insensitive)'))
value = models.CharField(max_length=200, blank=True, unique=False, help_text=_('Settings value'))
@ -781,6 +781,18 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'validator': bool,
},
# 2022-02-03
# This setting exists as an interim solution for extremely slow part page load times when the part has a complex BOM
# In an upcoming release, pricing history (and BOM pricing) will be cached,
# rather than having to be re-calculated every time the page is loaded!
# For now, we will simply hide part pricing by default
'PART_SHOW_PRICE_HISTORY': {
'name': _('Show Price History'),
'description': _('Display historical pricing for Part'),
'default': False,
'validator': bool,
},
'PART_SHOW_RELATED': {
'name': _('Show related parts'),
'description': _('Display related parts for a part'),
@ -1480,11 +1492,9 @@ class WebhookEndpoint(models.Model):
def process_webhook(self):
if self.token:
self.token = self.token
self.verify = VerificationMethod.TOKEN
# TODO make a object-setting
if self.secret:
self.secret = self.secret
self.verify = VerificationMethod.HMAC
# TODO make a object-setting
return True
@ -1494,6 +1504,7 @@ class WebhookEndpoint(models.Model):
# no token
if self.verify == VerificationMethod.NONE:
# do nothing as no method was chosen
pass
# static token

View File

@ -6,6 +6,7 @@ from django.template.loader import render_to_string
from allauth.account.models import EmailAddress
from InvenTree.helpers import inheritors
from InvenTree.ready import isImportingData
from common.models import NotificationEntry, NotificationMessage
import InvenTree.tasks
@ -144,6 +145,10 @@ def trigger_notifaction(obj, category=None, obj_ref='pk', targets=None, target_f
"""
Send out an notification
"""
# check if data is importet currently
if isImportingData():
return
# Resolve objekt reference
obj_ref_value = getattr(obj, obj_ref)
# Try with some defaults

View File

@ -10,6 +10,8 @@ from django.contrib.auth import get_user_model
from .models import InvenTreeSetting, WebhookEndpoint, WebhookMessage, NotificationEntry
from .api import WebhookView
CONTENT_TYPE_JSON = 'application/json'
class SettingsTest(TestCase):
"""
@ -105,7 +107,7 @@ class WebhookMessageTests(TestCase):
def test_missing_token(self):
response = self.client.post(
self.url,
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
)
assert response.status_code == HTTPStatus.FORBIDDEN
@ -116,7 +118,7 @@ class WebhookMessageTests(TestCase):
def test_bad_token(self):
response = self.client.post(
self.url,
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
**{'HTTP_TOKEN': '1234567fghj'},
)
@ -126,7 +128,7 @@ class WebhookMessageTests(TestCase):
def test_bad_url(self):
response = self.client.post(
'/api/webhook/1234/',
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
)
assert response.status_code == HTTPStatus.NOT_FOUND
@ -135,7 +137,7 @@ class WebhookMessageTests(TestCase):
response = self.client.post(
self.url,
data="{'this': 123}",
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
**{'HTTP_TOKEN': str(self.endpoint_def.token)},
)
@ -152,7 +154,7 @@ class WebhookMessageTests(TestCase):
# check
response = self.client.post(
self.url,
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
)
assert response.status_code == HTTPStatus.OK
@ -167,7 +169,7 @@ class WebhookMessageTests(TestCase):
# check
response = self.client.post(
self.url,
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
)
assert response.status_code == HTTPStatus.FORBIDDEN
@ -182,7 +184,7 @@ class WebhookMessageTests(TestCase):
# check
response = self.client.post(
self.url,
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
**{'HTTP_TOKEN': str('68MXtc/OiXdA5e2Nq9hATEVrZFpLb3Zb0oau7n8s31I=')},
)
@ -193,7 +195,7 @@ class WebhookMessageTests(TestCase):
response = self.client.post(
self.url,
data={"this": "is a message"},
content_type='application/json',
content_type=CONTENT_TYPE_JSON,
**{'HTTP_TOKEN': str(self.endpoint_def.token)},
)