2023-02-15 01:52:11 +00:00
|
|
|
import { Context } from 'support/commands';
|
2024-08-22 07:48:36 +00:00
|
|
|
import { ensureItemDoesntExist, ensureItemExists } from './ensure';
|
2022-10-11 13:29:23 +00:00
|
|
|
import { getOrgUnderTest } from './orgs';
|
2024-08-22 07:48:36 +00:00
|
|
|
import { API, Entity } from './types';
|
2022-10-11 13:29:23 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureProjectGrantExists(ctx: Context, foreignOrgId: string, foreignProjectId: string) {
|
|
|
|
return getOrgUnderTest(ctx).then((orgUnderTest) => {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemExists(
|
2023-02-15 01:52:11 +00:00
|
|
|
ctx.api,
|
|
|
|
`${ctx.api.mgmtBaseURL}/projectgrants/_search`,
|
2022-10-11 13:29:23 +00:00
|
|
|
(grant: any) => grant.grantedOrgId == orgUnderTest && grant.projectId == foreignProjectId,
|
2023-02-15 01:52:11 +00:00
|
|
|
`${ctx.api.mgmtBaseURL}/projects/${foreignProjectId}/grants`,
|
2022-10-11 13:29:23 +00:00
|
|
|
{ granted_org_id: orgUnderTest },
|
|
|
|
foreignOrgId,
|
|
|
|
'grantId',
|
|
|
|
'grantId',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2024-08-22 07:48:36 +00:00
|
|
|
|
|
|
|
export function ensureProjectGrantDoesntExist(ctx: Context, projectId: number, foreignOrgId: string) {
|
|
|
|
return getOrgUnderTest(ctx).then((orgUnderTest) => {
|
|
|
|
console.log('removing grant to foreignOrgId', foreignOrgId, 'in orgUnderTest', orgUnderTest, 'projectId', projectId);
|
|
|
|
return ensureItemDoesntExist(
|
|
|
|
ctx.api,
|
|
|
|
`${ctx.api.mgmtBaseURL}/projectgrants/_search`,
|
|
|
|
(grant: any) => grant.grantedOrgId == foreignOrgId && grant.projectId == projectId,
|
|
|
|
(grant: any) => `${ctx.api.mgmtBaseURL}/projects/${projectId}/grants/${grant.grantId}`,
|
|
|
|
orgUnderTest.toString(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|