add predefined_token in initial_datas

This commit is contained in:
Cayo Puigdefabregas 2025-01-23 17:58:07 +01:00
parent 60890ae8f1
commit d3d116a7e9
2 changed files with 17 additions and 3 deletions

View file

@ -7,9 +7,9 @@ from utils import credtools
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from decouple import config
from idhub.models import Schemas from idhub.models import Schemas
from oidc4vp.models import Organization from oidc4vp.models import Organization
from webhook.models import Token
User = get_user_model() User = get_user_model()
@ -20,9 +20,13 @@ class Command(BaseCommand):
DOMAIN = settings.DOMAIN DOMAIN = settings.DOMAIN
OIDC_ORGS = settings.OIDC_ORGS OIDC_ORGS = settings.OIDC_ORGS
def add_arguments(self, parser):
parser.add_argument('predefined_token', nargs='?', default='', type=str, help='predefined token')
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
ADMIN_EMAIL = settings.INITIAL_ADMIN_EMAIL ADMIN_EMAIL = settings.INITIAL_ADMIN_EMAIL
ADMIN_PASSWORD = settings.INITIAL_ADMIN_PASSWORD ADMIN_PASSWORD = settings.INITIAL_ADMIN_PASSWORD
self.predefined_token = kwargs['predefined_token']
self.create_admin_users(ADMIN_EMAIL, ADMIN_PASSWORD) self.create_admin_users(ADMIN_EMAIL, ADMIN_PASSWORD)
if settings.CREATE_TEST_USERS: if settings.CREATE_TEST_USERS:
@ -45,6 +49,9 @@ class Command(BaseCommand):
su = User.objects.create_superuser(email=email, password=password) su = User.objects.create_superuser(email=email, password=password)
su.save() su.save()
tk = Token.objects.filter(token=self.predefined_token).first()
if self.predefined_token and not tk:
Token.objects.create(token=self.predefined_token)
def create_users(self, email, password): def create_users(self, email, password):
u = User.objects.create(email=email, password=password) u = User.objects.create(email=email, password=password)

View file

@ -29,6 +29,10 @@ def webhook_verify(request):
if not tk: if not tk:
return JsonResponse({'error': 'Invalid or missing token'}, status=401) return JsonResponse({'error': 'Invalid or missing token'}, status=401)
user = User.objects.filter(is_admin=True).first()
if not user.accept_gdpr:
return JsonResponse({'error': 'Temporary out of service'}, status=400)
try: try:
data = json.loads(request.body) data = json.loads(request.body)
except json.JSONDecodeError: except json.JSONDecodeError:
@ -90,6 +94,9 @@ def webhook_issue(request):
return JsonResponse({'error': 'Invalid credential'}, status=400) return JsonResponse({'error': 'Invalid credential'}, status=400)
user = User.objects.filter(is_admin=True).first() user = User.objects.filter(is_admin=True).first()
if not user.accept_gdpr:
return JsonResponse({'error': 'Temporary out of service'}, status=400)
cred = VerificableCredential( cred = VerificableCredential(
csv_data=vc, csv_data=vc,
issuer_did=did, issuer_did=did,