From 0d7295b60ee0333aef6d0a9a33820e7a9d19f073 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 15:10:48 +0800 Subject: [PATCH 01/10] =?UTF-8?q?[Update]=20=E6=81=A2=E5=A4=8D=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84api=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/urls.py | 28 ++++++++++++++-------------- apps/jumpserver/views.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index e76b4f3a2..15db793d9 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -31,7 +31,7 @@ schema_view = get_schema_view( public=True, permission_classes=(permissions.AllowAny,), ) -api_url_pattern = re.compile(r'^/api/(?P\w+)/(?P\w+)/(?P.*)$') +api_url_pattern = re.compile(r'^/api/(?P\w+)/(?P\w+)/(?P.*)$') class HttpResponseTemporaryRedirect(HttpResponse): @@ -43,12 +43,12 @@ class HttpResponseTemporaryRedirect(HttpResponse): @csrf_exempt -def redirect_old_format_api(request, *args, **kwargs): +def redirect_new_format_api(request, *args, **kwargs): path, query = request.path, request.GET.urlencode() matched = api_url_pattern.match(path) if matched: - app, version, extra = matched.groups() - path = '/api/{version}/{app}/{extra}?{query}'.format(**{ + version, app, extra = matched.groups() + path = '/api/{app}/{version}/{extra}?{query}'.format(**{ "app": app, "version": version, "extra": extra, "query": query }) @@ -58,14 +58,14 @@ def redirect_old_format_api(request, *args, **kwargs): v1_api_patterns = [ - url(r'^users/', include('users.urls.api_urls', namespace='api-users')), - url(r'^assets/', include('assets.urls.api_urls', namespace='api-assets')), - url(r'^perms/', include('perms.urls.api_urls', namespace='api-perms')), - url(r'^terminal/', include('terminal.urls.api_urls', namespace='api-terminal')), - url(r'^ops/', include('ops.urls.api_urls', namespace='api-ops')), - url(r'^audits/', include('audits.urls.api_urls', namespace='api-audits')), - url(r'^orgs/', include('orgs.urls.api_urls', namespace='api-orgs')), - url(r'^common/', include('common.urls.api_urls', namespace='api-common')), + url(r'^users/v1/', include('users.urls.api_urls', namespace='api-users')), + url(r'^assets/v1/', include('assets.urls.api_urls', namespace='api-assets')), + url(r'^perms/v1/', include('perms.urls.api_urls', namespace='api-perms')), + url(r'^terminal/v1/', include('terminal.urls.api_urls', namespace='api-terminal')), + url(r'^ops/v1/', include('ops.urls.api_urls', namespace='api-ops')), + url(r'^audits/v1/', include('audits.urls.api_urls', namespace='api-audits')), + url(r'^orgs/v1/', include('orgs.urls.api_urls', namespace='api-orgs')), + url(r'^common/v1/', include('common.urls.api_urls', namespace='api-common')), ] app_view_patterns = [ @@ -84,8 +84,8 @@ urlpatterns = [ url(r'^luna/', LunaView.as_view(), name='luna-error'), url(r'^settings/', include('common.urls.view_urls', namespace='settings')), url(r'^common/', include('common.urls.view_urls', namespace='common')), - url(r'^api/v1/', include(v1_api_patterns)), - url(r'^api/(?P.*)/v1/.*', redirect_old_format_api), + url(r'^api/v1/.*', redirect_new_format_api), + url(r'^api/', include(v1_api_patterns)), # Api url view map # External apps url diff --git a/apps/jumpserver/views.py b/apps/jumpserver/views.py index 474eaf829..a924c5ef5 100644 --- a/apps/jumpserver/views.py +++ b/apps/jumpserver/views.py @@ -22,7 +22,7 @@ class IndexView(AdminUserRequiredMixin, TemplateView): session_month_dates_archive = [] def dispatch(self, request, *args, **kwargs): - if not request.user.is_org_admin: + if not request.user.is_authenticated or not request.user.is_org_admin: return redirect('assets:user-asset-list') return super(IndexView, self).dispatch(request, *args, **kwargs) From f7fb36a176afaf2d5e8b5a7e1d800b2471ae2b81 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 15:21:14 +0800 Subject: [PATCH 02/10] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index 15db793d9..f31f8cbae 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -43,7 +43,7 @@ class HttpResponseTemporaryRedirect(HttpResponse): @csrf_exempt -def redirect_new_format_api(request, *args, **kwargs): +def redirect_format_api(request, *args, **kwargs): path, query = request.path, request.GET.urlencode() matched = api_url_pattern.match(path) if matched: @@ -84,7 +84,7 @@ urlpatterns = [ url(r'^luna/', LunaView.as_view(), name='luna-error'), url(r'^settings/', include('common.urls.view_urls', namespace='settings')), url(r'^common/', include('common.urls.view_urls', namespace='common')), - url(r'^api/v1/.*', redirect_new_format_api), + url(r'^api/v1/.*', redirect_format_api), url(r'^api/', include(v1_api_patterns)), # Api url view map From c6d50802dbd611c1bd47fff66bdf829359394b72 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 15:35:12 +0800 Subject: [PATCH 03/10] [Bugfix] Fix perm name unique --- apps/jumpserver/urls.py | 3 --- apps/perms/forms.py | 3 +-- apps/perms/models.py | 5 ++++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index f31f8cbae..65de2eb4c 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -92,9 +92,6 @@ urlpatterns = [ url(r'^captcha/', include('captcha.urls')), ] urlpatterns += app_view_patterns - -# urlpatterns = wrapper_patterns_with_org(urlpatterns) - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/apps/perms/forms.py b/apps/perms/forms.py index 3ce3db6c5..d6383d927 100644 --- a/apps/perms/forms.py +++ b/apps/perms/forms.py @@ -29,8 +29,7 @@ class AssetPermissionForm(OrgModelForm): return users_field = self.fields.get('users') if hasattr(users_field, 'queryset'): - # users_field.queryset = User.objects.filter(orgs=current_org) - users_field.queryset = current_org.get_org_users().exclude(role=User.ROLE_APP) + users_field.queryset = current_org.get_org_users() class Meta: model = AssetPermission diff --git a/apps/perms/models.py b/apps/perms/models.py index 1c3a67d8e..89f09764e 100644 --- a/apps/perms/models.py +++ b/apps/perms/models.py @@ -25,7 +25,7 @@ class AssetPermissionManager(OrgManager): class AssetPermission(OrgModelMixin): id = models.UUIDField(default=uuid.uuid4, primary_key=True) - name = models.CharField(max_length=128, unique=True, verbose_name=_('Name')) + name = models.CharField(max_length=128, verbose_name=_('Name')) users = models.ManyToManyField('users.User', related_name='asset_permissions', blank=True, verbose_name=_("User")) user_groups = models.ManyToManyField('users.UserGroup', related_name='asset_permissions', blank=True, verbose_name=_("User group")) assets = models.ManyToManyField('assets.Asset', related_name='granted_by_permissions', blank=True, verbose_name=_("Asset")) @@ -40,6 +40,9 @@ class AssetPermission(OrgModelMixin): objects = AssetPermissionManager.from_queryset(AssetPermissionQuerySet)() + class Meta: + unique_together = [('org_id', 'name')] + def __str__(self): return self.name From 30392846663a0c515585b7da61a5f3e6c64a783c Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 16:15:04 +0800 Subject: [PATCH 04/10] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=A4=B1=E8=B4=A5api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/orgs/mixins.py | 8 +++++++- apps/perms/api.py | 3 ++- apps/perms/templates/perms/asset_permission_list.html | 2 -- apps/perms/views.py | 7 ++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/orgs/mixins.py b/apps/orgs/mixins.py index 244d967d0..071e70539 100644 --- a/apps/orgs/mixins.py +++ b/apps/orgs/mixins.py @@ -10,7 +10,7 @@ from django.forms import ModelForm from django.http.response import HttpResponseForbidden from common.utils import get_logger -from .utils import current_org, set_current_org +from .utils import current_org, set_current_org, set_to_root_org from .models import Organization logger = get_logger(__file__) @@ -85,6 +85,12 @@ class OrgViewGenericMixin: return super().dispatch(request, *args, **kwargs) +class RootOrgViewMixin: + def dispatch(self, request, *args, **kwargs): + set_to_root_org() + return super().dispatch(request, *args, **kwargs) + + class OrgModelForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/apps/perms/api.py b/apps/perms/api.py index 3851d401a..fd6a64ec4 100644 --- a/apps/perms/api.py +++ b/apps/perms/api.py @@ -9,6 +9,7 @@ from rest_framework.pagination import LimitOffsetPagination from common.utils import set_or_append_attr_bulk, get_object_or_none from common.permissions import IsValidUser, IsOrgAdmin, IsOrgAdminOrAppUser +from orgs.mixins import RootOrgViewMixin from .utils import AssetPermissionUtil from .models import AssetPermission from .hands import AssetGrantedSerializer, User, UserGroup, Asset, Node, \ @@ -236,7 +237,7 @@ class UserGroupGrantedNodeAssetsApi(ListAPIView): return assets -class ValidateUserAssetPermissionView(APIView): +class ValidateUserAssetPermissionView(RootOrgViewMixin, APIView): permission_classes = (IsOrgAdminOrAppUser,) @staticmethod diff --git a/apps/perms/templates/perms/asset_permission_list.html b/apps/perms/templates/perms/asset_permission_list.html index e9edd7637..5284a3354 100644 --- a/apps/perms/templates/perms/asset_permission_list.html +++ b/apps/perms/templates/perms/asset_permission_list.html @@ -247,12 +247,10 @@ function initTree() { value["iconSkin"] = value["is_node"] ? null : 'file'; }); zNodes = data; - {#$.fn.zTree.init($("#assetTree"), setting);#} $.fn.zTree.init($("#assetTree"), setting, zNodes); zTree = $.fn.zTree.getZTreeObj("assetTree"); var root = zTree.getNodes()[0]; zTree.expandNode(root); - {#selectQueryNode();#} }); } diff --git a/apps/perms/views.py b/apps/perms/views.py index 411405848..7782992d5 100644 --- a/apps/perms/views.py +++ b/apps/perms/views.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import from django.utils.translation import ugettext as _ -from django.views.generic import ListView, CreateView, UpdateView, DetailView +from django.views.generic import ListView, CreateView, UpdateView, DetailView, TemplateView from django.views.generic.edit import DeleteView, SingleObjectMixin from django.urls import reverse_lazy from django.conf import settings @@ -15,11 +15,8 @@ from .models import AssetPermission from .forms import AssetPermissionForm -class AssetPermissionListView(AdminUserRequiredMixin, ListView): - model = AssetPermission +class AssetPermissionListView(AdminUserRequiredMixin, TemplateView): template_name = 'perms/asset_permission_list.html' - paginate_by = settings.DISPLAY_PER_PAGE - user = user_group = asset = node = system_user = q = "" def get_context_data(self, **kwargs): context = { From d3dca5d0779705b4eb70cf69a93b22fcc3178f03 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 16:19:19 +0800 Subject: [PATCH 05/10] [Update] Merge with org --- apps/orgs/mixins.py | 3 ++- apps/perms/api.py | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/orgs/mixins.py b/apps/orgs/mixins.py index 071e70539..4a47f2ee3 100644 --- a/apps/orgs/mixins.py +++ b/apps/orgs/mixins.py @@ -17,7 +17,8 @@ logger = get_logger(__file__) tl = local() __all__ = [ - 'OrgManager', 'OrgViewGenericMixin', 'OrgModelMixin', 'OrgModelForm' + 'OrgManager', 'OrgViewGenericMixin', 'OrgModelMixin', 'OrgModelForm', + 'RootOrgViewMixin', ] diff --git a/apps/perms/api.py b/apps/perms/api.py index dd3c6e9c1..d8691a4c2 100644 --- a/apps/perms/api.py +++ b/apps/perms/api.py @@ -87,7 +87,7 @@ class UserGrantedAssetsApi(ListAPIView): return super().get_permissions() -class UserGrantedNodesApi(ListAPIView): +class UserGrantedNodesApi(RootOrgViewMixin, ListAPIView): permission_classes = (IsOrgAdmin,) serializer_class = NodeSerializer @@ -102,13 +102,12 @@ class UserGrantedNodesApi(ListAPIView): return nodes.keys() def get_permissions(self): - set_current_org(Organization.root()) if self.kwargs.get('pk') is None: self.permission_classes = (IsValidUser,) return super().get_permissions() -class UserGrantedNodesWithAssetsApi(ListAPIView): +class UserGrantedNodesWithAssetsApi(RootOrgViewMixin, ListAPIView): permission_classes = (IsOrgAdminOrAppUser,) serializer_class = NodeGrantedSerializer @@ -132,13 +131,12 @@ class UserGrantedNodesWithAssetsApi(ListAPIView): return queryset def get_permissions(self): - set_current_org(Organization.root()) if self.kwargs.get('pk') is None: self.permission_classes = (IsValidUser,) return super().get_permissions() -class UserGrantedNodeAssetsApi(ListAPIView): +class UserGrantedNodeAssetsApi(RootOrgViewMixin, ListAPIView): permission_classes = (IsOrgAdminOrAppUser,) serializer_class = AssetGrantedSerializer @@ -159,7 +157,6 @@ class UserGrantedNodeAssetsApi(ListAPIView): return assets def get_permissions(self): - set_current_org(Organization.root()) if self.kwargs.get('pk') is None: self.permission_classes = (IsValidUser,) return super().get_permissions() From d92d462dab6050852d62bae3508f7700bbefe5ef Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 16:54:40 +0800 Subject: [PATCH 06/10] =?UTF-8?q?[Update]=20=E6=9A=82=E6=97=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=80=E4=BA=9Burl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/urls.py | 5 +-- apps/users/urls/api_urls.py | 35 ++++++++---------- apps/users/urls/views_urls.py | 68 +++++++++++++++++------------------ 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index 65de2eb4c..1631d6f72 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import re from django.conf.urls import url, include +from django.urls import path from django.conf import settings from django.conf.urls.static import static from rest_framework.response import Response @@ -58,7 +59,7 @@ def redirect_format_api(request, *args, **kwargs): v1_api_patterns = [ - url(r'^users/v1/', include('users.urls.api_urls', namespace='api-users')), + path('users/v1/', include('users.urls.api_urls', namespace='api-users')), url(r'^assets/v1/', include('assets.urls.api_urls', namespace='api-assets')), url(r'^perms/v1/', include('perms.urls.api_urls', namespace='api-perms')), url(r'^terminal/v1/', include('terminal.urls.api_urls', namespace='api-terminal')), @@ -69,7 +70,7 @@ v1_api_patterns = [ ] app_view_patterns = [ - url(r'^users/', include('users.urls.views_urls', namespace='users')), + path('users/', include('users.urls.views_urls', namespace='users')), url(r'^assets/', include('assets.urls.views_urls', namespace='assets')), url(r'^perms/', include('perms.urls.views_urls', namespace='perms')), url(r'^terminal/', include('terminal.urls.views_urls', namespace='terminal')), diff --git a/apps/users/urls/api_urls.py b/apps/users/urls/api_urls.py index a5736a12a..32952b75e 100644 --- a/apps/users/urls/api_urls.py +++ b/apps/users/urls/api_urls.py @@ -3,7 +3,7 @@ # from __future__ import absolute_import -from django.conf.urls import url +from django.urls import path from rest_framework_bulk.routes import BulkRouter from .. import api @@ -15,26 +15,19 @@ router.register(r'groups', api.UserGroupViewSet, 'user-group') urlpatterns = [ - # url(r'', api.UserListView.as_view()), - url(r'^token/$', api.UserToken.as_view(), name='user-token'), - url(r'^connection-token/$', api.UserConnectionTokenApi.as_view(), name='connection-token'), - url(r'^profile/$', api.UserProfile.as_view(), name='user-profile'), - url(r'^auth/$', api.UserAuthApi.as_view(), name='user-auth'), - url(r'^otp/auth/$', api.UserOtpAuthApi.as_view(), name='user-otp-auth'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/password/$', - api.ChangeUserPasswordApi.as_view(), name='change-user-password'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/password/reset/$', - api.UserResetPasswordApi.as_view(), name='user-reset-password'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/pubkey/reset/$', - api.UserResetPKApi.as_view(), name='user-public-key-reset'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/pubkey/update/$', - api.UserUpdatePKApi.as_view(), name='user-public-key-update'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/unblock/$', - api.UserUnblockPKApi.as_view(), name='user-unblock'), - url(r'^users/(?P[0-9a-zA-Z\-]{36})/groups/$', - api.UserUpdateGroupApi.as_view(), name='user-update-group'), - url(r'^groups/(?P[0-9a-zA-Z\-]{36})/users/$', - api.UserGroupUpdateUserApi.as_view(), name='user-group-update-user'), + # path(r'', api.UserListView.as_view()), + path('token/', api.UserToken.as_view(), name='user-token'), + path('connection-token/', api.UserConnectionTokenApi.as_view(), name='connection-token'), + path('profile/', api.UserProfile.as_view(), name='user-profile'), + path('auth/', api.UserAuthApi.as_view(), name='user-auth'), + path('otp/auth/', api.UserOtpAuthApi.as_view(), name='user-otp-auth'), + path('users//password/', api.ChangeUserPasswordApi.as_view(), name='change-user-password'), + path('users//password/reset/', api.UserResetPasswordApi.as_view(), name='user-reset-password'), + path('users//pubkey/reset/', api.UserResetPKApi.as_view(), name='user-public-key-reset'), + path('users//pubkey/update/', api.UserUpdatePKApi.as_view(), name='user-public-key-update'), + path('users//unblock/', api.UserUnblockPKApi.as_view(), name='user-unblock'), + path('users//groups/', api.UserUpdateGroupApi.as_view(), name='user-update-group'), + path('groups//users/', api.UserGroupUpdateUserApi.as_view(), name='user-group-update-user'), ] urlpatterns += router.urls diff --git a/apps/users/urls/views_urls.py b/apps/users/urls/views_urls.py index 8052f1384..8e4fb531c 100644 --- a/apps/users/urls/views_urls.py +++ b/apps/users/urls/views_urls.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from django.conf.urls import url +from django.urls import path from .. import views @@ -8,45 +8,45 @@ app_name = 'users' urlpatterns = [ # Login view - url(r'^login/$', views.UserLoginView.as_view(), name='login'), - url(r'^logout/$', views.UserLogoutView.as_view(), name='logout'), - url(r'^login/otp/$', views.UserLoginOtpView.as_view(), name='login-otp'), - url(r'^password/forgot/$', views.UserForgotPasswordView.as_view(), name='forgot-password'), - url(r'^password/forgot/sendmail-success/$', views.UserForgotPasswordSendmailSuccessView.as_view(), name='forgot-password-sendmail-success'), - url(r'^password/reset/$', views.UserResetPasswordView.as_view(), name='reset-password'), - url(r'^password/reset/success/$', views.UserResetPasswordSuccessView.as_view(), name='reset-password-success'), + path('login/', views.UserLoginView.as_view(), name='login'), + path('logout/', views.UserLogoutView.as_view(), name='logout'), + path('login/otp/', views.UserLoginOtpView.as_view(), name='login-otp'), + path('password/forgot/', views.UserForgotPasswordView.as_view(), name='forgot-password'), + path('password/forgot/sendmail-success/', views.UserForgotPasswordSendmailSuccessView.as_view(), name='forgot-password-sendmail-success'), + path('password/reset/', views.UserResetPasswordView.as_view(), name='reset-password'), + path('password/reset/success/', views.UserResetPasswordSuccessView.as_view(), name='reset-password-success'), # Profile - url(r'^profile/$', views.UserProfileView.as_view(), name='user-profile'), - url(r'^profile/update/$', views.UserProfileUpdateView.as_view(), name='user-profile-update'), - url(r'^profile/password/update/$', views.UserPasswordUpdateView.as_view(), name='user-password-update'), - url(r'^profile/pubkey/update/$', views.UserPublicKeyUpdateView.as_view(), name='user-pubkey-update'), - url(r'^profile/pubkey/generate/$', views.UserPublicKeyGenerateView.as_view(), name='user-pubkey-generate'), - url(r'^profile/otp/enable/authentication/$', views.UserOtpEnableAuthenticationView.as_view(), name='user-otp-enable-authentication'), - url(r'^profile/otp/enable/install-app/$', views.UserOtpEnableInstallAppView.as_view(), name='user-otp-enable-install-app'), - url(r'^profile/otp/enable/bind/$', views.UserOtpEnableBindView.as_view(), name='user-otp-enable-bind'), - url(r'^profile/otp/disable/authentication/$', views.UserOtpDisableAuthenticationView.as_view(), name='user-otp-disable-authentication'), - url(r'^profile/otp/settings-success/$', views.UserOtpSettingsSuccessView.as_view(), name='user-otp-settings-success'), + path('profile/', views.UserProfileView.as_view(), name='user-profile'), + path('profile/update/', views.UserProfileUpdateView.as_view(), name='user-profile-update'), + path('profile/password/update/', views.UserPasswordUpdateView.as_view(), name='user-password-update'), + path('profile/pubkey/update/', views.UserPublicKeyUpdateView.as_view(), name='user-pubkey-update'), + path('profile/pubkey/generate/', views.UserPublicKeyGenerateView.as_view(), name='user-pubkey-generate'), + path('profile/otp/enable/authentication/', views.UserOtpEnableAuthenticationView.as_view(), name='user-otp-enable-authentication'), + path('profile/otp/enable/install-app/', views.UserOtpEnableInstallAppView.as_view(), name='user-otp-enable-install-app'), + path('profile/otp/enable/bind/', views.UserOtpEnableBindView.as_view(), name='user-otp-enable-bind'), + path('profile/otp/disable/authentication/', views.UserOtpDisableAuthenticationView.as_view(), name='user-otp-disable-authentication'), + path('profile/otp/settings-success/', views.UserOtpSettingsSuccessView.as_view(), name='user-otp-settings-success'), # User view - url(r'^user/$', views.UserListView.as_view(), name='user-list'), - url(r'^user/export/$', views.UserExportView.as_view(), name='user-export'), - url(r'^first-login/$', views.UserFirstLoginView.as_view(), name='user-first-login'), - url(r'^user/import/$', views.UserBulkImportView.as_view(), name='user-import'), - url(r'^user/create/$', views.UserCreateView.as_view(), name='user-create'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/update/$', views.UserUpdateView.as_view(), name='user-update'), - url(r'^user/update/$', views.UserBulkUpdateView.as_view(), name='user-bulk-update'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/$', views.UserDetailView.as_view(), name='user-detail'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/assets/$', views.UserGrantedAssetView.as_view(), name='user-granted-asset'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/login-history/$', views.UserDetailView.as_view(), name='user-login-history'), + path('user/', views.UserListView.as_view(), name='user-list'), + path('user/export/', views.UserExportView.as_view(), name='user-export'), + path('first-login/', views.UserFirstLoginView.as_view(), name='user-first-login'), + path('user/import/', views.UserBulkImportView.as_view(), name='user-import'), + path('user/create/', views.UserCreateView.as_view(), name='user-create'), + path('user//update/', views.UserUpdateView.as_view(), name='user-update'), + path('user/update/', views.UserBulkUpdateView.as_view(), name='user-bulk-update'), + path('user//', views.UserDetailView.as_view(), name='user-detail'), + path('user//assets/', views.UserGrantedAssetView.as_view(), name='user-granted-asset'), + path('user//login-history/', views.UserDetailView.as_view(), name='user-login-history'), # User group view - url(r'^user-group/$', views.UserGroupListView.as_view(), name='user-group-list'), - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/$', views.UserGroupDetailView.as_view(), name='user-group-detail'), - url(r'^user-group/create/$', views.UserGroupCreateView.as_view(), name='user-group-create'), - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/update/$', views.UserGroupUpdateView.as_view(), name='user-group-update'), - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/assets/$', views.UserGroupGrantedAssetView.as_view(), name='user-group-granted-asset'), + path('user-group/', views.UserGroupListView.as_view(), name='user-group-list'), + path('user-group//', views.UserGroupDetailView.as_view(), name='user-group-detail'), + path('user-group/create/', views.UserGroupCreateView.as_view(), name='user-group-create'), + path('user-group//update/', views.UserGroupUpdateView.as_view(), name='user-group-update'), + path('user-group//assets/', views.UserGroupGrantedAssetView.as_view(), name='user-group-granted-asset'), # Login log - url(r'^login-log/$', views.LoginLogListView.as_view(), name='login-log-list'), + path('login-log/', views.LoginLogListView.as_view(), name='login-log-list'), ] From 492fd9888238ce3c2668bc231e9cd03330d3d655 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 27 Jul 2018 17:43:18 +0800 Subject: [PATCH 07/10] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9url=20?= =?UTF-8?q?=E4=B8=BAdjango=202.0=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/urls/api_urls.py | 78 ++++++++++++++--------------- apps/assets/urls/views_urls.py | 76 ++++++++++++++-------------- apps/audits/urls/api_urls.py | 1 - apps/audits/urls/view_urls.py | 5 +- apps/common/urls/api_urls.py | 8 +-- apps/jumpserver/urls.py | 63 +++++++++++------------ apps/ops/urls/api_urls.py | 6 +-- apps/ops/urls/view_urls.py | 21 ++++---- apps/orgs/urls/api_urls.py | 2 - apps/orgs/urls/views_urls.py | 7 +-- apps/perms/urls/api_urls.py | 83 +++++++++++++++---------------- apps/perms/urls/views_urls.py | 15 +++--- apps/templates/_user_profile.html | 5 +- apps/terminal/urls/api_urls.py | 18 +++---- apps/terminal/urls/views_urls.py | 24 ++++----- 15 files changed, 202 insertions(+), 210 deletions(-) diff --git a/apps/assets/urls/api_urls.py b/apps/assets/urls/api_urls.py index 29d347c04..2b36024ce 100644 --- a/apps/assets/urls/api_urls.py +++ b/apps/assets/urls/api_urls.py @@ -1,5 +1,5 @@ # coding:utf-8 -from django.conf.urls import url +from django.urls import path from .. import api from rest_framework_bulk.routes import BulkRouter @@ -16,45 +16,45 @@ router.register(r'domain', api.DomainViewSet, 'domain') router.register(r'gateway', api.GatewayViewSet, 'gateway') urlpatterns = [ - url(r'^assets-bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/auth-info/', api.SystemUserAuthInfoApi.as_view(), - name='system-user-auth-info'), - url(r'^assets/(?P[0-9a-zA-Z\-]{36})/refresh/$', - api.AssetRefreshHardwareApi.as_view(), name='asset-refresh'), - url(r'^assets/(?P[0-9a-zA-Z\-]{36})/alive/$', - api.AssetAdminUserTestApi.as_view(), name='asset-alive-test'), - url(r'^assets/(?P[0-9a-zA-Z\-]{36})/gateway/$', - api.AssetGatewayApi.as_view(), name='asset-gateway'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/nodes/$', - api.ReplaceNodesAdminUserApi.as_view(), name='replace-nodes-admin-user'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/auth/$', - api.AdminUserAuthApi.as_view(), name='admin-user-auth'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/connective/$', - api.AdminUserTestConnectiveApi.as_view(), name='admin-user-connective'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/push/$', - api.SystemUserPushApi.as_view(), name='system-user-push'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/connective/$', - api.SystemUserTestConnectiveApi.as_view(), name='system-user-connective'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/children/$', - api.NodeChildrenApi.as_view(), name='node-children'), - url(r'^nodes/children/$', api.NodeChildrenApi.as_view(), name='node-children-2'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/children/add/$', - api.NodeAddChildrenApi.as_view(), name='node-add-children'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.NodeAssetsApi.as_view(), name='node-assets'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/assets/add/$', - api.NodeAddAssetsApi.as_view(), name='node-add-assets'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/assets/replace/$', - api.NodeReplaceAssetsApi.as_view(), name='node-replace-assets'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/assets/remove/$', - api.NodeRemoveAssetsApi.as_view(), name='node-remove-assets'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/refresh-hardware-info/$', - api.RefreshNodeHardwareInfoApi.as_view(), name='node-refresh-hardware-info'), - url(r'^nodes/(?P[0-9a-zA-Z\-]{36})/test-connective/$', - api.TestNodeConnectiveApi.as_view(), name='node-test-connective'), + path('assets-bulk/', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'), + path('system-user//auth-info/', + api.SystemUserAuthInfoApi.as_view(), name='system-user-auth-info'), + path('assets//refresh/', + api.AssetRefreshHardwareApi.as_view(), name='asset-refresh'), + path('assets//alive/', + api.AssetAdminUserTestApi.as_view(), name='asset-alive-test'), + path('assets//gateway/', + api.AssetGatewayApi.as_view(), name='asset-gateway'), + path('admin-user//nodes/', + api.ReplaceNodesAdminUserApi.as_view(), name='replace-nodes-admin-user'), + path('admin-user//auth/', + api.AdminUserAuthApi.as_view(), name='admin-user-auth'), + path('admin-user//connective/', + api.AdminUserTestConnectiveApi.as_view(), name='admin-user-connective'), + path('system-user//push/', + api.SystemUserPushApi.as_view(), name='system-user-push'), + path('system-user//connective/', + api.SystemUserTestConnectiveApi.as_view(), name='system-user-connective'), + path('nodes//children/', + api.NodeChildrenApi.as_view(), name='node-children'), + path('nodes/children/', api.NodeChildrenApi.as_view(), name='node-children-2'), + path('nodes//children/add/', + api.NodeAddChildrenApi.as_view(), name='node-add-children'), + path('nodes//assets/', + api.NodeAssetsApi.as_view(), name='node-assets'), + path('nodes//assets/add/', + api.NodeAddAssetsApi.as_view(), name='node-add-assets'), + path('nodes//assets/replace/', + api.NodeReplaceAssetsApi.as_view(), name='node-replace-assets'), + path('nodes//assets/remove/', + api.NodeRemoveAssetsApi.as_view(), name='node-remove-assets'), + path('nodes//refresh-hardware-info/', + api.RefreshNodeHardwareInfoApi.as_view(), name='node-refresh-hardware-info'), + path('nodes//test-connective/', + api.TestNodeConnectiveApi.as_view(), name='node-test-connective'), - url(r'^gateway/(?P[0-9a-zA-Z\-]{36})/test-connective/$', - api.GatewayTestConnectionApi.as_view(), name='test-gateway-connective'), + path('gateway//test-connective/', + api.GatewayTestConnectionApi.as_view(), name='test-gateway-connective'), ] urlpatterns += router.urls diff --git a/apps/assets/urls/views_urls.py b/apps/assets/urls/views_urls.py index 12c351154..9d160bedf 100644 --- a/apps/assets/urls/views_urls.py +++ b/apps/assets/urls/views_urls.py @@ -1,52 +1,52 @@ # coding:utf-8 -from django.conf.urls import url +from django.urls import path from .. import views app_name = 'assets' urlpatterns = [ # Resource asset url - url(r'^$', views.AssetListView.as_view(), name='asset-index'), - url(r'^asset/$', views.AssetListView.as_view(), name='asset-list'), - url(r'^asset/create/$', views.AssetCreateView.as_view(), name='asset-create'), - url(r'^asset/export/$', views.AssetExportView.as_view(), name='asset-export'), - url(r'^asset/import/$', views.BulkImportAssetView.as_view(), name='asset-import'), - url(r'^asset/(?P[0-9a-zA-Z\-]{36})/$', views.AssetDetailView.as_view(), name='asset-detail'), - url(r'^asset/(?P[0-9a-zA-Z\-]{36})/update/$', views.AssetUpdateView.as_view(), name='asset-update'), - url(r'^asset/(?P[0-9a-zA-Z\-]{36})/delete/$', views.AssetDeleteView.as_view(), name='asset-delete'), - url(r'^asset/update/$', views.AssetBulkUpdateView.as_view(), name='asset-bulk-update'), + path('', views.AssetListView.as_view(), name='asset-index'), + path('asset/', views.AssetListView.as_view(), name='asset-list'), + path('asset/create/', views.AssetCreateView.as_view(), name='asset-create'), + path('asset/export/', views.AssetExportView.as_view(), name='asset-export'), + path('asset/import/', views.BulkImportAssetView.as_view(), name='asset-import'), + path('asset//', views.AssetDetailView.as_view(), name='asset-detail'), + path('asset//update/', views.AssetUpdateView.as_view(), name='asset-update'), + path('asset//delete/', views.AssetDeleteView.as_view(), name='asset-delete'), + path('asset/update/', views.AssetBulkUpdateView.as_view(), name='asset-bulk-update'), # User asset view - url(r'^user-asset/$', views.UserAssetListView.as_view(), name='user-asset-list'), + path('user-asset/', views.UserAssetListView.as_view(), name='user-asset-list'), # Resource admin user url - url(r'^admin-user/$', views.AdminUserListView.as_view(), name='admin-user-list'), - url(r'^admin-user/create/$', views.AdminUserCreateView.as_view(), name='admin-user-create'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/$', views.AdminUserDetailView.as_view(), name='admin-user-detail'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/update/$', views.AdminUserUpdateView.as_view(), name='admin-user-update'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/delete/$', views.AdminUserDeleteView.as_view(), name='admin-user-delete'), - url(r'^admin-user/(?P[0-9a-zA-Z\-]{36})/assets/$', views.AdminUserAssetsView.as_view(), name='admin-user-assets'), + path('admin-user/', views.AdminUserListView.as_view(), name='admin-user-list'), + path('admin-user/create/', views.AdminUserCreateView.as_view(), name='admin-user-create'), + path('admin-user//', views.AdminUserDetailView.as_view(), name='admin-user-detail'), + path('admin-user//update/', views.AdminUserUpdateView.as_view(), name='admin-user-update'), + path('admin-user//delete/', views.AdminUserDeleteView.as_view(), name='admin-user-delete'), + path('admin-user//assets/', views.AdminUserAssetsView.as_view(), name='admin-user-assets'), # Resource system user url - url(r'^system-user/$', views.SystemUserListView.as_view(), name='system-user-list'), - url(r'^system-user/create/$', views.SystemUserCreateView.as_view(), name='system-user-create'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/$', views.SystemUserDetailView.as_view(), name='system-user-detail'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/update/$', views.SystemUserUpdateView.as_view(), name='system-user-update'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/delete/$', views.SystemUserDeleteView.as_view(), name='system-user-delete'), - url(r'^system-user/(?P[0-9a-zA-Z\-]{36})/asset/$', views.SystemUserAssetView.as_view(), name='system-user-asset'), - - url(r'^label/$', views.LabelListView.as_view(), name='label-list'), - url(r'^label/create/$', views.LabelCreateView.as_view(), name='label-create'), - url(r'^label/(?P[0-9a-zA-Z\-]{36})/update/$', views.LabelUpdateView.as_view(), name='label-update'), - url(r'^label/(?P[0-9a-zA-Z\-]{36})/delete/$', views.LabelDeleteView.as_view(), name='label-delete'), - - url(r'^domain/$', views.DomainListView.as_view(), name='domain-list'), - url(r'^domain/create/$', views.DomainCreateView.as_view(), name='domain-create'), - url(r'^domain/(?P[0-9a-zA-Z\-]{36})/$', views.DomainDetailView.as_view(), name='domain-detail'), - url(r'^domain/(?P[0-9a-zA-Z\-]{36})/update/$', views.DomainUpdateView.as_view(), name='domain-update'), - url(r'^domain/(?P[0-9a-zA-Z\-]{36})/delete/$', views.DomainDeleteView.as_view(), name='domain-delete'), - url(r'^domain/(?P[0-9a-zA-Z\-]{36})/gateway/$', views.DomainGatewayListView.as_view(), name='domain-gateway-list'), - - url(r'^domain/(?P[0-9a-zA-Z\-]{36})/gateway/create/$', views.DomainGatewayCreateView.as_view(), name='domain-gateway-create'), - url(r'^domain/gateway/(?P[0-9a-zA-Z\-]{36})/update/$', views.DomainGatewayUpdateView.as_view(), name='domain-gateway-update'), + path('system-user/', views.SystemUserListView.as_view(), name='system-user-list'), + path('system-user/create/', views.SystemUserCreateView.as_view(), name='system-user-create'), + path('system-user//', views.SystemUserDetailView.as_view(), name='system-user-detail'), + path('system-user//update/', views.SystemUserUpdateView.as_view(), name='system-user-update'), + path('system-user//delete/', views.SystemUserDeleteView.as_view(), name='system-user-delete'), + path('system-user//asset/', views.SystemUserAssetView.as_view(), name='system-user-asset'), + + path('label/', views.LabelListView.as_view(), name='label-list'), + path('label/create/', views.LabelCreateView.as_view(), name='label-create'), + path('label//update/', views.LabelUpdateView.as_view(), name='label-update'), + path('label//delete/', views.LabelDeleteView.as_view(), name='label-delete'), + + path('domain/', views.DomainListView.as_view(), name='domain-list'), + path('domain/create/', views.DomainCreateView.as_view(), name='domain-create'), + path('domain//', views.DomainDetailView.as_view(), name='domain-detail'), + path('domain//update/', views.DomainUpdateView.as_view(), name='domain-update'), + path('domain//delete/', views.DomainDeleteView.as_view(), name='domain-delete'), + path('domain//gateway/', views.DomainGatewayListView.as_view(), name='domain-gateway-list'), + + path('domain//gateway/create/', views.DomainGatewayCreateView.as_view(), name='domain-gateway-create'), + path('domain/gateway//update/', views.DomainGatewayUpdateView.as_view(), name='domain-gateway-update'), ] diff --git a/apps/audits/urls/api_urls.py b/apps/audits/urls/api_urls.py index 911d04c48..4413eafad 100644 --- a/apps/audits/urls/api_urls.py +++ b/apps/audits/urls/api_urls.py @@ -12,7 +12,6 @@ router = DefaultRouter() router.register(r'ftp-log', api.FTPLogViewSet, 'ftp-log') urlpatterns = [ -# url(r'^celery/task/(?P[0-9a-zA-Z\-]{36})/log/$', api.CeleryTaskLogApi.as_view(), name='celery-task-log'), ] urlpatterns += router.urls diff --git a/apps/audits/urls/view_urls.py b/apps/audits/urls/view_urls.py index 76afbef84..ee5c1333a 100644 --- a/apps/audits/urls/view_urls.py +++ b/apps/audits/urls/view_urls.py @@ -1,8 +1,7 @@ # ~*~ coding: utf-8 ~*~ from __future__ import unicode_literals - -from django.conf.urls import url +from django.urls import path from .. import views __all__ = ["urlpatterns"] @@ -10,5 +9,5 @@ __all__ = ["urlpatterns"] app_name = "audits" urlpatterns = [ - url(r'^ftp-log/$', views.FTPLogListView.as_view(), name='ftp-log-list'), + path('ftp-log/', views.FTPLogListView.as_view(), name='ftp-log-list'), ] diff --git a/apps/common/urls/api_urls.py b/apps/common/urls/api_urls.py index 731068d25..5b44684ec 100644 --- a/apps/common/urls/api_urls.py +++ b/apps/common/urls/api_urls.py @@ -1,13 +1,13 @@ from __future__ import absolute_import -from django.conf.urls import url +from django.urls import path from .. import api app_name = 'common' urlpatterns = [ - url(r'^mail/testing/$', api.MailTestingAPI.as_view(), name='mail-testing'), - url(r'^ldap/testing/$', api.LDAPTestingAPI.as_view(), name='ldap-testing'), - # url(r'^django-settings/$', api.DjangoSettingsAPI.as_view(), name='django-settings'), + path('mail/testing/', api.MailTestingAPI.as_view(), name='mail-testing'), + path('ldap/testing/', api.LDAPTestingAPI.as_view(), name='ldap-testing'), + # path('django-settings/', api.DjangoSettingsAPI.as_view(), name='django-settings'), ] diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index 1631d6f72..a6a365483 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -2,8 +2,7 @@ from __future__ import unicode_literals import re -from django.conf.urls import url, include -from django.urls import path +from django.urls import path, include, re_path from django.conf import settings from django.conf.urls.static import static from rest_framework.response import Response @@ -11,15 +10,11 @@ from django.views.decorators.csrf import csrf_exempt from django.http import HttpResponse from django.utils.encoding import iri_to_uri from rest_framework import permissions - -# from rest_framework.schemas import get_schema_view -# from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer from drf_yasg.views import get_schema_view from drf_yasg import openapi from .views import IndexView, LunaView -# schema_view = get_schema_view(title='Users API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer]) schema_view = get_schema_view( openapi.Info( title="Snippets API", @@ -45,52 +40,52 @@ class HttpResponseTemporaryRedirect(HttpResponse): @csrf_exempt def redirect_format_api(request, *args, **kwargs): - path, query = request.path, request.GET.urlencode() - matched = api_url_pattern.match(path) + _path, query = request.path, request.GET.urlencode() + matched = api_url_pattern.match(_path) if matched: version, app, extra = matched.groups() - path = '/api/{app}/{version}/{extra}?{query}'.format(**{ + _path = '/api/{app}/{version}/{extra}?{query}'.format(**{ "app": app, "version": version, "extra": extra, "query": query }) - return HttpResponseTemporaryRedirect(path) + return HttpResponseTemporaryRedirect(_path) else: - return Response({"msg": "Redirect url failed: {}".format(path)}, status=404) + return Response({"msg": "Redirect url failed: {}".format(_path)}, status=404) v1_api_patterns = [ path('users/v1/', include('users.urls.api_urls', namespace='api-users')), - url(r'^assets/v1/', include('assets.urls.api_urls', namespace='api-assets')), - url(r'^perms/v1/', include('perms.urls.api_urls', namespace='api-perms')), - url(r'^terminal/v1/', include('terminal.urls.api_urls', namespace='api-terminal')), - url(r'^ops/v1/', include('ops.urls.api_urls', namespace='api-ops')), - url(r'^audits/v1/', include('audits.urls.api_urls', namespace='api-audits')), - url(r'^orgs/v1/', include('orgs.urls.api_urls', namespace='api-orgs')), - url(r'^common/v1/', include('common.urls.api_urls', namespace='api-common')), + path('assets/v1/', include('assets.urls.api_urls', namespace='api-assets')), + path('perms/v1/', include('perms.urls.api_urls', namespace='api-perms')), + path('terminal/v1/', include('terminal.urls.api_urls', namespace='api-terminal')), + path('ops/v1/', include('ops.urls.api_urls', namespace='api-ops')), + path('audits/v1/', include('audits.urls.api_urls', namespace='api-audits')), + path('orgs/v1/', include('orgs.urls.api_urls', namespace='api-orgs')), + path('common/v1/', include('common.urls.api_urls', namespace='api-common')), ] app_view_patterns = [ path('users/', include('users.urls.views_urls', namespace='users')), - url(r'^assets/', include('assets.urls.views_urls', namespace='assets')), - url(r'^perms/', include('perms.urls.views_urls', namespace='perms')), - url(r'^terminal/', include('terminal.urls.views_urls', namespace='terminal')), - url(r'^ops/', include('ops.urls.view_urls', namespace='ops')), - url(r'^audits/', include('audits.urls.view_urls', namespace='audits')), - url(r'^orgs/', include('orgs.urls.views_urls', namespace='orgs')), + path('assets/', include('assets.urls.views_urls', namespace='assets')), + path('perms/', include('perms.urls.views_urls', namespace='perms')), + path('terminal/', include('terminal.urls.views_urls', namespace='terminal')), + path('ops/', include('ops.urls.view_urls', namespace='ops')), + path('audits/', include('audits.urls.view_urls', namespace='audits')), + path('orgs/', include('orgs.urls.views_urls', namespace='orgs')), ] urlpatterns = [ - url(r'^$', IndexView.as_view(), name='index'), - url(r'^luna/', LunaView.as_view(), name='luna-error'), - url(r'^settings/', include('common.urls.view_urls', namespace='settings')), - url(r'^common/', include('common.urls.view_urls', namespace='common')), - url(r'^api/v1/.*', redirect_format_api), - url(r'^api/', include(v1_api_patterns)), + path('', IndexView.as_view(), name='index'), + path('luna/', LunaView.as_view(), name='luna-error'), + path('settings/', include('common.urls.view_urls', namespace='settings')), + path('common/', include('common.urls.view_urls', namespace='common')), + re_path(r'^api/v1/.*', redirect_format_api), + path('api/', include(v1_api_patterns)), # Api url view map # External apps url - url(r'^captcha/', include('captcha.urls')), + path('captcha/', include('captcha.urls')), ] urlpatterns += app_view_patterns urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ @@ -98,7 +93,7 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ if settings.DEBUG: urlpatterns += [ - url(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'), - url(r'^docs/', schema_view.with_ui('swagger', cache_timeout=None), name="docs"), - url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=None), name='redoc'), + re_path('swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'), + path('docs/', schema_view.with_ui('swagger', cache_timeout=None), name="docs"), + path('redoc/', schema_view.with_ui('redoc', cache_timeout=None), name='redoc'), ] diff --git a/apps/ops/urls/api_urls.py b/apps/ops/urls/api_urls.py index ed963621e..d1e815800 100644 --- a/apps/ops/urls/api_urls.py +++ b/apps/ops/urls/api_urls.py @@ -1,7 +1,7 @@ # ~*~ coding: utf-8 ~*~ from __future__ import unicode_literals -from django.conf.urls import url +from django.urls import path from rest_framework.routers import DefaultRouter from .. import api @@ -14,8 +14,8 @@ router.register(r'adhoc', api.AdHocViewSet, 'adhoc') router.register(r'history', api.AdHocRunHistorySet, 'history') urlpatterns = [ - url(r'^tasks/(?P[0-9a-zA-Z\-]{36})/run/$', api.TaskRun.as_view(), name='task-run'), - url(r'^celery/task/(?P[0-9a-zA-Z\-]{36})/log/$', api.CeleryTaskLogApi.as_view(), name='celery-task-log'), + path('tasks//run/', api.TaskRun.as_view(), name='task-run'), + path('celery/task//log/', api.CeleryTaskLogApi.as_view(), name='celery-task-log'), ] urlpatterns += router.urls diff --git a/apps/ops/urls/view_urls.py b/apps/ops/urls/view_urls.py index 470d6f06d..f49506e80 100644 --- a/apps/ops/urls/view_urls.py +++ b/apps/ops/urls/view_urls.py @@ -1,8 +1,7 @@ # ~*~ coding: utf-8 ~*~ from __future__ import unicode_literals +from django.urls import path - -from django.conf.urls import url from .. import views __all__ = ["urlpatterns"] @@ -10,13 +9,13 @@ __all__ = ["urlpatterns"] app_name = "ops" urlpatterns = [ - # TResource Task url - url(r'^task/$', views.TaskListView.as_view(), name='task-list'), - url(r'^task/(?P[0-9a-zA-Z\-]{36})/$', views.TaskDetailView.as_view(), name='task-detail'), - url(r'^task/(?P[0-9a-zA-Z\-]{36})/adhoc/$', views.TaskAdhocView.as_view(), name='task-adhoc'), - url(r'^task/(?P[0-9a-zA-Z\-]{36})/history/$', views.TaskHistoryView.as_view(), name='task-history'), - url(r'^adhoc/(?P[0-9a-zA-Z\-]{36})/$', views.AdHocDetailView.as_view(), name='adhoc-detail'), - url(r'^adhoc/(?P[0-9a-zA-Z\-]{36})/history/$', views.AdHocHistoryView.as_view(), name='adhoc-history'), - url(r'^adhoc/history/(?P[0-9a-zA-Z\-]{36})/$', views.AdHocHistoryDetailView.as_view(), name='adhoc-history-detail'), - url(r'^celery/task/(?P[0-9a-zA-Z\-]{36})/log/$', views.CeleryTaskLogView.as_view(), name='celery-task-log'), + # Resource Task url + path('task/', views.TaskListView.as_view(), name='task-list'), + path('task//', views.TaskDetailView.as_view(), name='task-detail'), + path('task//adhoc/', views.TaskAdhocView.as_view(), name='task-adhoc'), + path('task//history/', views.TaskHistoryView.as_view(), name='task-history'), + path('adhoc//', views.AdHocDetailView.as_view(), name='adhoc-detail'), + path('adhoc//history/', views.AdHocHistoryView.as_view(), name='adhoc-history'), + path('adhoc/history//', views.AdHocHistoryDetailView.as_view(), name='adhoc-history-detail'), + path('celery/task//log/', views.CeleryTaskLogView.as_view(), name='celery-task-log'), ] diff --git a/apps/orgs/urls/api_urls.py b/apps/orgs/urls/api_urls.py index 8f3d46b73..a90d911e2 100644 --- a/apps/orgs/urls/api_urls.py +++ b/apps/orgs/urls/api_urls.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- # -from django.conf.urls import url - from rest_framework.routers import DefaultRouter from .. import api diff --git a/apps/orgs/urls/views_urls.py b/apps/orgs/urls/views_urls.py index e3408e741..225457827 100644 --- a/apps/orgs/urls/views_urls.py +++ b/apps/orgs/urls/views_urls.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- # -from django.conf.urls import url +from django.urls import path + from .. import views app_name = 'orgs' urlpatterns = [ - url(r'^(?P.*)/switch/$', views.SwitchOrgView.as_view(), name='org-switch'), - url(r'^switch-a-org/$', views.SwitchToAOrgView.as_view(), name='switch-a-org') + path('/switch/', views.SwitchOrgView.as_view(), name='org-switch'), + path('switch-a-org/', views.SwitchToAOrgView.as_view(), name='switch-a-org') ] diff --git a/apps/perms/urls/api_urls.py b/apps/perms/urls/api_urls.py index c41d1e291..7fdb74981 100644 --- a/apps/perms/urls/api_urls.py +++ b/apps/perms/urls/api_urls.py @@ -1,6 +1,6 @@ # coding:utf-8 -from django.conf.urls import url +from django.urls import path from rest_framework import routers from .. import api @@ -11,53 +11,52 @@ router.register('asset-permissions', api.AssetPermissionViewSet, 'asset-permissi urlpatterns = [ # 查询某个用户授权的资产和资产组 - url(r'^user/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.UserGrantedAssetsApi.as_view(), name='user-assets'), - url(r'^user/assets/$', api.UserGrantedAssetsApi.as_view(), - name='my-assets'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/nodes/$', - api.UserGrantedNodesApi.as_view(), name='user-nodes'), - url(r'^user/nodes/$', api.UserGrantedNodesApi.as_view(), - name='my-nodes'), - url( - r'^user/(?P[0-9a-zA-Z\-]{36})/nodes/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.UserGrantedNodeAssetsApi.as_view(), name='user-node-assets'), - url(r'^user/nodes/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.UserGrantedNodeAssetsApi.as_view(), name='my-node-assets'), - url(r'^user/(?P[0-9a-zA-Z\-]{36})/nodes-assets/$', - api.UserGrantedNodesWithAssetsApi.as_view(), name='user-nodes-assets'), - url(r'^user/nodes-assets/$', api.UserGrantedNodesWithAssetsApi.as_view(), - name='my-nodes-assets'), + path('user//assets/', + api.UserGrantedAssetsApi.as_view(), name='user-assets'), + path('user/assets/', api.UserGrantedAssetsApi.as_view(), + name='my-assets'), + path('user//nodes/', + api.UserGrantedNodesApi.as_view(), name='user-nodes'), + path('user/nodes/', api.UserGrantedNodesApi.as_view(), + name='my-nodes'), + path('user//nodes//assets/', + api.UserGrantedNodeAssetsApi.as_view(), name='user-node-assets'), + path('user/nodes//assets/', + api.UserGrantedNodeAssetsApi.as_view(), name='my-node-assets'), + path('user//nodes-assets/', + api.UserGrantedNodesWithAssetsApi.as_view(), name='user-nodes-assets'), + path('user/nodes-assets/', api.UserGrantedNodesWithAssetsApi.as_view(), + name='my-nodes-assets'), # 查询某个用户组授权的资产和资产组 - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.UserGroupGrantedAssetsApi.as_view(), name='user-group-assets'), - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/nodes/$', - api.UserGroupGrantedNodesApi.as_view(), name='user-group-nodes'), - url(r'^user-group/(?P[0-9a-zA-Z\-]{36})/nodes-assets/$', - api.UserGroupGrantedNodesWithAssetsApi.as_view(), - name='user-group-nodes-assets'), - url( - r'^user-group/(?P[0-9a-zA-Z\-]{36})/nodes/(?P[0-9a-zA-Z\-]{36})/assets/$', - api.UserGroupGrantedNodeAssetsApi.as_view(), - name='user-group-node-assets'), + path('user-group//assets/', + api.UserGroupGrantedAssetsApi.as_view(), name='user-group-assets'), + path('user-group//nodes/', + api.UserGroupGrantedNodesApi.as_view(), name='user-group-nodes'), + path('user-group//nodes-assets/', + api.UserGroupGrantedNodesWithAssetsApi.as_view(), + name='user-group-nodes-assets'), + path('user-group//nodes//assets/', + api.UserGroupGrantedNodeAssetsApi.as_view(), + name='user-group-node-assets'), # 用户和资产授权变更 - url(r'^asset-permissions/(?P[0-9a-zA-Z\-]{36})/user/remove/$', - api.AssetPermissionRemoveUserApi.as_view(), - name='asset-permission-remove-user'), - url(r'^asset-permissions/(?P[0-9a-zA-Z\-]{36})/user/add/$', - api.AssetPermissionAddUserApi.as_view(), - name='asset-permission-add-user'), - url(r'^asset-permissions/(?P[0-9a-zA-Z\-]{36})/asset/remove/$', - api.AssetPermissionRemoveAssetApi.as_view(), - name='asset-permission-remove-asset'), - url(r'^asset-permissions/(?P[0-9a-zA-Z\-]{36})/asset/add/$', - api.AssetPermissionAddAssetApi.as_view(), - name='asset-permission-add-asset'), + path('asset-permissions//user/remove/', + api.AssetPermissionRemoveUserApi.as_view(), + name='asset-permission-remove-user'), + path('asset-permissions//user/add/', + api.AssetPermissionAddUserApi.as_view(), + name='asset-permission-add-user'), + path('asset-permissions//asset/remove/', + api.AssetPermissionRemoveAssetApi.as_view(), + name='asset-permission-remove-asset'), + path('asset-permissions//asset/add/', + api.AssetPermissionAddAssetApi.as_view(), + name='asset-permission-add-asset'), # 验证用户是否有某个资产和系统用户的权限 - url(r'asset-permission/user/validate/$', api.ValidateUserAssetPermissionView.as_view(), name='validate-user-asset-permission'), + path('asset-permission/user/validate/', api.ValidateUserAssetPermissionView.as_view(), + name='validate-user-asset-permission'), ] urlpatterns += router.urls diff --git a/apps/perms/urls/views_urls.py b/apps/perms/urls/views_urls.py index a3cf7ff42..8b8348d28 100644 --- a/apps/perms/urls/views_urls.py +++ b/apps/perms/urls/views_urls.py @@ -1,16 +1,17 @@ # coding:utf-8 from django.conf.urls import url +from django.urls import path from .. import views app_name = 'perms' urlpatterns = [ - url(r'^asset-permission/$', views.AssetPermissionListView.as_view(), name='asset-permission-list'), - url(r'^asset-permission/create/$', views.AssetPermissionCreateView.as_view(), name='asset-permission-create'), - url(r'^asset-permission/(?P[0-9a-zA-Z\-]{36})/update/$', views.AssetPermissionUpdateView.as_view(), name='asset-permission-update'), - url(r'^asset-permission/(?P[0-9a-zA-Z\-]{36})/$', views.AssetPermissionDetailView.as_view(),name='asset-permission-detail'), - url(r'^asset-permission/(?P[0-9a-zA-Z\-]{36})/delete/$', views.AssetPermissionDeleteView.as_view(), name='asset-permission-delete'), - url(r'^asset-permission/(?P[0-9a-zA-Z\-]{36})/user/$', views.AssetPermissionUserView.as_view(), name='asset-permission-user-list'), - url(r'^asset-permission/(?P[0-9a-zA-Z\-]{36})/asset/$', views.AssetPermissionAssetView.as_view(), name='asset-permission-asset-list'), + path('asset-permission/', views.AssetPermissionListView.as_view(), name='asset-permission-list'), + path('asset-permission/create/', views.AssetPermissionCreateView.as_view(), name='asset-permission-create'), + path('asset-permission//update/', views.AssetPermissionUpdateView.as_view(), name='asset-permission-update'), + path('asset-permission//', views.AssetPermissionDetailView.as_view(),name='asset-permission-detail'), + path('asset-permission//delete/', views.AssetPermissionDeleteView.as_view(), name='asset-permission-delete'), + path('asset-permission//user/', views.AssetPermissionUserView.as_view(), name='asset-permission-user-list'), + path('asset-permission//asset/', views.AssetPermissionAssetView.as_view(), name='asset-permission-asset-list'), ] diff --git a/apps/templates/_user_profile.html b/apps/templates/_user_profile.html index f4129be9b..7a0c3c900 100644 --- a/apps/templates/_user_profile.html +++ b/apps/templates/_user_profile.html @@ -8,9 +8,10 @@ {#
#}
- image + image
- {% if ADMIN_ORGS and ADMIN_ORGS|length != 1 %} + {{ request.COOKIE.IN_ADMIN_PAGE }} + {% if ADMIN_ORGS and ADMIN_ORGS|length != 1 and request.COOKIES.IN_ADMIN_PAGE != 'No' %}
+ {% if ADMIN_ORGS and request.COOKIES.IN_ADMIN_PAGE != 'No' %} + {% if ADMIN_ORGS|length > 1 or not CURRENT_ORG.is_default %} + + {% endif %} {% endif %}