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

[ALS-5539] Parameterize user register TOS acceptance #159

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions addons/addon-base-ui/packages/base-ui/src/helpers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const branding = {
title: process.env.REACT_APP_USER_REGISTRATION_TITLE,
summary: process.env.REACT_APP_USER_REGISTRATION_SUMMARY,
success: process.env.REACT_APP_USER_REGISTRATION_SUCCESS,
tosRequired: process.env.REACT_APP_USER_REGISTRATION_TOS_REQUIRED === 'true',
},
tos: {
onLanding: process.env.REACT_APP_TOS_LINK_ON_LANDING === 'true',
},
main: {
title: process.env.REACT_APP_BRAND_MAIN_TITLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"pattern": "\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d:[0-5]\\d|Z)"
}
},
"required": ["email", "firstName", "lastName", "acceptedTerms"]
"required": ["email", "firstName", "lastName"]
}
8 changes: 6 additions & 2 deletions addons/addon-custom/packages/main/src/extend/withAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ function RegisterLogin(enableCustomRegister) {
Register
</Button>
)}
<Link to="/legal">Terms of Service</Link>
<br />
{branding.tos.onLanding && (
<>
<Link to="/legal">Terms of Service</Link>
<br />
</>
)}
{branding.main.loginWarning}
</>
);
Expand Down
68 changes: 39 additions & 29 deletions addons/addon-custom/packages/main/src/parts/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ class Register extends React.Component {
};
}

renderTOS() {
return (
<>
{this.terms.value !== termsState.unset.value && <Icon name={this.terms.icon} color={this.terms.color} />}
{this.terms.label} &nbsp;
<TermsModal
trigger={
<button
id="terms-modal"
className="link"
type="button"
ref={ref => {
this.termsModalButton = ref;
}}
>
Terms of Service
</button>
}
closeOnDimmerClick
acceptAction={this.setTerms(termsState.accepted)}
declineAction={this.setTerms(termsState.declined)}
/>
</>
);
}

renderRegisterationForm() {
return (
<Form size="large" loading={this.loading} onSubmit={this.handleSubmit}>
Expand All @@ -101,40 +127,16 @@ class Register extends React.Component {

{this.renderField('email')}
</div>
{branding.register.tosRequired && <div className="center mt2">{this.renderTOS()}</div>}
<div className="center mt3">
{this.terms.value !== termsState.unset.value && <Icon name={this.terms.icon} color={this.terms.color} />}
{this.terms.label} &nbsp;
<TermsModal
trigger={
<button
id="terms-modal"
className="link"
type="button"
ref={ref => {
this.termsModalButton = ref;
}}
>
Terms of Service
</button>
}
closeOnDimmerClick
acceptAction={this.setTerms(termsState.accepted)}
declineAction={this.setTerms(termsState.declined)}
/>
</div>
<div className="mt3 center">
<div>
<Form.Field>
{this.errors.form && (
<div className="mb1">
<Label prompt>{this.errors.form}</Label>
</div>
)}
<Form.Button
id="register-submit"
disabled={this.terms.value !== termsState.accepted.value}
color="green"
>
<Form.Button id="register-submit" disabled={this.submitDisabled()} color="green">
Create a new Service Workbench account
</Form.Button>
</Form.Field>
Expand All @@ -145,6 +147,10 @@ class Register extends React.Component {
);
}

submitDisabled() {
return branding.register.tosRequired ? this.terms.value !== termsState.accepted.value : false;
}

renderConfirmation() {
return (
<div>
Expand Down Expand Up @@ -207,20 +213,24 @@ class Register extends React.Component {
return;
}

// Validate that the terms have been accepted
if (this.terms.value !== termsState.accepted.value) {
// Validate that the terms have been accepted, if required
let acceptedTerms;
if (branding.register.tosRequired && this.terms.value !== termsState.accepted.value) {
runInAction(() => {
this.errors.form = termsErrorText;
this.formProcessing = false;
});
return;
}
if (branding.register.tosRequired) {
acceptedTerms = new Date().toISOString();
}

const result = await registerUser({
firstName: this.user.firstName,
lastName: this.user.lastName,
email: this.user.email,
acceptedTerms: new Date().toISOString(),
acceptedTerms,
});
// if we encounter an error then don't continue to process the form and instead display a message
if (result.error) {
Expand Down
6 changes: 6 additions & 0 deletions main/config/settings/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,11 @@ HostedZoneId: 'Z02455261RJ9QQPVHFZGA'
#userRegistrationSuccess: "<p>Your Service Workbench account has been successfully created. What you should expect next:</p><ol><li>The Service Workbench administrator will review your account.</li><li>Once your account is activated, you can login to Service Workbench and start your research.</li></ol>"
#loginWarning: "WARNING: You are entering a secure environment."

# Require the TOS to be accepted before registration can occur.
#tosRequired: true

# Should the TOS link be enabled on the landing page.
#tosLinkOnLanding: true

# URL for help link
#helpUrl: about:blank
2 changes: 2 additions & 0 deletions main/solution/post-deployment/config/infra/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ postDeployment:
APP_STUDY_DATA_BUCKET_NAME: ${self:custom.settings.studyDataBucketName}
APP_ENABLE_NATIVE_USER_POOL_USERS: ${self:custom.settings.enableNativeUserPoolUsers}
APP_ENABLE_CUSTOM_REGISTRATION: ${self:custom.settings.enableCustomRegistration}
APP_TOS_LINK_ON_LANDING : ${self:custom.settings.tosLinkOnLanding}
APP_USER_REGISTRATION_TOS_REQUIRED: ${self:custom.settings.tosRequired}
APP_AUTO_CONFIRM_NATIVE_USERS: ${self:custom.settings.autoConfirmNativeUsers}
APP_NATIVE_ADMIN_PASSWORD_PARAM_NAME: ${self:custom.settings.nativeAdminPasswordParamName}
APP_ENV_NAME: ${self:custom.settings.envName}
Expand Down
6 changes: 6 additions & 0 deletions main/solution/post-deployment/config/settings/.defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ enableUserSignUps: true
# Please also include the registration parameters to customize the registration page.
enableCustomRegistration: false

# Require the TOS to be accepted before registration can occur.
tosRequired: true

# Should the TOS link be enabled on the landing page.
tosLinkOnLanding: true

# Cognito domain prefix. Note random string will be padded at the end if specified domain is not available
cognitoUserPoolDomainPrefix: ${self:custom.settings.envName}-${self:custom.settings.solutionName}

Expand Down
2 changes: 2 additions & 0 deletions main/solution/ui/config/environment/env-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ REACT_APP_USER_REGISTRATION_SUMMARY: ${self:custom.settings.userRegistrationSumm
REACT_APP_USER_REGISTRATION_SUCCESS: ${self:custom.settings.userRegistrationSuccess}
REACT_APP_LOGIN_WARNING: ${self:custom.settings.loginWarning}
REACT_APP_HELP_URL: ${self:custom.settings.helpUrl}
REACT_APP_USER_REGISTRATION_TOS_REQUIRED: ${self:custom.settings.tosRequired}
REACT_APP_TOS_LINK_ON_LANDING: ${self:custom.settings.tosLinkOnLanding}

# ========================================================================
# Overrides for .env.local
Expand Down
6 changes: 6 additions & 0 deletions main/solution/ui/config/settings/.defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ userRegistrationTitle: "WELCOME TO SERVICE WORKBENCH"
userRegistrationSummary: "<p>Service Workbench provides a self-service, three-click, on-demand service for researchers to build research environments in minutes without needing cloud infrastructure knowledge. Fill out the form below to create your account on Service Workbench hosted on AWS.</p>"
userRegistrationSuccess: "<p>Your Service Workbench account has been successfully created. What you should expect next:</p><ol><li>The Service Workbench administrator will review your account.</li><li>Once your account is activated, you can login to Service Workbench and start your research.</li></ol>"
loginWarning: ""

# Require the TOS to be accepted before registration can occur.
tosRequired: true

# Should the TOS link be enabled on the landing page.
tosLinkOnLanding: true
Loading