Merge read json_request methods into existing methods, add identity requirement in a few places.
This commit is contained in:
parent
8aa7b66979
commit
494cf8fc8d
4 changed files with 13 additions and 49 deletions
|
@ -59,7 +59,7 @@ parser.add_option('-s', '--server',
|
||||||
class MakeShellAccounts(BaseClient):
|
class MakeShellAccounts(BaseClient):
|
||||||
def group_list(self, search='*'):
|
def group_list(self, search='*'):
|
||||||
params = {'search' : search}
|
params = {'search' : search}
|
||||||
data = self.send_request('json/group_list', auth=True, input=params)
|
data = self.send_request('group/list', auth=True, input=params)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def shadow_text(self, people=None):
|
def shadow_text(self, people=None):
|
||||||
|
@ -136,7 +136,7 @@ class MakeShellAccounts(BaseClient):
|
||||||
|
|
||||||
def people_list(self, search='*'):
|
def people_list(self, search='*'):
|
||||||
params = {'search' : search}
|
params = {'search' : search}
|
||||||
data = self.send_request('json/people_list', auth=True, input=params)
|
data = self.send_request('user/list', auth=True, input=params)
|
||||||
return data['people']
|
return data['people']
|
||||||
|
|
||||||
def make_group_db(self):
|
def make_group_db(self):
|
||||||
|
|
|
@ -112,22 +112,6 @@ class Group(controllers.Controller):
|
||||||
turbogears.redirect('/')
|
turbogears.redirect('/')
|
||||||
return dict(tg_errors=tg_errors)
|
return dict(tg_errors=tg_errors)
|
||||||
|
|
||||||
@expose(format="json")
|
|
||||||
def exportShellAccounts(self):
|
|
||||||
''' Replaces old "exportShellAccounts.py" '''
|
|
||||||
# TODO: Restrict access to this.
|
|
||||||
group = Groups.by_name('sysadmin-main')
|
|
||||||
users = {}
|
|
||||||
for role in userlist.roles:
|
|
||||||
if role.status == 'approved':
|
|
||||||
person = role.member
|
|
||||||
users[person.username] = {
|
|
||||||
'password' : person.password,
|
|
||||||
'ssh_key' : person.ssh_key,
|
|
||||||
}
|
|
||||||
groups = Groups.query.all()
|
|
||||||
return dict(users=users, groups=groups)
|
|
||||||
|
|
||||||
@identity.require(turbogears.identity.not_anonymous())
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@validate(validators=GroupView())
|
@validate(validators=GroupView())
|
||||||
@error_handler(error)
|
@error_handler(error)
|
||||||
|
@ -263,10 +247,10 @@ class Group(controllers.Controller):
|
||||||
groups = filter(lambda group: canViewGroup(person, group), groups)
|
groups = filter(lambda group: canViewGroup(person, group), groups)
|
||||||
if len(groups) <= 0:
|
if len(groups) <= 0:
|
||||||
turbogears.flash(_("No Groups found matching '%s'") % search)
|
turbogears.flash(_("No Groups found matching '%s'") % search)
|
||||||
groups = {}
|
memberships = {}
|
||||||
if self.jsonRequest():
|
for group in groups:
|
||||||
return ({'groups': groups})
|
memberships[group.id] = group.approved_roles
|
||||||
return dict(groups=groups, search=search)
|
return dict(groups=groups, search=search, memberships=memberships)
|
||||||
|
|
||||||
@identity.require(turbogears.identity.not_anonymous())
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@validate(validators=GroupApply())
|
@validate(validators=GroupApply())
|
||||||
|
|
|
@ -2,16 +2,8 @@ import turbogears
|
||||||
from turbogears import controllers, expose, paginate, identity, redirect, widgets, validate, validators, error_handler
|
from turbogears import controllers, expose, paginate, identity, redirect, widgets, validate, validators, error_handler
|
||||||
from turbogears.database import session
|
from turbogears.database import session
|
||||||
|
|
||||||
from cherrypy import request, response
|
|
||||||
|
|
||||||
import cherrypy
|
|
||||||
|
|
||||||
from fas.auth import *
|
from fas.auth import *
|
||||||
|
|
||||||
from textwrap import dedent
|
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
class JsonRequest(controllers.Controller):
|
class JsonRequest(controllers.Controller):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
'''Create a JsonRequest Controller.'''
|
'''Create a JsonRequest Controller.'''
|
||||||
|
@ -20,18 +12,4 @@ class JsonRequest(controllers.Controller):
|
||||||
def index(self):
|
def index(self):
|
||||||
'''Perhaps show a nice explanatory message about groups here?'''
|
'''Perhaps show a nice explanatory message about groups here?'''
|
||||||
return dict(help='This is a json interface')
|
return dict(help='This is a json interface')
|
||||||
|
|
||||||
@expose("json", allow_json=True)
|
|
||||||
def group_list(self, search='*'):
|
|
||||||
re_search = re.sub(r'\*', r'%', search).lower()
|
|
||||||
groups = Groups.query.filter(Groups.name.like(re_search)).order_by('name')
|
|
||||||
memberships = {}
|
|
||||||
for group in groups:
|
|
||||||
memberships[group.id] = group.approved_roles
|
|
||||||
return dict(groups=groups, memberships=memberships)
|
|
||||||
|
|
||||||
@expose("json", allow_json=True)
|
|
||||||
def people_list(self, search='*'):
|
|
||||||
re_search = re.sub(r'\*', r'%', search).lower()
|
|
||||||
people = People.query.filter(People.username.like(re_search)).order_by('username')
|
|
||||||
return dict(people=people)
|
|
||||||
|
|
|
@ -235,7 +235,9 @@ class User(controllers.Controller):
|
||||||
turbogears.redirect("/user/view/%s" % target.username)
|
turbogears.redirect("/user/view/%s" % target.username)
|
||||||
return dict(target=target)
|
return dict(target=target)
|
||||||
|
|
||||||
@identity.require(turbogears.identity.in_group("accounts")) #TODO: Use auth.py
|
# TODO: Decide who is allowed to see this.
|
||||||
|
#@identity.require(turbogears.identity.in_group("accounts")) #TODO: Use auth.py
|
||||||
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@expose(template="fas.templates.user.list", allow_json=True)
|
@expose(template="fas.templates.user.list", allow_json=True)
|
||||||
def list(self, search="a*"):
|
def list(self, search="a*"):
|
||||||
'''List users
|
'''List users
|
||||||
|
@ -244,11 +246,9 @@ class User(controllers.Controller):
|
||||||
people = People.query.filter(People.username.like(re_search)).order_by('username')
|
people = People.query.filter(People.username.like(re_search)).order_by('username')
|
||||||
if people.count() < 0:
|
if people.count() < 0:
|
||||||
turbogears.flash(_("No users found matching '%s'") % search)
|
turbogears.flash(_("No users found matching '%s'") % search)
|
||||||
if self.jsonRequest():
|
|
||||||
return ({'users': people})
|
|
||||||
|
|
||||||
return dict(people=people, search=search)
|
return dict(people=people, search=search)
|
||||||
|
|
||||||
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@expose(template='fas.templates.user.new')
|
@expose(template='fas.templates.user.new')
|
||||||
def new(self):
|
def new(self):
|
||||||
if turbogears.identity.not_anonymous():
|
if turbogears.identity.not_anonymous():
|
||||||
|
@ -256,6 +256,7 @@ class User(controllers.Controller):
|
||||||
turbogears.redirect('/user/view/%s' % turbogears.identity.current.user_name)
|
turbogears.redirect('/user/view/%s' % turbogears.identity.current.user_name)
|
||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@validate(validators=UserCreate())
|
@validate(validators=UserCreate())
|
||||||
@error_handler(error)
|
@error_handler(error)
|
||||||
@expose(template='fas.templates.new')
|
@expose(template='fas.templates.new')
|
||||||
|
@ -409,6 +410,7 @@ class User(controllers.Controller):
|
||||||
return dict(cert=certdump, key=keydump)
|
return dict(cert=certdump, key=keydump)
|
||||||
|
|
||||||
# Not sure where to take this yet.
|
# Not sure where to take this yet.
|
||||||
|
@identity.require(turbogears.identity.not_anonymous())
|
||||||
@expose(format="json")
|
@expose(format="json")
|
||||||
def search(self, username=None, groupname=None):
|
def search(self, username=None, groupname=None):
|
||||||
people = People.query.filter(People.username.like('%%%s%%' % username))
|
people = People.query.filter(People.username.like('%%%s%%' % username))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue