diff --git a/.gitignore b/.gitignore index e9814da..774c3b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ settings.ini +static *.pyo *.pyc diff --git a/README.md b/README.md index cdfe073..3a4f72e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ univnautes-idp : IdP multi-tenants pour UnivNautes cp settings.ini.example /somewhere/settings.ini export UNIVNAUTES_IDP_SETTINGS_INI=/somewhere/settings.ini -python manage.py sync_schemas --shared --noinput -python manage.py create-tenant xyz.univnautes-idp.dev.entrouvert.org xyz + +# creation du schema public +python manage.py sync_schemas --shared --noinput +python manage.py migrate_schemas +python manage.py create-tenant univnautes-idp.dev.entrouvert.org public +python manage.py createsuperuser -s public + +python manage.py create-tenant xyz.univnautes-idp.dev.entrouvert.org xyz +python manage.py createsuperuser -s xyz diff --git a/base/__init__.py b/base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/base/admin.py b/base/admin.py new file mode 100644 index 0000000..c024810 --- /dev/null +++ b/base/admin.py @@ -0,0 +1,13 @@ +from django.contrib import admin +from entrouvert.djommon.multitenant.models import Tenant, ClientSetting + +class TenantAdmin(admin.ModelAdmin): + list_display = ('schema_name', 'name', 'domain_url', 'is_active') + +class ClientSettingAdmin(admin.ModelAdmin): + list_display = ('tenant', 'name', 'value') + +admin.site.register(Tenant, TenantAdmin) +admin.site.register(ClientSetting, ClientSettingAdmin) + + diff --git a/base/models.py b/base/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/base/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/base/templates/base.html b/base/templates/base.html new file mode 100644 index 0000000..df06fe6 --- /dev/null +++ b/base/templates/base.html @@ -0,0 +1,56 @@ +{% load i18n %} + + + + + + + {% block title %}User test{% endblock %} + {{ openid_meta }} + {% block extra_scripts %} + {% endblock %} + + + +
+ + +
+ +
+ {% if request.user.is_authenticated %} +
+

+ {% blocktrans with request.user.get_full_name as username %}Hello {{ username }}.{% endblocktrans %} +

+
+ {% endif %} + {% block messages %} + {% if messages %} + + {% endif %} + {% endblock %} + {% block content %}{% endblock %} +
+ + +
+ + + diff --git a/base/templates/univnautes-idp/homepage.html b/base/templates/univnautes-idp/homepage.html new file mode 100644 index 0000000..9aa641e --- /dev/null +++ b/base/templates/univnautes-idp/homepage.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block content %} +

Gestion des tenants

+{% endblock %} diff --git a/base/views.py b/base/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/base/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/univnautes_idp/dashboard.py b/univnautes_idp/dashboard.py new file mode 100644 index 0000000..d63173d --- /dev/null +++ b/univnautes_idp/dashboard.py @@ -0,0 +1,123 @@ +""" +This file was generated with the customdashboard management command, it +contains the two classes for the main dashboard and app index dashboard. +You can customize these classes as you want. + +To activate your index dashboard add the following to your settings.py:: + ADMIN_TOOLS_INDEX_DASHBOARD = 'authentic2.dashboard.CustomIndexDashboard' + +And to activate the app index dashboard:: + ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'authentic2.dashboard.CustomAppIndexDashboard' +""" + +from django.utils.translation import ugettext_lazy as _ +from django.core.urlresolvers import reverse + +from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard +from admin_tools.utils import get_admin_site_name + + +class CustomIndexDashboard(Dashboard): + """ + Custom index dashboard for authentic2. + """ + def init_with_context(self, context): + site_name = get_admin_site_name(context) + + tenant = context.get('request').tenant.schema_name + + # append a link list module for "quick links" + self.children.append(modules.LinkList( + _('Quick links'), + layout='inline', + draggable=False, + deletable=False, + collapsible=False, + children=[ + [_('Return to site'), '/'], + [_('Change password'), + reverse('%s:password_change' % site_name)], + [_('Log out'), reverse('%s:logout' % site_name)], + ] + )) + + # append an app list module for "Applications" + self.children.append(modules.ModelList( + _('Users and groups'), + models=('authentic2.models.User', + 'django.contrib.auth.models.*'), + )) + + if tenant == 'public': + self.children.append(modules.ModelList( + _('Tenants'), + models=( + 'entrouvert.djommon.multitenant.models.*', + ), + )) + else: + self.children.append(modules.ModelList( + _('Services'), + models=( + 'authentic2.saml.models.LibertyProvider', + 'authentic2.saml.models.SPOptionsIdPPolicy', + 'authentic2.saml.models.IdPOptionsSPPolicy', + 'authentic2.idp.models.AttributePolicy', + 'authentic2.attribute_aggregator.models.AttributeList', + 'authentic2.attribute_aggregator.models.AttributeItem', + 'authentic2.attribute_aggregator.models.AttributeSource', + ), + )) + + # append a recent actions module + self.children.append(modules.RecentActions(_('Recent Actions'), 5)) + + # append another link list module for "support". + self.children.append(modules.LinkList( + _('Support'), + children=[ + { + 'title': _('Authentic2 documentation'), + 'url': 'http://pythonhosted.org/authentic2/', + 'external': True, + }, + { + 'title': _('Authentic2 project'), + 'url': 'http://dev.entrouvert.org/projects/authentic/', + 'external': True, + }, + { + 'title': _('Authentic Mailing List'), + 'url': 'http://listes.entrouvert.com/info/authentic', + 'external': True, + }, + ] + )) + + +class CustomAppIndexDashboard(AppIndexDashboard): + """ + Custom app index dashboard for authentic2. + """ + + # we disable title because its redundant with the model list module + title = '' + + def __init__(self, *args, **kwargs): + AppIndexDashboard.__init__(self, *args, **kwargs) + + # append a model list module and a recent actions module + self.children += [ + modules.ModelList(self.app_title, self.models), + modules.RecentActions( + _('Recent Actions'), + include_list=self.get_app_content_types(), + limit=5 + ) + ] + + def init_with_context(self, context): + """ + Use this method if you need to access the request context. + """ + return super(CustomAppIndexDashboard, self).init_with_context(context) diff --git a/univnautes_idp/settings.py b/univnautes_idp/settings.py index bac61a0..45e946e 100644 --- a/univnautes_idp/settings.py +++ b/univnautes_idp/settings.py @@ -131,7 +131,6 @@ MIDDLEWARE_CLASSES = ( # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) -ROOT_URLCONF = 'univnautes_idp.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'univnautes_idp.wsgi.application' @@ -140,8 +139,13 @@ TEMPLATE_DIRS = tuple(config.get('dirs', 'template_dirs').split()) MULTITENANT_TEMPLATE_DIRS = tuple(config.get('dirs', 'multitenant_template_dirs').split()) SHARED_APPS = ( + 'base', 'tenant_schemas', 'entrouvert.djommon.multitenant', + 'admin_tools', + 'admin_tools.theming', + 'admin_tools.menu', + 'admin_tools.dashboard', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.messages', @@ -152,6 +156,10 @@ SHARED_APPS = ( ) TENANT_APPS = ( + 'admin_tools', + 'admin_tools.theming', + 'admin_tools.menu', + 'admin_tools.dashboard', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.messages', @@ -159,10 +167,6 @@ TENANT_APPS = ( 'django.contrib.staticfiles', 'django.contrib.contenttypes', 'south', - 'admin_tools', - 'admin_tools.theming', - 'admin_tools.menu', - 'admin_tools.dashboard', 'registration', 'authentic2.nonce', 'authentic2.saml', @@ -180,6 +184,11 @@ INSTALLED_APPS = SHARED_APPS + TENANT_APPS INSTALLED_APPS += ('tenant_schemas', 'entrouvert.djommon.multitenant',) TENANT_MODEL = 'multitenant.Tenant' +PUBLIC_SCHEMA_NAME = 'public' + +ROOT_URLCONF = 'univnautes_idp.urls' +PUBLIC_SCHEMA_URLCONF = 'univnautes_idp.urls_public' + SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer' @@ -267,9 +276,9 @@ ACCOUNT_ACTIVATION_DAYS = 3 PASSWORD_RESET_TIMEOUT_DAYS = 3 # Admin tools -ADMIN_TOOLS_INDEX_DASHBOARD = 'authentic2.dashboard.CustomIndexDashboard' -ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'authentic2.dashboard.CustomAppIndexDashboard' -ADMIN_TOOLS_MENU = 'authentic2.menu.CustomMenu' +ADMIN_TOOLS_INDEX_DASHBOARD = 'univnautes_idp.dashboard.CustomIndexDashboard' +ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'univnautes_idp.dashboard.CustomAppIndexDashboard' +#ADMIN_TOOLS_MENU = 'authentic2.menu.CustomMenu' # AUTH systels AUTH_SAML2 = False diff --git a/univnautes_idp/urls_public.py b/univnautes_idp/urls_public.py new file mode 100644 index 0000000..ec4ec37 --- /dev/null +++ b/univnautes_idp/urls_public.py @@ -0,0 +1,12 @@ +from django.conf.urls import patterns, url, include +from django.views.generic import TemplateView +from authentic2.urls import urlpatterns as authentic2_urlpatterns + +from django.contrib import admin +admin.autodiscover() + +urlpatterns = patterns('', + url(r'^$', TemplateView.as_view(template_name="univnautes-idp/homepage.html")), + url(r'^admin/', include(admin.site.urls)), + url(r'^admin_tools/', include('admin_tools.urls')), +)