From 05818671a7b4b2a2541e7be2fbebcbedce59cac2 Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Mon, 26 Aug 2019 11:58:06 +0800 Subject: [PATCH] V52 (#3158) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 优化切换组织时重定向页面逻辑 (#3133) * [Update] 优化切换组织时重定向页面逻辑 * [Update] 优化切换组织时重定向页面逻辑 2 * [Update] WebTerminal 跳转添加时间戳 * [Update] 修复创建授权规则授权节点时,系统用户不自动推送的问题 --- apps/assets/signals_handler.py | 20 ++++++++++---------- apps/common/utils/common.py | 2 +- apps/orgs/views.py | 10 ++++++---- apps/terminal/views/terminal.py | 4 +++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/apps/assets/signals_handler.py b/apps/assets/signals_handler.py index 70eecbd10..b2316d7d0 100644 --- a/apps/assets/signals_handler.py +++ b/apps/assets/signals_handler.py @@ -57,16 +57,16 @@ def on_system_user_update(sender, instance=None, created=True, **kwargs): push_system_user_to_assets.delay(instance, assets) -# @receiver(m2m_changed, sender=SystemUser.nodes.through) -# def on_system_user_nodes_change(sender, instance=None, **kwargs): -# if instance and kwargs["action"] == "post_add": -# logger.info("System user `{}` nodes update signal received".format(instance)) -# assets = set() -# nodes = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']) -# for node in nodes: -# assets.update(set(node.get_all_assets())) -# instance.assets.add(*tuple(assets)) -# +@receiver(m2m_changed, sender=SystemUser.nodes.through) +def on_system_user_nodes_change(sender, instance=None, **kwargs): + if instance and kwargs["action"] == "post_add": + logger.info("System user `{}` nodes update signal received".format(instance)) + assets = set() + nodes = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']) + for node in nodes: + assets.update(set(node.get_all_assets())) + instance.assets.add(*tuple(assets)) + @receiver(m2m_changed, sender=SystemUser.assets.through) def on_system_user_assets_change(sender, instance=None, **kwargs): diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index 572820c49..0000d35b4 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -12,7 +12,7 @@ import copy import ipaddress -UUID_PATTERN = re.compile(r'[0-9a-zA-Z\-]{36}') +UUID_PATTERN = re.compile(r'\w{8}(-\w{4}){3}-\w{12}') ipip_db = None diff --git a/apps/orgs/views.py b/apps/orgs/views.py index e7bf9fc62..757129a7f 100644 --- a/apps/orgs/views.py +++ b/apps/orgs/views.py @@ -4,6 +4,7 @@ from django.http import HttpResponseForbidden from django.views.generic import DetailView, View from .models import Organization +from common.utils import UUID_PATTERN class SwitchOrgView(DetailView): @@ -17,10 +18,11 @@ class SwitchOrgView(DetailView): request.session['oid'] = oid host = request.get_host() referer = request.META.get('HTTP_REFERER') - if referer.find(host) != -1: - return redirect(referer) - else: - return redirect('index') + if referer.find(host) == -1: + return redirect(reverse('index')) + if UUID_PATTERN.search(referer): + return redirect(reverse('index')) + return redirect(referer) class SwitchToAOrgView(View): diff --git a/apps/terminal/views/terminal.py b/apps/terminal/views/terminal.py index 5ddb9312e..6396094ab 100644 --- a/apps/terminal/views/terminal.py +++ b/apps/terminal/views/terminal.py @@ -1,5 +1,6 @@ # ~*~ coding: utf-8 ~*~ # +import time from django.views.generic import ListView, UpdateView, DeleteView, \ DetailView, View from django.utils.translation import ugettext as _ @@ -128,7 +129,8 @@ class TerminalConnectView(PermissionsMixin, DetailView): class WebTerminalView(View): def get(self, request, *args, **kwargs): - return redirect('/luna/?' + request.GET.urlencode()) + redirect_url = '/luna/?_={}&'.format(int(time.time())) + return redirect(redirect_url + request.GET.urlencode()) class WebSFTPView(View):