@@ -7,6 +7,10 @@ type RegisterModelArgs = {
77 readAttributes ?: string [ ]
88 writeAttributes ?: string [ ]
99 findByAttributes ?: string [ ]
10+ permissions ?: {
11+ groupNames ?: string [ ]
12+ userEmails ?: string [ ]
13+ }
1014}
1115
1216export declare class MyMixinInterface {
@@ -35,6 +39,7 @@ function registerModel({
3539 readAttributes,
3640 writeAttributes,
3741 findByAttributes,
42+ permissions,
3843} : RegisterModelArgs & { rpc : RetoolRPC } ) {
3944 const modelName = capitalize ( model . name )
4045 // this will give us not just the name of the attribute, but also their type
@@ -57,6 +62,7 @@ function registerModel({
5762 rpc . register ( {
5863 name : `${ modelName } > create` ,
5964 arguments : writeAttributeArgs ,
65+ permissions,
6066 implementation : async ( args ) => {
6167 if ( typeof args !== 'object' || Array . isArray ( args ) ) {
6268 throw 'attributes must be an object'
@@ -76,6 +82,7 @@ function registerModel({
7682 primaryKey : { type : 'string' , required : true } ,
7783 ...writeAttributeArgs ,
7884 } ,
85+ permissions,
7986 implementation : async ( { primaryKey, ...attributes } ) => {
8087 return model . update ( attributes , {
8188 where : {
@@ -91,6 +98,7 @@ function registerModel({
9198 findAttributes : { type : 'dict' , required : true } ,
9299 ...writeAttributeArgs ,
93100 } ,
101+ permissions,
94102 implementation : async ( { findAttributes, ...writeAttributes } ) => {
95103 // Note: this is susceptible to race condition if there is no unique index
96104 // on the find attributes. It's the user's responsibility to avoid
@@ -115,6 +123,7 @@ function registerModel({
115123 offset : { type : 'number' } ,
116124 limit : { type : 'number' } ,
117125 } ,
126+ permissions,
118127 implementation : async ( { offset, limit } ) => {
119128 return model . findAll ( {
120129 attributes : readAttributes ,
@@ -130,6 +139,7 @@ function registerModel({
130139 arguments : {
131140 primaryKey : { type : 'string' , required : true } ,
132141 } ,
142+ permissions,
133143 implementation : async ( { primaryKey } ) => {
134144 return model . findByPk ( primaryKey , {
135145 attributes : readAttributes ,
@@ -141,6 +151,7 @@ function registerModel({
141151 rpc . register ( {
142152 name : `${ modelName } > findBy` ,
143153 arguments : findByAttributeArgs ,
154+ permissions,
144155 implementation : async ( attributesValues ) => {
145156 return model . findAll ( {
146157 where : attributesValues ,
0 commit comments