Skip to content

Instantly share code, notes, and snippets.

@trevorfoskett
Last active November 5, 2019 20:47
Show Gist options
  • Save trevorfoskett/9b9925ee5ffec93559ba9f71c9edf738 to your computer and use it in GitHub Desktop.
Save trevorfoskett/9b9925ee5ffec93559ba9f71c9edf738 to your computer and use it in GitHub Desktop.
Builds access control policy based on user checkbox selections.
/*
* Builds policy according to user inputs.
*
* @param {Array} authUsers The list of authorized users for this piece of content.
* @return {Policy} The policy for this piece of content.
*/
function buildPolicy() {
var policy = new Virtru.PolicyBuilder();
if ($('#watermark-toggle').is(":checked")) {
policy.enableWatermarking();
}
if ($('#disable-reshare-toggle').is(":checked")) {
policy.disableReshare();
}
if ($('#expiration-toggle').is(":checked")) {
if ($('#one-hour-expire').is(":checked")) {
var expTime = (60*60); // Expiration time is set in "seconds from now"
console.log(expTime);
}
if ($('#one-day-expire').is(":checked")) {
var expTime = (60*60*24);
console.log(expTime);
}
if ($('#one-week-expire').is(":checked")) {
var expTime = (60*60*24*7);
console.log(expTime);
}
if ($('#one-month-expire').is(":checked")) {
var expTime = (60*60*24*7*4);
console.log(expTime);
}
policy.enableExpirationDeadlineFromNow([expTime]);
}
return policy.build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment