Skip to content

Commit

Permalink
Merge pull request #733 from RakhithaRR/disable-sub-validation-final
Browse files Browse the repository at this point in the history
Support subscription validation disabling for OAuth tokens
  • Loading branch information
RakhithaRR committed Sep 19, 2024
2 parents 5e9aadd + c4b7fb2 commit d6e3b5b
Show file tree
Hide file tree
Showing 22 changed files with 882 additions and 386 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Link from '@mui/material/Link';
import Configurations from 'Config';
import Delete from 'AppComponents/Throttling/Subscription/Delete';
import API from 'AppData/api';
import CONSTS from 'AppData/Constants';
import EditIcon from '@mui/icons-material/Edit';
import { Link as RouterLink } from 'react-router-dom';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -290,6 +291,7 @@ export default function ListSubscriptionThrottlingPolicies() {
});

subscriptionThrottlingvalues = subscriptionPolicies
.filter((policy) => !policy.policyName.includes(CONSTS.DEFAULT_SUBSCRIPTIONLESS_PLAN))
.map(Object.values);
return (subscriptionThrottlingvalues);
}).catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const CONSTS = {
'apim:scope_manage', 'openid', 'apim:admin_settings', 'apim:tenantInfo', 'apim:api_provider_change',
],
},
DEFAULT_SUBSCRIPTIONLESS_PLAN: 'DefaultSubscriptionless',
DEFAULT_ASYNC_SUBSCRIPTIONLESS_PLAN: 'AsyncDefaultSubscriptionless',
};

export default CONSTS;
4 changes: 4 additions & 0 deletions portals/devportal/src/main/webapp/site/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"Apis.Details.ApiConsole.SelectAppPanel.environment.show.more.subscription.URLs": "Subscription Gateway URLs",
"Apis.Details.ApiConsole.SelectAppPanel.production.radio": "Production",
"Apis.Details.ApiConsole.SelectAppPanel.sandbox.radio": "Sandbox",
"Apis.Details.ApiConsole.SelectAppPanel.select.available.application": "Available applications",
"Apis.Details.ApiConsole.SelectAppPanel.select.key.type.heading": "Key Type",
"Apis.Details.ApiConsole.SelectAppPanel.select.subscribed.application": "Subscribed applications",
"Apis.Details.ApiConsole.TryOutController.default.km.msg.one": "The Resident Key Manager is selected for try out console.",
Expand Down Expand Up @@ -284,6 +285,8 @@
"Apis.Details.Overview.list.version": "Version",
"Apis.Details.Overview.select.env.error": "Error Selecting Environment",
"Apis.Details.Overview.source": "Source",
"Apis.Details.Overview.subscriptions.not.required": "No subscriptions required",
"Apis.Details.Overview.subscriptions.not.required.content": "Subscriptions are not required for this API. You can consume this without subscribing to it.",
"Apis.Details.Overview.subscriptions.title": "Subscriptions",
"Apis.Details.Overview.tags.title": "Tags",
"Apis.Details.PubTopic.copied": "Copied",
Expand Down Expand Up @@ -422,6 +425,7 @@
"Applications.Details.SubscriptionTableData.delete.subscription.confirmation.dialog.title": "Confirm",
"Applications.Details.SubscriptionTableData.delete.text": "Delete",
"Applications.Details.SubscriptionTableData.edit.text": "Edit",
"Applications.Details.SubscriptionTableData.policy.default.tooltip": "This is the default subscription policy used when subscription validation was disabled.",
"Applications.Details.SubscriptionTableData.update": "Update",
"Applications.Details.SubscriptionTableData.update.business.plan": "Current Business Plan :",
"Applications.Details.SubscriptionTableData.update.business.plan.name": "Business Plan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import Social from 'AppComponents/Apis/Details/Social/Social';
import ResourceNotFound from 'AppComponents/Base/Errors/ResourceNotFound';
import AuthManager from 'AppData/AuthManager';
import Alert from 'AppComponents/Shared/Alert';
import InlineMessage from 'AppComponents/Shared/InlineMessage';
import Progress from 'AppComponents/Shared/Progress';
import API from 'AppData/api';
import CONSTANTS from 'AppData/Constants';
import View from 'AppComponents/Apis/Details/Documents/View';
import SolaceEndpoints from './SolaceEndpoints';
import Environments from './Environments';
Expand Down Expand Up @@ -240,6 +242,9 @@ function Overview() {
return filteredApiPolicies && filteredApiPolicies.length > 0;
};

const isSubValidationDisabled = api.tiers && api.tiers.length === 1
&& api.tiers[0].tierName.includes(CONSTANTS.DEFAULT_SUBSCRIPTIONLESS_PLAN);

const updateSelectedEndpoint = (e) => {
const selectedEnvName = e.target.value;
const filteredEndpoints = api.endpointURLs.filter((ep) => ep.environmentName === selectedEnvName);
Expand Down Expand Up @@ -531,7 +536,28 @@ function Overview() {
</MUILink>
)}
</Box>
{api.gatewayVendor === 'wso2' && allPolicies && allPolicies.length > 0 && (
{isSubValidationDisabled && (
<Box mt={2} ml={1} pr={6}>
<InlineMessage
type='info'
title={(
<FormattedMessage
id='Apis.Details.Overview.subscriptions.not.required'
defaultMessage='No subscriptions required'
/>
)}
>
<Typography component='p'>
<FormattedMessage
id='Apis.Details.Overview.subscriptions.not.required.content'
defaultMessage='Subscriptions are not required for this API.
You can consume this without subscribing to it.'
/>
</Typography>
</InlineMessage>
</Box>
)}
{api.gatewayVendor === 'wso2' && allPolicies && allPolicies.length > 0 && !isSubValidationDisabled && (
<>
<Box mt={6}>
<Typography variant='subtitle2' component='h3' className={classes.sectionTitle}>
Expand All @@ -551,36 +577,38 @@ function Overview() {
textAlign='center'
>
{allPolicies && allPolicies.map((tier) => (
<Card className={classes.cardRoot} key={tier.name}>
<CardContent>
<Typography className={classes.cardMainTitle} color='textSecondary' gutterBottom>
{tier.name}
</Typography>
<Box mt={2}>
<Typography className={classes.requestCount} color='textSecondary'>
{tier.requestCount === 2147483647 ? 'Unlimited' : tier.requestCount}
tier.name.includes(CONSTANTS.DEFAULT_SUBSCRIPTIONLESS_PLAN) ? null : (
<Card className={classes.cardRoot} key={tier.name}>
<CardContent>
<Typography className={classes.cardMainTitle} color='textSecondary' gutterBottom>
{tier.name}
</Typography>
</Box>
<Box>
<Typography className={classes.requestUnit} color='textSecondary'>
<FormattedMessage
id='Apis.Details.Overview.business.plans.requests.unit'
defaultMessage='Requests/{timeUnit}'
values={{
timeUnit: tier.timeUnit in subscriptionTimeUnits
? subscriptionTimeUnits[tier.timeUnit]
: tier.timeUnit,
}}
/>
</Typography>
</Box>
</CardContent>
</Card>
<Box mt={2}>
<Typography className={classes.requestCount} color='textSecondary'>
{tier.requestCount === 2147483647 ? 'Unlimited' : tier.requestCount}
</Typography>
</Box>
<Box>
<Typography className={classes.requestUnit} color='textSecondary'>
<FormattedMessage
id='Apis.Details.Overview.business.plans.requests.unit'
defaultMessage='Requests/{timeUnit}'
values={{
timeUnit: tier.timeUnit in subscriptionTimeUnits
? subscriptionTimeUnits[tier.timeUnit]
: tier.timeUnit,
}}
/>
</Typography>
</Box>
</CardContent>
</Card>
)
))}
</Box>
</>
)}
{(showCredentials && subscribedApplications.length > 0) && (
{(showCredentials && subscribedApplications.length > 0) && !isSubValidationDisabled && (
<>
<Box mt={6}>
<Typography variant='subtitle2' component='h3' className={classes.sectionTitle}>
Expand Down Expand Up @@ -683,9 +711,15 @@ function Overview() {
defaultMessage='Subscriptions'
/>
</Typography>
<Typography variant='body2'>
{api.subscriptions || 0}
</Typography>
{ !isSubValidationDisabled ? (
<Typography variant='body2'>
{api.subscriptions || 0}
</Typography>
) : (
<Typography variant='body2'>
N/A
</Typography>
)}
</Box>
<Box mt={2} mb={1}>
<Typography variant='subtitle2' component='h3' className={classes.sectionTitle}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ class DetailsLegacy extends React.Component {
const pageUrl = new URL(window.location);
const isWidget = pageUrl.searchParams.get('widget');
const isAsyncApi = this.isAsyncAPI(api);
const isSubValidationDisabled = api && api.tiers && api.tiers.length === 1
&& api.tiers[0].tierName.includes(CONSTANTS.DEFAULT_SUBSCRIPTIONLESS_PLAN);

return api ? (
<Root>
Expand Down Expand Up @@ -537,7 +539,7 @@ class DetailsLegacy extends React.Component {
open={open}
id='left-menu-overview'
/>
{user && showCredentials && (
{user && showCredentials && !isSubValidationDisabled && (
<>

<LeftMenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import PropTypes from 'prop-types';
import MUIDataTable from 'mui-datatables';
import { injectIntl } from 'react-intl';
import API from 'AppData/api';
import CONSTANTS from 'AppData/Constants';
import NoApi from 'AppComponents/Apis/Listing/NoApi';
import Loading from 'AppComponents/Base/Loading/Loading';
import Alert from 'AppComponents/Shared/Alert';
Expand Down Expand Up @@ -175,9 +176,13 @@ class APICardView extends React.Component {
* @memberof APICardView
*/
updateUnsubscribedAPIsList(list) {
const listLocal = list;
const subscribedIds = this.getIdsOfSubscribedEntities();
const listLocal = list.filter((api) => !(api.throttlingPolicies.length === 1
&& api.throttlingPolicies[0].includes(CONSTANTS.DEFAULT_SUBSCRIPTIONLESS_PLAN)));
for (let i = 0; i < listLocal.length; i++) {
const policyList = listLocal[i].throttlingPolicies
.filter((policy) => !policy.includes(CONSTANTS.DEFAULT_SUBSCRIPTIONLESS_PLAN));
listLocal[i].throttlingPolicies = policyList;
if (!((!subscribedIds.includes(listLocal[i].id) && !listLocal[i].advertiseInfo.advertised)
&& listLocal[i].isSubscriptionAvailable)) {
listLocal[i].throttlingPolicies = null;
Expand Down
Loading

0 comments on commit d6e3b5b

Please sign in to comment.