From 6d6e9d97b5a560bf71c099c7504dea586fc1fa4e Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 18 Apr 2015 18:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jasset/views.py | 7 +++++-- jperm/views.py | 3 ++- jumpserver/api.py | 17 ++++++++--------- juser/views.py | 16 ++++++++-------- log_handler.py | 2 +- templates/jlog/log_online.html | 2 +- templates/juser/user_list.html | 4 ++-- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/jasset/views.py b/jasset/views.py index 430bf0a6f..346767af2 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -338,10 +338,13 @@ def host_list(request): Q(bis_group__name__contains=keyword) | Q(comment__contains=keyword)).distinct().order_by('ip') if did: - if is_common_user(request) or is_group_admin(request): + if is_common_user(request): return httperror(request, u'您无权查看!') - dept = DEPT.objects.get(id=did) + if is_group_admin(request): + user, dept = get_session_user_dept(request) + else: + dept = DEPT.objects.get(id=did) posts = dept.asset_set.all() return my_render('jasset/host_list_nop.html', locals(), request) diff --git a/jperm/views.py b/jperm/views.py index 237a929f0..b307740e7 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -176,8 +176,9 @@ def perm_edit_adm(request): else: user_group_id = request.POST.get('user_group_id') asset_group_id_list = request.POST.getlist('asset_groups_select') + print user_group_id, asset_group_id_list if not validate(request, user_group=[user_group_id], asset_group=asset_group_id_list): - return HttpResponseRedirect('/jperm/perm_list/') + return HttpResponseRedirect('/') perm_group_update(user_group_id, asset_group_id_list) return HttpResponseRedirect('/jperm/perm_list/') diff --git a/jumpserver/api.py b/jumpserver/api.py index 048031312..a8f7bace7 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -383,9 +383,9 @@ def get_connect_item(username, ip): def validate(request, user_group=None, user=None, asset_group=None, asset=None, edept=None): dept = get_session_user_dept(request)[1] if edept: - if dept.name != edept[0]: + print dept.id, edept[0] + if dept.id != int(edept[0]): return False - if user_group: dept_user_groups = dept.usergroup_set.all() user_group_ids = [] @@ -398,8 +398,8 @@ def validate(request, user_group=None, user=None, asset_group=None, asset=None, if user: dept_users = dept.user_set.all() user_ids = [] - for user in dept_users: - user_ids.append(str(user.id)) + for dept_user in dept_users: + user_ids.append(str(dept_user.id)) if not set(user).issubset(set(user_ids)): return False @@ -408,7 +408,7 @@ def validate(request, user_group=None, user=None, asset_group=None, asset=None, dept_asset_groups = dept.bisgroup_set.all() asset_group_ids = [] for group in dept_asset_groups: - asset_group_ids.append(group.id) + asset_group_ids.append(str(group.id)) if not set(asset_group).issubset(set(asset_group_ids)): return False @@ -416,8 +416,8 @@ def validate(request, user_group=None, user=None, asset_group=None, asset=None, if asset: dept_assets = dept.asset_set.all() asset_ids = [] - for asset in dept_assets: - asset_ids.append(str(asset.id)) + for dept_asset in dept_assets: + asset_ids.append(str(dept_asset.id)) if not set(asset).issubset(set(asset_ids)): return False @@ -453,7 +453,7 @@ def verify(request, user_group=None, user=None, asset_group=None, asset=None, ed dept_asset_groups = dept.bisgroup_set.all() asset_group_ids = [] for group in dept_asset_groups: - asset_group_ids.append(group.id) + asset_group_ids.append(str(group.id)) if not set(asset_group).issubset(set(asset_group_ids)): return False @@ -465,7 +465,6 @@ def verify(request, user_group=None, user=None, asset_group=None, asset=None, ed dept_assets_id.append(int(a.id)) for i in asset: assets_id.append(int(i)) - print assets_id, dept_assets_id if not set(assets_id).issubset(dept_assets_id): return False diff --git a/juser/views.py b/juser/views.py index 70bf92672..0fd6ee4c0 100644 --- a/juser/views.py +++ b/juser/views.py @@ -692,14 +692,14 @@ def user_add_adm(request): pass else: try: - db_add_user(username=username, - password=md5_crypt(password), - name=name, email=email, dept=dept, - groups=groups, role='CU', - ssh_key_pwd=md5_crypt(ssh_key_pwd), - ldap_pwd=CRYPTOR.encrypt(ldap_pwd), - is_active=is_active, - date_joined=datetime.datetime.now()) + user = db_add_user(username=username, + password=md5_crypt(password), + name=name, email=email, dept=dept, + groups=groups, role='CU', + ssh_key_pwd=md5_crypt(ssh_key_pwd), + ldap_pwd=CRYPTOR.encrypt(ldap_pwd), + is_active=is_active, + date_joined=datetime.datetime.now()) server_add_user(username, password, ssh_key_pwd) if LDAP_ENABLE: diff --git a/log_handler.py b/log_handler.py index b1ec0fccc..590d77bdb 100755 --- a/log_handler.py +++ b/log_handler.py @@ -16,7 +16,7 @@ from jlog.models import Log def log_hanler(id): log = Log.objects.get(id=id) - pattern = re.compile(r'(\[.*@.*\][\$#].*) | (mysql>.*)') + pattern = re.compile(r'([\[.*@.*\][\$#].* | mysql>.*])') if log: filename = log.log_path if os.path.isfile(filename): diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 6a89b9663..2ae318d88 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -154,7 +154,7 @@ // tag.append('

'+escapeString(obj.content.replace(regx,''))+'

'); if (option == 'new') { // tag.append('

' + escapeString(obj.content) + '

'); - tag.append('

'+escapeString(obj.content.replace(regx,' '))+'

'); + tag.append('

'+escapeString(obj.content.replace(regx,' '))+'

'); } else if (option == 'exist') { tag.append('
' + exsit_message + '
'); } diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index 86a702975..f9ef7c017 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -79,8 +79,8 @@ 编辑 删除 {% else %} - 编辑 - 删除 + 编辑 + 删除 {% endifequal %}