From 6c767525b7fdeb6c9af25732069b1911f3ac21dc Mon Sep 17 00:00:00 2001 From: silmyhasan Date: Fri, 7 Feb 2025 16:12:33 +0530 Subject: [PATCH] Improve UX of role addition. --- .../Apis/Details/Scopes/CreateScope.jsx | 23 +++++++++++++++---- .../Apis/Details/Scopes/EditScope.jsx | 23 +++++++++++++++---- .../components/Scopes/Create/CreateScope.jsx | 23 +++++++++++++++---- .../src/app/components/Scopes/EditScope.jsx | 23 +++++++++++++++---- 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/CreateScope.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/CreateScope.jsx index 4aef7dac529..eab5f4b1854 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/CreateScope.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/CreateScope.jsx @@ -227,10 +227,25 @@ class CreateScope extends React.Component { const promise = APIValidation.role.validate(base64url.encode(role)); promise .then(() => { - this.setState({ - roleValidity: true, - validRoles: [...validRoles, role], - }); + const splitRole = role.split('/', 2); + let validatedRole = ''; + if (splitRole.length > 1) { + const domain = splitRole.length > 0 ? splitRole[0] : ''; + if (domain.toUpperCase() !== 'INTERNAL') { + const domainUpperCase = domain.toUpperCase().concat('/'); + validatedRole = domainUpperCase.concat(splitRole[1]); + } else { + validatedRole = role; + } + } else { + validatedRole = role; + } + if (!validRoles.includes(validatedRole)) { + this.setState({ + roleValidity: true, + validRoles: [...validRoles, validatedRole], + }); + } }) .catch((error) => { if (error.status === 404) { diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/EditScope.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/EditScope.jsx index 4146bebb2fe..347a3fe02a6 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/EditScope.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Scopes/EditScope.jsx @@ -215,10 +215,25 @@ class EditScope extends React.Component { const promise = APIValidation.role.validate(base64url.encode(role)); promise .then(() => { - this.setState({ - roleValidity: true, - validRoles: [...validRoles, role], - }); + const splitRole = role.split('/', 2); + let validatedRole = ''; + if (splitRole.length > 1) { + const domain = splitRole.length > 0 ? splitRole[0] : ''; + if (domain.toUpperCase() !== 'INTERNAL') { + const domainUpperCase = domain.toUpperCase().concat('/'); + validatedRole = domainUpperCase.concat(splitRole[1]); + } else { + validatedRole = role; + } + } else { + validatedRole = role; + } + if (!validRoles.includes(validatedRole)) { + this.setState({ + roleValidity: true, + validRoles: [...validRoles, validatedRole], + }); + } }) .catch((error) => { if (error.status === 404) { diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Scopes/Create/CreateScope.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Scopes/Create/CreateScope.jsx index 1f4f9130aee..29df3e2b17b 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Scopes/Create/CreateScope.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Scopes/Create/CreateScope.jsx @@ -225,10 +225,25 @@ class CreateScope extends React.Component { const promise = APIValidation.role.validate(base64url.encode(role)); promise .then(() => { - this.setState({ - roleValidity: true, - validRoles: [...validRoles, role], - }); + const splitRole = role.split('/', 2); + let validatedRole = ''; + if (splitRole.length > 1) { + const domain = splitRole.length > 0 ? splitRole[0] : ''; + if (domain.toUpperCase() !== 'INTERNAL') { + const domainUpperCase = domain.toUpperCase().concat('/'); + validatedRole = domainUpperCase.concat(splitRole[1]); + } else { + validatedRole = role; + } + } else { + validatedRole = role; + } + if (!validRoles.includes(validatedRole)) { + this.setState({ + roleValidity: true, + validRoles: [...validRoles, validatedRole], + }); + } }) .catch((error) => { if (error.status === 404) { diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Scopes/EditScope.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Scopes/EditScope.jsx index adddef5b5b3..51b68170a97 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Scopes/EditScope.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Scopes/EditScope.jsx @@ -242,10 +242,25 @@ class EditScope extends React.Component { const promise = APIValidation.role.validate(base64url.encode(role)); promise .then(() => { - this.setState({ - roleValidity: true, - validRoles: [...validRoles, role], - }); + const splitRole = role.split('/', 2); + let validatedRole = ''; + if (splitRole.length > 1) { + const domain = splitRole.length > 0 ? splitRole[0] : ''; + if (domain.toUpperCase() !== 'INTERNAL') { + const domainUpperCase = domain.toUpperCase().concat('/'); + validatedRole = domainUpperCase.concat(splitRole[1]); + } else { + validatedRole = role; + } + } else { + validatedRole = role; + } + if (!validRoles.includes(validatedRole)) { + this.setState({ + roleValidity: true, + validRoles: [...validRoles, validatedRole], + }); + } }) .catch((error) => { if (error.status === 404) {