From 6717caa3fa81f8d033062b78e74e87ec148ad1ee Mon Sep 17 00:00:00 2001 From: Bin Date: Wed, 17 Oct 2018 15:55:51 +0800 Subject: [PATCH 1/2] huifenqi sso login support --- dbhub/settings/common.py | 16 ++++++++++++++++ dbhub/settings/prod.py | 3 +++ dbhub/urls.py | 18 ++++++++++++++++-- requirements.txt | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dbhub/settings/common.py b/dbhub/settings/common.py index a779f18..2aa1434 100644 --- a/dbhub/settings/common.py +++ b/dbhub/settings/common.py @@ -41,11 +41,13 @@ 'django_extensions', "django_tables2", "django_filters", + "oauthadmin", 'apps.schema', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', + 'oauthadmin.middleware.OauthAdminSessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -110,3 +112,17 @@ TITLE = '[DEMO] database dbhub schema' DB_INSTANCES = [] + +# django-admin-oauth2 +SESSION_SERIALIZER = "django.contrib.sessions.serializers.PickleSerializer" + +OAUTHADMIN_CLIENT_ID = '' +OAUTHADMIN_CLIENT_SECRET = '' +OAUTHADMIN_BASE_URL = "https://sso.huifenqi.com/sso/oauth/" +OAUTHADMIN_AUTH_URL = 'https://sso.huifenqi.com/sso/authorize/' +OAUTHADMIN_TOKEN_URL = 'https://sso.huifenqi.com/sso/token/' +OAUTHADMIN_GROUPS = ['editor'] +OAUTHADMIN_SCOPE = [] + +# replace admin login with oauth login +ENABLE_OAUTH = False diff --git a/dbhub/settings/prod.py b/dbhub/settings/prod.py index 472e316..14dd135 100644 --- a/dbhub/settings/prod.py +++ b/dbhub/settings/prod.py @@ -4,3 +4,6 @@ TITLE = '会分期数据库定义' DEBUG = False +ENABLE_OAUTH = True +OAUTHADMIN_CLIENT_ID = '' +OAUTHADMIN_CLIENT_SECRET = '' diff --git a/dbhub/urls.py b/dbhub/urls.py index f2476f1..636d66a 100644 --- a/dbhub/urls.py +++ b/dbhub/urls.py @@ -14,10 +14,24 @@ """ from django.conf.urls import include, url from django.contrib import admin - +from django.contrib.auth.decorators import login_required +from django.conf import settings from apps.schema.views import ColumnListView urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), url(r"^$", ColumnListView.as_view(), name="index"), ] + +if settings.ENABLE_OAUTH: + old_admin_login = admin.site.login + admin.site.login = login_required(admin.site.login) + urlpatterns += [ + url(r'^admin-login/', old_admin_login), + url(r'^oauth/', include('oauthadmin.urls')), + ] + settings.LOGIN_URL = '/oauth/login/' + settings.LOGOUT_REDIRECT_URL = '/oauth/logout_redirect/' + +urlpatterns += [ + url(r'^admin/', include(admin.site.urls)), +] diff --git a/requirements.txt b/requirements.txt index 40a3b03..dd9add1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ django-tables2==1.21.2 MySQL-python==1.2.5 uwsgi==2.0.17.1 git+ssh://git@github.com/huifenqi/python-libs.git@0.0.9 +git+ssh://git@github.com/bastionhost/django-admin-oauth2.git From 9a913ee56919d0823148c568ebcf0d022d5bd898 Mon Sep 17 00:00:00 2001 From: Bin Date: Wed, 17 Oct 2018 18:37:34 +0800 Subject: [PATCH 2/2] update style --- apps/schema/tables.py | 12 ++++++++++-- templates/columns.html | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/schema/tables.py b/apps/schema/tables.py index 9d5cea7..13fa135 100644 --- a/apps/schema/tables.py +++ b/apps/schema/tables.py @@ -6,13 +6,21 @@ from models import Column +TEMPLATE = """ +{% if record.is_deleted %}Deleted{% endif %} +{% if record.is_comment_dirty %}Not Match{% endif %} +""" + + class ColumnTable(tables.Table): table_comment = tables.TemplateColumn('{{ value|linebreaks }}', verbose_name='Table Comment', accessor='table.comment') comment = tables.TemplateColumn('{{ value|linebreaks }}') + warning_info = tables.TemplateColumn(TEMPLATE, verbose_name='Warning', orderable=False) class Meta: model = Column - sequence = ('name', 'table', 'data_type', 'is_null', 'default_value', 'comment', 'table_comment') + sequence = ('name', 'table', 'data_type', 'is_null', 'default_value', 'comment', 'table_comment', + 'warning_info') template_name = "django_tables2/semantic.html" - exclude = ("id",) + exclude = ("id", "is_comment_dirty", "is_enum", "is_deleted") diff --git a/templates/columns.html b/templates/columns.html index 60edbaa..9f9b8ed 100644 --- a/templates/columns.html +++ b/templates/columns.html @@ -20,6 +20,7 @@

{{ title }}

+

登录 / SSO 登录

{% render_table table %}   {% endblock %} @@ -30,6 +31,11 @@

{{ title }}

margin-top: 10px; } + #login { + margin-top: 10px; + float: right; + } + #id_word { margin-bottom: 10px; }