-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(backend): 招待機能を改修 * feat(backend): 招待コードのcreate/delete/listエンドポイントを追加 * add(misskey-js): エンドポイントと型を追加 * change(backend): metaでinvite関連の情報も返すように * add(misskey-js): エンドポイントと型を追加 * add(backend): `/endpoints/invite/limit`を追加 * fix: createdByがnullableではなかったのを修正 * fix: relationが取得できていなかった問題を修正 * fix: パラメータを間違えていたのを修正 * feat(client): 招待ページを実装 * change(client): インスタンスメニューの「招待」押した場合に招待ページに飛ぶように変更 * feat: 招待コードをコピーできるように * change(backend): metaに招待コード発行に関する情報を持たせるのをやめる * feat: ロールごとに招待コードの発行上限数などを設定できるように * change(client): 招待コードをコピーしたときにダイアログを出すように * add: 招待に関する管理者用のエンドポイントを追加 * change(backend): モデレーターであれば作成者以外でも招待コードを削除できるように * change(backend): admin/invite/listはオフセットでページネーションするように * feat(client): 招待コードの管理ページを追加 * feat(client): 招待コードのリストをソートできるように * change: `admin/invite/create`のレスポンスを修正 * fix(client): 有効期限を指定できていなかった問題を修正 * refactor: 必要のない箇所を削除 * perf(backend): use limit() instead of take() * change(client): 作成ボタンを見た目を変更 * refactor: 招待コードの生成部分を共通化し、コード内に"01OI"のいずれかの文字を含まないように * fix(client): paginationの仕様が変わっていたので修正 * change(backend): expiresAtパラメータのnullを許容 * change(client): 有効期限を設けないときは日付の入力欄を非表示に * fix: 自身のポリシーよりもインスタンス側のポリシーが優先表示される問題を修正 * fix: n時間のときに「n時間間」となってしまうのを修正 * fix(backend): ポリシーが途中で変更されたときに作成可能数がマイナス表記になってしまうのを修正 * change(client): 招待コードのユーザー名が不明な理由を表示するように * update: CHANGELOG.md * lint * refactor * refactor * tweak ui * 🎨 * 🎨 * add(backend): indexを追加 * change(backend): indexの追加に伴う変更 * change(client): インスタンスメニューの「招待」の場所を変更 * add(frontend): MkInviteCode用のstorybookを追加 * Update misskey-js.api.md * fix(misskey-js): InviteのcreatedByの型が間違っていたのを修正 --------- Co-authored-by: syuilo <[email protected]> Co-authored-by: tamaina <[email protected]>
- Loading branch information
1 parent
1c82e97
commit 02957a1
Showing
36 changed files
with
1,341 additions
and
56 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
25 changes: 25 additions & 0 deletions
25
packages/backend/migration/1688720440658-refactor-invite-system.js
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,25 @@ | ||
export class RefactorInviteSystem1688720440658 { | ||
name = 'RefactorInviteSystem1688720440658' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD "expiresAt" TIMESTAMP WITH TIME ZONE`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD "usedAt" TIMESTAMP WITH TIME ZONE`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD "pendingUserId" character varying(32)`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD "createdById" character varying(32)`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD "usedById" character varying(32)`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD CONSTRAINT "UQ_b6f93f2f30bdbb9a5ebdc7c7189" UNIQUE ("usedById")`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD CONSTRAINT "FK_beba993576db0261a15364ea96e" FOREIGN KEY ("createdById") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" ADD CONSTRAINT "FK_b6f93f2f30bdbb9a5ebdc7c7189" FOREIGN KEY ("usedById") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP CONSTRAINT "FK_b6f93f2f30bdbb9a5ebdc7c7189"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP CONSTRAINT "FK_beba993576db0261a15364ea96e"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP CONSTRAINT "UQ_b6f93f2f30bdbb9a5ebdc7c7189"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP COLUMN "usedById"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP COLUMN "createdById"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP COLUMN "pendingUserId"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP COLUMN "usedAt"`); | ||
await queryRunner.query(`ALTER TABLE "registration_ticket" DROP COLUMN "expiresAt"`); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/backend/migration/1688880985544-add-index-to-relations.js
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 @@ | ||
export class AddIndexToRelations1688880985544 { | ||
name = 'AddIndexToRelations1688880985544' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`CREATE INDEX "IDX_beba993576db0261a15364ea96" ON "registration_ticket" ("createdById") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_b6f93f2f30bdbb9a5ebdc7c718" ON "registration_ticket" ("usedById") `); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_b6f93f2f30bdbb9a5ebdc7c718"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_beba993576db0261a15364ea96"`); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
packages/backend/src/core/entities/InviteCodeEntityService.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,52 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { DI } from '@/di-symbols.js'; | ||
import type { RegistrationTicketsRepository } from '@/models/index.js'; | ||
import { awaitAll } from '@/misc/prelude/await-all.js'; | ||
import type { Packed } from '@/misc/json-schema.js'; | ||
import type { User } from '@/models/entities/User.js'; | ||
import type { RegistrationTicket } from '@/models/entities/RegistrationTicket.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { UserEntityService } from './UserEntityService.js'; | ||
|
||
@Injectable() | ||
export class InviteCodeEntityService { | ||
constructor( | ||
@Inject(DI.registrationTicketsRepository) | ||
private registrationTicketsRepository: RegistrationTicketsRepository, | ||
|
||
private userEntityService: UserEntityService, | ||
) { | ||
} | ||
|
||
@bindThis | ||
public async pack( | ||
src: RegistrationTicket['id'] | RegistrationTicket, | ||
me?: { id: User['id'] } | null | undefined, | ||
): Promise<Packed<'InviteCode'>> { | ||
const target = typeof src === 'object' ? src : await this.registrationTicketsRepository.findOneOrFail({ | ||
where: { | ||
id: src, | ||
}, | ||
relations: ['createdBy', 'usedBy'], | ||
}); | ||
|
||
return await awaitAll({ | ||
id: target.id, | ||
code: target.code, | ||
expiresAt: target.expiresAt ? target.expiresAt.toISOString() : null, | ||
createdAt: target.createdAt.toISOString(), | ||
createdBy: target.createdBy ? await this.userEntityService.pack(target.createdBy, me) : null, | ||
usedBy: target.usedBy ? await this.userEntityService.pack(target.usedBy, me) : null, | ||
usedAt: target.usedAt ? target.usedAt.toISOString() : null, | ||
used: !!target.usedAt, | ||
}); | ||
} | ||
|
||
@bindThis | ||
public packMany( | ||
targets: any[], | ||
me: { id: User['id'] }, | ||
) { | ||
return Promise.all(targets.map(x => this.pack(x, me))); | ||
} | ||
} |
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,20 @@ | ||
import { secureRndstr } from './secure-rndstr.js'; | ||
|
||
const CHARS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; // [0-9A-Z] w/o [01IO] (32 patterns) | ||
|
||
export function generateInviteCode(): string { | ||
const code = secureRndstr(8, { | ||
chars: CHARS, | ||
}); | ||
|
||
const uniqueId = []; | ||
let n = Math.floor(Date.now() / 1000 / 60); | ||
while (true) { | ||
uniqueId.push(CHARS[n % CHARS.length]); | ||
const t = Math.floor(n / CHARS.length); | ||
if (!t) break; | ||
n = t; | ||
} | ||
|
||
return code + uniqueId.reverse().join(''); | ||
} |
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
51 changes: 47 additions & 4 deletions
51
packages/backend/src/models/entities/RegistrationTicket.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 |
---|---|---|
@@ -1,17 +1,60 @@ | ||
import { PrimaryColumn, Entity, Index, Column } from 'typeorm'; | ||
import { PrimaryColumn, Entity, Index, Column, ManyToOne, JoinColumn, OneToOne } from 'typeorm'; | ||
import { id } from '../id.js'; | ||
import { User } from './User.js'; | ||
|
||
@Entity() | ||
export class RegistrationTicket { | ||
@PrimaryColumn(id()) | ||
public id: string; | ||
|
||
@Column('timestamp with time zone') | ||
public createdAt: Date; | ||
|
||
@Index({ unique: true }) | ||
@Column('varchar', { | ||
length: 64, | ||
}) | ||
public code: string; | ||
|
||
@Column('timestamp with time zone', { | ||
nullable: true, | ||
}) | ||
public expiresAt: Date | null; | ||
|
||
@Column('timestamp with time zone') | ||
public createdAt: Date; | ||
|
||
@ManyToOne(type => User, { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn() | ||
public createdBy: User | null; | ||
|
||
@Index() | ||
@Column({ | ||
...id(), | ||
nullable: true, | ||
}) | ||
public createdById: User['id'] | null; | ||
|
||
@OneToOne(type => User, { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn() | ||
public usedBy: User | null; | ||
|
||
@Index() | ||
@Column({ | ||
...id(), | ||
nullable: true, | ||
}) | ||
public usedById: User['id'] | null; | ||
|
||
@Column('timestamp with time zone', { | ||
nullable: true, | ||
}) | ||
public usedAt: Date | null; | ||
|
||
@Column('varchar', { | ||
length: 32, | ||
nullable: true, | ||
}) | ||
public pendingUserId: string | null; | ||
} |
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,45 @@ | ||
export const packedInviteCodeSchema = { | ||
type: 'object', | ||
properties: { | ||
id: { | ||
type: 'string', | ||
optional: false, nullable: false, | ||
format: 'id', | ||
example: 'xxxxxxxxxx', | ||
}, | ||
code: { | ||
type: 'string', | ||
optional: false, nullable: false, | ||
example: 'GR6S02ERUA5VR', | ||
}, | ||
expiresAt: { | ||
type: 'string', | ||
optional: false, nullable: true, | ||
format: 'date-time', | ||
}, | ||
createdAt: { | ||
type: 'string', | ||
optional: false, nullable: false, | ||
format: 'date-time', | ||
}, | ||
createdBy: { | ||
type: 'object', | ||
optional: false, nullable: true, | ||
ref: 'UserLite', | ||
}, | ||
usedBy: { | ||
type: 'object', | ||
optional: false, nullable: true, | ||
ref: 'UserLite', | ||
}, | ||
usedAt: { | ||
type: 'string', | ||
optional: false, nullable: true, | ||
format: 'date-time', | ||
}, | ||
used: { | ||
type: 'boolean', | ||
optional: false, nullable: false, | ||
}, | ||
}, | ||
} as const; |
Oops, something went wrong.
02957a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chromatic detects changes. Please review the changes on Chromatic.