mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 09:12:36 +10:00
fix workspace setup
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
import { LoginDto } from '../dto/login.dto';
|
import { LoginDto } from '../dto/login.dto';
|
||||||
import { CreateUserDto } from '../dto/create-user.dto';
|
import { CreateUserDto } from '../dto/create-user.dto';
|
||||||
import { UserService } from '../../user/user.service';
|
|
||||||
import { TokenService } from './token.service';
|
import { TokenService } from './token.service';
|
||||||
import { TokensDto } from '../dto/tokens.dto';
|
import { TokensDto } from '../dto/tokens.dto';
|
||||||
import { SignupService } from './signup.service';
|
import { SignupService } from './signup.service';
|
||||||
@ -12,14 +11,17 @@ import { comparePasswordHash } from '../../../helpers/utils';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
constructor(
|
constructor(
|
||||||
private userService: UserService,
|
|
||||||
private signupService: SignupService,
|
private signupService: SignupService,
|
||||||
private tokenService: TokenService,
|
private tokenService: TokenService,
|
||||||
private userRepo: UserRepo,
|
private userRepo: UserRepo,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async login(loginDto: LoginDto, workspaceId: string) {
|
async login(loginDto: LoginDto, workspaceId: string) {
|
||||||
const user = await this.userRepo.findByEmail(loginDto.email, workspaceId);
|
const user = await this.userRepo.findByEmail(
|
||||||
|
loginDto.email,
|
||||||
|
workspaceId,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!user ||
|
!user ||
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { BadRequestException, Injectable } from '@nestjs/common';
|
|||||||
import { CreateUserDto } from '../dto/create-user.dto';
|
import { CreateUserDto } from '../dto/create-user.dto';
|
||||||
import { WorkspaceService } from '../../workspace/services/workspace.service';
|
import { WorkspaceService } from '../../workspace/services/workspace.service';
|
||||||
import { CreateWorkspaceDto } from '../../workspace/dto/create-workspace.dto';
|
import { CreateWorkspaceDto } from '../../workspace/dto/create-workspace.dto';
|
||||||
import { SpaceService } from '../../space/services/space.service';
|
|
||||||
import { CreateAdminUserDto } from '../dto/create-admin-user.dto';
|
import { CreateAdminUserDto } from '../dto/create-admin-user.dto';
|
||||||
import { GroupUserService } from '../../group/services/group-user.service';
|
import { GroupUserService } from '../../group/services/group-user.service';
|
||||||
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
||||||
@ -16,7 +15,6 @@ export class SignupService {
|
|||||||
constructor(
|
constructor(
|
||||||
private userRepo: UserRepo,
|
private userRepo: UserRepo,
|
||||||
private workspaceService: WorkspaceService,
|
private workspaceService: WorkspaceService,
|
||||||
private spaceService: SpaceService,
|
|
||||||
private groupUserService: GroupUserService,
|
private groupUserService: GroupUserService,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
) {}
|
) {}
|
||||||
@ -63,7 +61,11 @@ export class SignupService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createWorkspace(user, workspaceName, trx?: KyselyTransaction) {
|
async createWorkspace(
|
||||||
|
user: User,
|
||||||
|
workspaceName: string,
|
||||||
|
trx?: KyselyTransaction,
|
||||||
|
) {
|
||||||
return await executeTx(
|
return await executeTx(
|
||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
|
|||||||
@ -12,5 +12,5 @@ export class CreateGroupDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum DefaultGroup {
|
export enum DefaultGroup {
|
||||||
EVERYONE = 'users',
|
EVERYONE = 'internal_users',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ export class GroupUserService {
|
|||||||
await executeTx(
|
await executeTx(
|
||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
await this.groupService.findAndValidateGroup(groupId, workspaceId);
|
// await this.groupService.findAndValidateGroup(groupId, workspaceId);
|
||||||
const groupUserExists = await this.groupUserRepo.getGroupUserById(
|
const groupUserExists = await this.groupUserRepo.getGroupUserById(
|
||||||
userId,
|
userId,
|
||||||
groupId,
|
groupId,
|
||||||
|
|||||||
@ -5,15 +5,11 @@ import { PaginationMetaDto } from '../../../helpers/pagination/pagination-meta-d
|
|||||||
import { PaginatedResult } from '../../../helpers/pagination/paginated-result';
|
import { PaginatedResult } from '../../../helpers/pagination/paginated-result';
|
||||||
import { UserRole } from '../../../helpers/types/permission';
|
import { UserRole } from '../../../helpers/types/permission';
|
||||||
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
||||||
import { WorkspaceRepo } from '@docmost/db/repos/workspace/workspace.repo';
|
|
||||||
import { User } from '@docmost/db/types/entity.types';
|
import { User } from '@docmost/db/types/entity.types';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class WorkspaceUserService {
|
export class WorkspaceUserService {
|
||||||
constructor(
|
constructor(private userRepo: UserRepo) {}
|
||||||
private workspaceRepo: WorkspaceRepo,
|
|
||||||
private userRepo: UserRepo,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async getWorkspaceUsers(
|
async getWorkspaceUsers(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
|
|||||||
@ -78,9 +78,8 @@ export class WorkspaceService {
|
|||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// add user to default group
|
// add user to default group
|
||||||
await this.groupUserService.addUserToGroup(
|
await this.groupUserService.addUserToDefaultGroup(
|
||||||
user.id,
|
user.id,
|
||||||
group.id,
|
|
||||||
workspace.id,
|
workspace.id,
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
@ -124,6 +123,7 @@ export class WorkspaceService {
|
|||||||
workspace.id,
|
workspace.id,
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
|
|||||||
@ -74,7 +74,6 @@ export class GroupRepo {
|
|||||||
.selectAll()
|
.selectAll()
|
||||||
.where('isDefault', '=', true)
|
.where('isDefault', '=', true)
|
||||||
.where('workspaceId', '=', workspaceId)
|
.where('workspaceId', '=', workspaceId)
|
||||||
|
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
|
|||||||
Reference in New Issue
Block a user