redo models again

This commit is contained in:
Jens Langhammer
2018-11-16 11:41:14 +01:00
parent de7a2fa034
commit c1276e9695
17 changed files with 139 additions and 88 deletions

View File

@ -1,13 +1,12 @@
# Generated by Django 2.1.3 on 2018-11-11 14:06
import uuid
# Generated by Django 2.1.3 on 2018-11-16 10:21
from django.conf import settings
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
@ -33,7 +32,6 @@ class Migration(migrations.Migration):
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
],
options={
'verbose_name': 'user',
@ -58,6 +56,12 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.CreateModel(
name='Provider',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='Rule',
fields=[
@ -114,6 +118,21 @@ class Migration(migrations.Migration):
name='application',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='passbook_core.Application'),
),
migrations.AddField(
model_name='application',
name='provider',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='passbook_core.Provider'),
),
migrations.AddField(
model_name='user',
name='applications',
field=models.ManyToManyField(to='passbook_core.Application'),
),
migrations.AddField(
model_name='user',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups'),
),
migrations.AddField(
model_name='user',
name='sources',

View File

@ -16,6 +16,13 @@ class User(AbstractUser):
"""Custom User model to allow easier adding o f user-based settings"""
sources = models.ManyToManyField('Source', through='UserSourceConnection')
applications = models.ManyToManyField('Application')
@reversion.register()
class Provider(models.Model):
"""Application-independant Provider instance. For example SAML2 Remote, OAuth2 Application"""
# This class defines no field for easier inheritance
@reversion.register()
class Application(UUIDModel, CreatedUpdatedModel):
@ -26,6 +33,7 @@ class Application(UUIDModel, CreatedUpdatedModel):
name = models.TextField()
launch_url = models.URLField(null=True, blank=True)
icon_url = models.TextField(null=True, blank=True)
provider = models.ForeignKey('Provider', null=True, default=None, on_delete=models.SET_DEFAULT)
objects = InheritanceManager()

View File

@ -53,9 +53,9 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'reversion',
'rest_framework',
'passbook.core',
'passbook.admin',
'rest_framework',
'passbook.lib',
'passbook.ldap',
'passbook.oauth_client',

View File

@ -1,11 +1,16 @@
{% load static %}
{% load i18n %}
{% load utils %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% trans 'passbook' %}</title>
<title>
{% block title %}
{% title %}
{% endblock %}
</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/patternfly.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/patternfly-additions.min.css' %}">
</head>

View File

@ -24,9 +24,12 @@ urlpatterns = [
include(('passbook.admin.urls', 'passbook_admin'), namespace='passbook_admin')),
path('source/oauth/', include(('passbook.oauth_client.urls',
'passbook_oauth_client'), namespace='passbook_oauth_client')),
path('application/oauth', include(('passbook.oauth_provider.urls',
'passbook_oauth_provider'),
namespace='passbook_oauth_provider')),
path('application/oauth/', include(('passbook.oauth_provider.urls',
'passbook_oauth_provider'),
namespace='passbook_oauth_provider')),
path('application/saml/', include(('passbook.saml_idp.urls',
'passbook_saml_idp'),
namespace='passbook_saml_idp')),
]
if settings.DEBUG:

View File

@ -75,7 +75,7 @@ class LoginView(UserPassesTestMixin, FormView):
login(request, user)
if cleaned_data.get('remember') is True:
request.session.set_expiry(CONFIG.get('passbook').get('session').get('remember_age'))
request.session.set_expiry(CONFIG.y('passbook.session.remember_age'))
else:
request.session.set_expiry(0) # Expires when browser is closed
messages.success(request, _("Successfully logged in!"))
@ -98,4 +98,5 @@ class LoginView(UserPassesTestMixin, FormView):
context = {
'reason': 'invalid',
}
raise NotImplementedError()
return render(request, 'login/invalid.html', context)

View File

@ -9,3 +9,7 @@ class OverviewView(LoginRequiredMixin, TemplateView):
and is not being forwarded"""
template_name = 'overview/index.html'
def get_context_data(self, **kwargs):
kwargs['applications'] = self.request.user.applications.objects.all()
return super().get_context_data(**kwargs)