From 889713f00e572db3ae2e00ca823052af8e2bb799 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Thu, 10 Feb 2022 13:14:17 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E8=AE=BE=E7=BD=AE=E6=98=BE=E7=A4=BA=E5=85=B6?= =?UTF-8?q?=E5=AE=83=E7=BB=84=E7=BB=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tickets/models/flow.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/tickets/models/flow.py b/apps/tickets/models/flow.py index ae5eea0ff..69aa6c432 100644 --- a/apps/tickets/models/flow.py +++ b/apps/tickets/models/flow.py @@ -6,7 +6,8 @@ from django.utils.translation import ugettext_lazy as _ from users.models import User from common.mixins.models import CommonModelMixin from orgs.mixins.models import OrgModelMixin -from orgs.utils import tmp_to_root_org, tmp_to_org, get_current_org_id +from orgs.models import Organization +from orgs.utils import tmp_to_org, get_current_org_id from ..const import TicketType, TicketApprovalLevel, TicketApprovalStrategy __all__ = ['TicketFlow', 'ApprovalRule'] @@ -75,6 +76,7 @@ class TicketFlow(CommonModelMixin, OrgModelMixin): else: flows = cls.objects.all() cur_flow_types = flows.values_list('type', flat=True) - with tmp_to_root_org(): - diff_global_flows = cls.objects.exclude(type__in=cur_flow_types) + root_id = Organization.ROOT_ID + with tmp_to_org(root_id): + diff_global_flows = cls.objects.exclude(type__in=cur_flow_types).filter(org_id=root_id) return flows | diff_global_flows From 755fa8efa856580bf88451779cc8aeee0ad50570 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Thu, 10 Feb 2022 18:01:10 +0800 Subject: [PATCH 2/7] =?UTF-8?q?perf:=20=E5=85=BC=E5=AE=B9=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=89=88=E6=9C=AC=E9=97=B4JumpServer=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=9A=84SAML2=E5=8D=8F=E8=AE=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/saml2/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/authentication/backends/saml2/views.py b/apps/authentication/backends/saml2/views.py index 6c7fb5cb8..a0b03bbad 100644 --- a/apps/authentication/backends/saml2/views.py +++ b/apps/authentication/backends/saml2/views.py @@ -171,6 +171,7 @@ class PrepareRequestMixin: valid_attrs = ['username', 'name', 'email', 'comment', 'phone'] for attr, value in attrs.items(): + attr = attr.rsplit('/')[-1] if attr not in valid_attrs: continue user_attrs[attr] = self.value_to_str(value) From ab34b9906e1d936f257b9c1d56eca0926b2628a3 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Thu, 10 Feb 2022 18:05:28 +0800 Subject: [PATCH 3/7] =?UTF-8?q?perf:=20=E5=88=87=E5=89=B2=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=B0=B1=E5=8F=AF=E4=BB=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/saml2/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentication/backends/saml2/views.py b/apps/authentication/backends/saml2/views.py index a0b03bbad..b0b8fef8d 100644 --- a/apps/authentication/backends/saml2/views.py +++ b/apps/authentication/backends/saml2/views.py @@ -171,7 +171,7 @@ class PrepareRequestMixin: valid_attrs = ['username', 'name', 'email', 'comment', 'phone'] for attr, value in attrs.items(): - attr = attr.rsplit('/')[-1] + attr = attr.rsplit('/', 1)[-1] if attr not in valid_attrs: continue user_attrs[attr] = self.value_to_str(value) From 597b02290537e19d7a82ee66422f54c9750a39f8 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 14 Feb 2022 10:58:30 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E6=96=87=E4=BB=B6=E4=B8=8D=E8=83=BD=E8=A2=AB?= =?UTF-8?q?=E6=B8=85=E7=90=86=E7=9A=84bug=20(#7604)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复历史会话文件不能被清理的bug * perf: 删除调试日志 Co-authored-by: halo --- apps/terminal/tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/terminal/tasks.py b/apps/terminal/tasks.py index 300aa0d0d..0f19d0435 100644 --- a/apps/terminal/tasks.py +++ b/apps/terminal/tasks.py @@ -18,7 +18,6 @@ from .models import Status, Session, Command from .backends import server_replay_storage from .utils import find_session_replay_local - CACHE_REFRESH_INTERVAL = 10 RUNNING = False logger = get_task_logger(__name__) @@ -64,7 +63,7 @@ def clean_expired_session_period(): logger.info("Clean session item done") expired_commands.delete() logger.info("Clean session command done") - command = "find %s -mtime +%s -name '*.gz' -exec rm -f {} \\;" % ( + command = "find %s -mtime +%s \\( -name '*.json' -o -name '*.tar' -o -name '*.gz' \\) -exec rm -f {} \\;" % ( replay_dir, days ) subprocess.call(command, shell=True) From 540679df11e1772785981a2519663d0a2bb3fd75 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Mon, 14 Feb 2022 10:57:52 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Doperatelog=20add?= =?UTF-8?q?=20remove=20=E7=BF=BB=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/audits/signals_handler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/audits/signals_handler.py b/apps/audits/signals_handler.py index 3e5086831..0f9356066 100644 --- a/apps/audits/signals_handler.py +++ b/apps/audits/signals_handler.py @@ -170,9 +170,9 @@ M2M_NEED_RECORD = { } M2M_ACTION = { - POST_ADD: 'add', - POST_REMOVE: 'remove', - POST_CLEAR: 'remove', + POST_ADD: OperateLog.ACTION_CREATE, + POST_REMOVE: OperateLog.ACTION_DELETE, + POST_CLEAR: OperateLog.ACTION_DELETE, } @@ -187,14 +187,14 @@ def on_m2m_changed(sender, action, instance, reverse, model, pk_set, **kwargs): sender_name = sender._meta.object_name if sender_name in M2M_NEED_RECORD: - action = M2M_ACTION[action] org_id = current_org.id remote_addr = get_request_ip(current_request) user = str(user) resource_type, resource_tmpl_add, resource_tmpl_remove = M2M_NEED_RECORD[sender_name] - if action == 'add': + action = M2M_ACTION[action] + if action == OperateLog.ACTION_CREATE: resource_tmpl = resource_tmpl_add - elif action == 'remove': + elif action == OperateLog.ACTION_DELETE: resource_tmpl = resource_tmpl_remove to_create = [] From fa5921cd86c704faee6a87d6090fc403d9d94872 Mon Sep 17 00:00:00 2001 From: xinwen Date: Mon, 14 Feb 2022 14:49:57 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=20can=5Freplay=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/models/session.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/apps/terminal/models/session.py b/apps/terminal/models/session.py index 75c64b41f..6d90bc57e 100644 --- a/apps/terminal/models/session.py +++ b/apps/terminal/models/session.py @@ -56,7 +56,6 @@ class Session(OrgModelMixin): upload_to = 'replay' ACTIVE_CACHE_KEY_PREFIX = 'SESSION_ACTIVE_{}' - _DATE_START_FIRST_HAS_REPLAY_RDP_SESSION = None SUFFIX_MAP = {1: '.gz', 2: '.replay.gz', 3: '.cast.gz'} DEFAULT_SUFFIXES = ['.replay.gz', '.cast.gz', '.gz'] @@ -125,25 +124,8 @@ class Session(OrgModelMixin): def user_obj(self): return User.objects.get(id=self.user_id) - @property - def _date_start_first_has_replay_rdp_session(self): - if self.__class__._DATE_START_FIRST_HAS_REPLAY_RDP_SESSION is None: - instance = self.__class__.objects.filter( - protocol='rdp', has_replay=True - ).order_by('date_start').first() - if not instance: - date_start = timezone.now() - timezone.timedelta(days=365) - else: - date_start = instance.date_start - self.__class__._DATE_START_FIRST_HAS_REPLAY_RDP_SESSION = date_start - return self.__class__._DATE_START_FIRST_HAS_REPLAY_RDP_SESSION - def can_replay(self): - if self.has_replay: - return True - if self.date_start < self._date_start_first_has_replay_rdp_session: - return True - return False + return self.has_replay @property def can_join(self): From 7f36958683faba4426cc39748273e455350c8faa Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Mon, 14 Feb 2022 15:23:35 +0800 Subject: [PATCH 7/7] =?UTF-8?q?perf:=20=E5=B7=A5=E5=8D=95=E6=B5=81?= =?UTF-8?q?=E5=8F=AA=E9=9C=80=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tickets/api/ticket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/tickets/api/ticket.py b/apps/tickets/api/ticket.py index 80bc034e3..bca98e1fd 100644 --- a/apps/tickets/api/ticket.py +++ b/apps/tickets/api/ticket.py @@ -33,7 +33,7 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet): 'title', 'applicant_display', 'status', 'state', 'action_display', 'date_created', 'serial_num', ) - ordering = ('-date_created', ) + ordering = ('-date_created',) def create(self, request, *args, **kwargs): raise MethodNotAllowed(self.action) @@ -81,7 +81,7 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet): class TicketFlowViewSet(JMSBulkModelViewSet): - permission_classes = (IsOrgAdmin, IsSuperUser) + permission_classes = (IsOrgAdmin,) serializer_class = serializers.TicketFlowSerializer filterset_fields = ['id', 'type']