Skip to content

PM-967 - check topgear urls #7082

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

Merged
merged 1 commit into from
Mar 28, 2025
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
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,5 @@ module.exports = {
ACCOUNT_SETTINGS_REDIRECT_URL: 'https://account-settings.topcoder-dev.com',
INNOVATION_CHALLENGES_TAG: 'Innovation Challenge',
PLATFORM_SITE_URL: 'https://platform.topcoder-dev.com',
TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS: ['wipro365.sharepoint.com', 'wipro365-my.sharepoint.com'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FilestackFilePicker extends React.Component {
this.state = {
inputUrl: '',
invalidUrl: false,
invalidDomain: false,
};
}

Expand Down Expand Up @@ -105,8 +106,10 @@ class FilestackFilePicker extends React.Component {
if (!isChallengeBelongToTopgearGroup) {
return;
}
if (this.isValidUrl(inputUrl)) {
this.setState({ invalidUrl: false });
const validUrl = this.isValidUrl(inputUrl);
const validDomain = this.isDomainAllowed(inputUrl);
if (validUrl && validDomain) {
this.setState({ invalidUrl: false, invalidDomain: false });
const path = this.generateFilePath();
const filename = inputUrl.substring(inputUrl.lastIndexOf('/') + 1);
setDragged(false);
Expand All @@ -119,7 +122,7 @@ class FilestackFilePicker extends React.Component {
originalPath: inputUrl,
}, path);
} else {
this.setState({ invalidUrl: true });
this.setState({ invalidUrl: true, invalidDomain: !validDomain });
}
}

Expand All @@ -132,6 +135,11 @@ class FilestackFilePicker extends React.Component {
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 */
}

isDomainAllowed(url) {
const domainReg = new RegExp(`^https?://(${config.TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS.join('|')})/`);
return !!url.match(domainReg);
}

/**
* Returns the path where the picked up file should be stored.
* @return {String}
Expand All @@ -157,6 +165,7 @@ class FilestackFilePicker extends React.Component {

const {
invalidUrl,
invalidDomain,
inputUrl,
} = this.state;

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