@modular-rest/server 1.13.0 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -23,7 +23,7 @@ interface CollectionDefinitionOptions {
|
|
|
23
23
|
* @type {Schema}
|
|
24
24
|
* @see https://mongoosejs.com/docs/5.x/docs/guide.html
|
|
25
25
|
*/
|
|
26
|
-
schema: Schema
|
|
26
|
+
schema: Schema<any>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* To have define any collection in your database you haveto use below method in your `db.[js|ts]` file and export an array of CollectionDefinition instances.
|
|
@@ -94,7 +94,7 @@ export declare class CollectionDefinition {
|
|
|
94
94
|
/** @readonly The name of the collection */
|
|
95
95
|
collection: string;
|
|
96
96
|
/** @readonly Mongoose schema definition */
|
|
97
|
-
schema: Schema
|
|
97
|
+
schema: Schema<any>;
|
|
98
98
|
/** @readonly List of permissions for the collection */
|
|
99
99
|
permissions: Permission[];
|
|
100
100
|
/** @readonly Optional database triggers */
|
|
@@ -178,11 +178,11 @@ function _getPermissionList(db, collection, operationType) {
|
|
|
178
178
|
function checkAccess(db, collection, operationType, queryOrDoc, user) {
|
|
179
179
|
const permissionList = _getPermissionList(db, collection, operationType);
|
|
180
180
|
return permissionList.some(permission => {
|
|
181
|
-
if (permission.
|
|
181
|
+
if (permission.accessType === 'god_access')
|
|
182
182
|
return true;
|
|
183
|
-
if (permission.
|
|
183
|
+
if (permission.accessType === 'anonymous_access' && user.type === 'anonymous')
|
|
184
184
|
return true;
|
|
185
|
-
if (permission.
|
|
185
|
+
if (permission.accessType === 'user_access' && user.type === 'user')
|
|
186
186
|
return true;
|
|
187
187
|
return false;
|
|
188
188
|
});
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@ interface CollectionDefinitionOptions {
|
|
|
25
25
|
* @type {Schema}
|
|
26
26
|
* @see https://mongoosejs.com/docs/5.x/docs/guide.html
|
|
27
27
|
*/
|
|
28
|
-
schema: Schema
|
|
28
|
+
schema: Schema<any>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -102,7 +102,7 @@ export class CollectionDefinition {
|
|
|
102
102
|
collection: string;
|
|
103
103
|
|
|
104
104
|
/** @readonly Mongoose schema definition */
|
|
105
|
-
schema: Schema
|
|
105
|
+
schema: Schema<any>;
|
|
106
106
|
|
|
107
107
|
/** @readonly List of permissions for the collection */
|
|
108
108
|
permissions: Permission[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose, { Connection, Model, PopulateOptions, Query } from 'mongoose';
|
|
2
|
-
import { AccessTypes, AccessDefinition } from '../../class/security';
|
|
2
|
+
import { AccessTypes, AccessDefinition, Permission } from '../../class/security';
|
|
3
3
|
import triggerOperator from '../../class/trigger_operator';
|
|
4
4
|
import TypeCasters from './typeCasters';
|
|
5
5
|
import { config } from '../../config';
|
|
@@ -191,7 +191,7 @@ export function getCollection<T>(db: string, collection: string): Model<T> {
|
|
|
191
191
|
* @returns {any[]} List of permissions
|
|
192
192
|
* @private
|
|
193
193
|
*/
|
|
194
|
-
function _getPermissionList(db: string, collection: string, operationType: string):
|
|
194
|
+
function _getPermissionList(db: string, collection: string, operationType: string): Permission[] {
|
|
195
195
|
if (!permissionDefinitions[db] || !permissionDefinitions[db][collection]) {
|
|
196
196
|
return [];
|
|
197
197
|
}
|
|
@@ -224,9 +224,9 @@ export function checkAccess(
|
|
|
224
224
|
): boolean {
|
|
225
225
|
const permissionList = _getPermissionList(db, collection, operationType);
|
|
226
226
|
return permissionList.some(permission => {
|
|
227
|
-
if (permission.
|
|
228
|
-
if (permission.
|
|
229
|
-
if (permission.
|
|
227
|
+
if (permission.accessType === 'god_access') return true;
|
|
228
|
+
if (permission.accessType === 'anonymous_access' && user.type === 'anonymous') return true;
|
|
229
|
+
if (permission.accessType === 'user_access' && user.type === 'user') return true;
|
|
230
230
|
return false;
|
|
231
231
|
});
|
|
232
232
|
}
|