• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / server / #7980

11 Aug 2024 06:30AM UTC coverage: 13.774%. First build
#7980

Pull #4388

travis-ci

Pull Request #4388: Feature account-spaces: Direct linkage to account for user + organization

79 of 4128 branches covered (1.91%)

Branch coverage included in aggregate %.

4 of 34 new or added lines in 7 files covered. (11.76%)

1914 of 10341 relevant lines covered (18.51%)

3.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.17
/src/domain/space/account.host/account.host.service.ts
1
import { Injectable, Inject, LoggerService } from '@nestjs/common';
29✔
2
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
3
import { IAccount } from '../account/account.interface';
29✔
4
import { AgentService } from '@domain/agent/agent/agent.service';
29✔
5
import { ILicensePlan } from '@platform/licensing/credential-based/license-plan/license.plan.interface';
6
import { LicenseIssuerService } from '@platform/licensing/credential-based/license-credential-issuer/license.issuer.service';
29✔
7
import { Account } from '../account/account.entity';
8
import { AuthorizationPolicy } from '@domain/common/authorization-policy/authorization.policy.entity';
9
import { StorageAggregatorService } from '@domain/storage/storage-aggregator/storage.aggregator.service';
10
import { InjectRepository } from '@nestjs/typeorm';
11
import { Repository } from 'typeorm';
12
import { StorageAggregatorType } from '@common/enums/storage.aggregator.type';
29✔
13
import { AgentType } from '@common/enums/agent.type';
29✔
14
import { AuthorizationPolicyType } from '@common/enums/authorization.policy.type';
29✔
15
import { AccountType } from '@common/enums/account.type';
16
import { IAgent } from '@domain/agent/agent/agent.interface';
29✔
17
import { LicenseService } from '@domain/common/license/license.service';
29✔
18
import { LicenseType } from '@common/enums/license.type';
29✔
19
import { LicenseEntitlementType } from '@common/enums/license.entitlement.type';
29✔
20
import { LicenseEntitlementDataType } from '@common/enums/license.entitlement.data.type';
21
import { LicensingFrameworkService } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.service';
29✔
22
import { IAccountLicensePlan } from '../account.license.plan/account.license.plan.interface';
29✔
23
import { DEFAULT_BASELINE_ACCOUNT_LICENSE_PLAN } from '../account/constants';
29✔
24

29✔
25
@Injectable()
29✔
26
export class AccountHostService {
27
  constructor(
28
    private agentService: AgentService,
29✔
29
    private licenseIssuerService: LicenseIssuerService,
30
    private licensingFrameworkService: LicensingFrameworkService,
×
31
    private licenseService: LicenseService,
×
32
    private storageAggregatorService: StorageAggregatorService,
×
33
    @InjectRepository(Account)
×
34
    private accountRepository: Repository<Account>,
35
    @Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
×
36
  ) {}
37

×
38
  async createAccount(accountType: AccountType): Promise<IAccount> {
×
39
    const account: IAccount = new Account();
40
    account.type = accountType;
41
    account.authorization = new AuthorizationPolicy(
42
      AuthorizationPolicyType.ACCOUNT
×
43
    );
×
44
    account.baselineLicensePlan = this.getBaselineAccountLicensePlan();
×
45
    account.storageAggregator =
46
      await this.storageAggregatorService.createStorageAggregator(
47
        StorageAggregatorType.ACCOUNT
48
      );
49

×
50
    account.agent = await this.agentService.createAgent({
51
      type: AgentType.ACCOUNT,
52
    });
53

×
54
    account.license = this.licenseService.createLicense({
55
      type: LicenseType.ACCOUNT,
×
56
      entitlements: [
57
        {
×
58
          type: LicenseEntitlementType.ACCOUNT_SPACE_FREE,
59
          dataType: LicenseEntitlementDataType.LIMIT,
60
          limit: 0,
61
          enabled: false,
62
        },
63
        {
NEW
64
          type: LicenseEntitlementType.ACCOUNT_SPACE_PLUS,
×
NEW
65
          dataType: LicenseEntitlementDataType.LIMIT,
×
NEW
66
          limit: 0,
×
67
          enabled: false,
68
        },
69
        {
NEW
70
          type: LicenseEntitlementType.ACCOUNT_SPACE_PREMIUM,
×
71
          dataType: LicenseEntitlementDataType.LIMIT,
72
          limit: 0,
73
          enabled: false,
74
        },
75
        {
76
          type: LicenseEntitlementType.ACCOUNT_VIRTUAL_CONTRIBUTOR,
NEW
77
          dataType: LicenseEntitlementDataType.LIMIT,
×
NEW
78
          limit: 0,
×
79
          enabled: false,
80
        },
81
        {
82
          type: LicenseEntitlementType.ACCOUNT_INNOVATION_HUB,
NEW
83
          dataType: LicenseEntitlementDataType.LIMIT,
×
84
          limit: 0,
85
          enabled: false,
86
        },
87
        {
88
          type: LicenseEntitlementType.ACCOUNT_INNOVATION_PACK,
89
          dataType: LicenseEntitlementDataType.LIMIT,
90
          limit: 0,
×
91
          enabled: false,
×
92
        },
93
      ],
94
    });
95

96
    return await this.accountRepository.save(account);
97
  }
×
98

×
99
  private getBaselineAccountLicensePlan(): IAccountLicensePlan {
×
100
    return DEFAULT_BASELINE_ACCOUNT_LICENSE_PLAN;
101
  }
102

×
103
  public async assignLicensePlansToSpace(
×
104
    spaceAgent: IAgent,
×
105
    spaceID: string,
×
106
    type: AccountType,
×
107
    licensePlanID?: string
108
  ): Promise<IAgent> {
109
    const licensingFramework =
×
110
      await this.licensingFrameworkService.getDefaultLicensingOrFail();
111
    const licensePlansToAssign: ILicensePlan[] = [];
112
    const licensePlans =
113
      await this.licensingFrameworkService.getLicensePlansOrFail(
×
114
        licensingFramework.id
×
115
      );
×
116
    for (const plan of licensePlans) {
117
      if (type === AccountType.USER && plan.assignToNewUserAccounts) {
118
        licensePlansToAssign.push(plan);
119
      } else if (
120
        type === AccountType.ORGANIZATION &&
121
        plan.assignToNewOrganizationAccounts
122
      ) {
123
        licensePlansToAssign.push(plan);
NEW
124
      }
×
125
    }
126
    if (licensePlanID) {
127
      const licensePlanAlreadyAssigned = licensePlansToAssign.find(
128
        plan => plan.id === licensePlanID
NEW
129
      );
×
NEW
130
      if (!licensePlanAlreadyAssigned) {
×
131
        const additionalPlan =
NEW
132
          await this.licensingFrameworkService.getLicensePlanOrFail(
×
133
            licensingFramework.id,
134
            licensePlanID
135
          );
136

NEW
137
        licensePlansToAssign.push(additionalPlan);
×
NEW
138
      }
×
139
    }
140

NEW
141
    for (const licensePlan of licensePlansToAssign) {
×
142
      await this.licenseIssuerService.assignLicensePlan(
143
        spaceAgent,
144
        licensePlan,
145
        spaceID
146
      );
147
    }
NEW
148
    return await this.agentService.getAgentOrFail(spaceAgent.id);
×
149
  }
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc