Client Permissions

Client Permissions

{{ client_permissions }}

The client_permissions object is available on every page, and contains information about whether or not the user (or developer) has granted permission to use specific features. By default the only feature controlled by this is sessions, but the permission system may be "extended" arbitrarily by the developer to control additional features.

The permissions feature requires cookies in order to work. Requests made without cookies (such as by bots or browsers with cookies disabled) will always behave like an initial page-load without existing permission information.

Name Type Description
is_valid Boolean Will always be true
cookiename String The name of the cookie used for storing permissions. Will always be "_mp_permissions"
has_cookie Boolean True if the permissions cookie was already set prior to this request. False on the first page load, after the client has cleared their cookies, or on all requests from browsers with cookies disabled
cookie_expires time The date and time that the permissions cookie is set to expire
min_permission_expiration_date time The next date and time that one of the permissions is set to expire. Note that this does not distinguish between "allow" and "deny" permissions and will ignore permissions with no expiration date set. If there are no permissions with expiration dates set this property will be empty
max_permission_expiration_date time The latest date and time that one of the permissions is set to expire. Note that this does not distinguish between "allow" and "deny" permissions and will ignore permissions with no expiration date set. If there are no permissions with expiration dates set this property will be empty
do_not_track Boolean Whether or not the browser sent the "DNT" header in the request
keys list The list of permissions (both allowed and denied) stored in the client_permissions object
* permission Specific permissions may be accessed using {{ client_permissions.permissionname }} or {{ client_permissions['permission-name'] }}
allow_* Boolean Shortcut to check if a specified permission is both defined AND allowed in the permission system.
output String JSON representation of the client_permissions object, similar to calling {{ client_permissions | inspect: 3, false }}

The client_permissions object is copyable, and when copied using the {% copy_to_dictionary %} method the keys will be the permission names and the values will be the corresponding permission objects.

The client_permissions object may also be enumerated using the {% for %} method, which will loop through all of the related permission objects when the for loop is started. Permissions that are added during enumeration will NOT be included, permissions that are removed during enumeration WILL be included, and permission s that are modified during enumeration will be included along with their updated properties.

{% set_client_permission %}

Defines whether the client has granted or deined permission for a particular feature (eg: sessions). The only permission defined by default is the session permission (configurable in the site properties). However, the template developer may use this mechanism for their own purposes as well.

The permissions defined by this method will be stored in the permissions cookie, which may be read and/or modified by client-side javascript.

If none of the expiration clauses are specified, the permission expiration date will default to 1 year in the future.

Remember that the expiration date specified here is for the permission, not for the effects of the permission. In the case of sessions, the expiration date defines how long the user has granted permission to have a session, regardless of the number or duration of sessions during that timeframe.

If the permission has a value, the value will be stored along with the permission regardless of whether the permission has been allowed or denied.

Permissions will never expire in the middle of a session - if a permission would be set to expire in the middle of a session, it will automatically be extended until the end of the session to prevent odd mid-session permission change bugs.

{% unset_client_permission %}

Removes the specified permissions from the permissions cookie. Note that this is not the same as denying permission since there will be no record that permission was either granted or denied after the permission has been unset.

Examples

set_client_permission deny

Copy
{% if request.query_params.allow_session == "true" %} {% var allow_length = "1 year" %} {% if request.query_params.allow_months %} {% set allow_length = request.query_params.allow_months | append: " months" %} {% endif %} {% set_client_permission allow session renew for allow_length %} {% elsif request.query_params.deny_session == "true" %} {% set_client_permission deny renew %} --equivalent to {% set_client_permission deny session renew for 1 year %} {% endif %}

set_client_permission by reference

Copy
{% if request.query_params.allow_networks %} {% var networks = request.query_params.allow_networks | split: ',' %} {% for network in networks %} {% set_client_permission allow &network %} {% endfor %} {% endif %} {% if request.query_params.deny_networks %} {% var networks = request.query_params.allow_networks | split: ',' %} {% for network in networks %} {% set_client_permission deny &network %} {% endfor %} {% endif %}

set_client_permission third_party_login

Copy
{% if request.query_params.third_party_login %} {% if request.query_params.third_party_login == "false" %} {% set_client_permission deny ThirdPartyLogin %} {% else %} {% set_client_permission allow ThirdPartyLogin with:request.query_params.third_party_login %} {% endif %} {% endif %}

Unset Client Permissions by reference

Copy
{% var unset_parties = request.query_params.third_party_unknowns | split: ',' %} {% for party in unset_parties %} {% unset_client_permissions &party %} {% endfor %}

Unset Client Permissions

Copy
{% if request.query_params.user_confirmation != permissions.external_user.value %} {% unset_client_permissions external_user %}

Some error message about failed confirmation and please try again

{% endif %}

Safely Unset Client Permissions

Copy
{% if unsafely_nuke_the_permissions %} {% unset_client_permissions %} {% elsif safely_nuke_the_permissions %} {% var oldSession = session.allowed %} {% unset_client_permissions %} {% if oldSession %} {% set_client_permissions allow session %} {% endif %} {% endif %}

Client Permissions

Copy
{% if client_permissions.do_not_track %}

You have requested that we do not track your information. We interpret that to mean __x__ and so will return a __y__ generic response.

{% else %} {% if client_permisions.allow_all %} --in this example "all" refers to a custom permission defined by the developer

You have granted us unlimited power! You should have the best possible experience.

{% if client_permissions.all.expires < request.date | add_weeks: 2 %}

Your permissions will expire on {{ client_permission.all.expires | date: 'MMM dd' }}. If you want to continue receiving the best possible experience, follow these instructions

{% endif %} {% else %} {% if client_permissions.allow_generous %}

You have allowed "generous" permissions. While not the best, this still allows for a good experience.

{% elsif client_permissions.allow_limited %}

You have allowed "limited" permissions. This is only slightly better than a completely anonymous experience.

{% else %}

You have not allowed any permissions. Your experience will be fully generic.

{% endif %}

To customize your options and improve your experience, click here.

{% endif %} {% endif %}

Client Permissions allow ads

Copy
{% if client_permissions.allow_advertisements %} {% assign allowed_ads = client_permissions.advertisements.value | default: "all" | split: "&" %}
    {% for ad in allowed_ads %}
  • {{ad | replace: '-' " " | replace: '_' " " | capitalize }} advertisements are allowed until {{client_permissions.advertisements.expires | date: 'MMMM dd, yyyy, H:mm'}}.
  • {% endfor %}
{% endif %}