Пример #1
0
 def spm_stop_portlet(self):
     portlethash = self.request.get('portlethash')
     portlethash = self.request.get('viewname')
     portlethash = self.request.get('hereurl')
     info = unhashPortletInfo(portlethash)
     assignments = assignment_mapping_from_key(self.context, 
                     info['manager'], info['category'], info['key'])
                     
     IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
     assigned = ISolgemaPortletAssignment(assignments[info['name']])
     if getattr(assigned, 'stopUrls', None) and len(getattr(assigned, 'stopUrls', [])) > 0:
         urls = assigned.stopUrls
         li = []
         added = False
         for url in urls:
             if hereurl in url and not added:
                 li.append(hereurl)
                 added = True
             else:
                 li.append(url)
         if not added:
             li.append(hereurl)
         assigned.stopUrls = li
     else:
         assigned.stopUrls = [hereurl]
     return self._render_column(info, viewname)
Пример #2
0
    def spm_stop_portlet(self):
        portlethash = self.request.get('portlethash')
        portlethash = self.request.get('viewname')
        portlethash = self.request.get('hereurl')
        info = unhashPortletInfo(portlethash)
        assignments = assignment_mapping_from_key(self.context,
                                                  info['manager'],
                                                  info['category'],
                                                  info['key'])

        IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
        assigned = ISolgemaPortletAssignment(assignments[info['name']])
        if getattr(assigned, 'stopUrls',
                   None) and len(getattr(assigned, 'stopUrls', [])) > 0:
            urls = assigned.stopUrls
            li = []
            added = False
            for url in urls:
                if hereurl in url and not added:
                    li.append(hereurl)
                    added = True
                else:
                    li.append(url)
            if not added:
                li.append(hereurl)
            assigned.stopUrls = li
        else:
            assigned.stopUrls = [hereurl]
        return self._render_column(info, viewname)
 def spm_allow_portlet(self, name):
     hereurl = self.request.get('here_url', '')
     assignments = aq_inner(self.context) 
     portlet = ISolgemaPortletAssignment(assignments[name])
     IPortletPermissionChecker(assignments)()
     li = []
     if len(getattr(portlet, 'stopUrls', [])) > 0:
         urls = portlet.stopUrls
         for url in urls:
             if url not in hereurl:
                 li.append(url)
     portlet.stopUrls = li
     if not self.request.get('ajax'):
         self.request.response.redirect(self._nextUrl())
     return 'OK'
Пример #4
0
 def spm_allow_portlet(self, portlethash, viewname, hereurl):
     info = unhashPortletInfo(portlethash)
     assignments = assignment_mapping_from_key(self.context, 
                     info['manager'], info['category'], info['key'])
                     
     IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
     li = []
     assigned = ISolgemaPortletAssignment(assignments[info['name']])
     if hasattr(assigned, 'stopUrls') and len(assigned.stopUrls) > 0:
         urls = assigned.stopUrls
         for url in urls:
             if url not in hereurl:
                 li.append(url)
     assigned.stopUrls = li
     return self._render_column(info, viewname)
Пример #5
0
 def spm_allow_portlet(self, name):
     hereurl = self.request.get('here_url', '')
     assignments = aq_inner(self.context)
     portlet = ISolgemaPortletAssignment(assignments[name])
     IPortletPermissionChecker(assignments)()
     li = []
     if len(getattr(portlet, 'stopUrls', [])) > 0:
         urls = portlet.stopUrls
         for url in urls:
             if url not in hereurl:
                 li.append(url)
     portlet.stopUrls = li
     if not self.request.get('ajax'):
         self.request.response.redirect(self._nextUrl())
     return 'OK'
 def spm_allow_portlet(self, name):
     hereurl = self.request.get('here_url', '')
     assignments = aq_inner(self.context) 
     portlet = ISolgemaPortletAssignment(assignments[name])
     return portlet
     IPortletPermissionChecker(assignments)()
     li = []
     if hasattr(portlet, 'stopUrls') and len(portlet.stopUrls) > 0:
         urls = portlet.stopUrls
         for url in urls:
             if url not in hereurl:
                 li.append(url)
     portlet.stopUrls = ['ergerg']
     return portlet.stopUrls
     self.request.response.redirect(self._nextUrl())
     return ''
Пример #7
0
    def spm_allow_portlet(self):
        portlethash = self.request.get('portlethash')
        portlethash = self.request.get('viewname')
        portlethash = self.request.get('hereurl')
        info = unhashPortletInfo(portlethash)
        assignments = assignment_mapping_from_key(self.context,
                                                  info['manager'],
                                                  info['category'],
                                                  info['key'])

        IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
        li = []
        assigned = ISolgemaPortletAssignment(assignments[info['name']])
        if hasattr(assigned, 'stopUrls') and len(assigned.stopUrls) > 0:
            urls = assigned.stopUrls
            for url in urls:
                if url not in hereurl:
                    li.append(url)
        assigned.stopUrls = li
        return self._render_column(info, viewname)
 def spm_stop_portlet(self, name):
     hereurl = self.request.get('here_url', '')
     assignments = aq_inner(self.context)
     portlet = ISolgemaPortletAssignment(assignments[name])
     IPortletPermissionChecker(assignments)()
     if len(getattr(portlet, 'stopUrls', [])) > 0:
         urls = portlet.stopUrls
         li = []
         added = False
         for url in urls:
             if hereurl in url and not added:
                 li.append(hereurl)
                 added = True
             else:
                 li.append(url)
         if not added:
             li.append(hereurl)
         portlet.stopUrls = li
     else:
         portlet.stopUrls = [hereurl]
     if not self.request.get('ajax'):
         self.request.response.redirect(self._nextUrl())
     return 'OK'
Пример #9
0
 def spm_stop_portlet(self, name):
     hereurl = self.request.get('here_url', '')
     assignments = aq_inner(self.context)
     portlet = ISolgemaPortletAssignment(assignments[name])
     IPortletPermissionChecker(assignments)()
     if len(getattr(portlet, 'stopUrls', [])) > 0:
         urls = portlet.stopUrls
         li = []
         added = False
         for url in urls:
             if hereurl in url and not added:
                 li.append(hereurl)
                 added = True
             else:
                 li.append(url)
         if not added:
             li.append(hereurl)
         portlet.stopUrls = li
     else:
         portlet.stopUrls = [hereurl]
     if not self.request.get('ajax'):
         self.request.response.redirect(self._nextUrl())
     return 'OK'
    def getManagedPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        Bypass blacklist tests
        """
        portal_state = getMultiAdapter((self.context, self.context.REQUEST),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = []

        blacklisted = {}

        manager = self.storage.__name__

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            assignable = ILocalPortletAssignable(current, None)
            if assignable is not None:
                annotations = IAnnotations(assignable)
                local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                if local is not None:
                    localManager = local.get(manager, None)
                    if localManager is not None:
                        categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a)
                                           for a in localManager.values()])

            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                currentpc = IPortletContext(current, None)

        # Get all global mappings for non-blacklisted categories

        for category, key in pcontext.globalPortletCategories(False):
            mapping = self.storage.get(category, None)
            if mapping is not None:
                for a in mapping.get(key, {}).values():
                    categories.append((
                        category,
                        key,
                        a,
                    ))

        managerUtility = getUtility(IPortletManager, manager, portal)

        if not getattr(managerUtility, 'listAllManagedPortlets', []):
            managerUtility.listAllManagedPortlets = []

        hashlist = getattr(managerUtility, 'listAllManagedPortlets', [])
        assignments = []
        for category, key, assignment in categories:
            portletHash = hashPortletInfo(
                dict(
                    manager=manager,
                    category=category,
                    key=key,
                    name=assignment.__name__,
                ))
            if portletHash not in hashlist:
                hashlist.append(portletHash)
            assignments.append({
                'category':
                category,
                'key':
                key,
                'name':
                assignment.__name__,
                'assignment':
                assignment,
                'hash':
                portletHash,
                'stopUrls':
                ISolgemaPortletAssignment(assignment).stopUrls,
                'manager':
                manager,
            })

        managerUtility.listAllManagedPortlets = hashlist

        #order the portlets
        assignments.sort(lambda a, b: cmp(hashlist.index(a['hash']),
                                          hashlist.index(b['hash'])))

        li = []
        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())
        for assigndict in assignments:
            stopped = False
            if assigndict.has_key('stopUrls') and hasattr(
                    assigndict['stopUrls'],
                    'sort') and len(assigndict['stopUrls']) > 0:
                for stopUrl in assigndict['stopUrls']:
                    if stopUrl in here_url:
                        stopped = True
            assigndict['stopped'] = stopped
            assigndict['here_url'] = here_url

        return assignments
    def getPortlets(self):

        portal_state = getMultiAdapter((self.context, self.context.REQUEST),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = []

        blacklisted = {}

        manager = self.storage.__name__

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            if ILocalPortletAssignable.providedBy(current):
                assignable = current
            else:
                assignable = queryAdapter(current, ILocalPortletAssignable)

            if assignable is not None:
                if IAnnotations.providedBy(assignable):
                    annotations = assignable
                else:
                    annotations = queryAdapter(assignable, IAnnotations)

                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            categories.extend([(CONTEXT_CATEGORY,
                                                currentpc.uid, a)
                                               for a in localManager.values()])

                blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY,
                                                  {}).get(manager, None)
                if blacklistStatus is not None:
                    for cat, status in blacklistStatus.items():
                        if cat == CONTEXT_CATEGORY:
                            if not parentsBlocked and status == True:
                                parentsBlocked = True
                        else:  # global portlet categories
                            if blacklisted.get(cat, False) is None:
                                blacklisted[cat] = status
                            if status is not None:
                                blacklistFetched.add(cat)

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break
            current = currentpc.getParent()
            if current is not None:
                if IPortletContext.providedBy(current):
                    currentpc = current
                else:
                    currentpc = queryAdapter(current, IPortletContext)

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((
                            category,
                            key,
                            a,
                        ))

        managerUtility = getUtility(IPortletManager, manager, portal)

        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())

        assignments = []
        for category, key, assignment in categories:
            assigned = ISolgemaPortletAssignment(assignment)
            portletHash = hashPortletInfo(
                dict(
                    manager=manager,
                    category=category,
                    key=key,
                    name=assignment.__name__,
                ))
            if not getattr(assigned, 'stopUrls', False) or len([
                    stopUrl for stopUrl in getattr(assigned, 'stopUrls', [])
                    if stopUrl in here_url
            ]) == 0:
                assignments.append({
                    'category':
                    category,
                    'key':
                    key,
                    'name':
                    assignment.__name__,
                    'assignment':
                    assignment,
                    'hash':
                    hashPortletInfo(
                        dict(
                            manager=manager,
                            category=category,
                            key=key,
                            name=assignment.__name__,
                        )),
                    'stopUrls':
                    ISolgemaPortletAssignment(assignment).stopUrls,
                })

        if hasattr(managerUtility, 'listAllManagedPortlets'):
            hashlist = managerUtility.listAllManagedPortlets
            assignments.sort(lambda a, b: cmp(
                hashlist.count(a['hash']) > 0 and hashlist.index(a['hash']
                                                                 ) or 0,
                hashlist.count(b['hash']) > 0 and hashlist.index(b['hash']) or
                0))

        return assignments