djblets.privacy.consent.tracker¶
Consent tracking and storage capabilities.
- class BaseConsentTracker¶
Bases:
object
Base class for a consent tracker.
Consent trackers are responsible for storing and looking up consent information from a source. This can be the database, an external record kept outside the database, a secure vault, or some other location as supported by the specific consent tracker being used.
By default,
DatabaseConsentTracker
is used. This can be changed throughsettings.DJBLETS_PRIVACY_CONSENT_TRACKER
.- get_audit_identifier(user)¶
Return an identifier to store for audit purposes.
This is used to help locate stored consent, perhaps after a user account was unregistered, in order to prove later that a user did or did not consent to something.
Data used in this identifier should never be used for any purpose other than locating the record for legal reasons. Stored audit identifiers may be erased at any time.
By default, this returns a SHA256 hash representing the user’s e-mail address, allowing lookups for known e-mail addresses without risking exposure. Subclasses can modify this.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to return an identifier for.- Returns:
An identifier to store to help locate the record of consent.
- Return type:
- record_consent_data(user, consent_data)¶
Record information on a consent decision made by a user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to record the consent decision for.consent_data (
djblets.privacy.consent.base.ConsentData
) – Data on the consent decision.
- get_consent(user, requirement_id)¶
Return the user’s consent decision for a given requirement.
- Parameters:
user (
django.contrib.auth.models.User
) – The user who made a decision on consent for a requirement.requirement_id (
unicode
) – The ID of the requirement to check on consent for.
- Returns:
The user’s consent decision for the requirement.
- Return type:
- get_pending_consent_requirements(user)¶
Return a list of consent requirements that are pending decisions.
This can be used to determine whether a user needs to be immediately shown a UI for deciding on consent.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to check consent decisions for.- Returns:
The list of consent requirements pending decisions.
- Return type:
list
ofdjblets.privacy.consent.base.ConsentRequirement
- record_consent_data_list(user, consent_data_list)¶
Record a list of all consent data made by a user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to record the consent data for.consent_data_list (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``djblets.privacy.consent.base.ConsentData
) – A list of consent data to record.
- get_all_consent(user)¶
Return all consent decisions made by a given user.
It’s important to note that a user may not have made a decision on consent for a given registered requirement, in which case the results will not include an entry for that requirement.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to return all consent information for.- Returns:
A dictionary of
BaseConsentRequirement
IDs toConsent
values.- Return type:
- store_recorded_consent_data_list(user, consent_data_list)¶
Record a list of all consent data made by a user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to record the consent data for.consent_data_list (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``djblets.privacy.consent.base.ConsentData
) – A list of consent data to record.
- get_all_consent_uncached(user)¶
Return all consent decisions made by a given user from the backend.
This is used by
get_all_consent()
to return data directly from the backend, bypassing the cache.- Parameters:
user (
django.contrib.auth.models.User
) – The user to return all consent information for.- Returns:
A dictionary of
BaseConsentRequirement
IDs toConsent
values.- Return type:
- class DatabaseConsentTracker¶
Bases:
BaseConsentTracker
A consent tracker that stores results in the database.
This consent tracker keeps the current consent information and audit history in the database for fast and easy lookup. This is the default consent tracker used.
- model¶
The model used to store consent data in the database.
alias of
StoredConsentData
- store_recorded_consent_data_list(user, consent_data_list)¶
Store a recorded list of all consent data made by a user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to record the consent data for.consent_data_list (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``djblets.privacy.consent.base.ConsentData
) – A list of consent data to record.
- get_all_consent_uncached(user)¶
Return all consent decisions made by a given user.
It’s important to note that a user may not have made a decision on consent for a given registered requirement, in which case the results will not include an entry for that requirement.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to return all consent information for.- Returns:
A dictionary of
BaseConsentRequirement
IDs toConsent
values.- Return type:
- get_consent_tracker()¶
Return the registered consent tracker instance.
- Returns:
The consent tracker instance.
- Return type:
- clear_consent_tracker()¶
Clear the registered consent tracker instance.
This is primarily useful for unit tests. It will remove the consent tracker, causing it to be re-instantiated based on settings on the next attempt.