mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
chore(server): add pro user for testing with extended workspace member limit (#10827)
This commit is contained in:
@@ -51,12 +51,24 @@ yarn affine server data-migration run
|
||||
yarn affine server dev
|
||||
```
|
||||
|
||||
when server started, it will created a default user for testing:
|
||||
when server started, it will created a default user and a pro user for testing:
|
||||
|
||||
### default user
|
||||
|
||||
Workspace members up to 3
|
||||
|
||||
- email: dev@affine.pro
|
||||
- name: Dev User
|
||||
- password: dev
|
||||
|
||||
### pro user
|
||||
|
||||
Workspace members up to 10
|
||||
|
||||
- email: pro@affine.pro
|
||||
- name: Pro User
|
||||
- password: pro
|
||||
|
||||
## Start frontend
|
||||
|
||||
```sh
|
||||
|
||||
@@ -3,7 +3,12 @@ import type { CookieOptions, Request, Response } from 'express';
|
||||
import { assign, pick } from 'lodash-es';
|
||||
|
||||
import { Config, MailService, SignUpForbidden } from '../../base';
|
||||
import { Models, type User, type UserSession } from '../../models';
|
||||
import {
|
||||
Models,
|
||||
type User,
|
||||
type UserFeatureName,
|
||||
type UserSession,
|
||||
} from '../../models';
|
||||
import { FeatureService } from '../features';
|
||||
import type { CurrentUser } from './session';
|
||||
|
||||
@@ -48,8 +53,28 @@ export class AuthService implements OnApplicationBootstrap {
|
||||
|
||||
async onApplicationBootstrap() {
|
||||
if (this.config.node.dev) {
|
||||
const devUsers: {
|
||||
email: string;
|
||||
name: string;
|
||||
password: string;
|
||||
features: UserFeatureName[];
|
||||
}[] = [
|
||||
{
|
||||
email: 'dev@affine.pro',
|
||||
name: 'Dev User',
|
||||
password: 'dev',
|
||||
features: ['free_plan_v1', 'unlimited_copilot', 'administrator'],
|
||||
},
|
||||
{
|
||||
email: 'pro@affine.pro',
|
||||
name: 'Pro User',
|
||||
password: 'pro',
|
||||
features: ['pro_plan_v1', 'unlimited_copilot', 'administrator'],
|
||||
},
|
||||
];
|
||||
|
||||
for (const { email, name, password, features } of devUsers) {
|
||||
try {
|
||||
const [email, name, password] = ['dev@affine.pro', 'Dev User', 'dev'];
|
||||
let devUser = await this.models.user.getUserByEmail(email);
|
||||
if (!devUser) {
|
||||
devUser = await this.models.user.create({
|
||||
@@ -58,21 +83,15 @@ export class AuthService implements OnApplicationBootstrap {
|
||||
password,
|
||||
});
|
||||
}
|
||||
await this.models.userFeature.add(
|
||||
devUser.id,
|
||||
'administrator',
|
||||
'dev user'
|
||||
);
|
||||
await this.models.userFeature.add(
|
||||
devUser.id,
|
||||
'unlimited_copilot',
|
||||
'dev user'
|
||||
);
|
||||
for (const feature of features) {
|
||||
await this.models.userFeature.add(devUser.id, feature, name);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async canSignIn(email: string) {
|
||||
return await this.feature.canEarlyAccess(email);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getStreamAsBuffer } from 'get-stream';
|
||||
|
||||
import {
|
||||
Cache,
|
||||
Config,
|
||||
MailService,
|
||||
NotFound,
|
||||
OnEvent,
|
||||
@@ -33,7 +34,8 @@ export class WorkspaceService {
|
||||
private readonly doc: DocReader,
|
||||
private readonly mailer: MailService,
|
||||
private readonly models: Models,
|
||||
private readonly url: URLHelper
|
||||
private readonly url: URLHelper,
|
||||
private readonly config: Config
|
||||
) {}
|
||||
|
||||
async getInviteInfo(inviteId: string): Promise<InviteInfo> {
|
||||
@@ -134,10 +136,15 @@ export class WorkspaceService {
|
||||
|
||||
const owner = await this.models.workspaceUser.getOwner(target.workspace.id);
|
||||
|
||||
const inviteUrl = this.url.link(`/invite/${inviteId}`);
|
||||
if (this.config.node.dev) {
|
||||
// make it easier to test in dev mode
|
||||
this.logger.debug(`Invite link: ${inviteUrl}`);
|
||||
}
|
||||
await this.mailer.sendMemberInviteMail(target.email, {
|
||||
workspace: target.workspace,
|
||||
user: owner,
|
||||
url: this.url.link(`/invite/${inviteId}`),
|
||||
url: inviteUrl,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user