96-add-serial-number-in-public-web #24

Merged
cayop merged 10 commits from 96-add-serial-number-in-public-web into main 2024-11-06 16:30:19 +00:00
4 changed files with 36 additions and 29 deletions
Showing only changes of commit a67fda6b51 - Show all commits

View File

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

View File

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

View File

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

View File

@ -140,15 +140,22 @@ class PublicDeviceWebView(TemplateView):
'shortid': self.object.shortid, 'shortid': self.object.shortid,
'uuids': self.object.uuids, 'uuids': self.object.uuids,
'hids': self.object.hids, 'hids': self.object.hids,
'components': self.remove_serial_numnber_from(self.object.components),
} }
@property @property
def authenticated_fields(self): def authenticated_fields(self):
return { return {
'serial_number': self.object.serial_number,
'components': self.object.components, '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): def get_device_data(self):
data = self.public_fields data = self.public_fields
if self.request.user.is_authenticated: if self.request.user.is_authenticated: