add details for user validated

This commit is contained in:
Cayo Puigdefabregas 2023-06-02 11:00:05 +02:00
parent c82db8caa0
commit 312f8a01bf
2 changed files with 84 additions and 63 deletions

View File

@ -4,7 +4,7 @@ import flask
from ereuseapi.methods import API from ereuseapi.methods import API
from flask import Blueprint from flask import Blueprint
from flask import current_app as app from flask import current_app as app
from flask import g, redirect, render_template, request, session from flask import g, render_template, request, session
from flask.json import jsonify from flask.json import jsonify
from flask.views import View from flask.views import View
@ -20,6 +20,8 @@ class DidView(View):
template_name = 'did/layout.html' template_name = 'did/layout.html'
def dispatch_request(self, id_dpp): def dispatch_request(self, id_dpp):
self.dpp = None
self.device = None
self.get_ids(id_dpp) self.get_ids(id_dpp)
# import pdb; pdb.set_trace() # import pdb; pdb.set_trace()
@ -28,10 +30,16 @@ class DidView(View):
'oidc': 'oidc' in app.blueprints.keys(), 'oidc': 'oidc' in app.blueprints.keys(),
'user': g.user, 'user': g.user,
'path': request.path, 'path': request.path,
'last_dpp': None,
'before_dpp': None,
'rols': [],
'rol': None,
} }
self.get_rols() self.get_rols()
self.get_rol() self.get_rol()
self.get_device() self.get_device()
self.get_last_dpp()
self.get_before_dpp()
if 'json' in request.headers['Accept']: if 'json' in request.headers['Accept']:
return jsonify(self.get_result()) return jsonify(self.get_result())
@ -52,7 +60,7 @@ class DidView(View):
return [] return []
if rols: if rols:
return [(k, k) for k in rols] self.context['rols'] = rols
if 'trublo' not in app.blueprints.keys(): if 'trublo' not in app.blueprints.keys():
return [] return []
@ -87,9 +95,13 @@ class DidView(View):
def get_device(self): def get_device(self):
if self.id_dpp: if self.id_dpp:
self.dpp = Dpp.query.filter_by(key=self.id_dpp).one() self.dpp = Dpp.query.filter_by(key=self.id_dpp).one()
device = Device.query.filter_by(chid=self.chid, active=True).first() device = self.dpp.device
else:
device = Device.query.filter_by(chid=self.chid, active=True).first()
if not device: if not device:
return flask.abort(404) return flask.abort(404)
abstract = None abstract = None
if device.placeholder: if device.placeholder:
abstract = device.placeholder.binding abstract = device.placeholder.binding
@ -98,6 +110,9 @@ class DidView(View):
device_abstract = placeholder and placeholder.binding or device device_abstract = placeholder and placeholder.binding or device
device_real = placeholder and placeholder.device or device device_real = placeholder and placeholder.device or device
self.device = device_abstract self.device = device_abstract
components = self.device.components
if self.dpp:
components = self.dpp.snapshot.components
self.context.update( self.context.update(
{ {
@ -106,20 +121,29 @@ class DidView(View):
'device_abstract': device_abstract, 'device_abstract': device_abstract,
'device_real': device_real, 'device_real': device_real,
'abstract': abstract, 'abstract': abstract,
'components': components,
} }
) )
def get_last_dpp(self, dpp): def get_last_dpp(self):
dpps = [ dpps = sorted(self.device.dpps, key=lambda x: x.created)
act.dpp[0] for act in dpp.device.actions if act.t == 'Snapshot' and act.dpp self.context['last_dpp'] = dpps and dpps[-1] or ''
] return self.context['last_dpp']
last_dpp = ''
for d in dpps:
if d.key == dpp.key:
return last_dpp
last_dpp = d.key
return last_dpp def get_before_dpp(self):
if not self.dpp:
self.context['before_dpp'] = ''
return ''
dpps = sorted(self.device.dpps, key=lambda x: x.created)
before_dpp = ''
for dpp in dpps:
if dpp == self.dpp:
break
before_dpp = dpp
self.context['before_dpp'] = before_dpp
return before_dpp
def get_result(self): def get_result(self):
data = { data = {
@ -130,7 +154,7 @@ class DidView(View):
if self.dpp: if self.dpp:
data['hardware'] = json.loads(self.dpp.snapshot.json_hw) data['hardware'] = json.loads(self.dpp.snapshot.json_hw)
last_dpp = self.get_last_dpp(self.id_dpp) last_dpp = self.get_last_dpp()
url_last = '' url_last = ''
if last_dpp: if last_dpp:
url_last = 'http://did.ereuse.org/{did}'.format(did=last_dpp) url_last = 'http://did.ereuse.org/{did}'.format(did=last_dpp)

View File

@ -67,8 +67,40 @@
<div class="card-body"> <div class="card-body">
<h3 class="nav-link mt-5" style="color: #993365">{{ device_real.type }} - {{ device_real.verbose_name }}</h3> <h3 class="nav-link mt-5" style="color: #993365">{{ device_real.type }} - {{ device_real.verbose_name }}</h3>
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-12">
<h5 class="card-title">Basic</h5> <h5 class="card-title">Basic</h5>
<div class="row">
<div class="col">
Device Identifier (CHID):
</div>
<div class="col">
<a href="{{ url_for('did.did', id_dpp=device_abstract.chid) }}">{{ device_abstract.chid }}</a>
</div>
</div>
<div class="row">
<div class="col">
Last Digital Passport (Last Dpp):
</div>
<div class="col">
{% if last_dpp %}
<a href="{{ url_for('did.did', id_dpp=last_dpp.key) }}">{{ last_dpp.key }}</a>
{% else %}
- not detected -
{% endif %}
</div>
</div>
<div class="row">
<div class="col">
Before Digital Passport (Before Dpp):
</div>
<div class="col">
{% if before_dpp %}
<a href="{{ url_for('did.did', id_dpp=before_dpp.key) }}">{{ before_dpp.key }}</a>
{% else %}
- not detected -
{% endif %}
</div>
</div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
Usody Identifier (DHID) Usody Identifier (DHID)
@ -122,55 +154,33 @@
Serial Number Serial Number
</div> </div>
<div class="col"> <div class="col">
- anonymized - {% if rol %}
</div> {{ device_abstract.serial_number and device_abstract.serial_number.upper() or '- not detected -' }}
</div> {% else %}
</div> - anonymized -
<div class="col-1"> {% endif %}
</div>
<div class="col-5">
<h5 class="card-title">Status</h5>
<div class="row">
<div class="col">
<div class="label"><b>Physical</b></div>
<div>{{ device_real.physical_status and device.physical_status.type or '- not status -' }}</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="label"><b>Lifecycle</b></div>
<div>{{ device_real.status and device_real.status.type or '- not status -' }}</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="label"><b>Allocation</b></div>
<div>
{% if device_real.allocated %}
Allocated
{% else %}
Not allocated
{% endif %}
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col-6"> <div class="col-12">
<h5 class="card-title">Components</h5> <h5 class="card-title">Components</h5>
<div class="row"> <div class="row">
{% if placeholder.binding %} {% if components %}
<div class="list-group col"> <div class="list-group col">
{% for component in placeholder.binding.components|sort(attribute='type') %} {% for component in components|sort(attribute='type') %}
<div class="list-group-item"> <div class="list-group-item">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ component.type }}</h5> <h5 class="mb-1">{{ component.type }}</h5>
<small class="text-muted">{{ component.created.strftime('%H:%M %d-%m-%Y') }}</small> <small class="text-muted">{{ component.created.strftime('%H:%M %d-%m-%Y') }}</small>
</div> </div>
<p class="mb-1"> <p class="mb-1">
{{ component.manufacturer or '- not detected -' }}<br /> Manufacturer: {{ component.manufacturer or '- not detected -' }}<br />
{{ component.model or '- not detected -' }}<br /> Model: {{ component.model or '- not detected -' }}<br />
{% if rol %}
Serial: {{ component.serial_number and component.serial_number.upper() or '- not detected -' }}
{% endif %}
</p> </p>
<small class="text-muted"> <small class="text-muted">
{% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %} {% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %}
@ -189,19 +199,6 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
<div class="col-6">
<h5 class="card-title">Repair history</h5>
<div class="row">
<div class="list-group col">
{% for action in placeholder.actions %}
<div class="list-group-item d-flex justify-content-between align-items-center">
{{ action.type }} {{ action.severity }}
<small class="text-muted">{{ action.created.strftime('%H:%M %d-%m-%Y') }}</small>
</div>
{% endfor %}
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>