Configuring access rights in the CRM Super Admin

This commit is contained in:
2026-09-20 11:24:14 +03:30
parent 04d37a9d12
commit 4a9fe0b07c
29 changed files with 1235 additions and 35 deletions
@@ -3,11 +3,18 @@ import { AuthModule } from '../auth/auth.module';
import { MembershipsModule } from '../memberships/memberships.module';
import { OrgRolesModule } from '../org-roles/org-roles.module';
import { PipelinesModule } from '../pipelines/pipelines.module';
import { BillingModule } from '../billing/billing.module';
import { OrganizationsController } from './organizations.controller';
import { OrganizationsService } from './organizations.service';
@Module({
imports: [AuthModule, MembershipsModule, OrgRolesModule, PipelinesModule],
imports: [
AuthModule,
MembershipsModule,
OrgRolesModule,
PipelinesModule,
BillingModule,
],
controllers: [OrganizationsController],
providers: [OrganizationsService],
})
@@ -15,6 +15,7 @@ import { isKnownCurrency } from '../common/currency';
import { MembershipsService } from '../memberships/memberships.service';
import { OrgRolesService } from '../org-roles/org-roles.service';
import { PipelinesService } from '../pipelines/pipelines.service';
import { BillingService } from '../billing/billing.service';
function slugify(input: string): string {
return (
@@ -34,6 +35,7 @@ export class OrganizationsService {
private readonly memberships: MembershipsService,
private readonly orgRoles: OrgRolesService,
private readonly pipelines: PipelinesService,
private readonly billing: BillingService,
) {}
async createForUser(
@@ -57,6 +59,8 @@ export class OrganizationsService {
throw new UnauthorizedException();
}
await this.billing.assertCanCreateOrganization(userId);
const baseSlug = slugify(name);
let slug = baseSlug;
let i = 1;
@@ -69,6 +73,7 @@ export class OrganizationsService {
name,
slug,
businessField,
enabledModules: this.billing.defaultModulesForNewOrg(),
},
});
await this.memberships.createMembership({
@@ -76,6 +81,7 @@ export class OrganizationsService {
organizationId: organization.id,
role: 'owner',
});
await this.billing.ensureTrialForOwner(userId);
await this.orgRoles.ensureDefaultRoles(organization.id);
await this.pipelines.ensureDefaultPipeline(organization.id);
return { id: organization.id };
@@ -219,6 +225,7 @@ export class OrganizationsService {
businessField: string | null;
baseCurrency: string;
enabledCurrencies: string[];
enabledModules?: string[];
exchangeRates: Array<{
currency: string;
rateToBase: Prisma.Decimal;
@@ -235,6 +242,7 @@ export class OrganizationsService {
: null,
baseCurrency: org.baseCurrency,
enabledCurrencies: org.enabledCurrencies,
enabledModules: this.billing.normalizeModules(org.enabledModules),
exchangeRates: org.exchangeRates.map((r) => ({
currency: r.currency,
rateToBase: Number(r.rateToBase),