Nico Schottelius 2020-02-21 11:32:41 +01:00
parent c456355059
commit 2cda4dd57b
9 changed files with 63 additions and 44 deletions

View file

@ -38,7 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'uncloud_api'
'uncloud_api',
'uncloud_auth'
]
MIDDLEWARE = [
@ -101,11 +102,13 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# LDAP
################################################################################
# AUTH/LDAP
import ldap
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
AUTHENTICATION_BACKENDS = ["django_auth_ldap.backend.LDAPBackend"]
AUTH_LDAP_SERVER_URI = "ldaps://ldap1.ungleich.ch,ldaps://ldap2.ungleich.ch"
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=customer,dc=ungleich,dc=ch"
@ -114,6 +117,16 @@ AUTH_LDAP_USER_SEARCH = LDAPSearch(
"ou=customer,dc=ungleich,dc=ch", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
)
################################################################################
# AUTH/Django
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend"
]
AUTH_USER_MODEL = 'uncloud_auth.User'
################################################################################
# AUTH/REST
REST_FRAMEWORK = {

View file

@ -27,6 +27,7 @@ router.register(r'groups', views.GroupViewSet)
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
path('admin/', admin.site.urls),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

View file

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
from .models import Product, Feature
admin.site.register(Product)
admin.site.register(Feature)

View file

@ -1,34 +0,0 @@
# Generated by Django 3.0.3 on 2020-02-21 09:40
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('recurring_period', models.CharField(choices=[('per_year', 'Per Year'), ('per_month', 'Per Month'), ('per_week', 'Per Week'), ('per_day', 'Per Day'), ('per_hour', 'Per Hour'), ('not_recurring', 'Not recurring')], default='not_recurring', max_length=256)),
],
),
migrations.CreateModel(
name='Feature',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('recurring_price', models.FloatField(default=0)),
('one_time_price', models.FloatField()),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_api.Product')),
],
),
]

View file

@ -1,6 +1,10 @@
from django.db import models
import uuid
from django.db import models
from django.contrib.auth import get_user_model
class Product(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=256)
@ -17,6 +21,8 @@ class Product(models.Model):
default="not_recurring"
)
def __str__(self):
return "{}".format(self.name)
@ -28,3 +34,25 @@ class Feature(models.Model):
one_time_price = models.FloatField()
product = models.ForeignKey(Product, on_delete=models.CASCADE)
def __str__(self):
return "'{}' - '{}'".format(self.product, self.name)
class Order(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE)
product = models.ForeignKey(Product,
on_delete=models.CASCADE)
class OrderReference(models.Model):
"""
An order can references another product / relate to it.
This model is used for the relation
"""
pass

View file

@ -1,8 +1,7 @@
from django.shortcuts import render
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
# Create your views here.
from django.contrib.auth.models import User, Group
from rest_framework import viewsets, permissions
from .serializers import UserSerializer, GroupSerializer
@ -12,7 +11,7 @@ class CreditCardViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows credit cards to be listed
"""
queryset = User.objects.all().order_by('-date_joined')
queryset = get_user_model().objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
@ -23,7 +22,7 @@ class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
queryset = get_user_model().objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]

View file

@ -0,0 +1,5 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, UserAdmin)

View file

@ -0,0 +1,4 @@
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass