From e3b2be0261f3bc44e483e3e656b04b9f7840f2db Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Tue, 24 Mar 2015 18:34:00 +0800 Subject: [PATCH] bugs --- jasset/urls.py | 1 - jasset/views.py | 19 ++++++++++++++----- jumpserver/api.py | 9 +++++++-- templates/jasset/host_add_multi.html | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/jasset/urls.py b/jasset/urls.py index ae8b89612..c37330264 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -3,7 +3,6 @@ from django.conf.urls import patterns, include, url from jasset.views import * urlpatterns = patterns('', - url(r'^$', index), url(r'^host_add/$', add_host), url(r"^host_add_multi/$", add_host_multi), url(r'^host_list/$', list_host), diff --git a/jasset/views.py b/jasset/views.py index 79c415cb3..f3552ed82 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -8,19 +8,19 @@ from django.template import RequestContext from django.shortcuts import render_to_response from models import IDC, Asset, BisGroup -from juser.models import UserGroup, DEPT +from juser.models import UserGroup, DEPT, User from connect import PyCrypt, KEY from jlog.models import Log from jumpserver.views import jasset_host_edit, pages -from jumpserver.api import asset_perm_api -from jumpserver.api import user_perm_group_api, require_login, require_super_user, \ +from jumpserver.api import asset_perm_api, validate +from jumpserver.api import require_login, require_super_user, \ require_admin, is_group_admin, is_super_user, is_common_user, get_user_dept cryptor = PyCrypt(KEY) -def index(request): - return render_to_response('jasset/jasset.html', ) +class RaiseError(Exception): + pass def f_add_host(ip, port, idc, jtype, group, dept, active, comment, username='', password=''): @@ -70,6 +70,7 @@ def add_host(request): user_id = request.session.get('user_id') edept = DEPT.objects.get(id=dept_id) egroup = edept.bisgroup_set.all() + if request.method == 'POST': j_ip = request.POST.get('j_ip') j_idc = request.POST.get('j_idc') @@ -80,6 +81,14 @@ def add_host(request): j_comment = request.POST.get('j_comment') j_dept = request.POST.getlist('j_dept') + try: + if is_group_admin(request) and not validate(request, asset_group=j_group): + print validate(request, asset_group=j_group), 'hello' + emg = u'滚Y' + raise RaiseError(emg) + except RaiseError: + pass + if Asset.objects.filter(ip=str(j_ip)): emg = u'该IP %s 已存在!' % j_ip return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request)) diff --git a/jumpserver/api.py b/jumpserver/api.py index 55f31945c..131dc78d1 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -321,10 +321,15 @@ def validate(request, user_group=None, user=None, asset_group=None, asset=None): if asset_group: dept_asset_groups = dept.bisgroup_set.all() asset_groups = [] - for asset_group_id in asset_group: - asset_groups.extend(BisGroup.objects.filter(id=asset_group_id)) + for asset_group_name in asset_group: + asset_groups.extend(BisGroup.objects.filter(name=asset_group_name)) + + if len(asset_groups) == 0: + print 'hehe' + return False if not set(asset_groups).issubset(set(dept_asset_groups)): + print 'not in' return False if asset: diff --git a/templates/jasset/host_add_multi.html b/templates/jasset/host_add_multi.html index 4fd629071..5df6bc89a 100644 --- a/templates/jasset/host_add_multi.html +++ b/templates/jasset/host_add_multi.html @@ -44,7 +44,7 @@ {% endif %}

按照文本框内主机信息格式填写, 多台主机回车换行

-
+