Jump to >

djblets.privacy.consent.tracker

Consent tracking and storage capabilities.

class BaseConsentTracker[source]

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 through settings.DJBLETS_PRIVACY_CONSENT_TRACKER.

get_audit_identifier(user)[source]

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:str

Record information on a consent decision made by a user.

Parameters:

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:

djblets.privacy.consent.base.Consent

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 of djblets.privacy.consent.base.ConsentRequirement

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 djblets.privacy.consent.base.ConsentData) – A list of consent data to record.

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 to Consent values.
Return type:dict

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 djblets.privacy.consent.base.ConsentData) – A list of consent data to record.

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 to Consent values.
Return type:dict
class DatabaseConsentTracker[source]

Bases: djblets.privacy.consent.tracker.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[source]

alias of djblets.privacy.models.StoredConsentData

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 djblets.privacy.consent.base.ConsentData) – A list of consent data to record.

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 to Consent values.
Return type:dict

Return the registered consent tracker instance.

Returns:The consent tracker instance.
Return type:BaseConsentTracker

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.