Do not show serial numbers if user not authenticated

This commit is contained in:
sergio_gimenez 2024-11-06 08:24:10 +01:00
parent a68403b05a
commit 26c3401f4d
4 changed files with 36 additions and 29 deletions

View File

@ -138,7 +138,6 @@
{% endfor %}
</div>
</div>
{% if user.is_authenticated %}
<h2 class="section-title mt-5">Components</h2>
<div class="row">
{% for component in object.components %}
@ -149,8 +148,10 @@
<p class="card-text">
{% for component_key, component_value in component.items %}
{% if component_key not in 'actions,type' %}
{% if component_key != 'serialNumber' or user.is_authenticated %}
<strong>{{ component_key }}:</strong> {{ component_value }}<br />
{% endif %}
{% endif %}
{% endfor %}
</p>
</div>
@ -158,11 +159,10 @@
</div>
{% endfor %}
</div>
{% endif %}
</div>
<footer>
<p>
&copy;{% now 'Y' %} eReuse. All rights reserved.
&copy;{% now 'Y' %}eReuse. All rights reserved.
</p>
</footer>

View File

@ -28,12 +28,14 @@ class TestDevice(Device):
{
'type': 'CPU',
'model': 'Intel i7',
'manufacturer': 'Intel'
'manufacturer': 'Intel',
'serialNumber': 'SN12345678'
},
{
'type': 'RAM',
'size': '8GB',
'manufacturer': 'Kingston'
'manufacturer': 'Kingston',
'serialNumber': 'SN87654321'
}
]
self.last_evidence = self._evidence

View File

@ -37,11 +37,7 @@ class PublicDeviceWebViewTests(TestCase):
self.assertContains(response, 'Computer')
self.assertContains(response, self.test_id)
self.assertNotContains(response, 'Serial Number')
self.assertNotContains(response, 'Components')
self.assertNotContains(response, 'CPU')
self.assertNotContains(response, 'Intel')
self.assertNotContains(response, 'RAM')
self.assertNotContains(response, 'Kingston')
self.assertNotContains(response, 'serialNumber')
@patch('device.views.Device')
def test_html_response_authenticated(self, MockDevice):
@ -77,8 +73,8 @@ class PublicDeviceWebViewTests(TestCase):
self.assertEqual(json_data['shortid'], self.test_id[:6].upper())
self.assertEqual(json_data['uuids'], [])
self.assertEqual(json_data['hids'], ['hid1', 'hid2'])
self.assertNotIn('components', json_data)
self.assertNotIn('serial_number', json_data)
self.assertNotIn('serialNumber', json_data)
@patch('device.views.Device')
def test_json_response_authenticated(self, MockDevice):
@ -99,12 +95,14 @@ class PublicDeviceWebViewTests(TestCase):
{
'type': 'CPU',
'model': 'Intel i7',
'manufacturer': 'Intel'
'manufacturer': 'Intel',
'serialNumber': 'SN12345678'
},
{
'type': 'RAM',
'size': '8GB',
'manufacturer': 'Kingston'
'manufacturer': 'Kingston',
'serialNumber': 'SN87654321'
}
])
self.assertEqual(json_data['serial_number'], 'SN123456')

View File

@ -140,15 +140,22 @@ class PublicDeviceWebView(TemplateView):
'shortid': self.object.shortid,
'uuids': self.object.uuids,
'hids': self.object.hids,
'components': self.remove_serial_numnber_from(self.object.components),
}
@property
def authenticated_fields(self):
return {
'serial_number': self.object.serial_number,
'components': self.object.components,
'serial_number': self.object.serial_number
}
def remove_serial_numnber_from(self, components):
for component in components:
if 'serial_number' in component:
del component['SerialNumber']
return components
def get_device_data(self):
data = self.public_fields
if self.request.user.is_authenticated: