Skip to content

Commit

Permalink
User validation and Api Version Column added
Browse files Browse the repository at this point in the history
  • Loading branch information
shnrndk committed Nov 28, 2023
1 parent e3cb8aa commit d57e2af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ApisTableContent extends Component {
<StyledTableCell align='left'>
{app.name}
</StyledTableCell>
<StyledTableCell align='left'>{app.version}</StyledTableCell>
<StyledTableCell align='left'>{app.provider}</StyledTableCell>
<StyledTableCell align='left'>
<EditApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ const apisTableHead = (props) => {
/>),
sorting: true,
},
{
id: 'version',
numeric: false,
disablePadding: true,
label: (<FormattedMessage
id='Apis.Listing.apiTableHead.version'
defaultMessage='Version'
/>),
sorting: true,
},
{
id: 'provider',
numeric: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,6 @@ function EditApi(props) {
dispatch({ field: e.target.name, value: e.target.value });
};

const validateProvider = () => {
let validationError = 'Something went wrong when validating user';

const apisWithSameName = apiList.filter(
(app) => app.name === name && app.provider === provider,
);

const promiseValidation = new Promise((resolve, reject) => {
if (apisWithSameName.length > 0) {
validationError = `${provider} already has an api with name: ${name}`;
reject(validationError);
}
const basicScope = 'apim:subscribe';
restApi.getUserScope(provider, basicScope)
.then(() => {
// This api returns 200 when only the $provider has the $basicScope.
resolve();
}).catch((error) => {
const { response } = error;
// 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 = `${provider} is not a valid Subscriber`;
}
}).finally(() => {
if (validationError) {
reject(validationError);
}
});
});

return promiseValidation;
};

const formSaveCallback = () => {
return restApi.updateApiProvider(dataRow.id, provider)
.then(() => {
Expand All @@ -120,12 +86,18 @@ function EditApi(props) {
);
})
.catch((error) => {
let validationError = 'Something went wrong when validating the user';
const { response } = error;
// This api returns 404 when the $provider is not found.

Check failure on line 91 in portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx

View workflow job for this annotation

GitHub Actions / build-product

Expected indentation of 16 spaces but found 20
// error codes: 901502, 901500 for user not found and scope not found

Check failure on line 92 in portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx

View workflow job for this annotation

GitHub Actions / build-product

Expected indentation of 16 spaces but found 20
if (response?.body?.code === 901502 || response?.body?.code === 901500) {

Check failure on line 93 in portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx

View workflow job for this annotation

GitHub Actions / build-product

Expected indentation of 16 spaces but found 20
validationError = `${provider} is not a valid User`;

Check failure on line 94 in portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx

View workflow job for this annotation

GitHub Actions / build-product

Expected indentation of 20 spaces but found 24
}

Check failure on line 95 in portals/admin/src/main/webapp/source/src/app/components/APISettings/EditApi.jsx

View workflow job for this annotation

GitHub Actions / build-product

Expected indentation of 16 spaces but found 20
if (response?.body?.code === 500) {
const notValidSubscriber = 'Error while updating providership to ' + provider;
throw notValidSubscriber;
const notValidUser = 'Error while updating the provider name to ' + provider;
throw notValidUser;
} else {
const updateError = 'Something went wrong when updating provider';
const updateError = validationError;
throw updateError;
}
})
Expand Down

0 comments on commit d57e2af

Please sign in to comment.