Skip to content

Commit 98cf7ee

Browse files
committed
PM-967 - check topgear urls
1 parent 0de5ca8 commit 98cf7ee

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,5 @@ module.exports = {
472472
ACCOUNT_SETTINGS_REDIRECT_URL: 'https://account-settings.topcoder-dev.com',
473473
INNOVATION_CHALLENGES_TAG: 'Innovation Challenge',
474474
PLATFORM_SITE_URL: 'https://platform.topcoder-dev.com',
475+
TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS: ['wipro365.sharepoint.com', 'wipro365-my.sharepoint.com'],
475476
};

src/shared/components/SubmissionPage/FilestackFilePicker/index.jsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FilestackFilePicker extends React.Component {
3535
this.state = {
3636
inputUrl: '',
3737
invalidUrl: false,
38+
invalidDomain: false,
3839
};
3940
}
4041

@@ -105,8 +106,10 @@ class FilestackFilePicker extends React.Component {
105106
if (!isChallengeBelongToTopgearGroup) {
106107
return;
107108
}
108-
if (this.isValidUrl(inputUrl)) {
109-
this.setState({ invalidUrl: false });
109+
const validUrl = this.isValidUrl(inputUrl);
110+
const validDomain = this.isDomainAllowed(inputUrl);
111+
if (validUrl && validDomain) {
112+
this.setState({ invalidUrl: false, invalidDomain: false });
110113
const path = this.generateFilePath();
111114
const filename = inputUrl.substring(inputUrl.lastIndexOf('/') + 1);
112115
setDragged(false);
@@ -119,7 +122,7 @@ class FilestackFilePicker extends React.Component {
119122
originalPath: inputUrl,
120123
}, path);
121124
} else {
122-
this.setState({ invalidUrl: true });
125+
this.setState({ invalidUrl: true, invalidDomain: !validDomain });
123126
}
124127
}
125128

@@ -132,6 +135,11 @@ class FilestackFilePicker extends React.Component {
132135
return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(url); /* eslint-disable-line no-useless-escape */
133136
}
134137

138+
isDomainAllowed(url) {
139+
const domainReg = new RegExp(`^https?://(${config.TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS.join('|')})/`);
140+
return !!url.match(domainReg);
141+
}
142+
135143
/**
136144
* Returns the path where the picked up file should be stored.
137145
* @return {String}
@@ -157,6 +165,7 @@ class FilestackFilePicker extends React.Component {
157165

158166
const {
159167
invalidUrl,
168+
invalidDomain,
160169
inputUrl,
161170
} = this.state;
162171

@@ -207,6 +216,14 @@ class FilestackFilePicker extends React.Component {
207216
isChallengeBelongToTopgearGroup && (
208217
<div styleName="url-input-container">
209218
{invalidUrl && (<div styleName="invalid-url-message">* Invalid URL</div>)}
219+
{invalidDomain && (
220+
<div styleName="invalid-url-message">
221+
Ensure that you submit a valid Wipro SharePoint link only.
222+
The link should point to the outcome/deliverable of the
223+
challenge and should reflect the work done.
224+
Please check the challenge submission guidelines.
225+
</div>
226+
)}
210227
<input styleName={(invalidUrl ? 'invalid' : '')} id="name" name="name" type="text" placeholder="URL" onChange={this.onUpdateInputUrl} value={inputUrl} required />
211228
</div>
212229
)

0 commit comments

Comments
 (0)