Skip to content

Commit d24a63d

Browse files
committed
fix seeder
1 parent 785ad4e commit d24a63d

File tree

5 files changed

+13
-147
lines changed

5 files changed

+13
-147
lines changed
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
import { Access, Prisma } from '@prisma/client';
22

3-
export const RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID = 'aa5b991b-ea21-450f-870d-55f2b9f1fac8';
4-
export const RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID = 'ff8aa31c-65df-4651-af6a-06751ccec77f';
5-
export const NONE_EXAM_DOCUMENT_ID = 'd50cdcba-adfc-41fa-a1d1-7a026f86b12b';
6-
export const RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID = '2b7c4da1-b909-4990-a13a-51b0ab2c1517';
7-
8-
const documentRoots: Prisma.DocumentRootCreateInput[] = [
9-
{
10-
id: RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID,
11-
access: Access.RW_DocumentRoot
12-
},
13-
{
14-
id: RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
15-
access: Access.RW_DocumentRoot
16-
},
17-
{
18-
id: NONE_EXAM_DOCUMENT_ID,
19-
access: Access.None_DocumentRoot
20-
},
21-
{
22-
id: RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
23-
access: Access.RO_DocumentRoot
24-
}
25-
];
3+
const documentRoots: Prisma.DocumentRootCreateInput[] = [];
264

275
export { documentRoots };

prisma/seed-files/documents.ts

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Prisma } from '@prisma/client';
22
import { FOO_BAR_ID, TEST_USER_ID } from './users';
3-
import {
4-
NONE_EXAM_DOCUMENT_ID,
5-
RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
6-
RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
7-
RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID
8-
} from './document-roots';
93

104
const { USER_EMAIL, USER_ID } = process.env;
115

@@ -17,105 +11,6 @@ export const FOO_BAR_EXAM_DOCUMENT_ID = '3fa55e05-6e82-4a86-922a-81b25325db69';
1711
export const FOO_BAR_VISIBILITY_WRAPPER_DOCUMENT_ID = 'bb1d0183-1640-46ef-9fa2-d4a37ae7714d';
1812
export const TEST_USER_VISIBILITY_WRAPPER_DOCUMENT_ID = 'b0b0baf9-e9ef-47c0-be59-5108915528d3';
1913

20-
const documents: Prisma.DocumentCreateManyInput[] = [
21-
{
22-
id: FOO_BAR_EXERCISE_LOREM_DOCUMENT_ID,
23-
authorId: FOO_BAR_ID, // foo@bar.ch
24-
documentRootId: RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID,
25-
type: 'text',
26-
data: {
27-
text: 'This is the Lorem exercise from [email protected]. They should be able to edit this document.'
28-
}
29-
},
30-
{
31-
id: TEST_USER_EXERCISE_LOREM_DOCUMENT_ID,
32-
authorId: TEST_USER_ID, // test@user.ch
33-
documentRootId: RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID,
34-
type: 'text',
35-
data: {
36-
text: 'This is the Lorem exercise from [email protected]. They should be able to edit this document because their user permission is set to RO.'
37-
}
38-
},
39-
{
40-
id: FOO_BAR_EXERCISE_IMPSUM_DOCUMENT_ID,
41-
authorId: FOO_BAR_ID, // foo@bar.ch
42-
documentRootId: RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
43-
type: 'text',
44-
data: {
45-
text: 'This is the Ipsum exercise from [email protected]. This document should be read-only for them, because their class has RO permission.'
46-
}
47-
},
48-
{
49-
id: TEST_USER_EXERCISE_IPSUM_DOCUMENT_ID,
50-
authorId: TEST_USER_ID, // test@user.ch
51-
documentRootId: RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
52-
type: 'text',
53-
data: {
54-
text: 'This is the Ipsum exercise from [email protected]. This document should be read-only for them, because their class has RO permission.'
55-
}
56-
},
57-
{
58-
id: FOO_BAR_EXAM_DOCUMENT_ID,
59-
authorId: FOO_BAR_ID, // foo@bar.ch
60-
documentRootId: NONE_EXAM_DOCUMENT_ID,
61-
type: 'text',
62-
data: {
63-
text: 'This is the exam from [email protected]. They should be able to edit it, because their class has RW permission.'
64-
}
65-
},
66-
{
67-
id: FOO_BAR_VISIBILITY_WRAPPER_DOCUMENT_ID,
68-
authorId: FOO_BAR_ID, // foo@bar.ch
69-
documentRootId: RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
70-
type: 'text',
71-
data: {
72-
text: 'This is a visibility wrapper for [email protected]. This document should be read-only for them, indicating that they can see the wrapped resource (but cannot change this document).'
73-
}
74-
},
75-
{
76-
id: TEST_USER_VISIBILITY_WRAPPER_DOCUMENT_ID,
77-
authorId: TEST_USER_ID, // test@user.ch
78-
documentRootId: RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
79-
type: 'text',
80-
data: {
81-
text: 'This is a visibility wrapper for [email protected]. They should not see this document, because their project group has None permission, indicating that they cannot see the wrapped resource.'
82-
}
83-
}
84-
];
85-
86-
if (USER_EMAIL && USER_ID) {
87-
documents.push({
88-
authorId: USER_ID,
89-
documentRootId: RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID,
90-
type: 'text',
91-
data: {
92-
text: `This is the Lorem exercise from ${USER_EMAIL}`
93-
}
94-
});
95-
documents.push({
96-
authorId: USER_ID,
97-
documentRootId: RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
98-
type: 'text',
99-
data: {
100-
text: `This is the Ipsum exercise from ${USER_EMAIL}`
101-
}
102-
});
103-
documents.push({
104-
authorId: USER_ID,
105-
documentRootId: NONE_EXAM_DOCUMENT_ID,
106-
type: 'text',
107-
data: {
108-
text: `This is the exam document from ${USER_EMAIL}`
109-
}
110-
});
111-
documents.push({
112-
authorId: USER_ID,
113-
documentRootId: RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
114-
type: 'text',
115-
data: {
116-
text: `This is the visibility wrapper document from ${USER_EMAIL}`
117-
}
118-
});
119-
}
14+
const documents: Prisma.DocumentCreateManyInput[] = [];
12015

12116
export { documents };

prisma/seed-files/student-groups.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ const studentGroups: Prisma.StudentGroupUncheckedCreateWithoutChildrenInput[] =
2424
}
2525
];
2626

27+
if (process.env.ADMIN_USER_GROUP_ID) {
28+
studentGroups.push({
29+
name: 'Administrators',
30+
description: 'Group containing all admin users',
31+
id: process.env.ADMIN_USER_GROUP_ID
32+
});
33+
}
34+
2735
export { studentGroups };

prisma/seed-files/users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const users: Prisma.UserCreateInput[] = [
1414
if (USER_EMAIL && USER_ID) {
1515
const name = USER_EMAIL.split('@')[0];
1616
users.push({
17-
email: USER_EMAIL,
17+
email: USER_EMAIL.toLocaleLowerCase(),
1818
id: USER_ID,
1919
firstName: name.split('.')[0],
2020
lastName: name.split('.')[1] || name,

prisma/seed.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import {
77
PROJECT_GROUP_ID,
88
studentGroups as seedStudentGroups
99
} from './seed-files/student-groups';
10-
import {
11-
documentRoots as seedDocumentRoots,
12-
NONE_EXAM_DOCUMENT_ID,
13-
RW_EXERCISE_IMPSUM_DOCUMENT_ROOT_ID,
14-
RO_VISIBILITY_WRAPPER_DOCUMENT_ROOT_ID,
15-
RW_EXERCISE_LOREM_DOCUMENT_ROOT_ID
16-
} from './seed-files/document-roots';
10+
import { documentRoots as seedDocumentRoots } from './seed-files/document-roots';
1711
import {
1812
rootUserPermissions as seedRootUserPermissions,
1913
rootGroupPermissions as seedRootGroupPermissions
@@ -28,9 +22,8 @@ async function main() {
2822
return;
2923
}
3024

31-
console.log(seedUsers);
3225
const users = await prisma.user.createMany({
33-
data: seedUsers
26+
data: seedUsers.map((user) => ({ ...user, email: user.email.toLowerCase() }))
3427
});
3528

3629
const documentRoots = await prisma.documentRoot.createMany({
@@ -100,14 +93,6 @@ async function main() {
10093
}
10194
}
10295
});
103-
104-
const rootUserPermissions = await prisma.rootUserPermission.createMany({
105-
data: seedRootUserPermissions
106-
});
107-
108-
const rootGroupPermissions = await prisma.rootGroupPermission.createMany({
109-
data: seedRootGroupPermissions
110-
});
11196
}
11297

11398
main()

0 commit comments

Comments
 (0)