mirror of
https://github.com/docmost/docmost.git
synced 2026-05-20 00:14:10 +08:00
refactor layout
* ui polishing * frontend and backend fixes
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import { IsString, IsUUID } from 'class-validator';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
} from 'class-validator';
|
||||
|
||||
export class PageIdDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
pageId: string;
|
||||
}
|
||||
|
||||
@@ -14,3 +21,9 @@ export class PageHistoryIdDto {
|
||||
@IsUUID()
|
||||
historyId: string;
|
||||
}
|
||||
|
||||
export class PageInfoDto extends PageIdDto {
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
includeSpace: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class RecentPageDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
spaceId: string;
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import { PageService } from './services/page.service';
|
||||
import { CreatePageDto } from './dto/create-page.dto';
|
||||
import { UpdatePageDto } from './dto/update-page.dto';
|
||||
import { MovePageDto } from './dto/move-page.dto';
|
||||
import { PageHistoryIdDto, PageIdDto } from './dto/page.dto';
|
||||
import { PageHistoryIdDto, PageIdDto, PageInfoDto } from './dto/page.dto';
|
||||
import { PageHistoryService } from './services/page-history.service';
|
||||
import { AuthUser } from '../../decorators/auth-user.decorator';
|
||||
import { AuthWorkspace } from '../../decorators/auth-workspace.decorator';
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
} from '../casl/interfaces/space-ability.type';
|
||||
import SpaceAbilityFactory from '../casl/abilities/space-ability.factory';
|
||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||
import { RecentPageDto } from './dto/recent-page.dto';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('pages')
|
||||
@@ -39,8 +40,10 @@ export class PageController {
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('/info')
|
||||
async getPage(@Body() pageIdDto: PageIdDto, @AuthUser() user: User) {
|
||||
const page = await this.pageRepo.findById(pageIdDto.pageId);
|
||||
async getPage(@Body() dto: PageInfoDto, @AuthUser() user: User) {
|
||||
const page = await this.pageRepo.findById(dto.pageId, {
|
||||
includeSpace: true,
|
||||
});
|
||||
|
||||
if (!page) {
|
||||
throw new NotFoundException('Page not found');
|
||||
@@ -117,24 +120,28 @@ export class PageController {
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('recent')
|
||||
async getRecentSpacePages(
|
||||
async getRecentPages(
|
||||
@Body() recentPageDto: RecentPageDto,
|
||||
@Body() pagination: PaginationOptions,
|
||||
@AuthUser() user: User,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
const ability = await this.spaceAbility.createForUser(
|
||||
user,
|
||||
workspace.defaultSpaceId,
|
||||
);
|
||||
if (recentPageDto.spaceId) {
|
||||
const ability = await this.spaceAbility.createForUser(
|
||||
user,
|
||||
recentPageDto.spaceId,
|
||||
);
|
||||
|
||||
if (ability.cannot(SpaceCaslAction.Read, SpaceCaslSubject.Page)) {
|
||||
throw new ForbiddenException();
|
||||
if (ability.cannot(SpaceCaslAction.Read, SpaceCaslSubject.Page)) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
return this.pageService.getRecentSpacePages(
|
||||
recentPageDto.spaceId,
|
||||
pagination,
|
||||
);
|
||||
}
|
||||
|
||||
return this.pageService.getRecentSpacePages(
|
||||
workspace.defaultSpaceId,
|
||||
pagination,
|
||||
);
|
||||
return this.pageService.getRecentPages(user.id, pagination);
|
||||
}
|
||||
|
||||
// TODO: scope to workspaces
|
||||
|
||||
@@ -18,7 +18,7 @@ import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
|
||||
import { MovePageDto } from '../dto/move-page.dto';
|
||||
import { ExpressionBuilder } from 'kysely';
|
||||
import { DB } from '@docmost/db/types/db';
|
||||
import { genPageShortId } from '../../../helpers/nanoid.utils';
|
||||
import { generateSlugId } from '../../../helpers';
|
||||
|
||||
@Injectable()
|
||||
export class PageService {
|
||||
@@ -31,8 +31,13 @@ export class PageService {
|
||||
pageId: string,
|
||||
includeContent?: boolean,
|
||||
includeYdoc?: boolean,
|
||||
includeSpace?: boolean,
|
||||
): Promise<Page> {
|
||||
return this.pageRepo.findById(pageId, { includeContent, includeYdoc });
|
||||
return this.pageRepo.findById(pageId, {
|
||||
includeContent,
|
||||
includeYdoc,
|
||||
includeSpace,
|
||||
});
|
||||
}
|
||||
|
||||
async create(
|
||||
@@ -92,7 +97,7 @@ export class PageService {
|
||||
}
|
||||
|
||||
const createdPage = await this.pageRepo.insertPage({
|
||||
slugId: genPageShortId(),
|
||||
slugId: generateSlugId(),
|
||||
title: createPageDto.title,
|
||||
position: pagePosition,
|
||||
icon: createPageDto.icon,
|
||||
@@ -266,9 +271,14 @@ export class PageService {
|
||||
spaceId: string,
|
||||
pagination: PaginationOptions,
|
||||
): Promise<PaginationResult<Page>> {
|
||||
const pages = await this.pageRepo.getRecentPageUpdates(spaceId, pagination);
|
||||
return await this.pageRepo.getRecentPagesInSpace(spaceId, pagination);
|
||||
}
|
||||
|
||||
return pages;
|
||||
async getRecentPages(
|
||||
userId: string,
|
||||
pagination: PaginationOptions,
|
||||
): Promise<PaginationResult<Page>> {
|
||||
return await this.pageRepo.getRecentPages(userId, pagination);
|
||||
}
|
||||
|
||||
async forceDelete(pageId: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user