Ejemplo n.º 1
0
 def deliverPackage(self, obj):
     """
     See IFeaturelet.
     """
     BaseFeaturelet.deliverPackage(self, obj)
     container = obj._getOb(self._info["content"][0]["id"])
     container.setLayout("mailing_lists")
     alsoProvides(container, IListenContainer)
     alsoProvides(container, ICanFeed)
     notify(ListenFeatureletCreatedEvent(obj))
     return self._info
Ejemplo n.º 2
0
    def deliverPackage(self, obj):
        wp_uri = self.wp_uri
        if not wp_uri:
            # either None or empty value mean do nothing
            log.info("Failed to add WordPress blog: no WP URI set")
            return

        uri = "%s/openplans-create-blog.php" % wp_uri
        params = {}

        params["domain"] = domain = "%s.openplans.org" % obj.getId()

        auth = obj.acl_users.credentials_signed_cookie_auth
        secret = auth.secret
        sig = hmac.new(secret, domain, sha).digest()
        params["signature"] = sig = sig.encode("base64").strip()

        params["title"] = obj.Title()

        if obj.getTeams():
            params["members"] = obj.restrictedTraverse("memberships.xml")()
        else:  # no team has been set up yet, so fake it
            pm = getToolByName(obj, "portal_membership")
            id_ = pm.getAuthenticatedMember().getId()
            params["members"] = "<members><member><id>%s</id><role>ProjectAdmin</role></member></members>" % id_

        # post = self.creation_command(**params)
        post = urllib.urlencode(params)
        headers = {"Content-type": "application/x-www-form-urlencoded"}
        response, content = self.http.request(uri, "POST", headers=headers, body=post)
        if response.status != 200:
            raise AssertionError("Failed to add blog: %s" % content)

        return BaseFeaturelet.deliverPackage(self, obj)
Ejemplo n.º 3
0
    def removePackage(self, obj, raise_error=True):
        wp_uri = self.wp_uri
        if not wp_uri:
            # either None or empty value mean do nothing
            log.info("Failed to remove WordPress blog: no WP URI set")
            return

        uri = "%s/openplans-delete-blog.php" % wp_uri
        params = {}

        params["domain"] = domain = "%s.openplans.org" % obj.getId()

        auth = obj.acl_users.credentials_signed_cookie_auth
        secret = auth.secret
        sig = hmac.new(secret, domain, sha).digest()
        params["signature"] = sig = sig.encode("base64").strip()

        params["title"] = obj.Title()
        post = urllib.urlencode(params)
        headers = {"Content-type": "application/x-www-form-urlencoded"}
        response, content = self.http.request(uri, "POST", headers=headers, body=post)

        if response.status != 200:
            if raise_error:
                raise AssertionError("Failed to remove WordPress blog: %s" % content)
            else:
                log.info("Failed to remove WordPress blog: %s" % content)

        return BaseFeaturelet.removePackage(self, obj)