You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This flow was erroring before.
1) Load document with permissions embedded.
2) write to that object
3) have the permissions get updated with post-write permissions
It broke because we were doing a really simple check to make sure we didn't overwrite data. In the case, we want to.
So the checks now only error if we haven't already embedded permissions.
// There's already something at the key where we're supposed to inset the permissions
12
-
// Throw an exception to help the developer avoid this error.
13
-
thrownewError(`Cannot embed permissions into mongoose document at \`${permsKey}\`because the key is already present in the document. Please specify a custom key.`);
12
+
if(permsKeyindoc){
13
+
if(!doc[embedPermissionsSymbol]){
14
+
// We haven't embedded permissions, but there is already a value at the path where
15
+
// we're supposed to insert the permissions. Throw an exception for the developer
16
+
// knows that something is wrong.
17
+
thrownewError(`Cannot embed permissions into mongoose document at \`${permsKey}\`because the key is already present in the document. Please specify a custom key.`);
18
+
}
19
+
}else{
20
+
Object.defineProperty(doc,permsKey,{
21
+
get(){returnthis[embedPermissionsSymbol];},
22
+
set(){thrownewError('Permissions are not writable');},
0 commit comments