[Cubicweb] WFHistoryVComponent show/hide

Adrien Di Mascio adrien.dimascio at logilab.fr
Tue Nov 29 07:47:32 CET 2011


Hi Carlos,

On 29/11/2011 07:00, Carlos Balderas wrote:
> I am trying to hide the workflow history component in views for
> anonymous users and I thought unregistering the component
> "WFHistoryVComponent" could be the way to go in this case. e.i.
>
> from cubicweb.web.views.workflow import WFHistoryVComponent
>
> MyView(primary.PrimaryView):
>
>    def call(self):
>        if self._cw.user.is_anonymous():
>            self._cw.vreg['ctxcomponents'].unregister(WFHistoryVComponent)
>        else:
>             # this will fail if the component is already registered!!
>             self._cw.vreg['ctxcomponents'].register(WFHistoryVComponent)

You do not want that, you're not supposed to modify the registry once 
the application is loaded (i.e. ready-to-serve), one reason being that 
the registry is a global variable shared by all threads (two users might 
ask the page at the same time).

If you want to hide this component from anonymous users, just change its 
selector :

     from cubicweb.selectors import authenticated_user
     from cubicweb.web.views.workflow import WFHistoryVComponent

     WFHistoryComponent.__select__ = WFHistoryComponent.__select__ & 
authenticated_user()

Regards,
-- 
Adrien Di Mascio - LOGILAB, Paris (France).
Tél: 01.45.32.03.12
Formations - http://www.logilab.fr/formations
Développements - http://www.logilab.fr/services
Gestion de connaissances - http://www.cubicweb.org/



More information about the Cubicweb mailing list