Skip to content

Commit 9f3368c

Browse files
authored
Merge pull request #21 from database-playground/pan93412/dbp-96-對-unverified-user-跳出「尚未註冊」警告視窗
feat(setup): unverified scope
2 parents 3d0a780 + db3a163 commit 9f3368c

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

internal/setup/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ setup 放置資料庫的初始化 (seeding) 共用程式碼。
1313

1414
- `admin` scopeset (`*`) 和 `admin` 群組
1515
- `student` scopeset (`me:*`, `question:read`, `database:read`, `ai`) 和 `student` 群組。
16-
- `unverified` scopeset (`me:read`) 和 `unverified` 群組
16+
- `unverified` scopeset (`unverified`, `me:read`) 和 `unverified` 群組
1717

1818
> [!INFO]
1919
> Scope 的具體定義,請參考 [scope 文件](../../docs/scope.md)。Wildcard 的意涵請參考 [scope 套件的實作](../scope/README.md)

internal/setup/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func Setup(ctx context.Context, entClient *ent.Client) (*SetupResult, error) {
8888
unverifiedScopeSet, err = entClient.ScopeSet.Create().
8989
SetSlug(useraccount.UnverifiedScopeSetSlug).
9090
SetDescription("Unverified users can only read their own initial data, and must be manually verified by an administrator.").
91-
SetScopes([]string{"me:read"}).
91+
SetScopes([]string{"me:read", "unverified"}).
9292
Save(ctx)
9393
if err != nil {
9494
return nil, err

internal/useraccount/register_flow_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ func TestGetOrRegister_NewUser(t *testing.T) {
3737
require.NoError(t, err)
3838
assert.Equal(t, useraccount.UnverifiedGroupSlug, group.Name)
3939

40-
// Verify user has me:read scope
40+
// Verify user has unverified scope
4141
scopeSets, err := user.QueryGroup().QueryScopeSets().All(context)
4242
require.NoError(t, err)
4343
require.Len(t, scopeSets, 1)
44-
assert.Contains(t, scopeSets[0].Scopes, "me:read")
44+
assert.Contains(t, scopeSets[0].Scopes, "unverified")
4545
}
4646

4747
func TestGetOrRegister_ExistingUser(t *testing.T) {
@@ -353,7 +353,7 @@ func TestRegistrationFlow_Complete(t *testing.T) {
353353

354354
tokenInfo, err := authStorage.Get(context, token)
355355
require.NoError(t, err)
356-
assert.Contains(t, tokenInfo.Scopes, "me:read")
356+
assert.Contains(t, tokenInfo.Scopes, "unverified")
357357

358358
// Step 3: Verify the user
359359
err = ctx.Verify(context, user.ID)

internal/useraccount/token_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestGrantToken_Success(t *testing.T) {
4747
assert.Equal(t, user.ID, tokenInfo.UserID)
4848
assert.Equal(t, user.Email, tokenInfo.UserEmail)
4949
assert.Equal(t, "test-machine", tokenInfo.Machine)
50-
assert.Contains(t, tokenInfo.Scopes, "me:read")
50+
assert.Contains(t, tokenInfo.Scopes, "unverified")
5151
assert.Equal(t, "registration", tokenInfo.Meta[useraccount.MetaInitiateFromFlow])
5252
assert.Empty(t, tokenInfo.Meta[useraccount.MetaImpersonation])
5353
}
@@ -82,7 +82,7 @@ func TestGrantToken_Impersonation(t *testing.T) {
8282
assert.Equal(t, user.ID, tokenInfo.UserID)
8383
assert.Equal(t, user.Email, tokenInfo.UserEmail)
8484
assert.Equal(t, "test-machine", tokenInfo.Machine)
85-
assert.Contains(t, tokenInfo.Scopes, "me:read")
85+
assert.Contains(t, tokenInfo.Scopes, "unverified")
8686
assert.Equal(t, "registration", tokenInfo.Meta[useraccount.MetaInitiateFromFlow])
8787
assert.Equal(t, strconv.Itoa(user.ID), tokenInfo.Meta[useraccount.MetaImpersonation])
8888
}

0 commit comments

Comments
 (0)