Skip to content

Commit 4eeb71f

Browse files
committed
Add validations to organization feature
Add validations to check whether the logged in user has an organization and organizations are available in the environment
1 parent 63619e6 commit 4eeb71f

File tree

3 files changed

+69
-26
lines changed

3 files changed

+69
-26
lines changed

portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/ShareAPI/ShareAPI.jsx

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const classes = {
4747
helpIcon: `${PREFIX}-helpIcon`,
4848
htmlTooltip: `${PREFIX}-htmlTooltip`,
4949
buttonSection: `${PREFIX}-buttonSection`,
50-
emptyBox: `${PREFIX}-emptyBox`
50+
emptyBox: `${PREFIX}-emptyBox`,
51+
shareAPIPaper: `${PREFIX}-shareAPIPaper`
5152
}
5253

53-
5454
const Root = styled('div')((
5555
{
5656
theme
@@ -62,6 +62,11 @@ const Root = styled('div')((
6262

6363
[`& .${classes.emptyBox}`]: {
6464
marginTop: theme.spacing(2),
65+
},
66+
67+
[`& .${classes.shareAPIPaper}`]: {
68+
padding: theme.spacing(2),
69+
marginTop: theme.spacing(2),
6570
}
6671
}));
6772

@@ -175,28 +180,44 @@ function ShareAPI(props) {
175180
defaultMessage='Share API'
176181
/>
177182
</Typography>
178-
<SharedOrganizations
179-
api={api}
180-
organizations={organizations}
181-
visibleOrganizations={visibleOrganizations}
182-
setVisibleOrganizations = {setVisibleOrganizations}
183-
selectionMode = {selectionMode}
184-
setSelectionMode = {setSelectionMode}
185-
/>
186-
{(api.gatewayVendor === 'wso2') &&
187-
(
188-
<>
189-
{organizations?.list?.length > 0 && selectionMode !== "none" &&
190-
<OrganizationSubscriptionPoliciesManage
191-
api={api}
192-
organizations={organizations.list}
193-
visibleOrganizations={visibleOrganizations}
194-
organizationPolicies={organizationPolicies}
195-
setOrganizationPolicies={setOrganizationPolicies}
196-
selectionMode = {selectionMode}
197-
/>
198-
}
199-
</>
183+
{organizations?.list?.length === 0 ? (
184+
<Paper className={classes.shareAPIPaper}>
185+
<Box display='flex' alignItems='center' >
186+
<FormLabel component='legend' style={{ marginTop: 8, marginBottom: 8}}>
187+
<FormattedMessage
188+
id='Apis.Details.Configuration.components.Share.API.no.organizations'
189+
defaultMessage='No organizations are currently registered under your current organization to share the API.'
190+
/>
191+
</FormLabel>
192+
</Box>
193+
</Paper>
194+
) : (
195+
<div>
196+
<SharedOrganizations
197+
api={api}
198+
organizations={organizations}
199+
visibleOrganizations={visibleOrganizations}
200+
setVisibleOrganizations = {setVisibleOrganizations}
201+
selectionMode = {selectionMode}
202+
setSelectionMode = {setSelectionMode}
203+
subValidationDisablingAllowed={settings.allowSubscriptionValidationDisabling}
204+
/>
205+
{(api.gatewayVendor === 'wso2') &&
206+
(
207+
<>
208+
{organizations?.list?.length > 0 && selectionMode !== "none" &&
209+
<OrganizationSubscriptionPoliciesManage
210+
api={api}
211+
organizations={organizations.list}
212+
visibleOrganizations={visibleOrganizations}
213+
organizationPolicies={organizationPolicies}
214+
setOrganizationPolicies={setOrganizationPolicies}
215+
selectionMode = {selectionMode}
216+
/>
217+
}
218+
</>
219+
)}
220+
</div>
200221
)}
201222
{(api.gatewayVendor === 'wso2') && (
202223
<Grid
@@ -211,7 +232,7 @@ function ShareAPI(props) {
211232
type='submit'
212233
variant='contained'
213234
color='primary'
214-
disabled={updateInProgress || api.isRevision
235+
disabled={organizations?.list?.length === 0 || updateInProgress || api.isRevision
215236
|| isRestricted(['apim:api_create', 'apim:api_publish'], api)}
216237
onClick={() => handleShareAPISave()}
217238
id='share-api-save-btn'

portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/components/APIDetailsTopMenu.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ const APIDetailsTopMenu = (props) => {
186186
}),
187187
};
188188

189+
const [userOrg, setUserOrg] = useState(null);
190+
191+
useEffect(() => {
192+
new API()
193+
.getUserOrganizationInfo()
194+
.then((result) => {
195+
setUserOrg(result.body.organizationId);
196+
})
197+
.catch((error) => {
198+
throw error;
199+
});
200+
}, []);
201+
189202
/**
190203
* The component for advanced endpoint configurations.
191204
* @param {string} name The name of the
@@ -467,7 +480,7 @@ const APIDetailsTopMenu = (props) => {
467480
)}
468481
{/* Page error banner */}
469482
{/* end of Page error banner */}
470-
{api.apiType !== API.CONSTS.APIProduct && isVisibleInStore
483+
{api.apiType !== API.CONSTS.APIProduct && isVisibleInStore && userOrg
471484
? <>
472485
<ShareButton buttonClass={classes.viewInStoreLauncher}
473486
api={api} isAPIProduct={isAPIProduct} />

portals/publisher/src/main/webapp/source/src/app/data/api.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,15 @@ class API extends Resource {
14571457
});
14581458
}
14591459

1460+
/**
1461+
* Get user organization information
1462+
*/
1463+
getUserOrganizationInfo() {
1464+
return this.client.then((client) => {
1465+
return client.apis.Users.organizationInformation(this._requestMetaData());
1466+
});
1467+
}
1468+
14601469
addDocument(api_id, body) {
14611470
const promised_addDocument = this.client.then(client => {
14621471
const payload = {

0 commit comments

Comments
 (0)