diff --git a/idhub/management/commands/initial_datas.py b/idhub/management/commands/initial_datas.py index 462e944..1f97399 100644 --- a/idhub/management/commands/initial_datas.py +++ b/idhub/management/commands/initial_datas.py @@ -7,9 +7,9 @@ from utils import credtools from django.conf import settings from django.core.management.base import BaseCommand from django.contrib.auth import get_user_model -from decouple import config from idhub.models import Schemas from oidc4vp.models import Organization +from webhook.models import Token User = get_user_model() @@ -20,9 +20,13 @@ class Command(BaseCommand): DOMAIN = settings.DOMAIN 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): ADMIN_EMAIL = settings.INITIAL_ADMIN_EMAIL ADMIN_PASSWORD = settings.INITIAL_ADMIN_PASSWORD + self.predefined_token = kwargs['predefined_token'] self.create_admin_users(ADMIN_EMAIL, ADMIN_PASSWORD) if settings.CREATE_TEST_USERS: @@ -31,8 +35,8 @@ class Command(BaseCommand): self.create_users(user, '1234') self.org = Organization.objects.create( - name=self.DOMAIN, - domain=self.DOMAIN, + name=self.DOMAIN, + domain=self.DOMAIN, main=True ) @@ -45,6 +49,9 @@ class Command(BaseCommand): su = User.objects.create_superuser(email=email, password=password) 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): u = User.objects.create(email=email, password=password) diff --git a/webhook/views.py b/webhook/views.py index 71625d7..1563ff1 100644 --- a/webhook/views.py +++ b/webhook/views.py @@ -29,6 +29,10 @@ def webhook_verify(request): if not tk: 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: data = json.loads(request.body) except json.JSONDecodeError: @@ -90,6 +94,9 @@ def webhook_issue(request): return JsonResponse({'error': 'Invalid credential'}, status=400) user = User.objects.filter(is_admin=True).first() + if not user.accept_gdpr: + return JsonResponse({'error': 'Temporary out of service'}, status=400) + cred = VerificableCredential( csv_data=vc, issuer_did=did,