-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: first login flow #7553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shortlight5980
wants to merge
1
commit into
labring:main
Choose a base branch
from
shortlight5980:first-login
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: first login flow #7553
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| import z from 'zod'; | ||
| import { UNSET_TEAM_MEMBER_NAME } from './constant'; | ||
|
|
||
| /** | ||
| * 成员名的统一交互式校验规则。 | ||
| * 保留值只用于新成员的待补齐状态,不能被用户或可信外部数据直接提交。 | ||
| */ | ||
| export const TeamMemberNameSchema = z | ||
| .string() | ||
| .trim() | ||
| .min(1, '成员名不能为空') | ||
| .max(20, '成员名长度不能超过 20 个字符') | ||
| .refine((value) => value !== UNSET_TEAM_MEMBER_NAME, '成员名非法!'); | ||
|
|
||
| /** 将交互式成员名规范化并在非法输入时抛出参数错误。 */ | ||
| export const normalizeTeamMemberName = (memberName: unknown) => | ||
| TeamMemberNameSchema.parse(memberName); | ||
|
|
||
| /** 仅返回有效成员名,供注册和同步等非交互式入口选择明确的缺省值。 */ | ||
| export const getValidTeamMemberName = (memberName: unknown) => { | ||
| const result = TeamMemberNameSchema.safeParse(memberName); | ||
| return result.success ? result.data : undefined; | ||
| }; |
This file contains hidden or 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 hidden or 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,26 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| getValidTeamMemberName, | ||
| normalizeTeamMemberName, | ||
| TeamMemberNameSchema | ||
| } from '@fastgpt/global/support/user/team/memberName'; | ||
| import { UNSET_TEAM_MEMBER_NAME } from '@fastgpt/global/support/user/team/constant'; | ||
|
|
||
| describe('TeamMemberNameSchema', () => { | ||
| it('trims and accepts names up to 20 characters', () => { | ||
| expect(TeamMemberNameSchema.parse(' Alice ')).toBe('Alice'); | ||
| expect(TeamMemberNameSchema.parse('a'.repeat(20))).toBe('a'.repeat(20)); | ||
| }); | ||
|
|
||
| it('rejects empty, overlong, and reserved names', () => { | ||
| expect(TeamMemberNameSchema.safeParse(' ').success).toBe(false); | ||
| expect(TeamMemberNameSchema.safeParse('a'.repeat(21)).success).toBe(false); | ||
| expect(TeamMemberNameSchema.safeParse(UNSET_TEAM_MEMBER_NAME).success).toBe(false); | ||
| }); | ||
|
|
||
| it('separates strict normalization from fallback validation', () => { | ||
| expect(normalizeTeamMemberName(' Bob ')).toBe('Bob'); | ||
| expect(getValidTeamMemberName(UNSET_TEAM_MEMBER_NAME)).toBeUndefined(); | ||
| expect(getValidTeamMemberName('')).toBeUndefined(); | ||
| }); | ||
| }); |
This file contains hidden or 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,14 @@ | ||
| import { LeaseCache } from '@fastgpt/dal/redis/caches'; | ||
| import { getLogger, LogCategories } from '../../common/logger'; | ||
|
|
||
| const lockTtlMs = 10 * 60 * 1000; | ||
| const leaseCache = new LeaseCache({ logger: getLogger(LogCategories.INFRA.REDIS) }); | ||
|
|
||
| /** 在团队维度串行化会同时修改团队成员关系或团队资源的操作。 */ | ||
| export const withTeamLock = async <T>(teamId: string, fn: () => Promise<T>) => | ||
| leaseCache.withLease({ | ||
| key: `team:${String(teamId)}`, | ||
| label: 'team-operation', | ||
| ttlMs: lockTtlMs, | ||
| fn: () => fn() | ||
| }); |
This file contains hidden or 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 hidden or 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,27 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { LeaseCache } from '@fastgpt/dal/redis/caches'; | ||
| import { withTeamLock } from '@fastgpt/service/support/user/lock'; | ||
|
|
||
| describe('team lock', () => { | ||
| let withLease: ReturnType<typeof vi.spyOn>; | ||
|
|
||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| withLease = vi.spyOn(LeaseCache.prototype, 'withLease'); | ||
| withLease.mockImplementation(async ({ fn }) => fn({} as any)); | ||
| }); | ||
|
|
||
| it('holds a team-scoped lease around the callback and returns its result', async () => { | ||
| const callback = vi.fn().mockResolvedValue('done'); | ||
|
|
||
| await expect(withTeamLock('team-1', callback)).resolves.toBe('done'); | ||
|
|
||
| expect(withLease).toHaveBeenCalledWith({ | ||
| key: 'team:team-1', | ||
| label: 'team-operation', | ||
| ttlMs: 600000, | ||
| fn: expect.any(Function) | ||
| }); | ||
| expect(callback).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.