mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 17:51:08 +10:00
Refactoring
* Refactor workspace membership system * Create setup endpoint * Use Passport.js * Several updates and fixes
This commit is contained in:
@ -20,7 +20,7 @@ export class GroupUser {
|
||||
@Column()
|
||||
userId: string;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.workspaceUsers, {
|
||||
@ManyToOne(() => User, (user) => user.groups, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'userId' })
|
||||
|
||||
@ -8,9 +8,8 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { GroupService } from './services/group.service';
|
||||
import { CreateGroupDto } from './dto/create-group.dto';
|
||||
import { JwtGuard } from '../auth/guards/jwt.guard';
|
||||
import { AuthUser } from '../../decorators/auth-user.decorator';
|
||||
import { CurrentWorkspace } from '../../decorators/current-workspace.decorator';
|
||||
import { AuthWorkspace } from '../../decorators/auth-workspace.decorator';
|
||||
import { User } from '../user/entities/user.entity';
|
||||
import { Workspace } from '../workspace/entities/workspace.entity';
|
||||
import { GroupUserService } from './services/group-user.service';
|
||||
@ -25,8 +24,9 @@ import { GroupUser } from './entities/group-user.entity';
|
||||
import { PoliciesGuard } from '../casl/guards/policies.guard';
|
||||
import { CheckPolicies } from '../casl/decorators/policies.decorator';
|
||||
import { AppAbility } from '../casl/abilities/casl-ability.factory';
|
||||
import { JwtAuthGuard } from '../../guards/jwt-auth.guard';
|
||||
|
||||
@UseGuards(JwtGuard)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('groups')
|
||||
export class GroupController {
|
||||
constructor(
|
||||
@ -39,21 +39,21 @@ export class GroupController {
|
||||
getWorkspaceGroups(
|
||||
@Body() pagination: PaginationOptions,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupService.getGroupsInWorkspace(workspace.id, pagination);
|
||||
return this.groupService.getWorkspaceGroups(workspace.id, pagination);
|
||||
}
|
||||
|
||||
@UseGuards(PoliciesGuard)
|
||||
@CheckPolicies((ability: AppAbility) => ability.can(Action.Read, Group))
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('/details')
|
||||
@Post('/info')
|
||||
getGroup(
|
||||
@Body() groupIdDto: GroupIdDto,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupService.getGroup(groupIdDto.groupId, workspace.id);
|
||||
return this.groupService.getGroupInfo(groupIdDto.groupId, workspace.id);
|
||||
}
|
||||
|
||||
@UseGuards(PoliciesGuard)
|
||||
@ -63,7 +63,7 @@ export class GroupController {
|
||||
createGroup(
|
||||
@Body() createGroupDto: CreateGroupDto,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupService.createGroup(user, workspace.id, createGroupDto);
|
||||
}
|
||||
@ -75,7 +75,7 @@ export class GroupController {
|
||||
updateGroup(
|
||||
@Body() updateGroupDto: UpdateGroupDto,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupService.updateGroup(workspace.id, updateGroupDto);
|
||||
}
|
||||
@ -87,7 +87,7 @@ export class GroupController {
|
||||
getGroupMembers(
|
||||
@Body() groupIdDto: GroupIdDto,
|
||||
@Body() pagination: PaginationOptions,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupUserService.getGroupUsers(
|
||||
groupIdDto.groupId,
|
||||
@ -103,7 +103,7 @@ export class GroupController {
|
||||
addGroupMember(
|
||||
@Body() addGroupUserDto: AddGroupUserDto,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupUserService.addUserToGroup(
|
||||
addGroupUserDto.userId,
|
||||
@ -134,7 +134,7 @@ export class GroupController {
|
||||
deleteGroup(
|
||||
@Body() groupIdDto: GroupIdDto,
|
||||
@AuthUser() user: User,
|
||||
@CurrentWorkspace() workspace: Workspace,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
return this.groupService.deleteGroup(groupIdDto.groupId, workspace.id);
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
|
||||
import { GroupService } from './services/group.service';
|
||||
import { GroupController } from './group.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { Group } from './entities/group.entity';
|
||||
import { GroupUser } from './entities/group-user.entity';
|
||||
import { GroupRepository } from './respositories/group.repository';
|
||||
@ -10,7 +9,7 @@ import { GroupUserRepository } from './respositories/group-user.repository';
|
||||
import { GroupUserService } from './services/group-user.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Group, GroupUser]), AuthModule],
|
||||
imports: [TypeOrmModule.forFeature([Group, GroupUser])],
|
||||
controllers: [GroupController],
|
||||
providers: [
|
||||
GroupService,
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
import { DataSource, EntityManager } from 'typeorm';
|
||||
import { GroupUserRepository } from '../respositories/group-user.repository';
|
||||
import { PaginationOptions } from '../../../helpers/pagination/pagination-options';
|
||||
import { WorkspaceUser } from '../../workspace/entities/workspace-user.entity';
|
||||
import { transactionWrapper } from '../../../helpers/db.helper';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { GroupUser } from '../entities/group-user.entity';
|
||||
@ -55,9 +54,10 @@ export class GroupUserService {
|
||||
groupId: string,
|
||||
workspaceId: string,
|
||||
manager?: EntityManager,
|
||||
): Promise<WorkspaceUser> {
|
||||
): Promise<any> {
|
||||
let addedUser;
|
||||
|
||||
/*
|
||||
await transactionWrapper(
|
||||
async (manager) => {
|
||||
const group = await manager.findOneBy(Group, {
|
||||
@ -106,7 +106,7 @@ export class GroupUserService {
|
||||
this.dataSource,
|
||||
manager,
|
||||
);
|
||||
|
||||
*/
|
||||
return addedUser;
|
||||
}
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ export class GroupService {
|
||||
return await this.groupRepository.save(group);
|
||||
}
|
||||
|
||||
async getGroup(groupId: string, workspaceId: string): Promise<Group> {
|
||||
async getGroupInfo(groupId: string, workspaceId: string): Promise<Group> {
|
||||
const group = await this.groupRepository
|
||||
.createQueryBuilder('group')
|
||||
.where('group.id = :groupId', { groupId })
|
||||
@ -68,11 +68,11 @@ export class GroupService {
|
||||
return group;
|
||||
}
|
||||
|
||||
async getGroupsInWorkspace(
|
||||
async getWorkspaceGroups(
|
||||
workspaceId: string,
|
||||
paginationOptions: PaginationOptions,
|
||||
): Promise<PaginatedResult<Group>> {
|
||||
const [groupsInWorkspace, count] = await this.groupRepository
|
||||
const [groups, count] = await this.groupRepository
|
||||
.createQueryBuilder('group')
|
||||
.where('group.workspaceId = :workspaceId', { workspaceId })
|
||||
.loadRelationCountAndMap(
|
||||
@ -86,7 +86,7 @@ export class GroupService {
|
||||
|
||||
const paginationMeta = new PaginationMetaDto({ count, paginationOptions });
|
||||
|
||||
return new PaginatedResult(groupsInWorkspace, paginationMeta);
|
||||
return new PaginatedResult(groups, paginationMeta);
|
||||
}
|
||||
|
||||
async deleteGroup(groupId: string, workspaceId: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user