Skip to content

Commit

Permalink
Fixed proper L0 space agent selection in recursive license assignment (
Browse files Browse the repository at this point in the history
…#4708)

* Fixed proper L0 account agent selection in recursive license assignment

* provide root space agent for sub-sub space
  • Loading branch information
valentinyanakiev authored and ccanos committed Nov 18, 2024
1 parent aaa12c8 commit 38ee287
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/domain/common/license/license.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class LicenseService {
e => e.type === childEntitlement.type
);
if (!parentEntitlement) {
throw new RelationshipNotFoundException(
throw new EntityNotFoundException(
`Parent entitlement not found: ${childEntitlement.type}`,
LogContext.LICENSE
);
Expand All @@ -194,7 +194,7 @@ export class LicenseService {
license: ILicense | undefined
): ILicenseEntitlement[] | never {
if (!license) {
throw new RelationshipNotFoundException(
throw new EntityNotFoundException(
'Unable to load Entitlements for License',
LogContext.LICENSE
);
Expand Down
16 changes: 13 additions & 3 deletions src/domain/space/space/space.service.license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export class SpaceLicenseService {
@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
) {}

async applyLicensePolicy(spaceID: string): Promise<ILicense[]> {
async applyLicensePolicy(
spaceID: string,
agent?: IAgent
): Promise<ILicense[]> {
const space = await this.spaceService.getSpaceOrFail(spaceID, {
relations: {
agent: {
Expand Down Expand Up @@ -59,8 +62,12 @@ export class SpaceLicenseService {

// Ensure always applying from a clean state
space.license = this.licenseService.reset(space.license);
const rootLevelSpaceAgent = agent ?? space.agent;

space.license = await this.extendLicensePolicy(space.license, space.agent);
space.license = await this.extendLicensePolicy(
space.license,
rootLevelSpaceAgent
);

updatedLicenses.push(space.license);

Expand All @@ -78,7 +85,10 @@ export class SpaceLicenseService {
updatedLicenses.push(...collaborationLicenses);

for (const subspace of space.subspaces) {
const subspaceLicenses = await this.applyLicensePolicy(subspace.id);
const subspaceLicenses = await this.applyLicensePolicy(
subspace.id,
rootLevelSpaceAgent
);
updatedLicenses.push(...subspaceLicenses);
}

Expand Down

0 comments on commit 38ee287

Please sign in to comment.