Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data-model-filter.parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export declare class DataModelFilterParser {
resolvingMember: AsyncSeriesEventEmitter<{ target: DataModelFilterParser, member: string, result: { $select: any, $expand?: any } }>;
resolvingMethod: AsyncSeriesEventEmitter<{ target: DataModelFilterParser, method: string, args: any, result: any }>;
parseAsync(str: string): Promise<{ $where: any, $expand?: any }>;
parse(str: string, callback: (err?: Error, result?: { $where: any, $expand?: any }) => void): void;
}
11 changes: 10 additions & 1 deletion data-permission.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// MOST Web Framework 2.0 Codename Blueshift BSD-3-Clause license Copyright (c) 2017-2022, THEMOST LP All rights reserved
import {DataModel} from "./data-model";
import {DataQueryable} from "./data-queryable";
import {BeforeExecuteEventListener, BeforeRemoveEventListener, BeforeSaveEventListener, DataEventArgs, DataModelPrivilege} from "./types";
import {
BeforeExecuteEventListener,
BeforeRemoveEventListener,
BeforeSaveEventListener,
DataContext,
DataEventArgs,
DataModelPrivilege
} from "./types";

export declare class DataPermissionEventArgs {
model: DataModel;
Expand Down Expand Up @@ -33,6 +40,8 @@ export declare class DataPermissionEventListener implements BeforeSaveEventListe
beforeExecute(event: DataEventArgs, callback: (err?: Error) => void): void;

validate(event: DataEventArgs, callback: (err?: Error) => void): void;

effectiveAccounts(context: DataContext, callback: (err?: Error, result?: { id?: unknown, name?: string }[]) => void): void;
}

export declare class DataPermissionExclusion {
Expand Down
13 changes: 6 additions & 7 deletions data-permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function DataPermissionEventArgs() {
this.model = null;
/**
* The underlying query expression
* @type {QueryExpression}
* @type {import('@themost/query').QueryExpression}
*/
this.query = null;
/**
Expand Down Expand Up @@ -198,8 +198,7 @@ DataPermissionExclusion.prototype.shouldExclude = function (privilege, callback)
});
};
/**
* @param {import("./types").DataModelPrivilege} privilege
* @param {function(Error=,boolean=)} callback
* @param {import("./types").DataModelPrivilege} privilege
*/
DataPermissionExclusion.prototype.shouldExcludeAsync = function (privilege) {
var self = this;
Expand Down Expand Up @@ -345,7 +344,7 @@ DataPermissionEventListener.prototype.validate = function(event, callback) {
//do nothing
return callback();
}
effectiveAccounts(context, function(err, accounts) {
DataPermissionEventListener.prototype.effectiveAccounts(context, function(err, accounts) {
if (err) {
return callback(err);
}
Expand Down Expand Up @@ -718,7 +717,7 @@ function queryUser(context, username, callback) {
* @param {function(Error=,Array=)} callback
* @private
*/
function effectiveAccounts(context, callback) {
DataPermissionEventListener.prototype.effectiveAccounts = function(context, callback) {
if (_.isNil(context)) {
//push no account
return callback(null, [ { id: null } ]);
Expand Down Expand Up @@ -876,7 +875,7 @@ DataPermissionEventListener.prototype.beforeExecute = function(event, callback)
//get model privileges (and clone them)
var modelPrivileges = _.cloneDeep(model.privileges || []);
// if there are no privileges
if (modelPrivileges.length == 0) {
if (modelPrivileges.length === 0) {
// add defaults
modelPrivileges.push.apply(modelPrivileges, [
{
Expand Down Expand Up @@ -920,7 +919,7 @@ DataPermissionEventListener.prototype.beforeExecute = function(event, callback)
return callback();
}

effectiveAccounts(context, function(err, accounts) {
DataPermissionEventListener.prototype.effectiveAccounts(context, function(err, accounts) {
if (err) { callback(err); return; }
//get all enabled privileges
var privileges = modelPrivileges.filter(function(x) {
Expand Down