From ae55a2b038e09851a04580bfc0076f8106dcada1 Mon Sep 17 00:00:00 2001 From: Sam Lichlyter Date: Thu, 2 Sep 2021 09:26:57 -0700 Subject: [PATCH 1/3] added support for enforcing AD group naming pattern --- .../src/components/CreateSDBoxForm/validator.js | 8 ++++++++ .../src/components/GroupSelect/GroupsSelect.js | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js b/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js index bc86320aa..cd8d9bfb0 100644 --- a/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js +++ b/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js @@ -46,6 +46,8 @@ const validate = values => { if (!values.owner) { errors.owner = 'You must select an owning user group'; + } else if (process.env.REACT_APP_AD_GROUP_NAME_PATTERN) { + validateOwner(values.owner, process.env.REACT_APP_AD_GROUP_NAME_PATTERN, errors); } if (values.userGroupPermissions) { @@ -60,6 +62,12 @@ const validate = values => { return errors; }; +const validateOwner = (owner, ownerPrefix, errors) => { + if (!owner.toLowerCase().startsWith(ownerPrefix.toLowerCase())) { + errors.owner = 'This AD Group name does not match your organizations specified naming pattern: ' + ownerPrefix; + } +} + const validateUserGroupPermissions = (permission, index, errors) => { errors.userGroupPermissions[`${index}`] = {}; if (!permission.name) { diff --git a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js index 2f18369bc..273654c43 100644 --- a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js +++ b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js @@ -23,8 +23,16 @@ export default class GroupsSelect extends Component { render() { const { userGroups, allowCustomValues, value, onChange, handleBeingTouched, touched, error } = this.props; - var options = userGroups.map(function (group) { - return { label: group, value: group }; + var options = []; + userGroups.forEach(group => { + if (process.env.REACT_APP_AD_GROUP_NAME_PATTERN) { + let groupNamingPattern = process.env.REACT_APP_AD_GROUP_NAME_PATTERN + if (group.toLowerCase().startsWith(groupNamingPattern)) { + options.push({ label: group, value: group }); + } + } else { + options.push({ label: group, value: group }); + } }); var containsValue = false; From 9af1506b576e39ec3f125ceb8fc191bd36e843c3 Mon Sep 17 00:00:00 2001 From: Sam Lichlyter Date: Thu, 2 Sep 2021 09:43:15 -0700 Subject: [PATCH 2/3] push groupNamingPattern to lowercase --- cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js index 273654c43..ec6a70b41 100644 --- a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js +++ b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js @@ -26,7 +26,7 @@ export default class GroupsSelect extends Component { var options = []; userGroups.forEach(group => { if (process.env.REACT_APP_AD_GROUP_NAME_PATTERN) { - let groupNamingPattern = process.env.REACT_APP_AD_GROUP_NAME_PATTERN + let groupNamingPattern = process.env.REACT_APP_AD_GROUP_NAME_PATTERN.toLowerCase() if (group.toLowerCase().startsWith(groupNamingPattern)) { options.push({ label: group, value: group }); } From d4aeac97996b077fd3c682ccf0436a291a3d7d51 Mon Sep 17 00:00:00 2001 From: Sam Lichlyter Date: Fri, 3 Sep 2021 09:01:34 -0700 Subject: [PATCH 3/3] renamed AD group var, added build step to look for .env file --- cerberus-dashboard/build.gradle | 9 +++++++++ .../src/components/CreateSDBoxForm/validator.js | 4 ++-- .../src/components/GroupSelect/GroupsSelect.js | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cerberus-dashboard/build.gradle b/cerberus-dashboard/build.gradle index f5911f220..42eddfc0b 100644 --- a/cerberus-dashboard/build.gradle +++ b/cerberus-dashboard/build.gradle @@ -24,6 +24,15 @@ node { } task buildDashboard(type: NpmTask, dependsOn: npmInstall) { + + doFirst { + if (System.getenv("FRONTEND_ENV_FILE_PATH")) { + String file_path = System.getenv("FRONTEND_ENV_FILE_PATH") + assert file(file_path).exists() + new File("${project.projectDir.absolutePath}", ".env").text = file(file_path).text + } + } + group 'build' args = ["run", "build"] } diff --git a/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js b/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js index cd8d9bfb0..8847b1924 100644 --- a/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js +++ b/cerberus-dashboard/src/components/CreateSDBoxForm/validator.js @@ -46,8 +46,8 @@ const validate = values => { if (!values.owner) { errors.owner = 'You must select an owning user group'; - } else if (process.env.REACT_APP_AD_GROUP_NAME_PATTERN) { - validateOwner(values.owner, process.env.REACT_APP_AD_GROUP_NAME_PATTERN, errors); + } else if (process.env.REACT_APP_AD_GROUP_NAME_PREFIX) { + validateOwner(values.owner, process.env.REACT_APP_AD_GROUP_NAME_PREFIX, errors); } if (values.userGroupPermissions) { diff --git a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js index ec6a70b41..055acfae9 100644 --- a/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js +++ b/cerberus-dashboard/src/components/GroupSelect/GroupsSelect.js @@ -25,8 +25,8 @@ export default class GroupsSelect extends Component { var options = []; userGroups.forEach(group => { - if (process.env.REACT_APP_AD_GROUP_NAME_PATTERN) { - let groupNamingPattern = process.env.REACT_APP_AD_GROUP_NAME_PATTERN.toLowerCase() + if (process.env.REACT_APP_AD_GROUP_NAME_PREFIX) { + let groupNamingPattern = process.env.REACT_APP_AD_GROUP_NAME_PREFIX.toLowerCase() if (group.toLowerCase().startsWith(groupNamingPattern)) { options.push({ label: group, value: group }); }