collective.privacy 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. collective/privacy/__init__.py +5 -0
  2. collective/privacy/browser/__init__.py +0 -0
  3. collective/privacy/browser/configure.zcml +48 -0
  4. collective/privacy/browser/consent.py +219 -0
  5. collective/privacy/browser/overrides/.gitkeep +0 -0
  6. collective/privacy/browser/overrides/Products.CMFPlone.browser.templates.sendto_template.pt +77 -0
  7. collective/privacy/browser/static/.gitkeep +0 -0
  8. collective/privacy/browser/static/consent.js +40 -0
  9. collective/privacy/browser/templates/consent_banner.pt +61 -0
  10. collective/privacy/configure.zcml +64 -0
  11. collective/privacy/identifiers.py +105 -0
  12. collective/privacy/interfaces.py +86 -0
  13. collective/privacy/lawful_basis.py +36 -0
  14. collective/privacy/lawful_basis.zcml +43 -0
  15. collective/privacy/locales/collective.privacy.pot +216 -0
  16. collective/privacy/locales/fr/LC_MESSAGES/collective.privacy.po +215 -0
  17. collective/privacy/locales/nl/LC_MESSAGES/collective.privacy.po +214 -0
  18. collective/privacy/locales/update.sh +12 -0
  19. collective/privacy/meta.zcml +18 -0
  20. collective/privacy/permissions.zcml +13 -0
  21. collective/privacy/plone_core/__init__.py +0 -0
  22. collective/privacy/plone_core/configure.zcml +52 -0
  23. collective/privacy/plone_core/sendto.py +17 -0
  24. collective/privacy/plone_core/webstats_js.py +13 -0
  25. collective/privacy/processing_reason.py +147 -0
  26. collective/privacy/profiles/default/browserlayer.xml +6 -0
  27. collective/privacy/profiles/default/catalog.xml +4 -0
  28. collective/privacy/profiles/default/componentregistry.xml +10 -0
  29. collective/privacy/profiles/default/metadata.xml +7 -0
  30. collective/privacy/profiles/default/registry.xml +19 -0
  31. collective/privacy/profiles/default/rolemap.xml +7 -0
  32. collective/privacy/profiles/default/toolset.xml +6 -0
  33. collective/privacy/profiles/uninstall/browserlayer.xml +6 -0
  34. collective/privacy/profiles/uninstall/componentregistry.xml +9 -0
  35. collective/privacy/profiles/uninstall/registry.xml +11 -0
  36. collective/privacy/profiles/uninstall/toolset.xml +6 -0
  37. collective/privacy/setuphandlers.py +19 -0
  38. collective/privacy/storage.py +136 -0
  39. collective/privacy/storage.zcml +8 -0
  40. collective/privacy/testing.py +35 -0
  41. collective/privacy/testing.zcml +9 -0
  42. collective/privacy/tests/__init__.py +0 -0
  43. collective/privacy/tests/data_use.zcml +14 -0
  44. collective/privacy/tests/test_consent.py +30 -0
  45. collective/privacy/tests/test_cookies.py +37 -0
  46. collective/privacy/tests/test_setup.py +70 -0
  47. collective/privacy/tool.py +127 -0
  48. collective/privacy/upgrades.py +5 -0
  49. collective/privacy/upgrades.zcml +17 -0
  50. collective/privacy/utils.py +17 -0
  51. collective/privacy/zcml.py +140 -0
  52. collective_privacy-2.0.0.dist-info/METADATA +490 -0
  53. collective_privacy-2.0.0.dist-info/RECORD +58 -0
  54. collective_privacy-2.0.0.dist-info/WHEEL +5 -0
  55. collective_privacy-2.0.0.dist-info/entry_points.txt +2 -0
  56. collective_privacy-2.0.0.dist-info/licenses/LICENSE.GPL +339 -0
  57. collective_privacy-2.0.0.dist-info/licenses/LICENSE.rst +15 -0
  58. collective_privacy-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,5 @@
1
+ """Init and utils."""
2
+
3
+ from zope.i18nmessageid import MessageFactory
4
+
5
+ _ = MessageFactory("collective.privacy")
File without changes
@@ -0,0 +1,48 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:browser="http://namespaces.zope.org/browser"
4
+ xmlns:plone="http://namespaces.plone.org/plone"
5
+ i18n_domain="collective.privacy"
6
+ >
7
+
8
+ <!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
9
+ <include
10
+ package="z3c.jbot"
11
+ file="meta.zcml"
12
+ />
13
+ <browser:jbot
14
+ directory="overrides"
15
+ layer="collective.privacy.interfaces.ICollectivePrivacyLayer"
16
+ />
17
+
18
+ <!-- Publish static files -->
19
+ <browser:resourceDirectory
20
+ name="collective.privacy"
21
+ directory="static"
22
+ />
23
+
24
+ <browser:page
25
+ name="consent"
26
+ for="plone.app.layout.navigation.interfaces.INavigationRoot"
27
+ class=".consent.ConsentForm"
28
+ permission="zope2.View"
29
+ />
30
+
31
+ <browser:viewlet
32
+ name="collective.privacy.banner"
33
+ for="*"
34
+ manager="plone.app.layout.viewlets.interfaces.IBelowContent"
35
+ class=".consent.ConsentBannerViewlet"
36
+ template="templates/consent_banner.pt"
37
+ permission="zope2.View"
38
+ layer="..interfaces.ICollectivePrivacyLayer"
39
+ />
40
+
41
+ <browser:page
42
+ name="consent-json"
43
+ for="*"
44
+ class=".consent.ConsentJSON"
45
+ permission="zope2.View"
46
+ />
47
+
48
+ </configure>
@@ -0,0 +1,219 @@
1
+ from collective.privacy import _
2
+ from collective.privacy.interfaces import IConsentFormView
3
+ from collective.privacy.utils import safe_fieldname
4
+ from plone import api
5
+ from plone.app.layout.viewlets import common as base
6
+ from plone.autoform import directives
7
+ from plone.autoform.form import AutoExtensibleForm
8
+ from Products.Five import BrowserView
9
+ from z3c.form import button
10
+ from z3c.form.browser.radio import RadioFieldWidget
11
+ from z3c.form.form import Form
12
+ from zope import schema
13
+ from zope.component import getMultiAdapter
14
+ from zope.i18n import translate
15
+ from zope.interface import implementer
16
+ from zope.interface import Interface
17
+ from zope.schema.vocabulary import SimpleTerm
18
+ from zope.schema.vocabulary import SimpleVocabulary
19
+ from zope.traversing.browser.absoluteurl import _safe as SAFE_URL_CHARACTERS
20
+ from zope.traversing.browser.interfaces import IAbsoluteURL
21
+
22
+ import json
23
+ import urllib.parse
24
+
25
+ consent_values = SimpleVocabulary(
26
+ [
27
+ SimpleTerm(value="Allowed", title=_("Allowed")),
28
+ SimpleTerm(value="Blocked", title=_("Blocked")),
29
+ ]
30
+ )
31
+
32
+
33
+ @implementer(IConsentFormView)
34
+ class ConsentForm(AutoExtensibleForm, Form):
35
+ """Define Form handling
36
+
37
+ This form can be accessed as http://yoursite/@@consent
38
+
39
+ """
40
+
41
+ ignoreContext = True
42
+
43
+ label = _("Privacy settings")
44
+ description = _("Choose to opt in or out of various pieces of functionality")
45
+
46
+ @property
47
+ def action(self):
48
+ return self._action
49
+
50
+ def url(self, name=None, data=None):
51
+ """Partially reimplement url method that came from plone.directives.form
52
+ Return string for the URL based on the obj and name. The data
53
+ argument is used to form a CGI query string.
54
+ """
55
+ obj = self.context
56
+
57
+ if data is None:
58
+ data = {}
59
+ else:
60
+ if not isinstance(data, dict):
61
+ raise TypeError("url() data argument must be a dict.")
62
+
63
+ url = getMultiAdapter((obj, self.request), IAbsoluteURL)()
64
+ if name is not None:
65
+ url += "/" + urllib.parse.quote(name.encode("utf-8"), SAFE_URL_CHARACTERS)
66
+ if not data:
67
+ return url
68
+
69
+ for k, v in data.items():
70
+ if isinstance(v, str):
71
+ data[k] = v.encode("utf-8")
72
+ if isinstance(v, (list, set, tuple)):
73
+ data[k] = [
74
+ isinstance(item, str) and item.encode("utf-8") or item for item in v
75
+ ]
76
+
77
+ return url + "?" + urllib.parse.urlencode(data, doseq=True)
78
+
79
+ @property
80
+ def schema(self):
81
+ reasons = self.context.portal_privacy.getAllReasons()
82
+ validated_user = None
83
+ self._action = self.url(name="consent")
84
+ if "user_id" in self.request.form:
85
+ processing_reason = self.request.form.get("processing_reason")
86
+ user_id = self.request.form.get("user_id")
87
+ authentication = self.request.form.get("authentication")
88
+ if self.context.portal_privacy.verifyIdentifier(
89
+ authentication, processing_reason, user_id
90
+ ):
91
+ reason_object = self.context.portal_privacy.getProcessingReason(
92
+ processing_reason
93
+ )
94
+ validated_user = (reason_object.identifier_factory.__name__, user_id)
95
+ self._action = self.url(
96
+ name="consent",
97
+ data={
98
+ "processing_reason": processing_reason,
99
+ "user_id": user_id,
100
+ "authentication": authentication,
101
+ },
102
+ )
103
+
104
+ class IConsentForm(Interface):
105
+ lang = api.portal.get_current_language()
106
+ for reason_id, reason in sorted(reasons.items()):
107
+ reason_match = (
108
+ validated_user
109
+ and validated_user[0] == reason.identifier_factory.__name__
110
+ )
111
+ if reason_match:
112
+ if (
113
+ reason.identifier_factory.getIdentifierForUser(
114
+ validated_user[1]
115
+ )
116
+ is None
117
+ ):
118
+ continue
119
+ elif (
120
+ reason.identifier_factory.getIdentifierForCurrentRequest(
121
+ self.request
122
+ )
123
+ is None
124
+ ):
125
+ continue
126
+ reason_id = reason_id.encode("ascii", "replace")
127
+ directives.widget(safe_fieldname(reason_id), RadioFieldWidget)
128
+ if not reason.can_object:
129
+ directives.mode(**{safe_fieldname(reason_id): "display"})
130
+ translated_title = translate(_(reason.Title), target_language=lang)
131
+ locals()[safe_fieldname(reason_id)] = schema.Choice(
132
+ title=translated_title,
133
+ description=reason.html_description,
134
+ vocabulary=consent_values,
135
+ required=True,
136
+ default=(
137
+ "Allowed"
138
+ if reason.isProcessingAllowed(
139
+ self.request,
140
+ identifier=validated_user[1] if reason_match else None,
141
+ )
142
+ else "Blocked"
143
+ ),
144
+ )
145
+ del lang
146
+ del translated_title
147
+ del reason_id
148
+ del reason_match
149
+ del reason
150
+
151
+ return IConsentForm
152
+
153
+ @button.buttonAndHandler(_("Ok"))
154
+ def handleApply(self, action):
155
+ data, errors = self.extractData()
156
+ if errors:
157
+ self.status = self.formErrorsMessage
158
+ return
159
+
160
+ privacy_tool = self.context.portal_privacy
161
+ for topic, answer in data.items():
162
+ answer = answer == "Allowed"
163
+ if answer:
164
+ privacy_tool.consentToProcessing(topic)
165
+ else:
166
+ privacy_tool.objectToProcessing(topic)
167
+
168
+ self.status = _("Your preferences have been saved.")
169
+
170
+ @button.buttonAndHandler(_("Cancel"))
171
+ def handleCancel(self, action):
172
+ """User cancelled. Redirect back to the front page."""
173
+
174
+
175
+ class ConsentBannerViewlet(base.ViewletBase):
176
+ def is_consent_required(self):
177
+ if not api.portal.get_registry_record("collective.privacy.solicit_consent"):
178
+ return False
179
+ if IConsentFormView.providedBy(self.view):
180
+ # Don't show consent banner on consent form
181
+ return False
182
+ consent_reasons = [
183
+ reason
184
+ for reason in self.context.portal_privacy.getAllReasons().values()
185
+ if reason.lawful_basis.__name__ == "consent"
186
+ ]
187
+ return len(consent_reasons) > 0
188
+
189
+
190
+ class ConsentJSON(BrowserView):
191
+ """
192
+ This view return a json for opinions required for the current user based on
193
+ collective.privacy cookie
194
+ """
195
+
196
+ def __call__(self):
197
+ found = []
198
+ self.request.response.setHeader("Content-type", "application/json")
199
+ consent_reasons = [
200
+ reason
201
+ for reason in self.context.portal_privacy.getAllReasons().values()
202
+ if reason.lawful_basis.__name__ == "consent"
203
+ ]
204
+ for reason in consent_reasons:
205
+ try:
206
+ if not reason.isOpinionExpressed(self.request):
207
+ found.append(
208
+ {
209
+ "Title": translate(_(reason.Title), context=self.request),
210
+ "Description": translate(
211
+ _(reason.Description), context=self.request
212
+ ),
213
+ "name": reason.__name__,
214
+ }
215
+ )
216
+ except Exception:
217
+ # FIXME
218
+ pass
219
+ return json.dumps(found)
File without changes
@@ -0,0 +1,77 @@
1
+ <div xmlns="http://www.w3.org/1999/xhtml"
2
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
3
+ xmlns:metal="http://xml.zope.org/namespaces/metal"
4
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
5
+ xml:lang="en"
6
+ tal:define="
7
+ utool nocall:context/portal_url;
8
+ charset python:context.portal_registry.get('email_charset', 'utf-8');
9
+ dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset);
10
+ "
11
+ tal:omit-tag=""
12
+ i18n:domain="plone"
13
+ ><div tal:omit-tag=""
14
+ i18n:translate="sendto_mailtemplate_body"
15
+ >
16
+ This link is sent to you from
17
+ <span tal:replace="structure utool"
18
+ tal:omit-tag=""
19
+ i18n:name="portal_url"
20
+ ></span>
21
+
22
+ You are receiving this mail because someone read a page at
23
+ <span tal:replace="structure utool/Title"
24
+ tal:omit-tag=""
25
+ i18n:name="portal_title"
26
+ ></span>
27
+ and thought it might interest you.
28
+
29
+ It is sent by
30
+ <span tal:replace="structure options/send_from_address"
31
+ tal:omit-tag=""
32
+ i18n:name="from_address"
33
+ ></span>
34
+ with the following comment:
35
+ "<span tal:replace="structure options/comment | nothing"
36
+ tal:omit-tag=""
37
+ i18n:name="comment"
38
+ ></span>"
39
+
40
+ <span tal:replace="structure options/title | context/Title"
41
+ tal:omit-tag=""
42
+ i18n:name="document_title"
43
+ ></span>
44
+
45
+ <span tal:replace="structure options/description | context/Description"
46
+ tal:omit-tag=""
47
+ i18n:name="document_description"
48
+ ></span>
49
+
50
+ <span tal:replace="structure options/url | context/absolute_url"
51
+ tal:omit-tag=""
52
+ i18n:name="document_url"
53
+ ></span>
54
+ </div>
55
+ --
56
+ <span tal:replace="structure options/email_from_name"></span>
57
+
58
+ </div>
59
+
60
+ <div tal:define="
61
+ utool nocall:context/portal_url;
62
+ "
63
+ tal:omit-tag=""
64
+ i18n:domain="collective.privacy"
65
+ i18n:translate="email_privacy_info"
66
+ >
67
+ If you would prefer not to receive these emails you can adjust your privacy settings on
68
+ <span tal:replace="structure utool/Title"
69
+ tal:omit-tag=""
70
+ i18n:name="portal_title"
71
+ ></span>
72
+ by visiting
73
+ <span tal:replace="structure python:context.portal_privacy.getConsentLink('send_to_form', options['send_to_address'])"
74
+ tal:omit-tag=""
75
+ i18n:name="consent_url"
76
+ ></span>
77
+ </div>
File without changes
@@ -0,0 +1,40 @@
1
+ jQuery(function($) {
2
+ var reasons = [];
3
+ var submitConsentForm = function(evt) {
4
+ var form = $(this).closest('form');
5
+ var data = form.serialize();
6
+ var url = form.attr('action');
7
+ data += '&'+this.name+'=1';
8
+ $.ajax({
9
+ type: "POST",
10
+ url: url,
11
+ data: data,
12
+ }).done(function() {
13
+ setConsentForm();
14
+ });
15
+ evt.preventDefault();
16
+ };
17
+ var setConsentForm = function() {
18
+ if (reasons.length > 0) {
19
+ $('#gdpr-consent-banner').show();
20
+ var reason = reasons.shift();
21
+ $('#gdpr-consent-banner form .gdpr-reason').html(
22
+ '<strong>' + reason.Title + '</strong>' +
23
+ '<p>' + reason.Description + '</p>' +
24
+ '<input type="hidden" name="processing_reason" value="' + reason.name + '" />'
25
+ );
26
+ $('#gdpr-consent-banner form .gdpr-actions input').one('click', submitConsentForm);
27
+ } else {
28
+ $('#gdpr-consent-banner').remove();
29
+ }
30
+ };
31
+ var url = $('#gdpr-consent-banner form').data('json-url');
32
+ $.ajax({
33
+ type: "GET",
34
+ url: url,
35
+ headers: {"Cache-Control": "no-cache"},
36
+ }).done(function(data) {
37
+ reasons = data;
38
+ setConsentForm();
39
+ });
40
+ });
@@ -0,0 +1,61 @@
1
+ <div id="gdpr-consent-banner"
2
+ style="
3
+ z-index: 999999;
4
+ width: 100%;
5
+ position: fixed;
6
+ bottom: 0;
7
+ left: 0;
8
+ padding: 5px;
9
+ background: orange;
10
+ display:none;"
11
+ tal:define="
12
+ portal_state context/@@plone_portal_state;
13
+ needed view/is_consent_required;
14
+ portal_url portal_state/portal_url;
15
+ navigation_root_url portal_state/navigation_root_url;
16
+ "
17
+ tal:condition="needed"
18
+ i18n:domain="collective.privacy"
19
+ >
20
+ <form method="POST"
21
+ style="max-width: 800px; margin: auto;"
22
+ tal:attributes="
23
+ action string:${portal_url}/portal_privacy/bannerConsent;
24
+ data-json-url string:${context/absolute_url}/@@consent-json;
25
+ "
26
+ >
27
+ <div class="gdpr-reason"
28
+ style="float: left; max-width: 60%;"
29
+ ></div>
30
+ <div class="gdpr-actions"
31
+ style="float: right; padding-top: 5px;"
32
+ >
33
+ <input name="consent"
34
+ style="padding: 5px; margin-right: 10px;"
35
+ type="submit"
36
+ value="Allow"
37
+ i18n:attributes="value"
38
+ />
39
+ <input name="refuse"
40
+ style="padding: 5px; margin-right: 10px;"
41
+ type="submit"
42
+ value="Refuse"
43
+ i18n:attributes="value"
44
+ />
45
+ </div>
46
+ </form>
47
+ <div style="clear: both; text-align: center;">
48
+ <a href=""
49
+ tal:attributes="
50
+ href string:${navigation_root_url}/@@consent;
51
+ "
52
+ i18n:translate=""
53
+ >Manage privacy settings</a>
54
+ </div>
55
+ <script defer="defer"
56
+ type="text/javascript"
57
+ tal:attributes="
58
+ src string:${portal_url}/++resource++collective.privacy/consent.js;
59
+ "
60
+ ></script>
61
+ </div>
@@ -0,0 +1,64 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:cmf="http://namespaces.zope.org/cmf"
4
+ xmlns:five="http://namespaces.zope.org/five"
5
+ xmlns:gdpr="http://namespaces.plone.org/gdpr"
6
+ xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
7
+ xmlns:i18n="http://namespaces.zope.org/i18n"
8
+ xmlns:plone="http://namespaces.plone.org/plone"
9
+ i18n_domain="collective.privacy"
10
+ >
11
+
12
+ <i18n:registerTranslations directory="locales" />
13
+
14
+ <include package=".browser" />
15
+
16
+ <include file="permissions.zcml" />
17
+ <include file="upgrades.zcml" />
18
+
19
+ <include file="lawful_basis.zcml" />
20
+ <include package=".plone_core" />
21
+
22
+ <gdpr:data_use_category
23
+ name="gdpr_cookies"
24
+ title="Cookies to record your privacy preferences"
25
+ description="These store if you've given consent or objected to various uses of your data. We need to store these to comply with data protection law."
26
+ identifier="collective.privacy.identifiers.NoChoiceIdentifier"
27
+ legal_basis="legal_obligation"
28
+ storage="collective.privacy.storage.NoChoiceStorage"
29
+ />
30
+
31
+
32
+ <genericsetup:registerProfile
33
+ name="default"
34
+ title="collective.privacy"
35
+ description="Installs the collective.privacy add-on."
36
+ provides="Products.GenericSetup.interfaces.EXTENSION"
37
+ directory="profiles/default"
38
+ post_handler=".setuphandlers.post_install"
39
+ />
40
+
41
+ <genericsetup:registerProfile
42
+ name="uninstall"
43
+ title="collective.privacy (uninstall)"
44
+ description="Uninstalls the collective.privacy add-on."
45
+ provides="Products.GenericSetup.interfaces.EXTENSION"
46
+ directory="profiles/uninstall"
47
+ post_handler=".setuphandlers.uninstall"
48
+ />
49
+
50
+ <utility
51
+ factory=".setuphandlers.HiddenProfiles"
52
+ name="collective.privacy-hiddenprofiles"
53
+ />
54
+
55
+ <five:registerClass
56
+ class=".tool.ProcessingReason"
57
+ permission="cmf.ManagePortal"
58
+ addview="addProcessingReason.html"
59
+ global="False"
60
+ meta_type="Processing Reason"
61
+ />
62
+
63
+
64
+ </configure>
@@ -0,0 +1,105 @@
1
+ from plone import api
2
+
3
+ import uuid
4
+
5
+
6
+ class CookieIdentifier:
7
+ __name__ = "cookie"
8
+
9
+ @classmethod
10
+ def getIdentifierForCurrentRequest(kls, request):
11
+ """It is not possible to get the user's email address from a request"""
12
+ return "current"
13
+
14
+ @classmethod
15
+ def getIdentifierForUser(kls, user):
16
+ return None
17
+
18
+
19
+ class EmailIdentifier:
20
+ __name__ = "Email"
21
+ NAMESPACE = uuid.UUID("a838b36d-d1d5-477e-8471-c1e2079417cf")
22
+
23
+ @classmethod
24
+ def getIdentifierForCurrentRequest(kls, request):
25
+ """It is not possible to get the user's email address from a request"""
26
+ try:
27
+ if api.portal.get_registry_record("collective.privacy.trust_member_emails"):
28
+ email = api.user.get_current().getProperty("email")
29
+ else:
30
+ email = None
31
+ if not email:
32
+ return None
33
+ return kls.getIdentifierForUser(email)
34
+ except Exception:
35
+ # FIXME
36
+ return None
37
+
38
+ @classmethod
39
+ def getIdentifierForUser(kls, user):
40
+ """Use UUID5 to get an integer ID in a namespace"""
41
+ return uuid.uuid5(kls.NAMESPACE, user).int
42
+
43
+
44
+ class IPIdentifier:
45
+ __name__ = "IP"
46
+ NAMESPACE = uuid.UUID("45865cac-1e4f-46d3-8e3e-1c277db76f3e")
47
+
48
+ @classmethod
49
+ def get_ip(seklslf, request):
50
+ """Extract the client IP address from the HTTP request in a proxy-compatible way.
51
+
52
+ @return: IP address as a string or None if not available
53
+ """
54
+ if "HTTP_X_FORWARDED_FOR" in request.environ:
55
+ # Virtual host
56
+ ip = request.environ["HTTP_X_FORWARDED_FOR"]
57
+ elif "HTTP_HOST" in request.environ:
58
+ # Non-virtualhost
59
+ ip = request.environ["REMOTE_ADDR"]
60
+ else:
61
+ # Unit test code?
62
+ ip = None
63
+ return ip
64
+
65
+ @classmethod
66
+ def getIdentifierForCurrentRequest(kls, request):
67
+ """It is not possible to get the user's email address from a request"""
68
+ return kls.getIdentifierForUser(kls.get_ip(request))
69
+
70
+ @classmethod
71
+ def getIdentifierForUser(kls, user):
72
+ """Use UUID5 to get an integer ID in a namespace"""
73
+ return uuid.uuid5(kls.NAMESPACE, user).int
74
+
75
+
76
+ class UserIdentifier:
77
+ __name__ = "User"
78
+ NAMESPACE = uuid.UUID("9d01c079-a268-4e43-81f7-0eecd4c45316")
79
+
80
+ @classmethod
81
+ def getIdentifierForCurrentRequest(kls, request):
82
+ """It is not possible to get the user's email address from a request"""
83
+ username = api.user.get_current().getUserName()
84
+ if not username:
85
+ return None
86
+ return kls.getIdentifierForUser(username)
87
+
88
+ @classmethod
89
+ def getIdentifierForUser(kls, user):
90
+ """Use UUID5 to get an integer ID in a namespace"""
91
+ return uuid.uuid5(kls.NAMESPACE, user).int
92
+
93
+
94
+ class NoChoiceIdentifier:
95
+ __name__ = "NoChoice"
96
+
97
+ @classmethod
98
+ def getIdentifierForCurrentRequest(kls, request):
99
+ """It is not possible to get the user's email address from a request"""
100
+ return 0
101
+
102
+ @classmethod
103
+ def getIdentifierForUser(kls, user):
104
+ """Use UUID5 to get an integer ID in a namespace"""
105
+ return 0