Changeset 3336 in products


Ignore:
Timestamp:
Jan 5, 2012 12:12:37 PM (12 years ago)
Author:
kroman0
Message:

Excluded/required roles in Static Stylish portlet

Location:
quintagroup.portlet.static/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.portlet.static/trunk/docs/HISTORY.txt

    r3283 r3336  
    11Changelog 
    22========= 
     3 
     4In next release ... 
     5 
     6* Changed option to display portlet for anonymous users only to 
     7  instead two settings respectively requiring and excluding users with 
     8  a given role (from a set of roles), e.g. "Member". 
    39 
    4100.5 - September 26, 2011 
  • quintagroup.portlet.static/trunk/quintagroup/portlet/static/configure.zcml

    r616 r3336  
    4747        /> 
    4848 
     49    <utility 
     50        component=".vocabularies.GlobalRolesVocabulary" 
     51        name="quintagroup.portlet.static.vocabularies.GlobalRoles" 
     52        /> 
     53 
    4954</configure> 
  • quintagroup.portlet.static/trunk/quintagroup/portlet/static/staticstylishportlet.py

    r3282 r3336  
    2424    """ 
    2525 
    26     anonymous_only = schema.Bool( 
    27         title=_(u"Anonymous only"), 
    28         description=_(u"Check this to hide the portlet for logged-in users."), 
     26    roles_excluded = schema.Tuple( 
     27        title=_(u"Roles excluded"), 
     28        description=_(u"Select excluded user roles."), 
     29        value_type=schema.Choice( 
     30            vocabulary="quintagroup.portlet.static.vocabularies.GlobalRoles" 
     31            ), 
    2932        required=False, 
    30         default=False, 
     33        ) 
     34 
     35    roles_required = schema.Tuple( 
     36        title=_(u"Roles required"), 
     37        description=_(u"Select required user roles."), 
     38        value_type=schema.Choice( 
     39            vocabulary="quintagroup.portlet.static.vocabularies.GlobalRoles" 
     40            ), 
     41        required=False, 
    3142        ) 
    3243 
     
    5061    styling = '' 
    5162 
    52     anonymous_only = False 
     63    roles_excluded = () 
     64 
     65    roles_required = () 
    5366 
    5467    def __init__(self, header=u"", text=u"", omit_border=False, footer=u"", 
    55                  more_url='', hide=False, styling='', anonymous_only=False): 
     68                 more_url='', hide=False, styling='', 
     69                 roles_excluded=(), roles_required=()): 
    5670        super(Assignment, self).__init__(header=header, text=text, omit_border=omit_border, footer=footer, 
    5771                                         more_url=more_url) 
    5872 
    5973        self.styling = styling 
    60         self.anonymous_only = anonymous_only 
     74        self.roles_excluded = roles_excluded 
     75        self.roles_required = roles_required 
     76 
    6177 
    6278class Renderer(static.Renderer): 
     
    7288    @property 
    7389    def available(self): 
    74         if self.data.anonymous_only: 
     90        if self.data.roles_excluded or self.data.roles_required: 
    7591            context = aq_inner(self.context) 
    7692            mtool = getToolByName(context, 'portal_membership') 
    77             return mtool.isAnonymousUser() 
     93 
     94            # Determine roles 
     95            if not mtool.isAnonymousUser(): 
     96                member = mtool.getAuthenticatedMember() 
     97                user = member.getUser() 
     98                roles = user.getRoles() 
     99            else: 
     100                roles = () 
     101 
     102            roles = frozenset(roles) 
     103 
     104            # Test excluded roles 
     105            if roles & set(self.data.roles_excluded): 
     106                return False 
     107 
     108            # Test required roles 
     109            if not set(self.data.roles_required) <= roles: 
     110                return False 
    78111 
    79112        return True 
  • quintagroup.portlet.static/trunk/quintagroup/portlet/static/vocabularies.py

    r3214 r3336  
    22from zope.interface import implements 
    33from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary 
     4from zope.i18n import translate 
    45 
    56from Products.CMFCore.utils import getToolByName 
     
    4142 
    4243PortletCSSVocabulary = PortletCSSVocabulary() 
     44 
     45 
     46class GlobalRolesVocabulary(object): 
     47    implements(IVocabularyFactory) 
     48 
     49    def __call__(self, context): 
     50        roles = context.getGlobalPortalRoles() 
     51 
     52        return SimpleVocabulary( 
     53            [SimpleTerm( 
     54                role, role, 
     55                translate(role, domain="plone", context=context.REQUEST) \ 
     56                ) for role in roles] 
     57            ) 
     58 
     59 
     60GlobalRolesVocabulary = GlobalRolesVocabulary() 
Note: See TracChangeset for help on using the changeset viewer.