As Adam said, it's a little hard to read your code but it *looks* ok.
A suggestion though, if I may.
With the large number of groups that you have I would use permissions
in this instance. It can give you much more granular control over who
has access to certain resources. All you need to do is add the
permissions to each group. This not only saves typing every group
that needs access in your identity decorator, but allows for more
flexibility - allowing a new group access to a method is as simple as
adding the relavant permission(s) to that group.
You can then use the
@identity.require(identity.has_permission("permission_name"))
decorator.
Check out the identity management docs[1] for more info.
[1]: http://docs.turbogears.org/1.0/IdentityManagment
Lee
On 12/15/06, Adam Jones <[EMAIL PROTECTED]> wrote:
>
> With longer bits of code like this you might want to consider using our
> paste instance at: http://paste.turbogears.org
>
> It is a lot easier to just give the link than it is to let the mailing
> list mangle your Python code on longer snippets like this.
>
> I am guessing that your problem is that accessing everything as an
> 'Administrador_orc' works, but the first controller that should allow
> 'Supervisor' to access it is not? If that is the case make sure to
> check the group membership for the account and make sure that you are
> specifying the group name correctly. I didn't really see anything wrong
> with the code you posted.
>
> -Adam
>
>
> Petry wrote:
> > Hi, I've a SubController with four methods, three of these, in your
> > decorator Identity I have many roles, including a administrator role
> > and another method with only a administrator Role. When i access
> > these method with a administrator user, everything works right, but
> > when I access the methods with for example, with a Supervisor role, I
> > receive the "Please login" message!
> >
> > Above, my subcontroller class:
> >
> > import logging
> >
> > import cherrypy
> >
> > import time
> >
> > import turbogears
> > from turbogears import controllers, expose, validate, redirect
> > from turbogears import identity
> > from turbogears.database import session
> >
> > from turbogears import widgets
> > from turbogears.widgets import DataGrid
> > from turbogears.widgets import PaginateDataGrid
> > from turbogears.widgets import
> > RemoteForm,TextField,CheckBox,RadioButtonList,PasswordField
> > from turbogears.widgets.base import WidgetsList
> >
> > from elementtree import ElementTree as ET
> > from tgorcamentos import json
> >
> > from Orcamentos.Despesas.CentroCustoDespesa import CentroCustoDespesa
> > from Orcamentos.Despesas.Despesas import Despesas as DespesasOrcamentos
> > from Orcamentos.Despesas.ContaContabil import ContaContabil
> >
> >
> > log = logging.getLogger("tgorcamentos.Orcamentos.Despesas.controllers")
> >
> >
> >
> > def getString(fieldname):
> > return lambda x: unicode(x.get(fieldname),'utf-8')
> > def getValor(fieldname):
> > return lambda x: x.get(fieldname)
> >
> >
> > # Gera um Link dentro do DataGrid.
> > class geraLink:
> > def __init__(self, baseurl, id, title, action):
> > self.baseurl=baseurl
> > self.id=id
> > self.title=title
> > self.action=action
> >
> > def __call__(self, obj):
> > url=controllers.url(self.baseurl,
> > dict(id=obj[self.id],action=self.action))
> > link = ET.Element('a', href=url, id='gridLink' )
> > link.text = obj[self.title]
> > return link
> >
> >
> >
> >
> > class ContasContabeis:
> >
> > #Datagrid (Lista Contas Contabeis Cadastradas)
> >
> > @expose(template="tgorcamentos.templates.contascontabeis")
> >
> > @identity.require(identity.in_any_group('Administrador_orc','ChefeDepartamento','ChefeGabinete',\
> >
> > 'Coordenador','CoordenadorCurso','DiretorCampus','DiretorCentro',\
> >
> > 'DiretorInstituto','DiretorMantida','DiretorNucleo','ProReitor',\
> > 'Reitor','Supervisor'))
> > @turbogears.paginate('contascontabeis', default_order='codigo',
> > limit=25)
> > def index(self):
> > cadastro = self.cadastro()
> >
> > mylink=geraLink('contascontabeis_cadastro',
> > 'COD_CONTA_CONTABIL', 'COD_CONTA_CONTABIL', 'edit')
> >
> > self.ccustoDespesa=CentroCustoDespesa()
> > contas=self.ccustoDespesa.carregarContasContabeis()
> >
> > lista_contas = PaginateDataGrid(
> > fields=[
> > PaginateDataGrid.Column(name='codigo', getter=mylink,
> > title=unicode('Código','utf-8'),
> > options=dict(sortable=True)),
> >
> > PaginateDataGrid.Column(name=unicode('descrição','utf-8'),
> > getter=getString('DESCRICAO'),
> > options=dict(sortable=True))
> > ])
> >
> > return dict(contascontabeis=contas , list=lista_contas)
> >
> >
> > @expose(template="tgorcamentos.templates.contascontabeis_cadastro")
> > @identity.require(identity.in_group('Administrador_orc'))
> > def cadastro(self):
> > item_searchform = RemoteForm(
> > name="FormCtaContabil",
> > fields=[TextField("codigo"),
> > TextField ("descricao")],
> > submit_text="Enviar")
> > return dict(item_searchform=item_searchform)
> >
> >
> > @turbogears.expose(format = "json")
> > @identity.require(identity.in_group('Administrador_orc'))
> > def cadastrar(self, **kw):
> > self.ccontabil = ContaContabil()
> > self.ccontabil.descricao=str(kw['descricao'])
> > self.ccontabil.codigo=str(kw['codigo'])
> > if self.ccontabil.gravar():
> > return "Item cadastrado com sucesso."
> > else:
> > return "Erro ao gravar!"
> > cadastrar = expose()(cadastrar)
> >
> >
> > class Orcamentos:
> > contascontabeis = ContasContabeis()
> >
> >
> > PS.: Sorry about my english, it's not so good! :P
>
>
> >
>
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
skype: fireflisystems
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---