*: update JSON fields to django 3.1

This commit is contained in:
Jens Langhammer 2020-08-15 21:04:22 +02:00
parent 54f0728005
commit 7334599efd
14 changed files with 44 additions and 101 deletions

View File

@ -33,7 +33,7 @@ class YAMLString(str):
"""YAML String type""" """YAML String type"""
class YAMLField(forms.CharField): class YAMLField(forms.JSONField):
"""Django's JSON Field converted to YAML""" """Django's JSON Field converted to YAML"""
default_error_messages = { default_error_messages = {

View File

@ -1,36 +0,0 @@
{% extends "administration/base.html" %}
{% load i18n %}
{% load passbook_utils %}
{% block content %}
<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content">
<h1>
<i class="pf-icon pf-icon-applications"></i>
{% trans 'Request' %}
</h1>
</div>
</section>
<section class="pf-c-page__main-section pf-m-no-padding-mobile">
<div class="pf-c-card">
<table class="pf-c-table pf-m-compact pf-m-grid-xl" role="grid">
<thead>
<tr role="row">
<th role="columnheader" scope="col" style="min-width: 150px;">{% trans 'Key' %}</th>
<th role="columnheader" scope="col">{% trans 'Value' %}</th>
</tr>
</thead>
<tbody role="rowgroup">
{% for key, value in request_dict.items %}
<tr role="row">
<td role="cell">{{ key }}</td>
<td role="cell">{{ value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
</div>
{% endblock %}

View File

@ -4,7 +4,6 @@ from django.urls import path
from passbook.admin.views import ( from passbook.admin.views import (
applications, applications,
certificate_key_pair, certificate_key_pair,
debug,
flows, flows,
groups, groups,
overview, overview,
@ -235,13 +234,17 @@ urlpatterns = [
name="user-password-reset", name="user-password-reset",
), ),
# Groups # Groups
path("group/", groups.GroupListView.as_view(), name="group"), path("groups/", groups.GroupListView.as_view(), name="group"),
path("group/create/", groups.GroupCreateView.as_view(), name="group-create"), path("groups/create/", groups.GroupCreateView.as_view(), name="group-create"),
path( path(
"group/<uuid:pk>/update/", groups.GroupUpdateView.as_view(), name="group-update" "groups/<uuid:pk>/update/",
groups.GroupUpdateView.as_view(),
name="group-update",
), ),
path( path(
"group/<uuid:pk>/delete/", groups.GroupDeleteView.as_view(), name="group-delete" "groups/<uuid:pk>/delete/",
groups.GroupDeleteView.as_view(),
name="group-delete",
), ),
# Certificate-Key Pairs # Certificate-Key Pairs
path( path(
@ -264,8 +267,4 @@ urlpatterns = [
certificate_key_pair.CertificateKeyPairDeleteView.as_view(), certificate_key_pair.CertificateKeyPairDeleteView.as_view(),
name="certificatekeypair-delete", name="certificatekeypair-delete",
), ),
# Groups
path("groups/", groups.GroupListView.as_view(), name="groups"),
# Debug
path("debug/request/", debug.DebugRequestView.as_view(), name="debug-request"),
] ]

View File

@ -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)

View File

@ -2,7 +2,6 @@
import uuid import uuid
import django.contrib.postgres.fields.jsonb
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -48,12 +47,7 @@ class Migration(migrations.Migration):
), ),
("date", models.DateTimeField(auto_now_add=True)), ("date", models.DateTimeField(auto_now_add=True)),
("app", models.TextField()), ("app", models.TextField()),
( ("context", models.JSONField(blank=True, default=dict),),
"context",
django.contrib.postgres.fields.jsonb.JSONField(
blank=True, default=dict
),
),
("client_ip", models.GenericIPAddressField(null=True)), ("client_ip", models.GenericIPAddressField(null=True)),
("created", models.DateTimeField(auto_now_add=True)), ("created", models.DateTimeField(auto_now_add=True)),
( (

View File

@ -7,12 +7,11 @@ from uuid import UUID, uuid4
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import JSONField
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.http import HttpRequest from django.http import HttpRequest
from django.utils.translation import gettext as _ 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 guardian.shortcuts import get_anonymous_user
from structlog import get_logger from structlog import get_logger
@ -26,8 +25,8 @@ def cleanse_dict(source: Dict[Any, Any]) -> Dict[Any, Any]:
final_dict = {} final_dict = {}
for key, value in source.items(): for key, value in source.items():
try: try:
if HIDDEN_SETTINGS.search(key): if SafeExceptionReporterFilter.hidden_settings.search(key):
final_dict[key] = CLEANSED_SUBSTITUTE final_dict[key] = SafeExceptionReporterFilter.cleansed_substitute
else: else:
final_dict[key] = value final_dict[key] = value
except TypeError: except TypeError:
@ -100,7 +99,7 @@ class Event(models.Model):
action = models.TextField(choices=EventAction.as_choices()) action = models.TextField(choices=EventAction.as_choices())
date = models.DateTimeField(auto_now_add=True) date = models.DateTimeField(auto_now_add=True)
app = models.TextField() app = models.TextField()
context = JSONField(default=dict, blank=True) context = models.JSONField(default=dict, blank=True)
client_ip = models.GenericIPAddressField(null=True) client_ip = models.GenericIPAddressField(null=True)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)

View File

@ -4,7 +4,6 @@ import uuid
import django.contrib.auth.models import django.contrib.auth.models
import django.contrib.auth.validators import django.contrib.auth.validators
import django.contrib.postgres.fields.jsonb
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone import django.utils.timezone
import guardian.mixins import guardian.mixins
@ -109,12 +108,7 @@ class Migration(migrations.Migration):
("uuid", models.UUIDField(default=uuid.uuid4, editable=False)), ("uuid", models.UUIDField(default=uuid.uuid4, editable=False)),
("name", models.TextField(help_text="User's display name.")), ("name", models.TextField(help_text="User's display name.")),
("password_change_date", models.DateTimeField(auto_now_add=True)), ("password_change_date", models.DateTimeField(auto_now_add=True)),
( ("attributes", models.JSONField(blank=True, default=dict),),
"attributes",
django.contrib.postgres.fields.jsonb.JSONField(
blank=True, default=dict
),
),
], ],
options={"permissions": (("reset_user_password", "Reset Password"),),}, options={"permissions": (("reset_user_password", "Reset Password"),),},
bases=(guardian.mixins.GuardianUserMixin, models.Model), bases=(guardian.mixins.GuardianUserMixin, models.Model),
@ -264,12 +258,7 @@ class Migration(migrations.Migration):
), ),
), ),
("name", models.CharField(max_length=80, verbose_name="name")), ("name", models.CharField(max_length=80, verbose_name="name")),
( ("attributes", models.JSONField(blank=True, default=dict),),
"attributes",
django.contrib.postgres.fields.jsonb.JSONField(
blank=True, default=dict
),
),
( (
"parent", "parent",
models.ForeignKey( models.ForeignKey(

View File

@ -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"
),
),
]

View File

@ -4,7 +4,6 @@ from typing import Any, Optional, Type
from uuid import uuid4 from uuid import uuid4
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import JSONField
from django.db import models from django.db import models
from django.db.models import Q, QuerySet from django.db.models import Q, QuerySet
from django.forms import ModelForm from django.forms import ModelForm
@ -42,7 +41,7 @@ class Group(models.Model):
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name="children", related_name="children",
) )
attributes = JSONField(default=dict, blank=True) attributes = models.JSONField(default=dict, blank=True)
def __str__(self): def __str__(self):
return f"Group {self.name}" return f"Group {self.name}"
@ -62,7 +61,7 @@ class User(GuardianUserMixin, AbstractUser):
groups = models.ManyToManyField("Group") groups = models.ManyToManyField("Group")
password_change_date = models.DateTimeField(auto_now_add=True) 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): def set_password(self, password):
if self.pk: if self.pk:

View File

@ -67,7 +67,6 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"django.contrib.postgres",
"django.contrib.humanize", "django.contrib.humanize",
"rest_framework", "rest_framework",
"django_filters", "django_filters",

View File

@ -28,5 +28,5 @@ class InvitationForm(forms.ModelForm):
labels = { labels = {
"fixed_data": _("Optional fixed data to enforce on user enrollment."), "fixed_data": _("Optional fixed data to enforce on user enrollment."),
} }
widgets = {"fixed_data": CodeMirrorWidget} widgets = {"fixed_data": CodeMirrorWidget()}
field_classes = {"fixed_data": YAMLField} field_classes = {"fixed_data": YAMLField}

View File

@ -2,7 +2,6 @@
import uuid import uuid
import django.contrib.postgres.fields.jsonb
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -59,10 +58,7 @@ class Migration(migrations.Migration):
), ),
), ),
("expires", models.DateTimeField(blank=True, default=None, null=True)), ("expires", models.DateTimeField(blank=True, default=None, null=True)),
( ("fixed_data", models.JSONField(default=dict),),
"fixed_data",
django.contrib.postgres.fields.jsonb.JSONField(default=dict),
),
( (
"created_by", "created_by",
models.ForeignKey( models.ForeignKey(

View File

@ -2,7 +2,6 @@
from typing import Type from typing import Type
from uuid import uuid4 from uuid import uuid4
from django.contrib.postgres.fields import JSONField
from django.db import models from django.db import models
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _ 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) created_by = models.ForeignKey(User, on_delete=models.CASCADE)
expires = models.DateTimeField(default=None, blank=True, null=True) expires = models.DateTimeField(default=None, blank=True, null=True)
fixed_data = JSONField(default=dict) fixed_data = models.JSONField(default=dict)
def __str__(self): def __str__(self):
return f"Invitation {self.invite_uuid.hex} created by {self.created_by}" return f"Invitation {self.invite_uuid.hex} created by {self.created_by}"

View File

@ -5477,7 +5477,7 @@ definitions:
minLength: 1 minLength: 1
context: context:
title: Context title: Context
type: object type: string
client_ip: client_ip:
title: Client ip title: Client ip
type: string type: string
@ -5565,7 +5565,7 @@ definitions:
uniqueItems: true uniqueItems: true
attributes: attributes:
title: Attributes title: Attributes
type: object type: string
Message: Message:
type: object type: object
properties: properties:
@ -6777,7 +6777,7 @@ definitions:
x-nullable: true x-nullable: true
fixed_data: fixed_data:
title: Fixed data title: Fixed data
type: object type: string
OTPStaticStage: OTPStaticStage:
required: required:
- name - name