Exemplo n.º 1
0
 class IConsentForm(Interface):
     lang = api.portal.get_current_language()
     for reason_id, reason in sorted(reasons.items()):
         reason_match = (validated_user and validated_user[0]
                         == reason.identifier_factory.__name__)
         if reason_match:
             if (reason.identifier_factory.getIdentifierForUser(
                     validated_user[1]) is None):
                 continue
         elif (reason.identifier_factory.getIdentifierForCurrentRequest(
                 self.request) is None):
             continue
         reason_id = reason_id.encode("ascii", "replace")
         directives.widget(safe_fieldname(reason_id), RadioFieldWidget)
         if not reason.can_object:
             directives.mode(**{safe_fieldname(reason_id): "display"})
         translated_title = translate(_(reason.Title),
                                      target_language=lang)
         locals()[safe_fieldname(reason_id)] = schema.Choice(
             title=translated_title,
             description=reason.html_description,
             vocabulary=consent_values,
             required=True,
             default="Allowed" if reason.isProcessingAllowed(
                 self.request,
                 identifier=validated_user[1] if reason_match else None,
             ) else "Blocked",
         )
     del lang
     del translated_title
     del reason_id
     del reason_match
     del reason
 def html_description(self):
     lang = api.portal.get_current_language()
     description = translate(_(self.Description), target_language=lang)
     if self.optinoptout_storage.uses_end_user_equipment:
         text = _(
             u"The preference you set here will be stored on your computer."
         )
         translated_text = translate(text, target_language=lang)
         description += u"<p>{0}<p>".format(translated_text)
     if not self.can_object:
         text = _(
             u"In order to comply with Data Protection laws, we cannot offer the ability to opt out of this."
         )
         translated_text = translate(text, target_language=lang)
         description += u"<p><strong>{0}</strong><p>".format(
             translated_text)
     return description
Exemplo n.º 3
0
 def __call__(self):
     found = []
     self.request.response.setHeader("Content-type", "application/json")
     consent_reasons = [
         reason
         for reason in self.context.portal_privacy.getAllReasons().values()
         if reason.lawful_basis.__name__ == "consent"
     ]
     for reason in consent_reasons:
         try:
             if not reason.isOpinionExpressed(self.request):
                 found.append({
                     "Title":
                     translate(_(reason.Title), context=self.request),
                     "Description":
                     translate(_(reason.Description), context=self.request),
                     "name":
                     reason.__name__,
                 })
         except Exception:
             # FIXME
             pass
     return json.dumps(found)
Exemplo n.º 4
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        privacy_tool = self.context.portal_privacy
        for topic, answer in data.items():
            answer = answer == "Allowed"
            if answer:
                privacy_tool.consentToProcessing(topic)
            else:
                privacy_tool.objectToProcessing(topic)

        self.status = _(u"Your preferences have been saved.")
Exemplo n.º 5
0
class ConsentForm(AutoExtensibleForm, Form):
    """ Define Form handling

    This form can be accessed as http://yoursite/@@consent

    """

    ignoreContext = True

    label = _(u"Privacy settings")
    description = _(
        u"Choose to opt in or out of various pieces of functionality")

    @property
    def action(self):
        return self._action

    def url(self, name=None, data=None):
        """ Partially reimplement url method that came from plone.directives.form
        Return string for the URL based on the obj and name. The data
        argument is used to form a CGI query string.
        """
        obj = self.context

        if data is None:
            data = {}
        else:
            if not isinstance(data, dict):
                raise TypeError('url() data argument must be a dict.')

        url = getMultiAdapter((obj, self.request), IAbsoluteURL)()
        if name is not None:
            url += '/' + urllib.parse.quote(name.encode('utf-8'),
                                            SAFE_URL_CHARACTERS)
        if not data:
            return url

        for k, v in data.items():
            if isinstance(v, text_type):
                data[k] = v.encode('utf-8')
            if isinstance(v, (list, set, tuple)):
                data[k] = [
                    isinstance(item, text_type) and item.encode('utf-8')
                    or item for item in v
                ]

        return url + '?' + urllib.parse.urlencode(data, doseq=True)

    @property
    def schema(self):
        reasons = self.context.portal_privacy.getAllReasons()
        validated_user = None
        self._action = self.url(name="consent")
        if "user_id" in self.request.form:
            processing_reason = self.request.form.get("processing_reason")
            user_id = self.request.form.get("user_id")
            authentication = self.request.form.get("authentication")
            if self.context.portal_privacy.verifyIdentifier(
                    authentication, processing_reason, user_id):
                reason_object = self.context.portal_privacy.getProcessingReason(
                    processing_reason)
                validated_user = (reason_object.identifier_factory.__name__,
                                  user_id)
                self._action = self.url(
                    name="consent",
                    data={
                        "processing_reason": processing_reason,
                        "user_id": user_id,
                        "authentication": authentication,
                    },
                )

        class IConsentForm(Interface):
            lang = api.portal.get_current_language()
            for reason_id, reason in sorted(reasons.items()):
                reason_match = (validated_user and validated_user[0]
                                == reason.identifier_factory.__name__)
                if reason_match:
                    if (reason.identifier_factory.getIdentifierForUser(
                            validated_user[1]) is None):
                        continue
                elif (reason.identifier_factory.getIdentifierForCurrentRequest(
                        self.request) is None):
                    continue
                reason_id = reason_id.encode("ascii", "replace")
                directives.widget(safe_fieldname(reason_id), RadioFieldWidget)
                if not reason.can_object:
                    directives.mode(**{safe_fieldname(reason_id): "display"})
                translated_title = translate(_(reason.Title),
                                             target_language=lang)
                locals()[safe_fieldname(reason_id)] = schema.Choice(
                    title=translated_title,
                    description=reason.html_description,
                    vocabulary=consent_values,
                    required=True,
                    default="Allowed" if reason.isProcessingAllowed(
                        self.request,
                        identifier=validated_user[1] if reason_match else None,
                    ) else "Blocked",
                )
            del lang
            del translated_title
            del reason_id
            del reason_match
            del reason

        return IConsentForm

    @button.buttonAndHandler(_(u"Ok"))
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        privacy_tool = self.context.portal_privacy
        for topic, answer in data.items():
            answer = answer == "Allowed"
            if answer:
                privacy_tool.consentToProcessing(topic)
            else:
                privacy_tool.objectToProcessing(topic)

        self.status = _(u"Your preferences have been saved.")

    @button.buttonAndHandler(_(u"Cancel"))
    def handleCancel(self, action):
        """User cancelled. Redirect back to the front page.
Exemplo n.º 6
0
import json
import pkg_resources

try:
    pkg_resources.get_distribution("plone.directives.form")
except pkg_resources.DistributionNotFound:
    HAS_DIRECTIVES = False
    from plone.autoform import directives
    from plone.autoform.form import AutoExtensibleForm
else:
    HAS_DIRECTIVES = True
    from plone.directives import form as directives
    from plone.directives.form import SchemaForm as AutoExtensibleForm

consent_values = SimpleVocabulary([
    SimpleTerm(value=u"Allowed", title=_(u"Allowed")),
    SimpleTerm(value=u"Blocked", title=_(u"Blocked")),
])


@implementer(IConsentFormView)
class ConsentForm(AutoExtensibleForm, Form):
    """ Define Form handling

    This form can be accessed as http://yoursite/@@consent

    """

    ignoreContext = True

    label = _(u"Privacy settings")
Exemplo n.º 7
0
class IDataUseCategory(Interface):
    """
    Register a data use category
    """

    name = TextLine(
        title=_("Name"), description=_("The id used for this category."), required=False
    )

    legal_basis = TextLine(
        title=_("Legal basis"),
        description=_("The identifier of a legal basis that is used here"),
        required=True,
    )

    identifier = GlobalObject(
        title=_("How users will be identified"),
        description=_("An object that provides IIdentifierFactory"),
        required=True,
    )

    storage = GlobalObject(
        title=_("Storage for this data"),
        description=_("An object that provides IOptInOptOutStorage"),
        required=True,
    )

    title = TextLine(
        title=_("Title"),
        description=_("The end-user visible title for this processing"),
        required=False,
    )

    description = TextLine(
        title=_("Description"),
        description=_("The end-user visible description of this processing"),
        required=False,
    )

    marketing = Bool(
        title=_("Marketing"),
        description=_("Is this used for marketing purposes?"),
        required=False,
        default=False,
    )

    tracking = Bool(
        title=_("Tracking"),
        description=_("Is this used for tracking purposes?"),
        required=False,
        default=False,
    )

    cookies = TextLine(
        title=_("Cookies names"),
        description=_(
            "List of cookies for this use : separeted by ',', wildcard (*) accepted"
        ),
        required=False,
    )