Exemplo n.º 1
0
    def unsubscribe(self):
        """ """
        if protect is not None:
            alsoProvides(self.request,
                         protect.interfaces.IDisableCSRFProtection)
        putils = getToolByName(self.context, "plone_utils")
        uid = self.request.get("subscriber")

        newsletter = self.context
        if not INewsletter.providedBy(newsletter):
            putils.addPortalMessage(
                _("Please use the correct unsubscribe url!"), "error")
            return self.request.response.redirect(
                api.portal.get_navigation_root(self).absolute_url())

        # We do the deletion as the owner of the newsletter object
        # so that this is possible without login.
        owner = newsletter.getWrappedOwner()
        newSecurityManager(newsletter, owner)
        subscriber = api.content.get(UID=uid)
        if subscriber is None or not INewsletterSubscriber.providedBy(
                subscriber):
            putils.addPortalMessage(_("An error occured"), "error")
        else:
            del newsletter[subscriber.id]
            putils.addPortalMessage(_("You have been unsubscribed."))

        return self.request.response.redirect(
            api.portal.get_navigation_root(self).absolute_url())
Exemplo n.º 2
0
    def test_ct_newsletter_subscriber_factory(self):
        fti = queryUtility(IDexterityFTI, name="Newsletter Subscriber")
        factory = fti.factory
        obj = createObject(factory)

        self.assertTrue(
            INewsletterSubscriber.providedBy(obj),
            "INewsletterSubscriber not provided by {0}!".format(obj, ),
        )
Exemplo n.º 3
0
    def test_ct_newsletter_subscriber_adding(self):
        setRoles(self.portal, TEST_USER_ID, ["Contributor"])
        obj = api.content.create(
            container=self.parent,
            type="Newsletter Subscriber",
            id="newsletter_subscriber",
        )

        self.assertTrue(
            INewsletterSubscriber.providedBy(obj),
            "INewsletterSubscriber not provided by {0}!".format(obj.id, ),
        )

        self.assertIn("newsletter_subscriber", self.parent.objectIds())

        # check that deleting the object works too
        api.content.delete(obj=obj)
        self.assertNotIn("newsletter_subscriber", self.parent.objectIds())
Exemplo n.º 4
0
    def __call__(self):
        """ """
        alsoProvides(self.request, protect.interfaces.IDisableCSRFProtection)
        uid = self.request.get("subscriber")

        newsletter = self.context
        if not INewsletter.providedBy(newsletter):
            api.portal.show_message(
                message=_("Please use the correct unsubscribe url!"),
                request=self.request,
                type="error",
            )
            return self.request.response.redirect(
                api.portal.get_navigation_root(self).absolute_url()
            )

        # We do the deletion as the owner of the newsletter object
        # so that this is possible without login.
        owner = newsletter.getWrappedOwner()
        newSecurityManager(newsletter, owner)
        subscriber = api.content.get(UID=uid)
        if subscriber is None or not INewsletterSubscriber.providedBy(subscriber):
            api.portal.show_message(
                message=_("An error occured"),
                request=self.request,
                type="error",
            )
        else:
            del newsletter[subscriber.id]
            api.portal.show_message(
                message=_("You have been unsubscribed."),
                request=self.request,
                type="info",
            )

        return self.request.response.redirect(
            api.portal.get_navigation_root(self).absolute_url()
        )