diff --git a/passbook/admin/fields.py b/passbook/admin/fields.py index 67ebac8e0..59ebb1fc9 100644 --- a/passbook/admin/fields.py +++ b/passbook/admin/fields.py @@ -33,7 +33,7 @@ class YAMLString(str): """YAML String type""" -class YAMLField(forms.CharField): +class YAMLField(forms.JSONField): """Django's JSON Field converted to YAML""" default_error_messages = { diff --git a/passbook/admin/templates/administration/debug/request.html b/passbook/admin/templates/administration/debug/request.html deleted file mode 100644 index 999890476..000000000 --- a/passbook/admin/templates/administration/debug/request.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "administration/base.html" %} - -{% load i18n %} -{% load passbook_utils %} - -{% block content %} - - - - - {% trans 'Request' %} - - - - - - - - - {% trans 'Key' %} - {% trans 'Value' %} - - - - {% for key, value in request_dict.items %} - - {{ key }} - {{ value }} - - {% endfor %} - - - - - -{% endblock %} diff --git a/passbook/admin/urls.py b/passbook/admin/urls.py index a660f02c0..99688a66b 100644 --- a/passbook/admin/urls.py +++ b/passbook/admin/urls.py @@ -4,7 +4,6 @@ from django.urls import path from passbook.admin.views import ( applications, certificate_key_pair, - debug, flows, groups, overview, @@ -235,13 +234,17 @@ urlpatterns = [ name="user-password-reset", ), # Groups - path("group/", groups.GroupListView.as_view(), name="group"), - path("group/create/", groups.GroupCreateView.as_view(), name="group-create"), + path("groups/", groups.GroupListView.as_view(), name="group"), + path("groups/create/", groups.GroupCreateView.as_view(), name="group-create"), path( - "group//update/", groups.GroupUpdateView.as_view(), name="group-update" + "groups//update/", + groups.GroupUpdateView.as_view(), + name="group-update", ), path( - "group//delete/", groups.GroupDeleteView.as_view(), name="group-delete" + "groups//delete/", + groups.GroupDeleteView.as_view(), + name="group-delete", ), # Certificate-Key Pairs path( @@ -264,8 +267,4 @@ urlpatterns = [ certificate_key_pair.CertificateKeyPairDeleteView.as_view(), name="certificatekeypair-delete", ), - # Groups - path("groups/", groups.GroupListView.as_view(), name="groups"), - # Debug - path("debug/request/", debug.DebugRequestView.as_view(), name="debug-request"), ] diff --git a/passbook/admin/views/debug.py b/passbook/admin/views/debug.py deleted file mode 100644 index d6dbc2f6c..000000000 --- a/passbook/admin/views/debug.py +++ /dev/null @@ -1,15 +0,0 @@ -"""passbook administration debug views""" -from django.contrib.auth.mixins import LoginRequiredMixin -from django.views.generic import TemplateView - - -class DebugRequestView(LoginRequiredMixin, TemplateView): - """Show debug info about request""" - - template_name = "administration/debug/request.html" - - def get_context_data(self, **kwargs): - kwargs["request_dict"] = {} - for key in dir(self.request): - kwargs["request_dict"][key] = getattr(self.request, key) - return super().get_context_data(**kwargs) diff --git a/passbook/audit/migrations/0001_initial.py b/passbook/audit/migrations/0001_initial.py index 993e943db..79987c37b 100644 --- a/passbook/audit/migrations/0001_initial.py +++ b/passbook/audit/migrations/0001_initial.py @@ -2,7 +2,6 @@ import uuid -import django.contrib.postgres.fields.jsonb import django.db.models.deletion from django.conf import settings from django.db import migrations, models @@ -48,12 +47,7 @@ class Migration(migrations.Migration): ), ("date", models.DateTimeField(auto_now_add=True)), ("app", models.TextField()), - ( - "context", - django.contrib.postgres.fields.jsonb.JSONField( - blank=True, default=dict - ), - ), + ("context", models.JSONField(blank=True, default=dict),), ("client_ip", models.GenericIPAddressField(null=True)), ("created", models.DateTimeField(auto_now_add=True)), ( diff --git a/passbook/audit/models.py b/passbook/audit/models.py index e5dfebab6..d1b78cd8c 100644 --- a/passbook/audit/models.py +++ b/passbook/audit/models.py @@ -7,12 +7,11 @@ from uuid import UUID, uuid4 from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import JSONField from django.core.exceptions import ValidationError from django.db import models from django.http import HttpRequest from django.utils.translation import gettext as _ -from django.views.debug import CLEANSED_SUBSTITUTE, HIDDEN_SETTINGS +from django.views.debug import SafeExceptionReporterFilter from guardian.shortcuts import get_anonymous_user from structlog import get_logger @@ -26,8 +25,8 @@ def cleanse_dict(source: Dict[Any, Any]) -> Dict[Any, Any]: final_dict = {} for key, value in source.items(): try: - if HIDDEN_SETTINGS.search(key): - final_dict[key] = CLEANSED_SUBSTITUTE + if SafeExceptionReporterFilter.hidden_settings.search(key): + final_dict[key] = SafeExceptionReporterFilter.cleansed_substitute else: final_dict[key] = value except TypeError: @@ -100,7 +99,7 @@ class Event(models.Model): action = models.TextField(choices=EventAction.as_choices()) date = models.DateTimeField(auto_now_add=True) app = models.TextField() - context = JSONField(default=dict, blank=True) + context = models.JSONField(default=dict, blank=True) client_ip = models.GenericIPAddressField(null=True) created = models.DateTimeField(auto_now_add=True) diff --git a/passbook/core/migrations/0001_initial.py b/passbook/core/migrations/0001_initial.py index a98a135d5..ed3b31165 100644 --- a/passbook/core/migrations/0001_initial.py +++ b/passbook/core/migrations/0001_initial.py @@ -4,7 +4,6 @@ import uuid import django.contrib.auth.models import django.contrib.auth.validators -import django.contrib.postgres.fields.jsonb import django.db.models.deletion import django.utils.timezone import guardian.mixins @@ -109,12 +108,7 @@ class Migration(migrations.Migration): ("uuid", models.UUIDField(default=uuid.uuid4, editable=False)), ("name", models.TextField(help_text="User's display name.")), ("password_change_date", models.DateTimeField(auto_now_add=True)), - ( - "attributes", - django.contrib.postgres.fields.jsonb.JSONField( - blank=True, default=dict - ), - ), + ("attributes", models.JSONField(blank=True, default=dict),), ], options={"permissions": (("reset_user_password", "Reset Password"),),}, bases=(guardian.mixins.GuardianUserMixin, models.Model), @@ -264,12 +258,7 @@ class Migration(migrations.Migration): ), ), ("name", models.CharField(max_length=80, verbose_name="name")), - ( - "attributes", - django.contrib.postgres.fields.jsonb.JSONField( - blank=True, default=dict - ), - ), + ("attributes", models.JSONField(blank=True, default=dict),), ( "parent", models.ForeignKey( diff --git a/passbook/core/migrations/0007_auto_20200815_1841.py b/passbook/core/migrations/0007_auto_20200815_1841.py new file mode 100644 index 000000000..6733e05d9 --- /dev/null +++ b/passbook/core/migrations/0007_auto_20200815_1841.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1 on 2020-08-15 18:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_core", "0006_auto_20200709_1608"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="first_name", + field=models.CharField( + blank=True, max_length=150, verbose_name="first name" + ), + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index fb29c1c64..756bbe1b1 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -4,7 +4,6 @@ from typing import Any, Optional, Type from uuid import uuid4 from django.contrib.auth.models import AbstractUser -from django.contrib.postgres.fields import JSONField from django.db import models from django.db.models import Q, QuerySet from django.forms import ModelForm @@ -42,7 +41,7 @@ class Group(models.Model): on_delete=models.SET_NULL, related_name="children", ) - attributes = JSONField(default=dict, blank=True) + attributes = models.JSONField(default=dict, blank=True) def __str__(self): return f"Group {self.name}" @@ -62,7 +61,7 @@ class User(GuardianUserMixin, AbstractUser): groups = models.ManyToManyField("Group") password_change_date = models.DateTimeField(auto_now_add=True) - attributes = JSONField(default=dict, blank=True) + attributes = models.JSONField(default=dict, blank=True) def set_password(self, password): if self.pk: diff --git a/passbook/root/settings.py b/passbook/root/settings.py index 0c8adc451..19b34d7d7 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -67,7 +67,6 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - "django.contrib.postgres", "django.contrib.humanize", "rest_framework", "django_filters", diff --git a/passbook/stages/invitation/forms.py b/passbook/stages/invitation/forms.py index 620d14db5..ad0515c66 100644 --- a/passbook/stages/invitation/forms.py +++ b/passbook/stages/invitation/forms.py @@ -28,5 +28,5 @@ class InvitationForm(forms.ModelForm): labels = { "fixed_data": _("Optional fixed data to enforce on user enrollment."), } - widgets = {"fixed_data": CodeMirrorWidget} + widgets = {"fixed_data": CodeMirrorWidget()} field_classes = {"fixed_data": YAMLField} diff --git a/passbook/stages/invitation/migrations/0001_initial.py b/passbook/stages/invitation/migrations/0001_initial.py index eabc35f97..b1d8061cf 100644 --- a/passbook/stages/invitation/migrations/0001_initial.py +++ b/passbook/stages/invitation/migrations/0001_initial.py @@ -2,7 +2,6 @@ import uuid -import django.contrib.postgres.fields.jsonb import django.db.models.deletion from django.conf import settings from django.db import migrations, models @@ -59,10 +58,7 @@ class Migration(migrations.Migration): ), ), ("expires", models.DateTimeField(blank=True, default=None, null=True)), - ( - "fixed_data", - django.contrib.postgres.fields.jsonb.JSONField(default=dict), - ), + ("fixed_data", models.JSONField(default=dict),), ( "created_by", models.ForeignKey( diff --git a/passbook/stages/invitation/models.py b/passbook/stages/invitation/models.py index db7e47011..b4ecbfc02 100644 --- a/passbook/stages/invitation/models.py +++ b/passbook/stages/invitation/models.py @@ -2,7 +2,6 @@ from typing import Type from uuid import uuid4 -from django.contrib.postgres.fields import JSONField from django.db import models from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ @@ -53,7 +52,7 @@ class Invitation(models.Model): created_by = models.ForeignKey(User, on_delete=models.CASCADE) expires = models.DateTimeField(default=None, blank=True, null=True) - fixed_data = JSONField(default=dict) + fixed_data = models.JSONField(default=dict) def __str__(self): return f"Invitation {self.invite_uuid.hex} created by {self.created_by}" diff --git a/swagger.yaml b/swagger.yaml index 6637f4edd..1fb279fa8 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -5477,7 +5477,7 @@ definitions: minLength: 1 context: title: Context - type: object + type: string client_ip: title: Client ip type: string @@ -5565,7 +5565,7 @@ definitions: uniqueItems: true attributes: title: Attributes - type: object + type: string Message: type: object properties: @@ -6777,7 +6777,7 @@ definitions: x-nullable: true fixed_data: title: Fixed data - type: object + type: string OTPStaticStage: required: - name