[822] | 1 | ## Script (Python) "prefs_comments_setup" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters= |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from quintagroup.plonecomments.utils import setAnonymCommenting, setStatusMsg |
---|
| 12 | from Products.CMFPlone import MessageFactory |
---|
| 13 | _ = MessageFactory('quintagroup.plonecomments') |
---|
| 14 | |
---|
| 15 | form = context.REQUEST.form |
---|
| 16 | pp = getToolByName(context, 'portal_properties') |
---|
| 17 | props_sheet = getattr(pp, 'qPloneComments') |
---|
| 18 | property_maps=[(m['id'], m['type']) for m in props_sheet.propertyMap() if not m['id']=='title'] |
---|
| 19 | request_ids = form.keys() |
---|
| 20 | |
---|
| 21 | kw={} |
---|
| 22 | for id,type in property_maps: |
---|
| 23 | if type == 'boolean': |
---|
| 24 | if id in request_ids: |
---|
| 25 | kw[id] = True |
---|
| 26 | else: |
---|
| 27 | kw[id] = False |
---|
| 28 | |
---|
| 29 | # Switch anonymouse commenting |
---|
| 30 | if id == 'enable_anonymous_commenting': |
---|
| 31 | allow = False |
---|
| 32 | if id in request_ids: |
---|
| 33 | allow = True |
---|
| 34 | setAnonymCommenting(context, allow) |
---|
| 35 | else: |
---|
| 36 | if id in request_ids: |
---|
| 37 | kw[id] = form[id] |
---|
| 38 | |
---|
| 39 | props_sheet.manage_changeProperties(**kw) |
---|
| 40 | |
---|
| 41 | moderate_discussion = 'Moderate Discussion' |
---|
| 42 | if not 'EnableManagerModeration' in request_ids: |
---|
| 43 | roles = [item['name'] for item in context.rolesOfPermission(moderate_discussion) |
---|
| 44 | if (item['name'] != 'Manager') and (item['selected'] == 'SELECTED')] |
---|
| 45 | context.manage_permission(moderate_discussion, roles, acquire=0) |
---|
| 46 | |
---|
| 47 | else: |
---|
| 48 | roles = [item['name'] for item in context.rolesOfPermission(moderate_discussion) |
---|
| 49 | if item['selected'] == 'SELECTED'] |
---|
| 50 | roles.append('Manager') |
---|
| 51 | context.manage_permission(moderate_discussion, roles, acquire=0) |
---|
| 52 | |
---|
| 53 | setStatusMsg(state, context, _(u'qPloneComments configuration changes saved.')) |
---|
| 54 | return state |
---|