mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
5 changed files with 97 additions and 0 deletions
@ -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(); |
||||
}); |
||||
}); |
@ -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' }; |
||||
} |
||||
} |
@ -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 {} |
@ -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(); |
||||
}); |
||||
}); |
@ -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…
Reference in new issue