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