diff --git a/jasset/models.py b/jasset/models.py
index 9874616b8..6bb5a7f21 100644
--- a/jasset/models.py
+++ b/jasset/models.py
@@ -1,6 +1,6 @@
import datetime
from django.db import models
-from juser.models import User, UserGroup, DEPT
+from juser.models import User, UserGroup
class IDC(models.Model):
@@ -17,7 +17,6 @@ class BisGroup(models.Model):
('A', 'ASSET'),
)
name = models.CharField(max_length=80, unique=True)
- dept = models.ForeignKey(DEPT)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
@@ -76,7 +75,6 @@ class Asset(models.Model):
port = models.IntegerField(max_length=6)
idc = models.ForeignKey(IDC)
bis_group = models.ManyToManyField(BisGroup)
- dept = models.ManyToManyField(DEPT)
login_type = models.CharField(max_length=1, choices=LOGIN_TYPE_CHOICES, default='L')
username = models.CharField(max_length=20, blank=True, null=True)
password = models.CharField(max_length=80, blank=True, null=True)
diff --git a/jperm/models.py b/jperm/models.py
index c29cb8e54..6541cb55f 100644
--- a/jperm/models.py
+++ b/jperm/models.py
@@ -3,7 +3,7 @@ import datetime
from uuidfield import UUIDField
from django.db import models
-from juser.models import UserGroup, DEPT
+from juser.models import UserGroup
from jasset.models import Asset, BisGroup
@@ -18,7 +18,6 @@ class Perm(models.Model):
class CmdGroup(models.Model):
name = models.CharField(max_length=50, unique=True)
cmd = models.CharField(max_length=999)
- dept = models.ForeignKey(DEPT)
comment = models.CharField(blank=True, null=True, max_length=50)
def __unicode__(self):
@@ -41,7 +40,6 @@ class Apply(models.Model):
applyer = models.CharField(max_length=20)
admin = models.CharField(max_length=20)
approver = models.CharField(max_length=20)
- dept = models.CharField(max_length=20)
bisgroup = models.CharField(max_length=500)
asset = models.CharField(max_length=500)
comment = models.TextField(blank=True, null=True)
diff --git a/jumpserver/api.py b/jumpserver/api.py
index 35fd8063e..58e322179 100644
--- a/jumpserver/api.py
+++ b/jumpserver/api.py
@@ -19,7 +19,7 @@ from functools import partial
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.http import HttpResponse, Http404
from django.template import RequestContext
-from juser.models import User, UserGroup, DEPT
+from juser.models import User, UserGroup
from jasset.models import Asset, BisGroup, IDC
from jlog.models import Log
from jasset.models import AssetAlias
diff --git a/juser/models.py b/juser/models.py
index a507e1c63..8f95231aa 100644
--- a/juser/models.py
+++ b/juser/models.py
@@ -3,17 +3,8 @@
from django.db import models
-class DEPT(models.Model):
- name = models.CharField(max_length=80, unique=True)
- comment = models.CharField(max_length=160, blank=True, null=True)
-
- def __unicode__(self):
- return self.name
-
-
class UserGroup(models.Model):
name = models.CharField(max_length=80, unique=True)
- dept = models.ForeignKey(DEPT)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
@@ -26,7 +17,7 @@ class UserGroup(models.Model):
class User(models.Model):
USER_ROLE_CHOICES = (
('SU', 'SuperUser'),
- ('DA', 'DeptAdmin'),
+ ('GA', 'GroupAdmin'),
('CU', 'CommonUser'),
)
username = models.CharField(max_length=80, unique=True)
@@ -34,7 +25,6 @@ class User(models.Model):
name = models.CharField(max_length=80)
email = models.EmailField(max_length=75)
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
- dept = models.ForeignKey(DEPT)
group = models.ManyToManyField(UserGroup)
ldap_pwd = models.CharField(max_length=128)
ssh_key_pwd = models.CharField(max_length=200)
diff --git a/juser/urls.py b/juser/urls.py
index cbaba7bb0..c9bc24d12 100644
--- a/juser/urls.py
+++ b/juser/urls.py
@@ -7,14 +7,7 @@ urlpatterns = patterns('juser.views',
# url(r'^$', 'jumpserver.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
- (r'^dept_list/$', view_splitter, {'su': dept_list, 'adm': dept_list_adm}),
- (r'^dept_add/$', 'dept_add'),
- (r'^dept_del/$', 'dept_del'),
- (r'^dept_detail/$', 'dept_detail'),
- (r'^dept_del_ajax/$', 'dept_del_ajax'),
- (r'^dept_edit/$', 'dept_edit'),
- (r'^dept_user_ajax/$', 'dept_user_ajax'),
- (r'^group_add/$', view_splitter, {'su': group_add, 'adm': group_add_adm}),
+ (r'^group_add/$', group_add),
(r'^group_list/$', view_splitter, {'su': group_list, 'adm': group_list_adm}),
(r'^group_detail/$', 'group_detail'),
(r'^group_del/$', view_splitter, {'su': group_del, 'adm': group_del_adm}),
diff --git a/juser/views.py b/juser/views.py
index f3d5525f4..e26adb5e4 100644
--- a/juser/views.py
+++ b/juser/views.py
@@ -12,51 +12,6 @@ from django.db.models import ObjectDoesNotExist
from juser.user_api import *
-@require_role(role='super')
-def dept_add(request):
- header_title, path1, path2 = '添加部门', '用户管理', '添加部门'
- if request.method == 'POST':
- name = request.POST.get('name', '')
- comment = request.POST.get('comment', '')
-
- try:
- if not name:
- raise ServerError('部门名称不能为空')
- if DEPT.objects.filter(name=name):
- raise ServerError(u'部门名称 %s 已存在' % name)
- except ServerError, e:
- error = e
- else:
- DEPT(name=name, comment=comment).save()
- msg = u'添加部门 %s 成功' % name
-
- return render_to_response('juser/dept_add.html', locals(), context_instance=RequestContext(request))
-
-
-@require_role(role='super')
-def dept_list(request):
- header_title, path1, path2 = '查看部门', '用户管理', '查看部门'
- keyword = request.GET.get('search')
- if keyword:
- contact_list = DEPT.objects.filter(Q(name__icontains=keyword) | Q(comment__icontains=keyword)).order_by('name')
- else:
- contact_list = DEPT.objects.all().order_by('id')
-
- contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
-
- return render_to_response('juser/dept_list.html', locals(), context_instance=RequestContext(request))
-
-
-@require_role(role='admin')
-def dept_list_adm(request):
- header_title, path1, path2 = '查看部门', '用户管理', '查看部门'
- user, dept = get_session_user_dept(request)
- contact_list = [dept]
- contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
-
- return render_to_response('juser/dept_list.html', locals(), context_instance=RequestContext(request))
-
-
def chg_role(request):
role = {'SU': 2, 'DA': 1, 'CU': 0}
user, dept = get_session_user_dept(request)
@@ -67,177 +22,31 @@ def chg_role(request):
return HttpResponseRedirect('/')
-@require_role(role='super')
-def dept_detail(request):
- dept_id = request.GET.get('id', None)
- if not dept_id:
- return HttpResponseRedirect('/juser/dept_list/')
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- users = dept.user_set.all()
- return render_to_response('juser/dept_detail.html', locals(), context_instance=RequestContext(request))
-
-
-@require_role(role='super')
-def dept_del(request):
- dept_id = request.GET.get('id', None)
- if not dept_id or dept_id in ['1', '2']:
- return HttpResponseRedirect('/juser/dept_list/')
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- dept.delete()
- return HttpResponseRedirect('/juser/dept_list/')
-
-
-def dept_member(dept_id):
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- return dept.user_set.all()
-
-
-def dept_member_update(dept, users_id_list):
- old_users = dept.user_set.all()
- new_users = []
- for user_id in users_id_list:
- new_users.extend(User.objects.filter(id=user_id))
-
- remove_user = [user for user in old_users if user not in new_users]
- add_user = [user for user in new_users if user not in old_users]
-
- for user in add_user:
- user.dept = dept
- user.save()
-
- dept_default = DEPT.objects.get(id=2)
- for user in remove_user:
- user.dept = dept_default
- user.save()
-
-
-@require_role(role='super')
-def dept_del_ajax(request):
- dept_ids = request.POST.get('dept_ids')
- for dept_id in dept_ids.split(','):
- if int(dept_id) > 2:
- DEPT.objects.filter(id=dept_id).delete()
- return HttpResponse("删除成功")
-
-
-@require_role(role='super')
-def dept_edit(request):
- header_title, path1, path2 = '部门编辑', '用户管理', '部门编辑'
- if request.method == 'GET':
- dept_id = request.GET.get('id', '')
- if dept_id:
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- users = dept_member(dept_id)
- users_all = User.objects.all()
- users_other = [user for user in users_all if user not in users]
- else:
- error = 'id 错误'
- else:
- error = u'部门不存在'
- else:
- dept_id = request.POST.get('id', '')
- name = request.POST.get('name', '')
- users = request.POST.getlist('users_selected', [])
- comment = request.POST.get('comment', '')
-
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept.update(name=name, comment=comment)
- dept_member_update(dept[0], users)
- else:
- error = '部门不存在'
- return HttpResponseRedirect('/juser/dept_list/')
- return render_to_response('juser/dept_edit.html', locals(), context_instance=RequestContext(request))
-
-
-def dept_user_ajax(request):
- dept_id = request.GET.get('id', '4')
- if dept_id not in ['1', '2']:
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- users = dept.user_set.all()
- else:
- users = User.objects.all()
-
- return render_to_response('juser/dept_user_ajax.html', locals())
-
-
-
@require_role(role='super')
def group_add(request):
error = ''
msg = ''
- header_title, path1, path2 = '添加小组', '用户管理', '添加小组'
+ header_title, path1, path2 = '添加用户组', '用户管理', '添加用户组'
user_all = User.objects.all()
- dept_all = DEPT.objects.all()
if request.method == 'POST':
group_name = request.POST.get('group_name', '')
- dept_id = request.POST.get('dept_id', '')
users_selected = request.POST.getlist('users_selected', '')
comment = request.POST.get('comment', '')
try:
- if '' in [group_name, dept_id]:
- error = u'组名 或 部门 不能为空'
+ if not group_name:
+ error = u'组名 不能为空'
raise ServerError(error)
if UserGroup.objects.filter(name=group_name):
error = u'组名已存在'
raise ServerError(error)
-
- dept = DEPT.objects.filter(id=dept_id)
- if dept:
- dept = dept[0]
- else:
- error = u'部门不存在'
- raise ServerError(error)
-
- db_add_group(name=group_name, users=users_selected, dept=dept, comment=comment)
+ db_add_group(name=group_name, users_id=users_selected, comment=comment)
except ServerError:
pass
except TypeError:
- error = u'保存小组失败'
- else:
- msg = u'添加组 %s 成功' % group_name
-
- return render_to_response('juser/group_add.html', locals(), context_instance=RequestContext(request))
-
-
-@require_role(role='admin')
-def group_add_adm(request):
- error = ''
- msg = ''
- header_title, path1, path2 = '添加小组', '用户管理', '添加小组'
- user, dept = get_session_user_dept(request)
- user_all = dept.user_set.all()
-
- if request.method == 'POST':
- group_name = request.POST.get('group_name', '')
- users_selected = request.POST.getlist('users_selected', '')
- comment = request.POST.get('comment', '')
-
- try:
- if not validate(request, user=users_selected):
- raise ServerError('没有某用户权限')
- if '' in [group_name]:
- error = u'组名不能为空'
- raise ServerError(error)
-
- db_add_group(name=group_name, users=users_selected, dept=dept, comment=comment)
- except ServerError:
- pass
- except TypeError:
- error = u'保存小组失败'
+ error = u'添加小组失败'
else:
msg = u'添加组 %s 成功' % group_name
diff --git a/templates/juser/dept_add.html b/templates/juser/dept_add.html
deleted file mode 100644
index 322df22e5..000000000
--- a/templates/juser/dept_add.html
+++ /dev/null
@@ -1,100 +0,0 @@
-{% extends 'base.html' %}
-
-{% block content %}
- {% include 'nav_cat_bar.html' %}
-
-
-{% endblock %}
-
-{% block self_footer_js %}
-
-{% endblock %}
\ No newline at end of file
diff --git a/templates/juser/dept_detail.html b/templates/juser/dept_detail.html
deleted file mode 100644
index 81aab3f79..000000000
--- a/templates/juser/dept_detail.html
+++ /dev/null
@@ -1,116 +0,0 @@
-{% extends 'base.html' %}
-{% load mytags %}
-{% block content %}
-{% include 'nav_cat_bar.html' %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
-
-
- {% include 'paginator.html' %}
-
-
-
-
-
-
-
-
-
-{% endblock %}
\ No newline at end of file
diff --git a/templates/juser/dept_edit.html b/templates/juser/dept_edit.html
deleted file mode 100644
index 5ade4bad8..000000000
--- a/templates/juser/dept_edit.html
+++ /dev/null
@@ -1,133 +0,0 @@
-{% extends 'base.html' %}
-
-{% block content %}
- {% include 'nav_cat_bar.html' %}
-
-
-
-{% endblock %}
\ No newline at end of file
diff --git a/templates/juser/dept_list.html b/templates/juser/dept_list.html
deleted file mode 100644
index 82bf9d539..000000000
--- a/templates/juser/dept_list.html
+++ /dev/null
@@ -1,126 +0,0 @@
-{% extends 'base.html' %}
-{% load mytags %}
-{% block content %}
-{% include 'nav_cat_bar.html' %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
-
-
- {% include 'paginator.html' %}
-
-
-
-
-
-
-
-
-
-{% endblock %}
\ No newline at end of file
diff --git a/templates/juser/dept_user_ajax.html b/templates/juser/dept_user_ajax.html
deleted file mode 100644
index 3d73f4eae..000000000
--- a/templates/juser/dept_user_ajax.html
+++ /dev/null
@@ -1,3 +0,0 @@
-{% for user in users %}
- {{ user.name }}
-{% endfor %}
\ No newline at end of file
diff --git a/templates/juser/group_add.html b/templates/juser/group_add.html
index c6867e08c..e2f1c61ce 100644
--- a/templates/juser/group_add.html
+++ b/templates/juser/group_add.html
@@ -15,12 +15,6 @@
-
@@ -35,27 +29,15 @@
{{ msg }}
{% endif %}
- {% ifequal session_role_id 2 %}
+
- {% endifequal %}
-
-
+{% endblock %}
+
+{% block self_footer_js %}