Rest of terms/policies renaming
This commit is contained in:
parent
8de5c348f3
commit
0316aa11b7
2 changed files with 25 additions and 23 deletions
22
src/Terms.js
22
src/Terms.js
|
@ -86,18 +86,18 @@ export async function startTermsFlow(services, interactionCallback) {
|
||||||
const terms = await Promise.all(termsPromises);
|
const terms = await Promise.all(termsPromises);
|
||||||
const policiesAndServicePairs = terms.map((t, i) => { return { 'service': services[i], 'policies': t.policies }; });
|
const policiesAndServicePairs = terms.map((t, i) => { return { 'service': services[i], 'policies': t.policies }; });
|
||||||
|
|
||||||
const agreedUrls = await interactionCallback(termsAndServices);
|
const agreedUrls = await interactionCallback(policiesAndServicePairs);
|
||||||
console.log("User has agreed to URLs", agreedUrls);
|
console.log("User has agreed to URLs", agreedUrls);
|
||||||
|
|
||||||
const agreePromises = termsAndServices.map((termsAndService) => {
|
const agreePromises = policiesAndServicePairs.map((policiesAndService) => {
|
||||||
// filter the agreed URL list for ones that are actually for this service
|
// filter the agreed URL list for ones that are actually for this service
|
||||||
// (one URL may be used for multiple services)
|
// (one URL may be used for multiple services)
|
||||||
// Not a particularly efficient loop but probably fine given the numbers involved
|
// Not a particularly efficient loop but probably fine given the numbers involved
|
||||||
const urlsForService = agreedUrls.filter((url) => {
|
const urlsForService = agreedUrls.filter((url) => {
|
||||||
for (const policy of Object.values(policiesAndService)) {
|
for (const policy of Object.values(policiesAndService.policies)) {
|
||||||
for (const lang of Object.keys(terms)) {
|
for (const lang of Object.keys(policy)) {
|
||||||
if (lang === 'version') continue;
|
if (lang === 'version') continue;
|
||||||
if (terms[lang].url === url) return true;
|
if (policy[lang].url === url) return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -106,22 +106,22 @@ export async function startTermsFlow(services, interactionCallback) {
|
||||||
if (urlsForService.length === 0) return Promise.resolve();
|
if (urlsForService.length === 0) return Promise.resolve();
|
||||||
|
|
||||||
return MatrixClientPeg.get().agreeToTerms(
|
return MatrixClientPeg.get().agreeToTerms(
|
||||||
termsAndService.service.serviceType,
|
policiesAndService.service.serviceType,
|
||||||
termsAndService.service.baseUrl,
|
policiesAndService.service.baseUrl,
|
||||||
termsAndService.service.accessToken,
|
policiesAndService.service.accessToken,
|
||||||
urlsForService,
|
urlsForService,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return Promise.all(agreePromises);
|
return Promise.all(agreePromises);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dialogTermsInteractionCallback(termsWithServices) {
|
function dialogTermsInteractionCallback(policiesAndServicePairs) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("Terms that need agreement", termsWithServices);
|
console.log("Terms that need agreement", policiesAndServicePairs);
|
||||||
const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog");
|
const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog");
|
||||||
|
|
||||||
Modal.createTrackedDialog('Terms of Service', '', TermsDialog, {
|
Modal.createTrackedDialog('Terms of Service', '', TermsDialog, {
|
||||||
termsWithServices,
|
policiesAndServicePairs,
|
||||||
onFinished: (done, agreedUrls) => {
|
onFinished: (done, agreedUrls) => {
|
||||||
if (!done) {
|
if (!done) {
|
||||||
reject(new TermsNotSignedError());
|
reject(new TermsNotSignedError());
|
||||||
|
|
|
@ -44,9 +44,10 @@ class TermsCheckbox extends React.PureComponent {
|
||||||
export default class TermsDialog extends React.PureComponent {
|
export default class TermsDialog extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
/**
|
/**
|
||||||
* Array of TermsWithService
|
* Array of [Service, terms] pairs, where terms is the response from the
|
||||||
|
* /terms endpoint for that service
|
||||||
*/
|
*/
|
||||||
termsWithServices: PropTypes.arrayOf(PropTypes.object).isRequired,
|
policiesAndServicePairs: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called with:
|
* Called with:
|
||||||
|
@ -101,8 +102,9 @@ export default class TermsDialog extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTermsCheckboxChange = (url, checked) => {
|
_onTermsCheckboxChange = (url, checked) => {
|
||||||
this.state.agreedUrls[url] = checked;
|
this.setState({
|
||||||
this.setState({agreedUrls: this.state.agreedUrls});
|
agreedUrls: Object.assign({}, this.state.agreedUrls, { [url]: checked }),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -110,19 +112,19 @@ export default class TermsDialog extends React.PureComponent {
|
||||||
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
||||||
|
|
||||||
const rows = [];
|
const rows = [];
|
||||||
for (const termsWithService of this.props.termsWithServices) {
|
for (const policiesAndService of this.props.policiesAndServicePairs) {
|
||||||
const parsedBaseUrl = url.parse(termsWithService.service.baseUrl);
|
const parsedBaseUrl = url.parse(policiesAndService.service.baseUrl);
|
||||||
|
|
||||||
const termsValues = Object.values(termsWithService.terms);
|
const termsValues = Object.values(policiesAndService.policies);
|
||||||
for (let i = 0; i < termsValues.length; ++i) {
|
for (let i = 0; i < termsValues.length; ++i) {
|
||||||
const termDoc = termsValues[i];
|
const termDoc = termsValues[i];
|
||||||
const termsLang = pickBestLanguage(Object.keys(termDoc).filter((k) => k !== 'version'));
|
const termsLang = pickBestLanguage(Object.keys(termDoc).filter((k) => k !== 'version'));
|
||||||
let serviceName;
|
let serviceName;
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
serviceName = this._nameForServiceType(termsWithService.service.serviceType, parsedBaseUrl.host);
|
serviceName = this._nameForServiceType(policiesAndService.service.serviceType, parsedBaseUrl.host);
|
||||||
}
|
}
|
||||||
const summary = this._summaryForServiceType(
|
const summary = this._summaryForServiceType(
|
||||||
termsWithService.service.serviceType,
|
policiesAndService.service.serviceType,
|
||||||
termsValues.length > 1 ? termDoc[termsLang].name : null,
|
termsValues.length > 1 ? termDoc[termsLang].name : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -144,9 +146,9 @@ export default class TermsDialog extends React.PureComponent {
|
||||||
// if all the documents for at least one service have been checked, we can enable
|
// if all the documents for at least one service have been checked, we can enable
|
||||||
// the submit button
|
// the submit button
|
||||||
let enableSubmit = false;
|
let enableSubmit = false;
|
||||||
for (const termsWithService of this.props.termsWithServices) {
|
for (const policiesAndService of this.props.policiesAndServicePairs) {
|
||||||
let docsAgreedForService = 0;
|
let docsAgreedForService = 0;
|
||||||
for (const terms of Object.values(termsWithService.terms)) {
|
for (const terms of Object.values(policiesAndService.policies)) {
|
||||||
let docAgreed = false;
|
let docAgreed = false;
|
||||||
for (const lang of Object.keys(terms)) {
|
for (const lang of Object.keys(terms)) {
|
||||||
if (lang === 'version') continue;
|
if (lang === 'version') continue;
|
||||||
|
@ -159,7 +161,7 @@ export default class TermsDialog extends React.PureComponent {
|
||||||
++docsAgreedForService;
|
++docsAgreedForService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (docsAgreedForService === Object.keys(termsWithService.terms).length) {
|
if (docsAgreedForService === Object.keys(policiesAndService.policies).length) {
|
||||||
enableSubmit = true;
|
enableSubmit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue