-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: space supports displaying the plan level * chore: update icons and table component * feat: add the PAYMENT_REQUIRED http code * feat: admin user & setting config * feat: usage limit * feat: add paste checker for usage * chore: db migration * feat: user limit for license * feat: admin settings * refactor: use generics as the type for the custom ssrApi * fix: type error * fix: setting for disallow signup * refactor: obtain the settings from the database instead of from cls
- Loading branch information
Showing
86 changed files
with
1,429 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
apps/nestjs-backend/src/event-emitter/events/space/collaborator.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Events } from '../event.enum'; | ||
|
||
export class CollaboratorCreateEvent { | ||
public readonly name = Events.COLLABORATOR_CREATE; | ||
|
||
constructor(public readonly spaceId: string) {} | ||
} | ||
|
||
export class CollaboratorDeleteEvent { | ||
public readonly name = Events.COLLABORATOR_DELETE; | ||
|
||
constructor(public readonly spaceId: string) {} | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/nestjs-backend/src/event-emitter/events/user/user.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Events } from '../event.enum'; | ||
|
||
export class UserSignUpEvent { | ||
public readonly name = Events.USER_SIGNUP; | ||
|
||
constructor(public readonly userId: string) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { CanActivate } from '@nestjs/common'; | ||
import { ForbiddenException, Injectable } from '@nestjs/common'; | ||
import { PrismaService } from '@teable/db-main-prisma'; | ||
import { ClsService } from 'nestjs-cls'; | ||
import type { IClsStore } from '../../types/cls'; | ||
|
||
@Injectable() | ||
export class AdminGuard implements CanActivate { | ||
constructor( | ||
private readonly cls: ClsService<IClsStore>, | ||
private readonly prismaService: PrismaService | ||
) {} | ||
|
||
async canActivate() { | ||
const userId = this.cls.get('user.id'); | ||
|
||
const user = await this.prismaService.user.findUnique({ | ||
where: { id: userId, deletedTime: null, deactivatedTime: null }, | ||
}); | ||
|
||
if (!user || !user.isAdmin) { | ||
throw new ForbiddenException('User is not an admin'); | ||
} | ||
|
||
return true; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/nestjs-backend/src/features/setting/setting.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Body, Controller, Get, Patch, UseGuards } from '@nestjs/common'; | ||
import { IUpdateSettingRo, updateSettingRoSchema } from '@teable/openapi'; | ||
import type { ISettingVo } from '@teable/openapi'; | ||
import { ZodValidationPipe } from '../../zod.validation.pipe'; | ||
import { Public } from '../auth/decorators/public.decorator'; | ||
import { AdminGuard } from './admin.guard'; | ||
import { SettingService } from './setting.service'; | ||
|
||
@Controller('api/admin/setting') | ||
export class SettingController { | ||
constructor(private readonly settingService: SettingService) {} | ||
|
||
@Public() | ||
@Get() | ||
async getSetting(): Promise<ISettingVo> { | ||
return await this.settingService.getSetting(); | ||
} | ||
|
||
@UseGuards(AdminGuard) | ||
@Patch() | ||
async updateSetting( | ||
@Body(new ZodValidationPipe(updateSettingRoSchema)) | ||
updateSettingRo: IUpdateSettingRo | ||
): Promise<ISettingVo> { | ||
return await this.settingService.updateSetting(updateSettingRo); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/nestjs-backend/src/features/setting/setting.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AdminGuard } from './admin.guard'; | ||
import { SettingController } from './setting.controller'; | ||
import { SettingService } from './setting.service'; | ||
|
||
@Module({ | ||
controllers: [SettingController], | ||
exports: [SettingService], | ||
providers: [SettingService, AdminGuard], | ||
}) | ||
export class SettingModule {} |
30 changes: 30 additions & 0 deletions
30
apps/nestjs-backend/src/features/setting/setting.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { PrismaService } from '@teable/db-main-prisma'; | ||
import type { ISettingVo, IUpdateSettingRo } from '@teable/openapi'; | ||
|
||
@Injectable() | ||
export class SettingService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async getSetting(): Promise<ISettingVo> { | ||
return await this.prismaService.setting | ||
.findFirstOrThrow({ | ||
select: { | ||
instanceId: true, | ||
disallowSignUp: true, | ||
disallowSpaceCreation: true, | ||
}, | ||
}) | ||
.catch(() => { | ||
throw new NotFoundException('Setting not found'); | ||
}); | ||
} | ||
|
||
async updateSetting(updateSettingRo: IUpdateSettingRo) { | ||
const setting = await this.getSetting(); | ||
return await this.prismaService.setting.update({ | ||
where: { instanceId: setting.instanceId }, | ||
data: updateSettingRo, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.