-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.keel
136 lines (121 loc) · 3.26 KB
/
schema.keel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// User Model
model User {
fields {
identity Identity @unique
name Text
email Text
teams TeamMembership[]
documents Document[]
}
actions {
get me() {
@where(user.identity == ctx.identity)
}
list listUsers() {
@where(user.identity == ctx.identity)
}
delete deleteUser(id)
create createUser() with (name, email) {
@set(user.identity = ctx.identity)
@permission(expression: ctx.isAuthenticated)
}
update updateUser(id) with (name?, email?)
}
@permission(
actions: [get, update, list, delete],
expression: user.identity == ctx.identity
)
}
// Team Model
model Team {
fields {
name Text
description Text?
members TeamMembership[]
documents Document[]
}
actions {
get getTeam(id)
list listTeams() {
@where(ctx.identity in team.members.user.identity)
}
delete deleteTeam(id)
update updateTeam(id) with (name?, description?)
}
@permission(
actions: [get, list, update, delete],
expression: ctx.identity in team.members.user.identity
)
}
// Team Membership Model
model TeamMembership {
fields {
user User
team Team
}
actions {
create createTeam() with (team.name, team.description, user.id) {
@permission(expression: ctx.isAuthenticated)
}
}
}
// Document Model
model Document {
fields {
title Text
content Text
user User
team Team?
}
actions {
get getDocument(id, user.id) {
@permission(expression: document.user.identity == ctx.identity)
}
list listDocuments(user.id?, team.id?) {
@where(document.user.identity == ctx.identity or ctx.identity in document.team.members.user.identity)
}
delete deleteDocument(id, user.id?, team.id?) {
@permission(expression: document.user.identity == ctx.identity)
}
create createDocument() with (title, content, team.id?, user.id) {
@permission(expression: ctx.isAuthenticated)
}
update updateDocument(id) with (title?, content?, team.id?, user.id?)
}
@permission(
actions: [get, list, update, delete],
expression: document.user.identity == ctx.identity or ctx.identity in document.team.members.user.identity
)
}
// Profile Image Model
model ProfileImage {
fields {
path Text @unique
user User?
team Team?
}
actions {
get getImage(id) {
@permission(expression: ctx.identity == profileImage.user.identity)
}
list listImages() {
@where(ctx.identity == profileImage.user.identity)
}
delete deleteImage(id)
write uploadImageToCloudinary(UploadImageInput) returns (
UploadImageResponse
)
}
@permission(
actions: [get, delete, list],
expression: profileImage.user.identity == ctx.identity or ctx.identity in profileImage.team.members.user.identity
)
}
message UploadImageInput {
base64Image Text
userId ID
teamId ID?
}
message UploadImageResponse {
path Text
}