Browse Source

feat: org license apis

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
4003468d33
  1. 20
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.spec.ts
  2. 28
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts
  3. 9
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.module.ts
  4. 18
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.service.spec.ts
  5. 22
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.service.ts

20
packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.spec.ts

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { OrgLcenseController } from './org-lcense.controller';
import { OrgLcenseService } from './org-lcense.service';
describe('OrgLcenseController', () => {
let controller: OrgLcenseController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [OrgLcenseController],
providers: [OrgLcenseService],
}).compile();
controller = module.get<OrgLcenseController>(OrgLcenseController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

28
packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts

@ -0,0 +1,28 @@
import { Controller, Get, Post } from '@nestjs/common';
import { OrgUserRoles } from 'nocodb-sdk';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { OrgLcenseService } from './org-lcense.service';
@Controller('org-lcense')
export class OrgLcenseController {
constructor(private readonly orgLcenseService: OrgLcenseService) {}
@Get('/api/v1/license')
@Acl('licenseGet', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
})
async licenseGet(_req, res) {
return await this.orgLcenseService.licenseGet();
}
@Post('/api/v1/license')
@Acl('licenseSet', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
})
async licenseSet(req, res) {
await this.orgLcenseService.licenseSet({ key: req.body.key });
return { msg: 'The license key has been saved' };
}
}

9
packages/nocodb-nest/src/modules/org-lcense/org-lcense.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { OrgLcenseService } from './org-lcense.service';
import { OrgLcenseController } from './org-lcense.controller';
@Module({
controllers: [OrgLcenseController],
providers: [OrgLcenseService]
})
export class OrgLcenseModule {}

18
packages/nocodb-nest/src/modules/org-lcense/org-lcense.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { OrgLcenseService } from './org-lcense.service';
describe('OrgLcenseService', () => {
let service: OrgLcenseService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [OrgLcenseService],
}).compile();
service = module.get<OrgLcenseService>(OrgLcenseService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

22
packages/nocodb-nest/src/modules/org-lcense/org-lcense.service.ts

@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { NC_LICENSE_KEY } from '../../constants';
import { validatePayload } from '../../helpers';
import { Store } from '../../models';
import Noco from '../../Noco';
@Injectable()
export class OrgLcenseService {
async licenseGet() {
const license = await Store.get(NC_LICENSE_KEY);
return { key: license?.value };
}
async licenseSet(param: { key: string }) {
validatePayload('swagger.json#/components/schemas/LicenseReq', param);
await Store.saveOrUpdate({ value: param.key, key: NC_LICENSE_KEY });
await Noco.loadEEState();
return true;
}
}
Loading…
Cancel
Save