From e76eec530f4625ee458434f9e02946aaba37149c Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 23 Feb 2022 17:06:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0018_auto_20220223_1642.py | 18 ++++++++++++++ .../migrations/0087_auto_20220223_1642.py | 18 ++++++++++++++ apps/common/migrations/0007_permission.py | 24 +++++++++++++++++++ apps/common/models.py | 9 +++++++ apps/jumpserver/api.py | 2 +- .../migrations/0025_auto_20220223_1642.py | 18 ++++++++++++++ apps/rbac/builtin.py | 1 + .../migrations/0044_auto_20220223_1642.py | 18 ++++++++++++++ 8 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 apps/applications/migrations/0018_auto_20220223_1642.py create mode 100644 apps/assets/migrations/0087_auto_20220223_1642.py create mode 100644 apps/common/migrations/0007_permission.py create mode 100644 apps/common/models.py create mode 100644 apps/perms/migrations/0025_auto_20220223_1642.py create mode 100644 apps/terminal/migrations/0044_auto_20220223_1642.py diff --git a/apps/applications/migrations/0018_auto_20220223_1642.py b/apps/applications/migrations/0018_auto_20220223_1642.py new file mode 100644 index 000000000..5f3af1455 --- /dev/null +++ b/apps/applications/migrations/0018_auto_20220223_1642.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2022-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('applications', '0017_auto_20220217_2135'), + ] + + operations = [ + migrations.AlterField( + model_name='application', + name='type', + field=models.CharField(choices=[('mysql', 'MySQL'), ('oracle', 'Oracle'), ('postgresql', 'PostgreSQL'), ('mariadb', 'MariaDB'), ('sqlserver', 'SQLServer'), ('redis', 'Redis'), ('mongodb', 'MongoDB'), ('chrome', 'Chrome'), ('mysql_workbench', 'MySQL Workbench'), ('vmware_client', 'vSphere Client'), ('custom', 'Custom'), ('k8s', 'Kubernetes')], max_length=16, verbose_name='Type'), + ), + ] diff --git a/apps/assets/migrations/0087_auto_20220223_1642.py b/apps/assets/migrations/0087_auto_20220223_1642.py new file mode 100644 index 000000000..c2a1b020f --- /dev/null +++ b/apps/assets/migrations/0087_auto_20220223_1642.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2022-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0086_auto_20220217_2135'), + ] + + operations = [ + migrations.AlterField( + model_name='systemuser', + name='protocol', + field=models.CharField(choices=[('ssh', 'SSH'), ('rdp', 'RDP'), ('telnet', 'Telnet'), ('vnc', 'VNC'), ('mysql', 'MySQL'), ('oracle', 'Oracle'), ('mariadb', 'MariaDB'), ('postgresql', 'PostgreSQL'), ('sqlserver', 'SQLServer'), ('redis', 'Redis'), ('mongodb', 'MongoDB'), ('k8s', 'K8S')], default='ssh', max_length=16, verbose_name='Protocol'), + ), + ] diff --git a/apps/common/migrations/0007_permission.py b/apps/common/migrations/0007_permission.py new file mode 100644 index 000000000..8794b7c5b --- /dev/null +++ b/apps/common/migrations/0007_permission.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.14 on 2022-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('common', '0006_auto_20190304_1515'), + ] + + operations = [ + migrations.CreateModel( + name='Permission', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + options={ + 'permissions': [('view_resourcestatistics', 'Can view resource statistics')], + }, + ), + ] diff --git a/apps/common/models.py b/apps/common/models.py new file mode 100644 index 000000000..e716113cd --- /dev/null +++ b/apps/common/models.py @@ -0,0 +1,9 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ + + +class Permission(models.Model): + class Meta: + permissions = [ + ('view_resourcestatistics', _('Can view resource statistics')) + ] diff --git a/apps/jumpserver/api.py b/apps/jumpserver/api.py index 8edc35e76..d69d27c68 100644 --- a/apps/jumpserver/api.py +++ b/apps/jumpserver/api.py @@ -214,7 +214,7 @@ class DatesLoginMetricMixin: class IndexApi(DatesLoginMetricMixin, APIView): http_method_names = ['get'] rbac_perms = { - 'GET': 'view_auditview' + 'GET': 'common.view_resourcestatistics' } def get(self, request, *args, **kwargs): diff --git a/apps/perms/migrations/0025_auto_20220223_1642.py b/apps/perms/migrations/0025_auto_20220223_1642.py new file mode 100644 index 000000000..120039e40 --- /dev/null +++ b/apps/perms/migrations/0025_auto_20220223_1642.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2022-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('perms', '0024_auto_20220217_2135'), + ] + + operations = [ + migrations.AlterField( + model_name='applicationpermission', + name='type', + field=models.CharField(choices=[('mysql', 'MySQL'), ('oracle', 'Oracle'), ('postgresql', 'PostgreSQL'), ('mariadb', 'MariaDB'), ('sqlserver', 'SQLServer'), ('redis', 'Redis'), ('mongodb', 'MongoDB'), ('chrome', 'Chrome'), ('mysql_workbench', 'MySQL Workbench'), ('vmware_client', 'vSphere Client'), ('custom', 'Custom'), ('k8s', 'Kubernetes')], max_length=16, verbose_name='Type'), + ), + ] diff --git a/apps/rbac/builtin.py b/apps/rbac/builtin.py index 71f7d0bc4..6d8d2490f 100644 --- a/apps/rbac/builtin.py +++ b/apps/rbac/builtin.py @@ -4,6 +4,7 @@ from .const import Scope, system_exclude_permissions, org_exclude_permissions auditor_perms = ( + ('common', 'permission', 'view', 'resourcestatistics'), ('audits', '*', '*', '*'), ('rbac', 'menupermission', 'view', 'auditview'), ('terminal', 'session', '*', '*'), diff --git a/apps/terminal/migrations/0044_auto_20220223_1642.py b/apps/terminal/migrations/0044_auto_20220223_1642.py new file mode 100644 index 000000000..463312f8e --- /dev/null +++ b/apps/terminal/migrations/0044_auto_20220223_1642.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2022-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('terminal', '0043_auto_20220217_2135'), + ] + + operations = [ + migrations.AlterField( + model_name='session', + name='protocol', + field=models.CharField(choices=[('ssh', 'ssh'), ('rdp', 'rdp'), ('vnc', 'vnc'), ('telnet', 'telnet'), ('mysql', 'mysql'), ('oracle', 'oracle'), ('mariadb', 'mariadb'), ('sqlserver', 'sqlserver'), ('postgresql', 'postgresql'), ('redis', 'redis'), ('mongodb', 'MongoDB'), ('k8s', 'kubernetes')], db_index=True, default='ssh', max_length=16), + ), + ] From a1d15ef20668083299149e1b9465e8d1bf450c47 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 23 Feb 2022 17:09:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=BB=88=E6=96=AD=E4=BC=9A=E8=AF=9DAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/task.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/terminal/api/task.py b/apps/terminal/api/task.py index 937ed2faf..c7e1a2681 100644 --- a/apps/terminal/api/task.py +++ b/apps/terminal/api/task.py @@ -12,7 +12,6 @@ from .. import serializers from terminal.utils import is_session_approver from orgs.utils import tmp_to_root_org - __all__ = ['TaskViewSet', 'KillSessionAPI', 'KillSessionForTicketAPI'] logger = logging.getLogger(__file__) @@ -45,6 +44,11 @@ class KillSessionAPI(APIView): 'POST': 'terminal.terminate_session' } + def post(self, request, *args, **kwargs): + session_ids = request.data + validated_session = kill_sessions(session_ids, request.user) + return Response({"ok": validated_session}) + class KillSessionForTicketAPI(APIView): permission_classes = (IsAuthenticated, ) @@ -61,4 +65,3 @@ class KillSessionForTicketAPI(APIView): validated_session = kill_sessions(session_ids, request.user) return Response({"ok": validated_session}) -