Skip to content

Commit

Permalink
Merge pull request #4731 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Entitlements
  • Loading branch information
valentinyanakiev authored Nov 26, 2024
2 parents 0b87e63 + 2bbe672 commit 3030ba4
Show file tree
Hide file tree
Showing 136 changed files with 3,516 additions and 842 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-server",
"version": "0.95.4",
"version": "0.96.0",
"description": "Alkemio server, responsible for managing the shared Alkemio platform",
"author": "Alkemio Foundation",
"private": false,
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { PlatformHubModule } from '@platform/platform.hub/platform.hub.module';
import { AdminContributorsModule } from '@platform/admin/avatars/admin.avatar.module';
import { InputCreatorModule } from '@services/api/input-creator/input.creator.module';
import { TemplateApplierModule } from '@domain/template/template-applier/template.applier.module';
import { LoaderCreatorModule } from '@core/dataloader/creators/loader.creator.module';
import { Cipher, EncryptionModule } from '@hedger/nestjs-encryption';
import { AdminUsersModule } from '@platform/admin/users/admin.users.module';

Expand Down Expand Up @@ -247,6 +248,7 @@ import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
};
},
}),
LoaderCreatorModule,
ScalarsModule,
AuthenticationModule,
AuthorizationModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export const CREDENTIAL_RULE_TYPES_SPACE_COMMUNITY_APPLY_GLOBAL_REGISTERED =
'credentialRuleTypes-spaceCommunityApplyGlobalRegistered';
export const CREDENTIAL_RULE_TYPES_SPACE_COMMUNITY_JOIN_GLOBAL_REGISTERED =
'credentialRuleTypes-spaceCommunityJoinGlobalRegistered';
export const CREDENTIAL_RULE_TYPES_ACCESS_VIRTUAL_CONTRIBUTORS =
'credentialRuleTypes-accessVirtualContributors';
export const CREDENTIAL_RULE_TYPES_CALLOUT_SAVE_AS_TEMPLATE =
'credentialRuleTypes-calloutSaveAsTemplate';
export const CREDENTIAL_RULE_TYPES_CALLOUT_UPDATE_PUBLISHER_ADMINS =
'credentialRuleTypes-calloutUpdatePublisherGlobalAdmins';
export const CREDENTIAL_RULE_TYPES_COMMUNITY_ADD_MEMBERS =
Expand Down
2 changes: 0 additions & 2 deletions src/common/constants/authorization/policy.rule.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export const POLICY_RULE_COLLABORATION_CREATE =
'policyRule-collaborationCreate';
export const POLICY_RULE_COLLABORATION_WHITEBOARD_CREATE =
'policyRule-collaborationWhiteboardCreate';
export const POLICY_RULE_COLLABORATION_WHITEBOARD_CONTRIBUTORS_CREATE =
'policyRule-collaborationWhiteboardContributorsCreate';
export const POLICY_RULE_STORAGE_BUCKET_UPDATER_FILE_UPLOAD =
'policyRule-storageBucketUpdaterFileUpload';
export const POLICY_RULE_STORAGE_BUCKET_CONTRIBUTOR_FILE_UPLOAD =
Expand Down
2 changes: 2 additions & 0 deletions src/common/enums/alkemio.error.status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export enum AlkemioErrorStatus {
NOT_ENABLED = 'NOT_ENABLED',
USER_NOT_REGISTERED = 'USER_NOT_REGISTERED',
LICENSE_NOT_FOUND = 'LICENSE_NOT_FOUND',
LICENSE_ENTITLEMENT_NOT_AVAILABLE = 'LICENSE_ENTITLEMENT_NOT_AVAILABLE',
LICENSE_ENTITLEMENT_NOT_SUPPORTED = 'LICENSE_ENTITLEMENT_NOT_SUPPORTED',
MATRIX_ENTITY_NOT_FOUND_ERROR = 'MATRIX_ENTITY_NOT_FOUND_ERROR',
BOOTSTRAP_FAILED = 'BOOTSTRAP_FAILED',
NOTIFICATION_PAYLOAD_BUILDER_ERROR = 'NOTIFICATION_PAYLOAD_BUILDER_ERROR',
Expand Down
1 change: 1 addition & 0 deletions src/common/enums/authorization.policy.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export enum AuthorizationPolicyType {
LIBRARY = 'library',
IN_MEMORY = 'in-memory',
LICENSING = 'licensing',
LICENSE = 'license',
LICENSE_POLICY = 'license-policy',
UNKNOWN = 'unknown',
AI_PERSONA_SERVICE = 'ai-persona-service',
Expand Down
4 changes: 1 addition & 3 deletions src/common/enums/authorization.privilege.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum AuthorizationPrivilege {
GRANT = 'grant', // allow the issuing / revoking of credentials of the same type within a given scope
GRANT_GLOBAL_ADMINS = 'grant-global-admins',
AUTHORIZATION_RESET = 'authorization-reset',
LICENSE_RESET = 'license-reset',
PLATFORM_ADMIN = 'platform-admin', // To determine if the user should have access to the platform administration
CONTRIBUTE = 'contribute',
CREATE_CALLOUT = 'create-callout',
Expand All @@ -17,7 +18,6 @@ export enum AuthorizationPrivilege {
CREATE_MESSAGE_REPLY = 'create-message-reply',
CREATE_MESSAGE_REACTION = 'create-message-reaction',
CREATE_WHITEBOARD = 'create-whiteboard',
CREATE_WHITEBOARD_RT = 'create-whiteboard-rt',
CREATE_SPACE = 'create-space',
CREATE_SUBSPACE = 'create-subspace',
CREATE_ORGANIZATION = 'create-organization',
Expand All @@ -40,9 +40,7 @@ export enum AuthorizationPrivilege {
MOVE_POST = 'move-post',
MOVE_CONTRIBUTION = 'move-contribution',
ACCESS_INTERACTIVE_GUIDANCE = 'access-interactive-guidance',
ACCESS_VIRTUAL_CONTRIBUTOR = 'access-virtual-contributor',
UPDATE_CONTENT = 'update-content',
SAVE_AS_TEMPLATE = 'save-as-template',
TRANSFER_RESOURCE = 'transfer-resource',
}

Expand Down
10 changes: 10 additions & 0 deletions src/common/enums/license.entitlement.data.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicenseEntitlementDataType {
LIMIT = 'limit',
FLAG = 'flag',
}

registerEnumType(LicenseEntitlementDataType, {
name: 'LicenseEntitlementDataType',
});
20 changes: 20 additions & 0 deletions src/common/enums/license.entitlement.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicenseEntitlementType {
ACCOUNT_SPACE_FREE = 'account-space-free',
ACCOUNT_SPACE_PLUS = 'account-space-plus',
ACCOUNT_SPACE_PREMIUM = 'account-space-premium',
ACCOUNT_VIRTUAL_CONTRIBUTOR = 'account-virtual-contributor',
ACCOUNT_INNOVATION_PACK = 'account-innovation-pack',
ACCOUNT_INNOVATION_HUB = 'account-innovation-hub',
SPACE_FREE = 'space-free',
SPACE_PLUS = 'space-plus',
SPACE_PREMIUM = 'space-premium',
SPACE_FLAG_SAVE_AS_TEMPLATE = 'space-flag-save-as-template',
SPACE_FLAG_VIRTUAL_CONTRIBUTOR_ACCESS = 'space-flag-virtual-contributor-access',
SPACE_FLAG_WHITEBOARD_MULTI_USER = 'space-flag-whiteboard-multi-user',
}

registerEnumType(LicenseEntitlementType, {
name: 'LicenseEntitlementType',
});
15 changes: 0 additions & 15 deletions src/common/enums/license.privilege.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/common/enums/license.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicenseType {
ACCOUNT = 'account',
SPACE = 'space',
WHITEBOARD = 'whiteboard',
ROLESET = 'roleset',
COLLABORATION = 'collaboration',
}

registerEnumType(LicenseType, {
name: 'LicenseType',
});
4 changes: 2 additions & 2 deletions src/common/exceptions/forbidden.license.policy.exception.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AlkemioErrorStatus, LogContext } from '@common/enums';
import { BaseException } from './base.exception';
import { LicensePrivilege } from '@common/enums/license.privilege';
import { LicenseEntitlementType } from '@common/enums/license.entitlement.type';

export class ForbiddenLicensePolicyException extends BaseException {
constructor(
error: string,
public checkedPrivilege: LicensePrivilege,
public checkedEntitlement: LicenseEntitlementType,
public licensePolicyId: string,
public licenseId: string
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LogContext, AlkemioErrorStatus } from '@common/enums';
import { BaseException } from './base.exception';

export class LicenseEntitlementNotAvailableException extends BaseException {
constructor(error: string, context: LogContext, code?: AlkemioErrorStatus) {
super(
error,
context,
code ?? AlkemioErrorStatus.LICENSE_ENTITLEMENT_NOT_AVAILABLE
);
}
}
12 changes: 12 additions & 0 deletions src/common/exceptions/license.entitlement.not.supported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LogContext, AlkemioErrorStatus } from '@common/enums';
import { BaseException } from './base.exception';

export class LicenseEntitlementNotSupportedException extends BaseException {
constructor(error: string, context: LogContext, code?: AlkemioErrorStatus) {
super(
error,
context,
code ?? AlkemioErrorStatus.LICENSE_ENTITLEMENT_NOT_SUPPORTED
);
}
}
6 changes: 4 additions & 2 deletions src/core/bootstrap/bootstrap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ import { ContributorModule } from '@domain/community/contributor/contributor.mod
import { TemplatesSetModule } from '@domain/template/templates-set/templates.set.module';
import { TemplatesManagerModule } from '@domain/template/templates-manager/templates.manager.module';
import { TemplateDefaultModule } from '@domain/template/template-default/template.default.module';
import { LicensingModule } from '@platform/licensing/licensing.module';
import { LicenseModule } from '@domain/common/license/license.module';
import { LicensePlanModule } from '@platform/license-plan/license.plan.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';

@Module({
imports: [
AiServerModule,
AgentModule,
AuthorizationPolicyModule,
LicenseModule,
ContributorModule,
SpaceModule,
OrganizationModule,
Expand All @@ -43,7 +45,7 @@ import { LicensePlanModule } from '@platform/license-plan/license.plan.module';
TemplatesSetModule,
TemplatesManagerModule,
TemplateDefaultModule,
LicensingModule,
LicensingFrameworkModule,
LicensePlanModule,
],
providers: [BootstrapService],
Expand Down
21 changes: 17 additions & 4 deletions src/core/bootstrap/bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ import { bootstrapSpaceCallouts } from './platform-template-definitions/space/bo
import { bootstrapSpaceTutorialsInnovationFlowStates } from './platform-template-definitions/space-tutorials/bootstrap.space.tutorials.innovation.flow.states';
import { bootstrapSpaceTutorialsCalloutGroups } from './platform-template-definitions/space-tutorials/bootstrap.space.tutorials.callout.groups';
import { bootstrapSpaceTutorialsCallouts } from './platform-template-definitions/space-tutorials/bootstrap.space.tutorials.callouts';
import { LicensingService } from '@platform/licensing/licensing.service';
import { LicenseService } from '@domain/common/license/license.service';
import { AccountLicenseService } from '@domain/space/account/account.service.license';
import { LicensePlanService } from '@platform/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing-framework/licensing.framework.service';

@Injectable()
export class BootstrapService {
Expand Down Expand Up @@ -84,7 +86,9 @@ export class BootstrapService {
private templatesManagerService: TemplatesManagerService,
private templatesSetService: TemplatesSetService,
private templateDefaultService: TemplateDefaultService,
private licensingService: LicensingService,
private accountLicenseService: AccountLicenseService,
private licenseService: LicenseService,
private licensingFrameworkService: LicensingFrameworkService,
private licensePlanService: LicensePlanService
) {}

Expand Down Expand Up @@ -273,14 +277,15 @@ export class BootstrapService {

async createLicensePlans(licensePlansData: any[]) {
try {
const licensing = await this.licensingService.getDefaultLicensingOrFail();
const licensing =
await this.licensingFrameworkService.getDefaultLicensingOrFail();
for (const licensePlanData of licensePlansData) {
const planExists =
await this.licensePlanService.licensePlanByNameExists(
licensePlanData.name
);
if (!planExists) {
await this.licensingService.createLicensePlan({
await this.licensingFrameworkService.createLicensePlan({
...licensePlanData,
licensingID: licensing.id,
});
Expand Down Expand Up @@ -454,6 +459,10 @@ export class BootstrapService {
account
);
await this.authorizationPolicyService.saveAll(accountAuthorizations);

const accountEntitlements =
await this.accountLicenseService.applyLicensePolicy(account.id);
await this.licenseService.saveAll(accountEntitlements);
}
}

Expand Down Expand Up @@ -508,6 +517,10 @@ export class BootstrapService {
await this.spaceAuthorizationService.applyAuthorizationPolicy(space);
await this.authorizationPolicyService.saveAll(spaceAuthorizations);

const accountEntitlements =
await this.accountLicenseService.applyLicensePolicy(account.id);
await this.licenseService.saveAll(accountEntitlements);

return this.spaceService.getSpaceOrFail(space.id);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/dataloader/creators/loader.creators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './profile/profile.tagsets.loader.creator';
export * from './callout-framing/callout.framing.whiteboard.loader';

export * from './profile.loader.creator';
export * from './license.loader.creator';
export * from './preferences.loader.creator';
export * from './agent.loader.creator';
export * from './authorization.loader.creator';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { EntityManager } from 'typeorm';
import { Injectable } from '@nestjs/common';
import { InjectEntityManager } from '@nestjs/typeorm';
import { DataLoaderInitError } from '@common/exceptions/data-loader';
import { createTypedRelationDataLoader } from '../../utils';
import { DataLoaderCreator, DataLoaderCreatorOptions } from '../base';
import { ILicense } from '@domain/common/license/license.interface';
import { License } from '@domain/common/license/license.entity';

@Injectable()
export class LicenseLoaderCreator implements DataLoaderCreator<ILicense> {
constructor(@InjectEntityManager() private manager: EntityManager) {}

create(
options?: DataLoaderCreatorOptions<
ILicense,
{ id: string; license?: License }
>
) {
if (!options?.parentClassRef) {
throw new DataLoaderInitError(
`${this.constructor.name} requires the 'parentClassRef' to be provided.`
);
}

return createTypedRelationDataLoader(
this.manager,
options.parentClassRef,
{
license: true,
},
this.constructor.name,
options
);
}
}
Loading

0 comments on commit 3030ba4

Please sign in to comment.