Skip to content

Commit

Permalink
Continuing to expand upon account self-service features. Additionally…
Browse files Browse the repository at this point in the history
…, solving multi-tenant / account access through use of host name registration for accounts.
  • Loading branch information
AzorianMatt committed Feb 3, 2024
1 parent 0bb155b commit 7eaa097
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 56 deletions.
16 changes: 11 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ cors:
allow_credentials: true
headers: ['*']
methods: ['*']
origins: ['127.0.0.1', 'localhost']
origins: ['127.0.0.1', 'localhost', 'dev.powerdnsadmin.net', '*']
csrf:
origins: ['http://127.0.0.1', 'http://localhost']
origins: ['http://127.0.0.1', 'http://localhost', 'https://dev.powerdnsadmin.net', 'https://*.pda.powerdnsadmin.net']
web:
protocol: http # http, https
host: localhost
port: 80
name: PowerDNS Admin
protocol: https # http, https
host: pda.powerdnsadmin.net
port: 443
stopgap:
enabled: true
protocol: https # http, https
domain: pda.powerdnsadmin.net
port: 443
paths:
root: $e{PWD}
security:
Expand Down
8 changes: 7 additions & 1 deletion defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ cors:
csrf:
origins: ['http://127.0.0.1', 'http://localhost']
web:
name: PowerDNS Admin
protocol: https # http, https
host: your-domain.com
host: pda.your-domain.com
port: 443
stopgap:
enabled: true
protocol: https # http, https
domain: pda.your-domain.com
port: 443
paths:
root: $e{PWD}
security:
Expand Down
Empty file.
32 changes: 0 additions & 32 deletions src/apps/account/forms.py

This file was deleted.

30 changes: 20 additions & 10 deletions src/apps/account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2024-02-02 21:09
# Generated by Django 4.2.7 on 2024-02-03 00:05

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -9,8 +9,6 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('data', '0001_initial'),
('user', '0001_initial'),
]

operations = [
Expand All @@ -21,17 +19,21 @@ class Migration(migrations.Migration):
('uuid', models.UUIDField(default=None, null=True)),
('org_name', models.CharField(max_length=30, null=True)),
('is_setup', models.BooleanField(default=False)),
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.country')),
('timezone', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.timezone')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='AccountUser',
name='AccountDomain',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('role', models.CharField(max_length=30)),
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.account')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='user.user')),
('uuid', models.UUIDField(default=None, null=True)),
('domain', models.CharField(max_length=255)),
('is_pending', models.BooleanField(default=True)),
('is_stopgap', models.BooleanField(default=False)),
('is_valid', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
Expand All @@ -51,8 +53,16 @@ class Migration(migrations.Migration):
('is_deleted', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='AccountUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('role', models.CharField(max_length=30)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.account')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='user.user')),
],
),
]
48 changes: 48 additions & 0 deletions src/apps/account/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 4.2.7 on 2024-02-03 00:05

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('user', '0001_initial'),
('data', '0001_initial'),
('account', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='accountuser',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='user.user'),
),
migrations.AddField(
model_name='accountinvitation',
name='account',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.account'),
),
migrations.AddField(
model_name='accountinvitation',
name='user',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='user.user'),
),
migrations.AddField(
model_name='accountdomain',
name='account',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.account'),
),
migrations.AddField(
model_name='account',
name='country',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.country'),
),
migrations.AddField(
model_name='account',
name='timezone',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.timezone'),
),
]
15 changes: 15 additions & 0 deletions src/apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ class Account(models.Model):
country = models.ForeignKey(Country, on_delete=models.CASCADE)
timezone = models.ForeignKey(Timezone, on_delete=models.CASCADE)
is_setup = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)


class AccountDomain(models.Model):
uuid = models.UUIDField(default=None, null=True)
account = models.ForeignKey(Account, on_delete=models.CASCADE)
domain = models.CharField(max_length=255)
is_pending = models.BooleanField(default=True)
is_stopgap = models.BooleanField(default=False)
is_valid = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)


class AccountInvitation(models.Model):
Expand Down Expand Up @@ -37,3 +50,5 @@ class AccountUser(models.Model):
account = models.ForeignKey(Account, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
role = models.CharField(max_length=30)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
3 changes: 3 additions & 0 deletions src/apps/account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
path('/', RedirectView.as_view(url='/account', permanent=False), name='index_redirect'),
path('/start', views.start, name='start'),
path('/create', views.create, name='create'),
path('/domains', views.create, name='domains'),
path('/invite', views.invite, name='invite'),
path('/join', views.join, name='join'),
path('/join/verify/<str:token>', views.invite_view, name='join-verify'),
]
22 changes: 20 additions & 2 deletions src/apps/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,40 @@ def index(request: HttpRequest):
return render(request, os.path.join(view_directory, 'index.jinja2'), params)


@login_required
def start(request: HttpRequest):
import os
from django.shortcuts import render

return render(request, os.path.join(view_directory, 'start.jinja2'))


@login_required
def create(request: HttpRequest):
import os
from django.shortcuts import render

return render(request, os.path.join(view_directory, 'create.jinja2'))
return render(request, os.path.join(view_directory, 'create/step1.jinja2'))


@login_required
def join(request: HttpRequest):
import os
from django.shortcuts import render

return render(request, os.path.join(view_directory, 'join.jinja2'))
return render(request, os.path.join(view_directory, 'join/step1.jinja2'))


@login_required
def invite(request: HttpRequest):
import os
from django.shortcuts import render

return render(request, os.path.join(view_directory, 'invite/index.jinja2'))


def invite_view(request: HttpRequest, token: str):
import os
from django.shortcuts import render

return render(request, os.path.join(view_directory, 'invite/view.jinja2'))
4 changes: 3 additions & 1 deletion src/apps/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2024-02-02 21:08
# Generated by Django 4.2.7 on 2024-02-03 00:05

from django.conf import settings
from django.db import migrations, models
Expand All @@ -21,6 +21,8 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(default=None, null=True)),
('is_setup', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.country')),
('timezone', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='data.timezone')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
Expand Down
2 changes: 2 additions & 0 deletions src/apps/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ class User(models.Model):
country = models.ForeignKey(Country, on_delete=models.CASCADE)
timezone = models.ForeignKey(Timezone, on_delete=models.CASCADE)
is_setup = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
5 changes: 4 additions & 1 deletion src/apps/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def index(request: HttpRequest):
return redirect(reverse('user:index'))

params: dict = {
'user': user,
'app_user': user,
'countries': Country.objects.all(),
'timezones': Timezone.objects.all(),
}
Expand All @@ -111,6 +111,7 @@ def register(request: HttpRequest):
return render(request, os.path.join(view_directory, 'register.jinja2'), {'form': form})


@login_required
def change_password(request: HttpRequest):
import os
from django.contrib.auth.forms import PasswordChangeForm
Expand All @@ -128,6 +129,7 @@ def change_password(request: HttpRequest):
return render(request, os.path.join(view_directory, 'password_change.jinja2'), {'form': form})


@login_required
def change_password_done(request: HttpRequest):
import os
from django.shortcuts import render
Expand All @@ -145,6 +147,7 @@ def password_reset(request: HttpRequest):

if form.is_valid():
options = {
'domain_override': config.web.host().ref,
'subject_template_name': 'user/password_reset_subject.jinja2',
'email_template_name': 'user/password_reset_email_text.jinja2',
'html_email_template_name': 'user/password_reset_email_html.jinja2',
Expand Down
4 changes: 3 additions & 1 deletion src/pda/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = settings.debug

SITE_NAME = c.web.name().ref

ALLOWED_HOSTS = c.cors.origins().ref
CSRF_TRUSTED_ORIGINS = c.csrf.origins().ref

Expand Down Expand Up @@ -195,7 +197,7 @@
REMOVE_SLASH = True

# Configure Authentication
LOGIN_URL = '/account/login'
LOGIN_URL = '/user/login'

# Celery Configuration
CELERY_RESULT_BACKEND = 'django-db'
Expand Down
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions src/templates/user/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="col-12">
{{ callout.screen_size() }}

{% if not user.id %}
{% if not app_user.id %}
<div class="callout callout-danger">
<h5>{{ gettext('Notice!') }}</h5>
<p>{{ gettext('You must finish setting up your profile before you can access the features of this application.') }}</p>
Expand Down Expand Up @@ -76,7 +76,7 @@
<option value="">{{ gettext('Please select a country') }}</option>
{% for country in countries %}
<option value="{{ country.pk }}"
{% if user.country == country %}selected{% endif %}>
{% if app_user.country == country %}selected{% endif %}>
{{ country.name }}
</option>
{% endfor %}
Expand All @@ -93,7 +93,7 @@
<option value="">{{ gettext('Please select a timezone') }}</option>
{% for timezone in timezones %}
<option value="{{ timezone.pk }}"
{% if user.timezone == timezone %}selected{% endif %}>
{% if app_user.timezone == timezone %}selected{% endif %}>
{{ timezone.name }}
</option>
{% endfor %}
Expand Down

0 comments on commit 7eaa097

Please sign in to comment.