activate/deactivate DPP from env

This commit is contained in:
Cayo Puigdefabregas 2024-12-05 10:54:41 +01:00
parent f7051c3130
commit 14277c17cb
6 changed files with 37 additions and 38 deletions

View file

@ -29,9 +29,11 @@
<li class="nav-item"> <li class="nav-item">
<a href="#evidences" class="nav-link" data-bs-toggle="tab" data-bs-target="#evidences">{% trans 'Evidences' %}</a> <a href="#evidences" class="nav-link" data-bs-toggle="tab" data-bs-target="#evidences">{% trans 'Evidences' %}</a>
</li> </li>
{% if dpps %}
<li class="nav-item"> <li class="nav-item">
<a href="#dpps" class="nav-link" data-bs-toggle="tab" data-bs-target="#dpps">{% trans 'Dpps' %}</a> <a href="#dpps" class="nav-link" data-bs-toggle="tab" data-bs-target="#dpps">{% trans 'Dpps' %}</a>
</li> </li>
{% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'device:device_web' object.id %}" target="_blank">Web</a> <a class="nav-link" href="{% url 'device:device_web' object.id %}" target="_blank">Web</a>
</li> </li>
@ -239,7 +241,8 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% if dpps %}
<div class="tab-pane fade" id="dpps"> <div class="tab-pane fade" id="dpps">
<h5 class="card-title">{% trans 'List of dpps' %}</h5> <h5 class="card-title">{% trans 'List of dpps' %}</h5>
<div class="list-group col"> <div class="list-group col">
@ -256,6 +259,7 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}
@ -264,12 +268,12 @@
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// Obtener el hash de la URL (ejemplo: #components) // Obtener el hash de la URL (ejemplo: #components)
const hash = window.location.hash const hash = window.location.hash
// Verificar si hay un hash en la URL // Verificar si hay un hash en la URL
if (hash) { if (hash) {
// Buscar el botón o enlace que corresponde al hash y activarlo // Buscar el botón o enlace que corresponde al hash y activarlo
const tabTrigger = document.querySelector(`[data-bs-target="${hash}"]`) const tabTrigger = document.querySelector(`[data-bs-target="${hash}"]`)
if (tabTrigger) { if (tabTrigger) {
// Crear una instancia de tab de Bootstrap para activar el tab // Crear una instancia de tab de Bootstrap para activar el tab
const tab = new bootstrap.Tab(tabTrigger) const tab = new bootstrap.Tab(tabTrigger)

View file

@ -1,6 +1,5 @@
from django.http import JsonResponse from django.http import JsonResponse
from django.conf import settings
from django.http import Http404
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404, Http404 from django.shortcuts import get_object_or_404, Http404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -13,10 +12,11 @@ from django.views.generic.base import TemplateView
from dashboard.mixins import DashboardView, Http403 from dashboard.mixins import DashboardView, Http403
from evidence.models import Annotation from evidence.models import Annotation
from lot.models import LotTag from lot.models import LotTag
from dpp.models import Proof
from dpp.api_dlt import PROOF_TYPE
from device.models import Device from device.models import Device
from device.forms import DeviceFormSet from device.forms import DeviceFormSet
if settings.DPP:
from dpp.models import Proof
from dpp.api_dlt import PROOF_TYPE
class NewDeviceView(DashboardView, FormView): class NewDeviceView(DashboardView, FormView):
@ -104,10 +104,12 @@ class DetailsView(DashboardView, TemplateView):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
self.object.initial() self.object.initial()
lot_tags = LotTag.objects.filter(owner=self.request.user.institution) lot_tags = LotTag.objects.filter(owner=self.request.user.institution)
dpps = Proof.objects.filter( dpps = []
uuid__in=self.object.uuids, if settings.DPP:
type=PROOF_TYPE["IssueDPP"] dpps = Proof.objects.filter(
) uuid__in=self.object.uuids,
type=PROOF_TYPE["IssueDPP"]
)
context.update({ context.update({
'object': self.object, 'object': self.object,
'snapshot': self.object.get_last_evidence(), 'snapshot': self.object.get_last_evidence(),

View file

@ -89,10 +89,13 @@ INSTALLED_APPS = [
"dashboard", "dashboard",
"admin", "admin",
"api", "api",
"dpp",
"did",
] ]
DPP = config("DPP", default=False, cast=bool)
if DPP:
INSTALLED_APPS.extend(["dpp", "did"])
MIDDLEWARE = [ MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",

View file

@ -14,7 +14,7 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.conf import settings
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
@ -27,6 +27,10 @@ urlpatterns = [
path("user/", include("user.urls")), path("user/", include("user.urls")),
path("lot/", include("lot.urls")), path("lot/", include("lot.urls")),
path('api/', include('api.urls')), path('api/', include('api.urls')),
path('dpp/', include('dpp.urls')),
path('did/', include('did.urls')),
] ]
if settings.DPP:
urlpatterns.extend([
path('dpp/', include('dpp.urls')),
path('did/', include('did.urls')),
])

View file

@ -9,6 +9,11 @@ from evidence.models import Annotation
from evidence.xapian import index from evidence.xapian import index
from dpp.api_dlt import register_device_dlt, register_passport_dlt from dpp.api_dlt import register_device_dlt, register_passport_dlt
from evidence.parse_details import get_inxi_key, get_inxi from evidence.parse_details import get_inxi_key, get_inxi
from django.conf import settings
if settings.DPP:
from dpp.api_dlt import register_device_dlt, register_passport_dlt
logger = logging.getLogger('django') logger = logging.getLogger('django')
@ -49,7 +54,8 @@ class Build:
self.index() self.index()
self.create_annotations() self.create_annotations()
self.register_device_dlt() if settings.DPP:
self.register_device_dlt()
def index(self): def index(self):
snap = json.dumps(self.evidence) snap = json.dumps(self.evidence)
@ -152,26 +158,6 @@ class Build:
value=v value=v
) )
<<<<<<< HEAD
=======
def get_chassis_dh(self):
chassis = self.get_chassis()
lower_type = chassis.lower()
for k, v in CHASSIS_DH.items():
if lower_type in v:
return k
return self.default
def get_sku(self):
return self.dmi.get("System")[0].get("SKU Number", "n/a").strip()
def get_chassis(self):
return self.dmi.get("Chassis")[0].get("Type", '_virtual') #
def get_version(self):
return self.dmi.get("System")[0].get("Verson", '_virtual')
>>>>>>> 5949049 (new document and out device and components)
def get_hid(self, snapshot): def get_hid(self, snapshot):
try: try:
self.inxi = self.json["data"]["inxi"] self.inxi = self.json["data"]["inxi"]

View file

@ -137,7 +137,7 @@ class DownloadEvidenceView(DashboardView, TemplateView):
evidence.get_doc() evidence.get_doc()
data = json.dumps(evidence.doc) data = json.dumps(evidence.doc)
response = HttpResponse(data, content_type="application/json") response = HttpResponse(data, content_type="application/json")
response['Content-Disposition'] = 'attachment; filename={}'.format("credential.json") response['Content-Disposition'] = 'attachment; filename={}'.format("evidence.json")
return response return response