Do not show serial numbers if user not authenticated
This commit is contained in:
parent
a68403b05a
commit
26c3401f4d
|
@ -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,11 +159,10 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<p>
|
<p>
|
||||||
©{% now 'Y' %} eReuse. All rights reserved.
|
©{% now 'Y' %}eReuse. All rights reserved.
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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')
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue