From 6ef6552949bdb4d6a5af573f461af3776cfd6a88 Mon Sep 17 00:00:00 2001 From: honglei5181 Date: Wed, 11 May 2016 15:21:30 +0800 Subject: [PATCH] fix bug --- states_config/views.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/states_config/views.py b/states_config/views.py index e1a25e7..2df17d4 100644 --- a/states_config/views.py +++ b/states_config/views.py @@ -1,6 +1,9 @@ from django.shortcuts import render from django.http import HttpResponse from django.contrib.auth.decorators import login_required +from django.contrib.auth.models import User +from account.models import Businesses,Privileges,UserProfiles +from groups.models import Groups,Hosts from shaker.shaker_core import * from shaker.nodegroups import * from shaker.highstate import * @@ -9,9 +12,34 @@ @login_required(login_url="/account/login/") def highstate(request): - group = NodeGroups() high = HighState() - all_host = group.list_groups_hosts() + #group = NodeGroups() + #all_host = group.list_groups_hosts() + _u = request.user + _user = User.objects.get(username=_u) + + _businesses = [] + all = {} + try: + if _user.is_superuser: + _userprofile = UserProfiles.objects.all() + _b = Businesses.objects.all() + else: + _userprofile = UserProfiles.objects.get(user=_user) + _b = _userprofile.business.all() + for _tmp in _b: + _businesses.append(_tmp.name) + + _groups=Groups.objects.filter(business__in = _businesses) + for _group in _groups: + _h=[] + _hosts=_group.groups_hosts_related.all() + for _host in _hosts: + _h.append(_host.minion.minion_id) + all[_group.name]=_h + except Exception as e: + pass + all_host = all all_sls = high.list_sls('/srv/salt/') return render(request, 'states_config/highstate.html', {'list_groups': all_host, 'all_sls': all_sls})