Changeset 3336 in products
- Timestamp:
- Jan 5, 2012 12:12:37 PM (12 years ago)
- Location:
- quintagroup.portlet.static/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.portlet.static/trunk/docs/HISTORY.txt
r3283 r3336 1 1 Changelog 2 2 ========= 3 4 In 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". 3 9 4 10 0.5 - September 26, 2011 -
quintagroup.portlet.static/trunk/quintagroup/portlet/static/configure.zcml
r616 r3336 47 47 /> 48 48 49 <utility 50 component=".vocabularies.GlobalRolesVocabulary" 51 name="quintagroup.portlet.static.vocabularies.GlobalRoles" 52 /> 53 49 54 </configure> -
quintagroup.portlet.static/trunk/quintagroup/portlet/static/staticstylishportlet.py
r3282 r3336 24 24 """ 25 25 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 ), 29 32 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, 31 42 ) 32 43 … … 50 61 styling = '' 51 62 52 anonymous_only = False 63 roles_excluded = () 64 65 roles_required = () 53 66 54 67 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=()): 56 70 super(Assignment, self).__init__(header=header, text=text, omit_border=omit_border, footer=footer, 57 71 more_url=more_url) 58 72 59 73 self.styling = styling 60 self.anonymous_only = anonymous_only 74 self.roles_excluded = roles_excluded 75 self.roles_required = roles_required 76 61 77 62 78 class Renderer(static.Renderer): … … 72 88 @property 73 89 def available(self): 74 if self.data. anonymous_only:90 if self.data.roles_excluded or self.data.roles_required: 75 91 context = aq_inner(self.context) 76 92 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 78 111 79 112 return True -
quintagroup.portlet.static/trunk/quintagroup/portlet/static/vocabularies.py
r3214 r3336 2 2 from zope.interface import implements 3 3 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary 4 from zope.i18n import translate 4 5 5 6 from Products.CMFCore.utils import getToolByName … … 41 42 42 43 PortletCSSVocabulary = PortletCSSVocabulary() 44 45 46 class 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 60 GlobalRolesVocabulary = GlobalRolesVocabulary()
Note: See TracChangeset
for help on using the changeset viewer.