Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sending RTC with consentState policy adherence #15951

Merged
merged 8 commits into from Jun 12, 2018

Conversation

bradfrizzell
Copy link
Contributor

See #15588

/**
* Returns whether a given callout object is valid to send an RTC request
* to, for the given consentState.
* @param {Object|string} callout

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -445,3 +445,10 @@ AMP.require;
* @typedef {function(number, boolean):?|function(number):?}
*/
var TransitionDef;

const CONSENT_POLICY_STATE = {
Copy link
Contributor

@glevitzky glevitzky Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add /** @enum {number} ... .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* See src/consent-state.js for more information.
* @enum {number}
*/
const CONSENT_POLICY_STATE = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is now externed can we delete src/consent-state.js (and carry-over documentation)?

/**
* Returns whether a given callout object is valid to send an RTC request
* to, for the given consentState.
* @param {Object|string} callout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calloutConfig sounds like a better name IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Returns whether a given callout object is valid to send an RTC request
* to, for the given consentState.
* @param {Object|string} callout
* @return {boolean}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return false;
}

const sendRegardlessOfConsentState =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch (typeof callout.sendRegardlessOfConsentState) {
case 'boolean':
return callout.sendRegardlessOfConsentState;
case 'Array':
return sendRegardlessOfConsentState.includes(this.consentState_);
default:
user().warn(TAG, 'WHAT?! ...');
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

* custom URL.
*/
modifyRtcConfigForConsentStateSettings() {
if (!(this.consentState_ == CONSENT_POLICY_STATE.INSUFFICIENT ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code? Can you just call isValidCalloutForConsentState with the global value? Also what if global sendRegardlessOfConsentState is false but individual callout is true (or array with value)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, and the current setup is that the default is the global is false, and any individual can override.

// 'macros'. This is for backwards compatability.
const vendorMacros =
this.rtcConfig_.vendors[vendor]['macros'] &&
isObject(this.rtcConfig_.vendors[vendor]['macros']) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the first check here? I would assume isObject returns false if undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ghost
Copy link

ghost commented Jun 11, 2018

This pull request introduces 1 alert when merging 0eda166 into 289a745 - view on LGTM.com

new alerts:

  • 1 for Useless type test

Comment posted by LGTM.com

@ghost
Copy link

ghost commented Jun 12, 2018

This pull request introduces 1 alert when merging 5f9bd7a into 289a745 - view on LGTM.com

new alerts:

  • 1 for Useless type test

Comment posted by LGTM.com

customMacros = this.assignMacros(customMacros);
this.rtcStartTime_ = Date.now();
this.handleRtcForCustomUrls(customMacros);
this.handleRtcForVendorUrls(customMacros);
return Promise.all(this.promiseArray_);
return this.promiseArray_.length ? Promise.all(this.promiseArray_) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume that Promise.all empty array is equivalent to Promise.resolve... Why return null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same thing but I was having issues in testing where that was not the case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still surprises me... r u sure?

}
return false;
}
user().warn(TAG, 'Invalid value for sendRegardlessOfConsentState');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include callout info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (isArray(sendRegardlessOfConsentState)) {
for (let i = 0; i < sendRegardlessOfConsentState.length; i++) {
if (this.consentState_ ==
CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could warn here when a constent state given does not exist in the enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do a switch here:

switch (sendRegardlessOfConsentState[i]) {
case this.consentState_:
return true;
case undefined:
Log... break;
}

urls.push(this.rtcConfig_.urls[i]);
}
}
this.rtcConfig_.urls = urls;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.rtcConfig_.urls = this.rtcConfig_.urls.filter(url => this.isValidCalloutForConsentState(url));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return;
}

if (this.isValidCalloutForConsentState(this.rtcConfig_)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So global overrides the value on a per callout/vendor level? Image pub has:

{vendors: {foo: {sendRegardlessOfConsentState: ['unknown']}}, sendRegardlessOfConsentState: true}

If consent state is insufficient should we call out to vendor foo? I would argue no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (isArray(sendRegardlessOfConsentState)) {
for (let i = 0; i < sendRegardlessOfConsentState.length; i++) {
if (this.consentState_ ==
CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do a switch here:

switch (sendRegardlessOfConsentState[i]) {
case this.consentState_:
return true;
case undefined:
Log... break;
}

* Returns whether a given callout object is valid to send an RTC request
* to, for the given consentState.
* @param {Object|string} calloutConfig
* @param {boolean=} optIsGloballyValid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this not optional and just pass false when calling on the global object

customMacros = this.assignMacros(customMacros);
this.rtcStartTime_ = Date.now();
this.handleRtcForCustomUrls(customMacros);
this.handleRtcForVendorUrls(customMacros);
return Promise.all(this.promiseArray_);
return this.promiseArray_.length ? Promise.all(this.promiseArray_) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still surprises me... r u sure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants