From f60cef93554fb42fd327c5864b1e40658beb93d1 Mon Sep 17 00:00:00 2001 From: Benedikt Kuehne Date: Thu, 16 Mar 2023 10:31:07 +0100 Subject: [PATCH 01/16] truncate linux-strings --- embark/reporter/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index 9947b6666..cb8c9629e 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -187,6 +187,12 @@ def get_accumulated_reports(request): data[charfield] = {} value = result.pop(charfield) + + # clean-up for linux extensive os-descriptions + if value.startswith("Linux"): + value = value.split("/", 2)[:2] + value = (value[:16] + '..') if len(value) > 18 else value + if value not in data[charfield]: data[charfield][value] = 0 From 82724f7d41dfe4fbb948eeee7daa799e993131e1 Mon Sep 17 00:00:00 2001 From: Benedikt Kuehne Date: Tue, 21 Mar 2023 08:16:27 +0100 Subject: [PATCH 02/16] rm shorten --- embark/reporter/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index cb8c9629e..a0e16e603 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -191,7 +191,8 @@ def get_accumulated_reports(request): # clean-up for linux extensive os-descriptions if value.startswith("Linux"): value = value.split("/", 2)[:2] - value = (value[:16] + '..') if len(value) > 18 else value + # value = (value[:16] + '..') if len(value) > 18 else value + value = value[:16] if value not in data[charfield]: data[charfield][value] = 0 From a199bb98e91087468dd6e3065971f61f66beee53 Mon Sep 17 00:00:00 2001 From: Benedikt Kuehne Date: Tue, 21 Mar 2023 08:58:22 +0100 Subject: [PATCH 03/16] update filter os --- embark/reporter/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index a0e16e603..68ba27be1 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -183,16 +183,16 @@ def get_accumulated_reports(request): strcpy_bins[key] += int(strcpy_bin[key]) for charfield in charfields: + # clean-up for linux extensive os-descriptions + if charfield.startswith("Linux"): + charfield = charfield.split("/", 2)[:2] + charfield = (charfield[:16] + '..') if len(charfield) > 18 else charfield + if charfield not in data: data[charfield] = {} value = result.pop(charfield) - - # clean-up for linux extensive os-descriptions - if value.startswith("Linux"): - value = value.split("/", 2)[:2] - # value = (value[:16] + '..') if len(value) > 18 else value - value = value[:16] + if value not in data[charfield]: data[charfield][value] = 0 From eb13b9ee603dc5ef04b7bf5dae9544ce195d2f67 Mon Sep 17 00:00:00 2001 From: Benedikt Kuehne Date: Tue, 21 Mar 2023 09:30:23 +0100 Subject: [PATCH 04/16] clean --- embark/reporter/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index 68ba27be1..2995a1308 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -192,7 +192,6 @@ def get_accumulated_reports(request): data[charfield] = {} value = result.pop(charfield) - if value not in data[charfield]: data[charfield][value] = 0 From b0c85aedccdcc49204826f8415ebbceea4bedc03 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 09:58:31 +0100 Subject: [PATCH 05/16] update --- embark/reporter/views.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index d436bb23f..2995a1308 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -193,11 +193,6 @@ def get_accumulated_reports(request): value = result.pop(charfield) - # clean-up for linux extensive os-descriptions - if value.startswith("Linux"): - value = value.split("/", 2)[:2] - value = (value[:16] + '..') if len(value) > 18 else value - if value not in data[charfield]: data[charfield][value] = 0 From a28deb381b2b0dd136bbb9190d69ec3c196b6daf Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 10:20:10 +0100 Subject: [PATCH 06/16] fix creations --- embark/uploader/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index dfefad16e..9c960a60c 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -66,7 +66,7 @@ def device_setup(request): new_device = form.save(commit=False) new_device.device_user = request.user - if Device.objects.filter(device_name=request.device_name, device_vendor=request.device_vendor).exists(): + if Device.objects.filter(device_name=new_device.device_name, device_vendor=new_device.device_vendor).exists(): messages.error(request, 'Device already exists') return redirect('..') new_device = form.save() @@ -86,7 +86,7 @@ def vendor(request): logger.info("User %s tryied to create vendor %s", request.user.username, request.POST['vendor_name']) new_vendor = form.save(commit=False) - if Vendor.objects.filter(vendor_name=request.vendor_name).exists(): + if Vendor.objects.filter(vendor_name=new_vendor.vendor_name).exists(): messages.error(request, 'Vendor already exists') return redirect('..') new_vendor = form.save() @@ -107,7 +107,7 @@ def label(request): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) new_label = form.save(commit=False) - if Label.objects.filter(label_name=request.label_name).exists(): + if Label.objects.filter(label_name=new_label.label_name).exists(): messages.error(request, 'Label already exists') return redirect('..') new_label = form.save() From 30e4e7d94b489c845a3c5dbe1d88c55a5b2381a8 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 10:27:03 +0100 Subject: [PATCH 07/16] fix redu check --- embark/uploader/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 9c960a60c..2ee570a9b 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -66,7 +66,7 @@ def device_setup(request): new_device = form.save(commit=False) new_device.device_user = request.user - if Device.objects.filter(device_name=new_device.device_name, device_vendor=new_device.device_vendor).exists(): + if Device.objects.filter(device_name=form.cleaned_data['device_name'], device_vendor=form.cleaned_data['device_vendor']).exists(): messages.error(request, 'Device already exists') return redirect('..') new_device = form.save() @@ -86,7 +86,7 @@ def vendor(request): logger.info("User %s tryied to create vendor %s", request.user.username, request.POST['vendor_name']) new_vendor = form.save(commit=False) - if Vendor.objects.filter(vendor_name=new_vendor.vendor_name).exists(): + if Vendor.objects.filter(vendor_name=form.cleaned_data['vendor_name']).exists(): messages.error(request, 'Vendor already exists') return redirect('..') new_vendor = form.save() @@ -107,7 +107,7 @@ def label(request): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) new_label = form.save(commit=False) - if Label.objects.filter(label_name=new_label.label_name).exists(): + if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): messages.error(request, 'Label already exists') return redirect('..') new_label = form.save() From 54f39daf1c57c4276ac52fd914f1e79cac4e1d4e Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 10:36:18 +0100 Subject: [PATCH 08/16] add debug --- embark/uploader/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 2ee570a9b..6b536ac13 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -107,6 +107,7 @@ def label(request): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) new_label = form.save(commit=False) + logger.debug("got: %s", form.cleaned_data['label_name']) if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): messages.error(request, 'Label already exists') return redirect('..') From 6231fd5157d85dc32fa699d3e6b76ca9bd51a010 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 10:42:24 +0100 Subject: [PATCH 09/16] update exists check --- embark/uploader/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 6b536ac13..ead6e454e 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -103,16 +103,14 @@ def vendor(request): @login_required(login_url='/' + settings.LOGIN_URL) def label(request): form = LabelForm(request.POST) + logger.debug("got: %s", form.cleaned_data['label_name']) + if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): + messages.error(request, 'Label already exists') + return redirect('..') if form.is_valid(): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) - new_label = form.save(commit=False) - logger.debug("got: %s", form.cleaned_data['label_name']) - if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): - messages.error(request, 'Label already exists') - return redirect('..') new_label = form.save() - messages.info(request, 'creation successful of' + str(new_label)) return redirect('..') logger.error("label form invalid %s ", request.POST) From 75e8e601e596a98f77c8479332d848e5d2de9459 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 10:47:12 +0100 Subject: [PATCH 10/16] update exists check --- embark/uploader/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index ead6e454e..5f4ffb5b7 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -103,6 +103,7 @@ def vendor(request): @login_required(login_url='/' + settings.LOGIN_URL) def label(request): form = LabelForm(request.POST) + form.clean() logger.debug("got: %s", form.cleaned_data['label_name']) if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): messages.error(request, 'Label already exists') From 509b689d16b79996610ebedb9952f0832ee29588 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 11:12:34 +0100 Subject: [PATCH 11/16] add validation error --- embark/uploader/forms.py | 6 ++++++ embark/uploader/views.py | 10 ++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/embark/uploader/forms.py b/embark/uploader/forms.py index 809c7255e..a5bee2100 100644 --- a/embark/uploader/forms.py +++ b/embark/uploader/forms.py @@ -21,6 +21,12 @@ class Meta: model = models.Label fields = ['label_name'] + + def clean_label_name(self): + name = self.cleaned_data['label_name'] + if models.Label.objects.filter(label_name=name).exists(): + raise forms.ValidationError('The label_name [%s] already exists' % name) + return name class DeviceForm(forms.ModelForm): diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 5f4ffb5b7..0883e54c7 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -103,11 +103,6 @@ def vendor(request): @login_required(login_url='/' + settings.LOGIN_URL) def label(request): form = LabelForm(request.POST) - form.clean() - logger.debug("got: %s", form.cleaned_data['label_name']) - if Label.objects.filter(label_name=form.cleaned_data['label_name']).exists(): - messages.error(request, 'Label already exists') - return redirect('..') if form.is_valid(): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) new_label = form.save(commit=False) @@ -115,7 +110,10 @@ def label(request): messages.info(request, 'creation successful of' + str(new_label)) return redirect('..') logger.error("label form invalid %s ", request.POST) - messages.error(request, 'creation failed.') + if 'label_name' in form.errors: + messages.error(request, 'Label already exists') + else: + messages.error(request, 'creation failed.') return redirect('..') From c44277f42c459cfd3e491ec7d51082615c66f5ba Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 11:31:37 +0100 Subject: [PATCH 12/16] update exists checks --- embark/uploader/views.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 0883e54c7..378571c5d 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -63,17 +63,16 @@ def device_setup(request): form = DeviceForm(request.POST) if form.is_valid(): logger.info("User %s tryied to create device", request.user.username) - new_device = form.save(commit=False) new_device.device_user = request.user - if Device.objects.filter(device_name=form.cleaned_data['device_name'], device_vendor=form.cleaned_data['device_vendor']).exists(): - messages.error(request, 'Device already exists') - return redirect('..') new_device = form.save() messages.info(request, 'creation successful of ' + str(new_device)) return redirect('..') logger.error("device form invalid %s ", request.POST) - messages.error(request, 'creation failed.') + if 'device_name' in form.errors or 'device_vendor' in form.errors: + messages.error(request, 'Device already exists') + else: + messages.error(request, 'creation failed.') return redirect('..') @@ -84,17 +83,14 @@ def vendor(request): form = VendorForm(request.POST) if form.is_valid(): logger.info("User %s tryied to create vendor %s", request.user.username, request.POST['vendor_name']) - - new_vendor = form.save(commit=False) - if Vendor.objects.filter(vendor_name=form.cleaned_data['vendor_name']).exists(): - messages.error(request, 'Vendor already exists') - return redirect('..') new_vendor = form.save() - messages.info(request, 'creation successful of ' + str(new_vendor)) return redirect('..') logger.error("vendor form invalid %s ", request.POST) - messages.error(request, 'creation failed.') + if 'vendor_name' in form.errors: + messages.error(request, 'Vendor already exists') + else: + messages.error(request, 'creation failed.') return redirect('..') @@ -105,7 +101,6 @@ def label(request): form = LabelForm(request.POST) if form.is_valid(): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) - new_label = form.save(commit=False) new_label = form.save() messages.info(request, 'creation successful of' + str(new_label)) return redirect('..') From accb869732055a292a4d9a7f1c37295b781c14b4 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 11:43:03 +0100 Subject: [PATCH 13/16] update --- embark/uploader/forms.py | 1 + embark/uploader/views.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/embark/uploader/forms.py b/embark/uploader/forms.py index a5bee2100..aa66a8918 100644 --- a/embark/uploader/forms.py +++ b/embark/uploader/forms.py @@ -35,6 +35,7 @@ class Meta: model = models.Device fields = ['device_name', 'device_label', 'device_vendor'] + unique_together = ('device_name', 'device_vendor',) class FirmwareAnalysisForm(forms.ModelForm): diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 378571c5d..9507a4415 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -102,7 +102,7 @@ def label(request): if form.is_valid(): logger.info("User %s tryied to create label %s", request.user.username, request.POST['label_name']) new_label = form.save() - messages.info(request, 'creation successful of' + str(new_label)) + messages.info(request, 'creation successful of ' + str(new_label)) return redirect('..') logger.error("label form invalid %s ", request.POST) if 'label_name' in form.errors: From 459d1a1a670154c4a160dd795a929b424aab052a Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 12:03:59 +0100 Subject: [PATCH 14/16] cleanup --- embark/embark/settings/deploy.py | 4 ++-- embark/uploader/forms.py | 16 +++++++++------- embark/uploader/views.py | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/embark/embark/settings/deploy.py b/embark/embark/settings/deploy.py index 7b6f8f157..e8a8e2ca7 100644 --- a/embark/embark/settings/deploy.py +++ b/embark/embark/settings/deploy.py @@ -178,7 +178,7 @@ }, 'reporter': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], - 'level': 'DEBUG', + 'level': 'INFO', }, 'tracker': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], @@ -186,7 +186,7 @@ }, 'porter': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], - 'level': 'DEBUG', # TODO change to INFO + 'level': 'INFO', }, 'embark': { 'handlers': ['debug_handler', 'info_handler', 'console_handler'], diff --git a/embark/uploader/forms.py b/embark/uploader/forms.py index aa66a8918..ba11afd96 100644 --- a/embark/uploader/forms.py +++ b/embark/uploader/forms.py @@ -21,12 +21,6 @@ class Meta: model = models.Label fields = ['label_name'] - - def clean_label_name(self): - name = self.cleaned_data['label_name'] - if models.Label.objects.filter(label_name=name).exists(): - raise forms.ValidationError('The label_name [%s] already exists' % name) - return name class DeviceForm(forms.ModelForm): @@ -35,7 +29,15 @@ class Meta: model = models.Device fields = ['device_name', 'device_label', 'device_vendor'] - unique_together = ('device_name', 'device_vendor',) + + def clean(self): + cleaned_data = super(DeviceForm, self.clean) + name = cleaned_data.get('device_name') + vendor = cleaned_data.get('device_vendor') + if name and vendor: + if models.Device.objects.filter(device_name=name, device_vendor=vendor).exists(): + self.add_error('device_name', 'device already created') + return cleaned_data class FirmwareAnalysisForm(forms.ModelForm): diff --git a/embark/uploader/views.py b/embark/uploader/views.py index 9507a4415..a28acd3a2 100644 --- a/embark/uploader/views.py +++ b/embark/uploader/views.py @@ -13,7 +13,7 @@ from uploader.boundedexecutor import BoundedExecutor from uploader.forms import DeviceForm, FirmwareAnalysisForm, DeleteFirmwareForm, LabelForm, VendorForm -from uploader.models import Device, FirmwareFile, Label, Vendor +from uploader.models import FirmwareFile logger = logging.getLogger(__name__) @@ -69,7 +69,7 @@ def device_setup(request): messages.info(request, 'creation successful of ' + str(new_device)) return redirect('..') logger.error("device form invalid %s ", request.POST) - if 'device_name' in form.errors or 'device_vendor' in form.errors: + if 'device_name' in form.errors: messages.error(request, 'Device already exists') else: messages.error(request, 'creation failed.') From 003c4e1ed96e14f78b7b7e4ad53c1c1fd8b3e197 Mon Sep 17 00:00:00 2001 From: BenediktMKuehne Date: Fri, 24 Mar 2023 12:08:33 +0100 Subject: [PATCH 15/16] fix --- embark/uploader/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embark/uploader/forms.py b/embark/uploader/forms.py index ba11afd96..9e2955ed0 100644 --- a/embark/uploader/forms.py +++ b/embark/uploader/forms.py @@ -31,7 +31,7 @@ class Meta: fields = ['device_name', 'device_label', 'device_vendor'] def clean(self): - cleaned_data = super(DeviceForm, self.clean) + cleaned_data = super().clean() name = cleaned_data.get('device_name') vendor = cleaned_data.get('device_vendor') if name and vendor: From f17e0fe8ad5655eac2eaffdef5b36db830c0cde9 Mon Sep 17 00:00:00 2001 From: Benedikt Kuehne Date: Tue, 28 Mar 2023 09:55:49 +0200 Subject: [PATCH 16/16] fix back into string --- embark/reporter/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/embark/reporter/views.py b/embark/reporter/views.py index 2995a1308..46baafcbf 100644 --- a/embark/reporter/views.py +++ b/embark/reporter/views.py @@ -186,6 +186,7 @@ def get_accumulated_reports(request): # clean-up for linux extensive os-descriptions if charfield.startswith("Linux"): charfield = charfield.split("/", 2)[:2] + charfield = f"{charfield[0]}{charfield[1]}" charfield = (charfield[:16] + '..') if len(charfield) > 18 else charfield if charfield not in data: