@saluzi/saluzi-edu 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -16,12 +16,20 @@ import { initDatabase, resetDbSingleton, getDb } from '../db/sqlite'
|
|
|
16
16
|
import { issueSessionToken } from '../auth/session'
|
|
17
17
|
|
|
18
18
|
function freshDb(): Database {
|
|
19
|
-
try {
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
resetDbSingleton()
|
|
21
|
+
} catch {}
|
|
22
|
+
const path = resolve(
|
|
23
|
+
tmpdir(),
|
|
24
|
+
`rcs-team-${randomUUID().replace(/-/g, '').slice(0, 8)}.db`,
|
|
25
|
+
)
|
|
21
26
|
return initDatabase(path)
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
function createUser(
|
|
29
|
+
function createUser(
|
|
30
|
+
db: Database,
|
|
31
|
+
role = 'member',
|
|
32
|
+
): { id: string; username: string } {
|
|
25
33
|
const id = `usr_${randomUUID().replace(/-/g, '')}`
|
|
26
34
|
const now = new Date().toISOString()
|
|
27
35
|
db.query(
|
|
@@ -35,7 +43,13 @@ function createTeam(db: Database, createdBy: string): string {
|
|
|
35
43
|
const now = new Date().toISOString()
|
|
36
44
|
db.query(
|
|
37
45
|
`INSERT INTO teams (id, name, slug, created_by, created_at, updated_at) VALUES ($id, $n, $s, $by, $now, $now)`,
|
|
38
|
-
).run({
|
|
46
|
+
).run({
|
|
47
|
+
$id: id,
|
|
48
|
+
$n: 'Eng',
|
|
49
|
+
$s: `eng-${id.slice(0, 6)}`,
|
|
50
|
+
$by: createdBy,
|
|
51
|
+
$now: now,
|
|
52
|
+
})
|
|
39
53
|
db.query(
|
|
40
54
|
`INSERT INTO team_members (team_id, user_id, role, added_at, added_by) VALUES ($t, $u, 'member', $now, $by)`,
|
|
41
55
|
).run({ $t: id, $u: createdBy, $now: now, $by: createdBy })
|
|
@@ -74,7 +88,11 @@ describe('团队域 session 创建与 environment 可见性', () => {
|
|
|
74
88
|
teamId = createTeam(db, user.id)
|
|
75
89
|
|
|
76
90
|
// Register an environment and link it to the team
|
|
77
|
-
const env = storeCreateEnvironment({
|
|
91
|
+
const env = storeCreateEnvironment({
|
|
92
|
+
secret: 'secret',
|
|
93
|
+
machineName: 'dev',
|
|
94
|
+
username: user.id,
|
|
95
|
+
})
|
|
78
96
|
envId = env.id
|
|
79
97
|
linkEnvToTeam(db, envId, teamId)
|
|
80
98
|
|
|
@@ -86,7 +104,10 @@ describe('团队域 session 创建与 environment 可见性', () => {
|
|
|
86
104
|
test('团队域新建 session 应设 visibility=team 并绑 team owner', async () => {
|
|
87
105
|
const res = await app.request('/web/sessions', {
|
|
88
106
|
method: 'POST',
|
|
89
|
-
headers: {
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Type': 'application/json',
|
|
109
|
+
...authHeader(accessToken),
|
|
110
|
+
},
|
|
90
111
|
body: JSON.stringify({
|
|
91
112
|
title: 'Team Session',
|
|
92
113
|
environment_id: envId,
|
|
@@ -101,8 +122,13 @@ describe('团队域 session 创建与 environment 可见性', () => {
|
|
|
101
122
|
|
|
102
123
|
// session_owners 应有 owner_type='team', owner_id=teamId
|
|
103
124
|
const owners = db
|
|
104
|
-
.query(
|
|
105
|
-
|
|
125
|
+
.query(
|
|
126
|
+
'SELECT owner_type, owner_id FROM session_owners WHERE session_id = $sid',
|
|
127
|
+
)
|
|
128
|
+
.all({ $sid: session.id }) as Array<{
|
|
129
|
+
owner_type: string
|
|
130
|
+
owner_id: string
|
|
131
|
+
}>
|
|
106
132
|
const teamOwner = owners.find(o => o.owner_type === 'team')
|
|
107
133
|
expect(teamOwner).toBeDefined()
|
|
108
134
|
expect(teamOwner!.owner_id).toBe(teamId)
|
|
@@ -112,7 +138,10 @@ describe('团队域 session 创建与 environment 可见性', () => {
|
|
|
112
138
|
// Create a session in team context
|
|
113
139
|
const createRes = await app.request('/web/sessions', {
|
|
114
140
|
method: 'POST',
|
|
115
|
-
headers: {
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
...authHeader(accessToken),
|
|
144
|
+
},
|
|
116
145
|
body: JSON.stringify({
|
|
117
146
|
title: 'Team Session',
|
|
118
147
|
environment_id: envId,
|
|
@@ -125,7 +154,12 @@ describe('团队域 session 创建与 environment 可见性', () => {
|
|
|
125
154
|
const member2 = createUser(db)
|
|
126
155
|
db.query(
|
|
127
156
|
`INSERT INTO team_members (team_id, user_id, role, added_at, added_by) VALUES ($t, $u, 'member', $now, $by)`,
|
|
128
|
-
).run({
|
|
157
|
+
).run({
|
|
158
|
+
$t: teamId,
|
|
159
|
+
$u: member2.id,
|
|
160
|
+
$now: new Date().toISOString(),
|
|
161
|
+
$by: user.id,
|
|
162
|
+
})
|
|
129
163
|
|
|
130
164
|
// Member2 should be able to resolve the session (not 403)
|
|
131
165
|
const { accessToken: at2 } = issueSessionToken(member2.id, db)
|
|
@@ -28,7 +28,9 @@ app.get('/environments', sessionAuth, async c => {
|
|
|
28
28
|
.all({ $userId: userId }) as Array<{ team_id: string }>
|
|
29
29
|
const teamIds = new Set(teamRows.map(r => r.team_id))
|
|
30
30
|
|
|
31
|
-
const filtered = allEnvs.filter(
|
|
31
|
+
const filtered = allEnvs.filter(
|
|
32
|
+
env => !env.team_id || teamIds.has(env.team_id),
|
|
33
|
+
)
|
|
32
34
|
return c.json(filtered, 200)
|
|
33
35
|
})
|
|
34
36
|
|