[344] | 1 | from zope.interface import implements |
---|
| 2 | from zope.component import getMultiAdapter, getUtility |
---|
| 3 | from zope.publisher.interfaces.browser import IDefaultBrowserLayer |
---|
| 4 | |
---|
| 5 | from AccessControl import Unauthorized |
---|
| 6 | from Acquisition import aq_inner |
---|
| 7 | from Acquisition import aq_base |
---|
| 8 | from Products.Five import BrowserView |
---|
| 9 | |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from Products.CMFCore.interfaces import ISiteRoot |
---|
| 12 | |
---|
| 13 | from plone.portlets.interfaces import IPortletManager |
---|
| 14 | from plone.portlets.interfaces import IPortletAssignmentMapping |
---|
| 15 | from plone.portlets.interfaces import ILocalPortletAssignmentManager |
---|
| 16 | |
---|
| 17 | from plone.portlets.constants import USER_CATEGORY |
---|
| 18 | from plone.portlets.constants import GROUP_CATEGORY |
---|
| 19 | from plone.portlets.constants import CONTENT_TYPE_CATEGORY |
---|
| 20 | from plone.portlets.constants import CONTEXT_CATEGORY |
---|
| 21 | |
---|
| 22 | from plone.app.portlets.storage import PortletAssignmentMapping |
---|
| 23 | from plone.app.portlets.storage import UserPortletAssignmentMapping |
---|
| 24 | |
---|
| 25 | from plone.app.portlets.interfaces import IPortletPermissionChecker |
---|
| 26 | |
---|
| 27 | from plone.app.portlets.browser.interfaces import IManagePortletsView |
---|
| 28 | from plone.app.portlets.browser.interfaces import IManageContextualPortletsView |
---|
| 29 | from plone.app.portlets.browser.interfaces import IManageDashboardPortletsView |
---|
| 30 | from plone.app.portlets.browser.interfaces import IManageGroupPortletsView |
---|
| 31 | from plone.app.portlets.browser.interfaces import IManageContentTypePortletsView |
---|
| 32 | |
---|
| 33 | from plone.app.portlets import utils |
---|
| 34 | from plone.memoize.view import memoize |
---|
| 35 | |
---|
| 36 | class ManageContextualPortlets(BrowserView): |
---|
| 37 | implements(IManageContextualPortletsView) |
---|
| 38 | |
---|
| 39 | def __init__(self, context, request): |
---|
| 40 | super(ManageContextualPortlets, self).__init__(context, request) |
---|
| 41 | self.request.set('disable_border', True) |
---|
| 42 | |
---|
| 43 | # IManagePortletsView implementation |
---|
| 44 | |
---|
| 45 | @property |
---|
| 46 | def category(self): |
---|
| 47 | return CONTEXT_CATEGORY |
---|
| 48 | |
---|
| 49 | @property |
---|
| 50 | def key(self): |
---|
| 51 | return '/'.join(self.context.getPhysicalPath()) |
---|
| 52 | |
---|
| 53 | def getAssignmentMappingUrl(self, manager): |
---|
| 54 | baseUrl = str(getMultiAdapter((self.context, self.request), name='absolute_url')) |
---|
| 55 | return '%s/++contextportlets++%s' % (baseUrl, manager.__name__) |
---|
| 56 | |
---|
| 57 | def getAssignmentsForManager(self, manager): |
---|
| 58 | assignments = getMultiAdapter((self.context, manager), IPortletAssignmentMapping) |
---|
| 59 | return assignments.values() |
---|
| 60 | |
---|
| 61 | # view @@manage-portlets |
---|
| 62 | |
---|
| 63 | def has_legacy_portlets(self): |
---|
| 64 | left_slots = getattr(aq_base(self.context), 'left_slots', []) |
---|
| 65 | right_slots = getattr(aq_base(self.context), 'right_slots', []) |
---|
| 66 | |
---|
| 67 | return (left_slots or right_slots) |
---|
| 68 | |
---|
| 69 | # view @@set-portlet-blacklist-status |
---|
| 70 | def set_blacklist_status(self, manager, group_status, content_type_status, context_status): |
---|
| 71 | portletManager = getUtility(IPortletManager, name=manager) |
---|
| 72 | assignable = getMultiAdapter((self.context, portletManager,), ILocalPortletAssignmentManager) |
---|
| 73 | assignments = getMultiAdapter((self.context, portletManager), IPortletAssignmentMapping) |
---|
| 74 | |
---|
| 75 | IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))() |
---|
| 76 | |
---|
| 77 | def int2status(status): |
---|
| 78 | if status == 0: |
---|
| 79 | return None |
---|
| 80 | elif status > 0: |
---|
| 81 | return True |
---|
| 82 | else: |
---|
| 83 | return False |
---|
| 84 | |
---|
| 85 | assignable.setBlacklistStatus(GROUP_CATEGORY, int2status(group_status)) |
---|
| 86 | assignable.setBlacklistStatus(CONTENT_TYPE_CATEGORY, int2status(content_type_status)) |
---|
| 87 | assignable.setBlacklistStatus(CONTEXT_CATEGORY, int2status(context_status)) |
---|
| 88 | |
---|
| 89 | baseUrl = str(getMultiAdapter((self.context, self.request), name='absolute_url')) |
---|
| 90 | self.request.response.redirect(baseUrl + '/@@manage-portlets') |
---|
| 91 | return '' |
---|
| 92 | |
---|
| 93 | # view @@convert-legacy-portlets |
---|
| 94 | |
---|
| 95 | def convert_legacy_portlets(self): |
---|
| 96 | utils.convert_legacy_portlets(self.context) |
---|
| 97 | self.context.request.response.redirect(self.context.absolute_url() + '/@@manage-portlets') |
---|
| 98 | |
---|
| 99 | def is_portal_root(self): |
---|
| 100 | context = aq_inner(self.context) |
---|
| 101 | portal = getUtility(ISiteRoot) |
---|
| 102 | return aq_base(context) is aq_base(portal) |
---|