web/views/basecomponents.py
changeset 6396 a9e4c51fc1c1
parent 6389 72ba82a26e05
child 6428 de95bbed8781
equal deleted inserted replaced
6395:30582ba8b368 6396:a9e4c51fc1c1
    24 
    24 
    25 __docformat__ = "restructuredtext en"
    25 __docformat__ = "restructuredtext en"
    26 _ = unicode
    26 _ = unicode
    27 
    27 
    28 from logilab.mtconverter import xml_escape
    28 from logilab.mtconverter import xml_escape
       
    29 from logilab.common.deprecation import class_renamed
    29 from rql import parse
    30 from rql import parse
    30 
    31 
    31 from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params,
    32 from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params,
    32                                 match_context, configuration_values,
    33                                 match_context, configuration_values,
    33                                 anonymous_user, authenticated_user)
    34                                 anonymous_user, authenticated_user)
    96 class _UserLink(component.Component):
    97 class _UserLink(component.Component):
    97     """if the user is the anonymous user, build a link to login else display a menu
    98     """if the user is the anonymous user, build a link to login else display a menu
    98     with user'action (preference, logout, etc...)
    99     with user'action (preference, logout, etc...)
    99     """
   100     """
   100     __abstract__ = True
   101     __abstract__ = True
   101     cw_property_defs = VISIBLE_PROP_DEF
       
   102     # don't want user to hide this component using an cwproperty
       
   103     site_wide = True
       
   104     __regid__ = 'loggeduserlink'
   102     __regid__ = 'loggeduserlink'
       
   103     cw_property_defs = VISIBLE_PROP_DEF
       
   104     # don't want user to hide this component using an cwproperty
       
   105     site_wide = True
   105 
   106 
   106 
   107 
   107 class CookieAnonUserLink(_UserLink):
   108 class CookieAnonUserLink(_UserLink):
   108     __select__ = _UserLink.__select__ & configuration_values('auth-mode', 'cookie') & anonymous_user()
   109     __select__ = (_UserLink.__select__ & anonymous_user()
       
   110                   & configuration_values('auth-mode', 'cookie'))
   109     loginboxid = 'popupLoginBox'
   111     loginboxid = 'popupLoginBox'
   110 
   112 
   111     def call(self):
   113     def call(self):
   112         w = self.w
   114         w = self.w
   113         w(self._cw._('anonymous'))
   115         w(self._cw._('anonymous'))
   114         w(u"""[<a class="logout" href="javascript: cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]"""
   116         w(u"""[<a class="logout" href="javascript: cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]"""
   115           % (self.loginboxid, self._cw._('i18n_login_popup')))
   117           % (self.loginboxid, self._cw._('i18n_login_popup')))
   116         self.wview('logform', rset=self.cw_rset, id=self.loginboxid,
   118         self.wview('logform', rset=self.cw_rset, id=self.loginboxid,
   117                    klass='hidden', title=False, showmessage=False)
   119                    klass='hidden', title=False, showmessage=False)
   118 
   120 
       
   121 AnonUserLink = class_renamed('AnonUserLink', CookieAnonUserLink)
       
   122 
   119 class HTTPAnonUserLink(_UserLink):
   123 class HTTPAnonUserLink(_UserLink):
   120     __select__ = _UserLink.__select__ & configuration_values('auth-mode', 'http') & anonymous_user()
   124     __select__ = (_UserLink.__select__ & anonymous_user()
   121     loginboxid = 'popupLoginBox'
   125                   & configuration_values('auth-mode', 'http'))
   122 
   126 
   123     def call(self):
   127     def call(self):
   124         w = self.w
   128         w = self.w
   125         w(self._cw._('anonymous'))
   129         w(self._cw._('anonymous'))
   126         # this redirects to the 'login' controller which in turn
   130         # this redirects to the 'login' controller which in turn