Skip to content

Commit caf757c

Browse files
committed
Merge branch 'feat/check_perm' into alpha
2 parents 31a7981 + dd1ceeb commit caf757c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/model.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ReadForViewOpts,
2020
ReadAggOpts,
2121
ModelGetToolbarOpts,
22+
ModelCheckPermOpts,
2223
} from "./types";
2324
import {
2425
createSearchPayload,
@@ -40,6 +41,7 @@ import {
4041
createReadForViewPayload,
4142
createReadAggPayload,
4243
createGetToolbarPayload,
44+
createCheckPermPayload,
4345
} from "./payloads";
4446

4547
export class Model {
@@ -500,4 +502,24 @@ export class Model {
500502
options,
501503
});
502504
}
505+
506+
public async check_perm(
507+
data: ModelCheckPermOpts,
508+
options?: RequestOptions,
509+
): Promise<any> {
510+
const { model, type } = data;
511+
const { database, token } = this.client;
512+
513+
const payload = createCheckPermPayload({
514+
database: database!,
515+
token: token!,
516+
model,
517+
type,
518+
});
519+
520+
return await this.client._fetch({
521+
payload,
522+
options,
523+
});
524+
}
503525
}

lib/payloads.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ReadViewPrefsPayload,
2929
ModelGetToolbarPayload,
3030
ParseConditionsPayload,
31+
ModelCheckPermPayload,
3132
ModelRawExecutePayload,
3233
} from "./types";
3334

@@ -535,3 +536,10 @@ export const createReadViewPrefsPayload = (
535536
{},
536537
];
537538
};
539+
540+
export const createCheckPermPayload = (
541+
options: ModelCheckPermPayload,
542+
): Payload => {
543+
const { database, token, model, type } = options;
544+
return ["execute", database, "token", token, model, "check_perm", type];
545+
};

lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,10 @@ export type ModelGetToolbarPayload = Model &
290290
Database &
291291
Token &
292292
ModelGetToolbarOpts;
293+
294+
export type ModelCheckPermOpts = {
295+
model: string;
296+
type: string;
297+
};
298+
299+
export type ModelCheckPermPayload = Database & Token & ModelCheckPermOpts;

0 commit comments

Comments
 (0)