@@ -113,7 +113,7 @@ export const getEntityToMutate = async (
113
113
. map ( ( [ key , value ] ) => `${ key } : ${ value } ` )
114
114
. join ( ', ' ) } `
115
115
) ;
116
- throw new PermissionError ( action , `this ${ model . name } ` , 'no available permissions applied' ) ;
116
+ throw new PermissionError ( ctx . user . role , action , `this ${ model . name } ` , 'no available permissions applied' ) ;
117
117
}
118
118
119
119
if ( model . parent ) {
@@ -139,7 +139,7 @@ export const checkCanWrite = async (
139
139
return ;
140
140
}
141
141
if ( permissionStack === false ) {
142
- throw new PermissionError ( action , model . plural , 'no applicable permissions' ) ;
142
+ throw new PermissionError ( ctx . user . role , action , model . plural , 'no applicable permissions' ) ;
143
143
}
144
144
145
145
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- using `select(1 as any)` to instantiate an "empty" query builder
@@ -157,7 +157,12 @@ export const checkCanWrite = async (
157
157
158
158
const fieldPermissions = field [ action === 'CREATE' ? 'creatable' : 'updatable' ] ;
159
159
if ( fieldPermissions && typeof fieldPermissions === 'object' && ! fieldPermissions . roles ?. includes ( ctx . user . role ) ) {
160
- throw new PermissionError ( action , `this ${ model . name } 's ${ field . name } ` , 'field permission not available' ) ;
160
+ throw new PermissionError (
161
+ ctx . user . role ,
162
+ action ,
163
+ `this ${ model . name } 's ${ field . name } ` ,
164
+ 'field permission not available'
165
+ ) ;
161
166
}
162
167
163
168
linked = true ;
@@ -172,7 +177,12 @@ export const checkCanWrite = async (
172
177
}
173
178
174
179
if ( fieldPermissionStack === false || ! fieldPermissionStack . length ) {
175
- throw new PermissionError ( action , `this ${ model . name } 's ${ field . name } ` , 'no applicable permissions on data to link' ) ;
180
+ throw new PermissionError (
181
+ ctx . user . role ,
182
+ action ,
183
+ `this ${ model . name } 's ${ field . name } ` ,
184
+ 'no applicable permissions on data to link'
185
+ ) ;
176
186
}
177
187
178
188
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we do not need to await knex here
@@ -187,10 +197,10 @@ export const checkCanWrite = async (
187
197
if ( linked ) {
188
198
const canMutate = await query ;
189
199
if ( ! canMutate ) {
190
- throw new PermissionError ( action , `this ${ model . name } ` , 'no linkable entities' ) ;
200
+ throw new PermissionError ( ctx . user . role , action , `this ${ model . name } ` , 'no linkable entities' ) ;
191
201
}
192
202
} else if ( action === 'CREATE' ) {
193
- throw new PermissionError ( action , `this ${ model . name } ` , 'no linkable entities' ) ;
203
+ throw new PermissionError ( ctx . user . role , action , `this ${ model . name } ` , 'no linkable entities' ) ;
194
204
}
195
205
} ;
196
206
0 commit comments