From e3cb8aa34ab349924a2f586c69bd31c9a10636aa Mon Sep 17 00:00:00 2001 From: shnrndk Date: Tue, 28 Nov 2023 10:02:46 +0530 Subject: [PATCH] Add change api provider and get all apis rest api. --- .../main/webapp/site/public/locales/en.json | 9 +- .../APISettings/ApisTableContent.jsx | 2 +- .../components/APISettings/ApisTableHead.jsx | 6 +- .../app/components/APISettings/EditApi.jsx | 88 +++++++++---------- .../app/components/APISettings/ListApis.jsx | 20 ++--- .../main/webapp/source/src/app/data/api.js | 23 +++++ 6 files changed, 85 insertions(+), 63 deletions(-) diff --git a/portals/admin/src/main/webapp/site/public/locales/en.json b/portals/admin/src/main/webapp/site/public/locales/en.json index 52ae05f5dc5..c0d04c740cf 100644 --- a/portals/admin/src/main/webapp/site/public/locales/en.json +++ b/portals/admin/src/main/webapp/site/public/locales/en.json @@ -88,14 +88,14 @@ "Apis.Details.Scopes.CreateScope.roles.help": "Enter a valid role and press `Enter`.", "Apis.Details.Scopes.Roles.Invalid": "A Role is invalid", "Apis.Listing.Listing.apis.search": "Search", - "Apis.Listing.Listing.apis.search.label": "Search Api by Api Owner", + "Apis.Listing.Listing.apis.search.label": "Search Api by Api Provider", "Apis.Listing.Listing.apis.searching": "Searching", "Apis.Listing.Listing.clear.search": "Clear Search", "Apis.Listing.Listing.empty.message": "No Data to Display", - "Apis.Listing.Listing.search.placeholder": "Api Owner", + "Apis.Listing.Listing.search.placeholder": "Api Provider", "Apis.Listing.apiTableHead.actions": "Actions", "Apis.Listing.apiTableHead.name": "Name", - "Apis.Listing.apiTableHead.owner": "Owner", + "Apis.Listing.apiTableHead.provider": "Provider", "Apis.Shared.AdminRootErrorBoundary.refresh": "Refresh", "Apis.Shared.AdminRootErrorBoundary.refresh.or.try.again.message": "You may refresh the page now or try again later", "Apis.Shared.AdminRootErrorBoundary.something.went.wrong.while.rendering.button": "Something went wrong while rendering the", @@ -130,7 +130,8 @@ "Base.RouteMenuMapping.application.creation": "Application Creation", "Base.RouteMenuMapping.application.deletion": "Application Deletion", "Base.RouteMenuMapping.application.throttling.policies": "Application Policies", - "Base.RouteMenuMapping.applications": "Applications", + "Base.RouteMenuMapping.applications": "Change Application Owner", + "Base.RouteMenuMapping.apis": "Change Api Provder", "Base.RouteMenuMapping.apps": "Apps", "Base.RouteMenuMapping.blacklisted.items": "Deny Policies", "Base.RouteMenuMapping.custom.throttling.policies": "Custom Policies", diff --git a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx index 19f783a5d7b..5ef97e46308 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx @@ -141,7 +141,7 @@ class ApisTableContent extends Component { {app.name} - {app.owner} + {app.provider} { sorting: true, }, { - id: 'owner', + id: 'provider', numeric: false, disablePadding: false, label: (), sorting: true, }, diff --git a/portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx b/portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx index cfd38b04db2..183b96427c8 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx @@ -38,7 +38,7 @@ const useStyles = makeStyles((theme) => ({ function reducer(state, { field, value }) { switch (field) { case 'name': - case 'owner': + case 'provider': return { ...state, [field]: value }; case 'editDetails': return value; @@ -47,7 +47,7 @@ function reducer(state, { field, value }) { } } /** - * Render a pop-up dialog to change ownership of an Api + * Render a pop-up dialog to change providership of an Api * @param {JSON} props props passed from parent * @returns {JSX}. */ @@ -59,45 +59,45 @@ function EditApi(props) { } = props; const [initialState, setInitialState] = useState({ name: '', - owner: '', + provider: '', }); const [state, dispatch] = useReducer(reducer, initialState); - const { name, owner } = state; + const { name, provider } = state; useEffect(() => { setInitialState({ name: '', - owner: '', + provider: '', }); }, []); const onChange = (e) => { dispatch({ field: e.target.name, value: e.target.value }); }; - const validateOwner = () => { + const validateProvider = () => { let validationError = 'Something went wrong when validating user'; const apisWithSameName = apiList.filter( - (app) => app.name === name && app.owner === owner, + (app) => app.name === name && app.provider === provider, ); const promiseValidation = new Promise((resolve, reject) => { if (apisWithSameName.length > 0) { - validationError = `${owner} already has an api with name: ${name}`; + validationError = `${provider} already has an api with name: ${name}`; reject(validationError); } const basicScope = 'apim:subscribe'; - restApi.getUserScope(owner, basicScope) + restApi.getUserScope(provider, basicScope) .then(() => { - // This api returns 200 when only the $owner has the $basicScope. + // This api returns 200 when only the $provider has the $basicScope. resolve(); }).catch((error) => { const { response } = error; - // This api returns 404 when the $owner is not found. + // This api returns 404 when the $provider is not found. // error codes: 901502, 901500 for user not found and scope not found if (response?.body?.code === 901502 || response?.body?.code === 901500) { - validationError = `${owner} is not a valid Subscriber`; + validationError = `${provider} is not a valid Subscriber`; } }).finally(() => { if (validationError) { @@ -110,35 +110,33 @@ function EditApi(props) { }; const formSaveCallback = () => { - return validateOwner().then(() => { - return restApi.updateApiOwner(dataRow.apiId, owner) - .then(() => { - return ( - - ); - }) - .catch((error) => { - const { response } = error; - if (response?.body?.code === 500) { - const notValidSubscriber = 'Error while updating ownership to ' + owner; - throw notValidSubscriber; - } else { - const updateError = 'Something went wrong when updating owner'; - throw updateError; - } - }) - .finally(() => { - updateList(); - }); - }); + return restApi.updateApiProvider(dataRow.id, provider) + .then(() => { + return ( + + ); + }) + .catch((error) => { + const { response } = error; + if (response?.body?.code === 500) { + const notValidSubscriber = 'Error while updating providership to ' + provider; + throw notValidSubscriber; + } else { + const updateError = 'Something went wrong when updating provider'; + throw updateError; + } + }) + .finally(() => { + updateList(); + }); }; const dialogOpenCallback = () => { if (dataRow) { - const { name: originalName, owner: originalOwner } = dataRow; - dispatch({ field: 'editDetails', value: { name: originalName, owner: originalOwner } }); + const { name: originalName, provider: originalProvider } = dataRow; + dispatch({ field: 'editDetails', value: { name: originalName, provider: originalProvider } }); } }; return ( @@ -170,16 +168,16 @@ function EditApi(props) { )} variant='outlined' @@ -195,8 +193,8 @@ EditApi.defaultProps = { EditApi.propTypes = { updateList: PropTypes.func.isRequired, dataRow: PropTypes.shape({ - apiId: PropTypes.string.isRequired, - owner: PropTypes.string.isRequired, + id: PropTypes.string.isRequired, + provider: PropTypes.string.isRequired, name: PropTypes.string.isRequired, }).isRequired, icon: PropTypes.element, diff --git a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx index a4b9356ecbc..4ee40589b24 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx @@ -72,17 +72,17 @@ export default function ListApis() { const [totalApps, setTotalApps] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); const [page, setPage] = useState(0); - const [owner, setOwner] = useState(''); + const [provider, setProvider] = useState(''); /** * API call to get api list * @returns {Promise}. */ - function apiCall(pageNo, user = owner) { + function apiCall(pageNo, user = provider) { setLoading(true); const restApi = new API(); return restApi - .getApplicationList({ limit: rowsPerPage, offset: pageNo * rowsPerPage, user }) + .getApiList({ limit: rowsPerPage, offset: pageNo * rowsPerPage, user }) .then((result) => { setApiList(result.body.list); const { pagination: { total } } = result.body; @@ -129,7 +129,7 @@ export default function ListApis() { function clearSearch() { setPage(0); - setOwner(''); + setProvider(''); apiCall(page, '').then((result) => { setApiList(result); }); @@ -140,7 +140,7 @@ export default function ListApis() { if (newQuery === '') { clearSearch(); } else { - setOwner(newQuery); + setProvider(newQuery); } } @@ -166,22 +166,22 @@ export default function ListApis() { fullWidth id='search-label' label={intl.formatMessage({ - defaultMessage: 'Search Api by Api Owner', + defaultMessage: 'Search Api by Api Provider', id: 'Apis.Listing.Listing.apis.search.label', })} placeholder={intl.formatMessage({ - defaultMessage: 'Api Owner', + defaultMessage: 'Api Provider', id: 'Apis.Listing.Listing.search.placeholder', })} InputProps={{ disableUnderline: true, className: classes.searchInput, }} - value={owner} + value={provider} onChange={setQuery} // onKeyPress={this.handleSearchKeyPress} /> - { owner.length > 0 + { provider.length > 0 && ( , - title: 'Change Api Owner', + title: 'Change Api Provider', apiList, }} EditComponent={EditApi} diff --git a/portals/admin/src/main/webapp/source/src/app/data/api.js b/portals/admin/src/main/webapp/source/src/app/data/api.js index 305510cbe41..ae41917de76 100644 --- a/portals/admin/src/main/webapp/source/src/app/data/api.js +++ b/portals/admin/src/main/webapp/source/src/app/data/api.js @@ -420,6 +420,17 @@ class API extends Resource { }); } + /** + * Get a list of apis from all users + */ + getApiList(params) { + return this.client.then((client) => { + return client.apis['APIs'].getAllAPIs( + params, this._requestMetaData(), + ); + }); + } + /** * Get Subscription Throttling Policies */ @@ -445,6 +456,18 @@ class API extends Resource { }); } + /** + * Update an api's owner + */ + updateApiProvider(apiId, provider) { + return this.client.then((client) => { + return client.apis["Api Provider Change"].providerProviderNameApisApiIdPut( + { providerName: provider, apiId: apiId }, + this._requestMetaData(), + ); + }); + } + /** * Get a list of available Gateway Environments */