Skip to content

Commit 08692cd

Browse files
feat: new check perms method (#50)
gisce/webclient#2308
1 parent a57b65d commit 08692cd

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
@@ -20,6 +20,7 @@ import {
2020
ReadAggOpts,
2121
ModelGetToolbarOpts,
2222
ModelCheckPermOpts,
23+
ModelCheckPermsOpts,
2324
} from "./types";
2425
import {
2526
createSearchPayload,
@@ -42,6 +43,7 @@ import {
4243
createReadAggPayload,
4344
createGetToolbarPayload,
4445
createCheckPermPayload,
46+
createCheckPermsPayload,
4547
} from "./payloads";
4648

4749
export class Model {
@@ -522,4 +524,24 @@ export class Model {
522524
options,
523525
});
524526
}
527+
528+
public async check_perms(
529+
data: ModelCheckPermsOpts,
530+
options?: RequestOptions,
531+
): Promise<any> {
532+
const { model, types } = data;
533+
const { database, token } = this.client;
534+
535+
const payload = createCheckPermsPayload({
536+
database: database!,
537+
token: token!,
538+
model,
539+
types,
540+
});
541+
542+
return await this.client._fetch({
543+
payload,
544+
options,
545+
});
546+
}
525547
}

lib/payloads.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ParseConditionsPayload,
3131
ModelRawExecutePayload,
3232
ModelCheckPermPayload,
33+
ModelCheckPermsPayload,
3334
} from "./types";
3435

3536
export const makeLoginTokenPayload = (options: LoginTokenPayload): Payload => {
@@ -543,3 +544,10 @@ export const createCheckPermPayload = (
543544
const { database, token, model, type } = options;
544545
return ["execute", database, "token", token, model, "check_perm", type];
545546
};
547+
548+
export const createCheckPermsPayload = (
549+
options: ModelCheckPermsPayload,
550+
): Payload => {
551+
const { database, token, model, types } = options;
552+
return ["execute", database, "token", token, model, "check_perms", types];
553+
};

lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,10 @@ export type ModelCheckPermOpts = {
297297
};
298298

299299
export type ModelCheckPermPayload = Database & Token & ModelCheckPermOpts;
300+
301+
export type ModelCheckPermsOpts = {
302+
model: string;
303+
types: string[];
304+
};
305+
306+
export type ModelCheckPermsPayload = Database & Token & ModelCheckPermsOpts;

0 commit comments

Comments
 (0)