diff --git a/docs/AddUserAsset.py b/docs/AddUserAsset.py index b1750caf6..8ae015568 100644 --- a/docs/AddUserAsset.py +++ b/docs/AddUserAsset.py @@ -108,14 +108,13 @@ def test_add_log(): if __name__ == '__main__': + # test_add_dept() + # test_add_group() + # test_add_user() + # test_add_idc() + # test_add_asset_group() test_add_asset() - test_add_dept() - test_add_group() - test_add_user() - test_add_idc() - test_add_asset_group() - test_add_asset() - test_add_log() + # test_add_log() diff --git a/jperm/models.py b/jperm/models.py index bfc2bbf6e..6aca0ff4f 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -1,16 +1,31 @@ from django.db import models -from juser.models import UserGroup -from jasset.models import BisGroup +from juser.models import User, UserGroup, DEPT +from jasset.models import Asset, BisGroup class Perm(models.Model): - name = models.CharField(max_length=100) - user_group = models.ManyToManyField(UserGroup) - asset_group = models.ManyToManyField(BisGroup) - comment = models.CharField(max_length=100) + user = models.ForeignKey(User) + asset = models.ForeignKey(Asset) def __unicode__(self): - return '%s_%s' % (self.user_group.name, self.asset_group.name) + return '%s_%s' % (self.user.name, self.asset.ip) + + +class DeptPerm(models.Model): + dept = models.ForeignKey(DEPT) + asset = models.ForeignKey(Asset) + + def __unicode__(self): + return '%s_%s' % (self.dept.name, self.asset.ip) + + +class ShowPerm(models.Model): + uid = models.CharField(max_length=500, blank=True, null=True) + gid = models.CharField(max_length=500, blank=True, null=True) + did = models.CharField(max_length=500, blank=True, null=True) + aid = models.CharField(max_length=500, blank=True, null=True) + bid = models.CharField(max_length=500, blank=True, null=True) + comment = models.CharField(max_length=200, blank=True, null=True) class CmdGroup(models.Model): diff --git a/jperm/views.py b/jperm/views.py index ee91942f4..4cfe98aca 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -42,6 +42,8 @@ def perm_add(request): if request.method == 'GET': user_groups = UserGroup.objects.filter(id__gt=2) asset_groups = BisGroup.objects.all() + users = User.objects.all() + assets = Asset.objects.all() else: name = request.POST.get('name', '') diff --git a/jumpserver/views.py b/jumpserver/views.py index 09afd48fa..3a114ad57 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -18,7 +18,7 @@ from django.template import RequestContext from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.template import RequestContext -from juser.models import User +from juser.models import User, UserGroup from jlog.models import Log from jasset.models import Asset, BisGroup, IDC @@ -301,6 +301,21 @@ class PyCrypt(object): return plain_text.rstrip('\0') +def filter_ajax_api(request): + attr = request.GET.get('attr', 'user') + value = request.GET.get('value', '') + if attr == 'user': + contact_list = User.objects.filter(name__icontains=value) + elif attr == "user_group": + contact_list = UserGroup.objects.filter(name__icontains=value) + elif attr == "asset": + contact_list = Asset.objects.filter(ip__icontains=value) + elif attr == "asset": + contact_list = BisGroup.objects.filter(name__icontains=value) + + return render_to_response('filter_ajax_api.html', locals()) + + # def perm_user_asset(user_id=None, username=None): # if user_id: # user = User.objects.get(id=user_id) diff --git a/templates/filter_ajax_api.html b/templates/filter_ajax_api.html new file mode 100644 index 000000000..0698300a9 --- /dev/null +++ b/templates/filter_ajax_api.html @@ -0,0 +1,9 @@ +{% for object in contact_list %} + {% ifequal attr "asset" %} + + {% else %} + + {% endifequal %} + + +{% endfor %} \ No newline at end of file diff --git a/templates/jperm/perm_add.html b/templates/jperm/perm_add.html index e65f960b3..464181d92 100644 --- a/templates/jperm/perm_add.html +++ b/templates/jperm/perm_add.html @@ -36,23 +36,45 @@ {% if msg %}