From d0a7bf5ecc4168b8c69f1ccc9cb5f7ae8dd217df Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 23 Nov 2018 17:05:41 +0100 Subject: [PATCH] Add api and audit structure --- passbook/api/__init__.py | 2 ++ passbook/api/apps.py | 10 +++++++ passbook/api/urls.py | 3 +++ passbook/api/v1/__init__.py | 0 passbook/api/v1/serializers.py | 0 passbook/api/v1/urls.py | 0 passbook/api/v1/views.py | 1 + passbook/audit/__init__.py | 3 +++ passbook/audit/apps.py | 10 +++++++ passbook/audit/migrations/0001_initial.py | 32 +++++++++++++++++++++++ passbook/audit/migrations/__init__.py | 0 passbook/audit/models.py | 22 ++++++++++++++++ passbook/audit/urls.py | 2 ++ passbook/core/settings.py | 1 + 14 files changed, 86 insertions(+) create mode 100644 passbook/api/__init__.py create mode 100644 passbook/api/apps.py create mode 100644 passbook/api/urls.py create mode 100644 passbook/api/v1/__init__.py create mode 100644 passbook/api/v1/serializers.py create mode 100644 passbook/api/v1/urls.py create mode 100644 passbook/api/v1/views.py create mode 100644 passbook/audit/__init__.py create mode 100644 passbook/audit/apps.py create mode 100644 passbook/audit/migrations/0001_initial.py create mode 100644 passbook/audit/migrations/__init__.py create mode 100644 passbook/audit/models.py create mode 100644 passbook/audit/urls.py diff --git a/passbook/api/__init__.py b/passbook/api/__init__.py new file mode 100644 index 000000000..2d5331ead --- /dev/null +++ b/passbook/api/__init__.py @@ -0,0 +1,2 @@ +"""passbook api""" +default_app_config = 'passbook.api.apps.PassbookAPIConfig' diff --git a/passbook/api/apps.py b/passbook/api/apps.py new file mode 100644 index 000000000..bb23a6df5 --- /dev/null +++ b/passbook/api/apps.py @@ -0,0 +1,10 @@ +"""passbook API AppConfig""" + +from django.apps import AppConfig + +class PassbookAPIConfig(AppConfig): + """passbook API Config""" + + name = 'passbook.api' + label = 'passbook_api' + mountpoint = 'api/' diff --git a/passbook/api/urls.py b/passbook/api/urls.py new file mode 100644 index 000000000..1e0015469 --- /dev/null +++ b/passbook/api/urls.py @@ -0,0 +1,3 @@ +"""passbook api urls""" + +urlpatterns = [] diff --git a/passbook/api/v1/__init__.py b/passbook/api/v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/api/v1/serializers.py b/passbook/api/v1/serializers.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/api/v1/urls.py b/passbook/api/v1/urls.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/api/v1/views.py b/passbook/api/v1/views.py new file mode 100644 index 000000000..957e59bea --- /dev/null +++ b/passbook/api/v1/views.py @@ -0,0 +1 @@ +from rest_framework.viewsets import ViewSet diff --git a/passbook/audit/__init__.py b/passbook/audit/__init__.py new file mode 100644 index 000000000..f90622927 --- /dev/null +++ b/passbook/audit/__init__.py @@ -0,0 +1,3 @@ +"""passbook audit Header""" +__version__ = '0.0.1-alpha' +default_app_config = 'passbook.audit.apps.PassbookAuditConfig' diff --git a/passbook/audit/apps.py b/passbook/audit/apps.py new file mode 100644 index 000000000..6d62ebbc4 --- /dev/null +++ b/passbook/audit/apps.py @@ -0,0 +1,10 @@ +"""passbook audit app""" +from django.apps import AppConfig + + +class PassbookAuditConfig(AppConfig): + """passbook audit app""" + + name = 'passbook.audit' + label = 'passbook_audit' + mountpoint = 'audit/' diff --git a/passbook/audit/migrations/0001_initial.py b/passbook/audit/migrations/0001_initial.py new file mode 100644 index 000000000..8cc08d842 --- /dev/null +++ b/passbook/audit/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 2.1.3 on 2018-11-22 10:03 + +import uuid + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='AuditEntry', + fields=[ + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('action', models.TextField()), + ('date', models.DateTimeField(auto_now_add=True)), + ('app', models.TextField()), + ('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/passbook/audit/migrations/__init__.py b/passbook/audit/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/audit/models.py b/passbook/audit/models.py new file mode 100644 index 000000000..b1fd2e268 --- /dev/null +++ b/passbook/audit/models.py @@ -0,0 +1,22 @@ +"""passbook audit models""" + +from django.conf import settings +from django.db import models +from reversion import register + +from passbook.lib.models import UUIDModel + + +@register() +class AuditEntry(UUIDModel): + """An individual audit log entry""" + + user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL) + action = models.TextField() + date = models.DateTimeField(auto_now_add=True) + app = models.TextField() + + def save(self, *args, **kwargs): + if self.pk: + raise NotImplementedError("you may not edit an existing %s" % self._meta.model_name) + super().save(*args, **kwargs) diff --git a/passbook/audit/urls.py b/passbook/audit/urls.py new file mode 100644 index 000000000..f7327b0ac --- /dev/null +++ b/passbook/audit/urls.py @@ -0,0 +1,2 @@ +"""passbook audit urls""" +urlpatterns = [] diff --git a/passbook/core/settings.py b/passbook/core/settings.py index e8102f3b2..28a55e3b4 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -59,6 +59,7 @@ INSTALLED_APPS = [ 'crispy_forms', 'passbook.core', 'passbook.admin', + 'passbook.api', 'passbook.audit', 'passbook.lib', 'passbook.ldap',