@holoyan/adonisjs-permissions 0.1.0 → 0.5.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.
- package/README.md +160 -59
- package/build/index.d.ts +10 -4
- package/build/index.js +10 -5
- package/build/providers/role_permission_provider.d.ts +3 -0
- package/build/providers/role_permission_provider.js +21 -0
- package/build/src/acl.d.ts +10 -5
- package/build/src/acl.js +17 -9
- package/build/src/decorators.js +1 -0
- package/build/src/mixins/has_permissions.d.ts +58 -26
- package/build/src/mixins/has_permissions.js +123 -18
- package/build/src/model_manager.d.ts +7 -0
- package/build/src/model_manager.js +15 -0
- package/build/src/models/permission.d.ts +4 -4
- package/build/src/models/permission.js +2 -7
- package/build/src/models/role.d.ts +1 -1
- package/build/src/models/role.js +2 -7
- package/build/src/morph_map.d.ts +5 -2
- package/build/src/morph_map.js +16 -9
- package/build/src/services/helper.d.ts +2 -3
- package/build/src/services/helper.js +1 -7
- package/build/src/services/model_has_role_permissions.d.ts +41 -39
- package/build/src/services/model_has_role_permissions.js +92 -111
- package/build/src/services/model_service.d.ts +15 -6
- package/build/src/services/model_service.js +39 -14
- package/build/src/services/permissions/empty_permission.d.ts +8 -0
- package/build/src/services/permissions/empty_permission.js +17 -0
- package/build/src/services/permissions/permission_has_model_roles.d.ts +12 -8
- package/build/src/services/permissions/permission_has_model_roles.js +28 -19
- package/build/src/services/permissions/permissions_service.d.ts +42 -30
- package/build/src/services/permissions/permissions_service.js +198 -155
- package/build/src/services/query_helper.d.ts +7 -0
- package/build/src/services/query_helper.js +12 -0
- package/build/src/services/roles/empty_roles.d.ts +8 -0
- package/build/src/services/roles/empty_roles.js +17 -0
- package/build/src/services/roles/role_has_model_permissions.d.ts +32 -33
- package/build/src/services/roles/role_has_model_permissions.js +64 -78
- package/build/src/services/roles/roles_service.d.ts +20 -9
- package/build/src/services/roles/roles_service.js +90 -34
- package/build/src/types.d.ts +65 -5
- package/build/stubs/configs/permissions.stub +1 -1
- package/build/stubs/migrations/create_db.stub +8 -8
- package/package.json +3 -1
- package/build/src/mixins/has_role_permissions.d.ts +0 -128
- package/build/src/mixins/has_role_permissions.js +0 -10
- package/build/src/mixins/has_roles.d.ts +0 -1
- package/build/src/mixins/has_roles.js +0 -47
|
@@ -1,92 +1,104 @@
|
|
|
1
1
|
import { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
|
|
2
|
-
import
|
|
3
|
-
import Permission from '../../models/permission.js';
|
|
4
|
-
import { ModelPermissionsQuery } from '../../types.js';
|
|
2
|
+
import { ModelPermissionsQuery, MorphInterface, PermissionInterface, PermissionModel } from '../../types.js';
|
|
5
3
|
import BaseService from '../base_service.js';
|
|
4
|
+
import { BaseModel } from '@adonisjs/lucid/orm';
|
|
6
5
|
export default class PermissionsService extends BaseService {
|
|
6
|
+
private permissionClassName;
|
|
7
|
+
private roleClassName;
|
|
8
|
+
private modelPermissionClassName;
|
|
9
|
+
private modelRoleClassName;
|
|
10
|
+
private map;
|
|
11
|
+
private permissionQuery;
|
|
12
|
+
private readonly permissionTable;
|
|
13
|
+
private modelPermissionQuery;
|
|
14
|
+
private readonly modelPermissionTable;
|
|
15
|
+
private readonly modelRoleTable;
|
|
16
|
+
constructor(permissionClassName: typeof BaseModel, roleClassName: typeof BaseModel, modelPermissionClassName: typeof BaseModel, modelRoleClassName: typeof BaseModel, map: MorphInterface);
|
|
7
17
|
/**
|
|
8
|
-
* return all permissions, including
|
|
18
|
+
* return all permissions, including forbidden
|
|
9
19
|
*/
|
|
10
|
-
all(modelType: string, modelId: number,
|
|
20
|
+
all(modelType: string, modelId: number, includeForbiddings?: boolean): Promise<PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>[]>;
|
|
11
21
|
/**
|
|
12
22
|
* return only global assigned permissions, through role or direct
|
|
13
23
|
*/
|
|
14
|
-
global(modelType: string, modelId: number,
|
|
24
|
+
global(modelType: string, modelId: number, includeForbiddings?: boolean): Promise<PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>[]>;
|
|
15
25
|
/**
|
|
16
26
|
* get all permissions which is assigned to concrete resource
|
|
17
27
|
*/
|
|
18
|
-
onResource(modelType: string, modelId: number,
|
|
28
|
+
onResource(modelType: string, modelId: number, includeForbiddings?: boolean): Promise<PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>[]>;
|
|
19
29
|
/**
|
|
20
30
|
* all direct permissions
|
|
21
31
|
*/
|
|
22
|
-
direct(modelType: string, modelId: number,
|
|
23
|
-
directGlobal(modelType: string, modelId: number,
|
|
32
|
+
direct(modelType: string, modelId: number, includeForbiddings?: boolean): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
33
|
+
directGlobal(modelType: string, modelId: number, includeForbiddings?: boolean): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
24
34
|
/**
|
|
25
35
|
* return direct and resource assigned permissions
|
|
26
36
|
*/
|
|
27
|
-
directResource(modelType: string, modelId: number,
|
|
37
|
+
directResource(modelType: string, modelId: number, includeForbiddings?: boolean): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
28
38
|
/**
|
|
29
39
|
* @param modelType
|
|
30
40
|
* @param modelId
|
|
31
|
-
* @param
|
|
41
|
+
* @param permissions
|
|
42
|
+
* @param entityType
|
|
43
|
+
* @param entityId
|
|
32
44
|
* @returns
|
|
33
45
|
*/
|
|
34
|
-
hasAnyDirect(modelType: string, modelId: number,
|
|
35
|
-
hasAllDirect(modelType: string, modelId: number,
|
|
46
|
+
hasAnyDirect(modelType: string, modelId: number, permissions: (string | PermissionInterface)[], entityType: string | null, entityId: number | null): Promise<boolean>;
|
|
47
|
+
hasAllDirect(modelType: string, modelId: number, permissions: (string | PermissionInterface)[], entityType: string | null, entityId: number | null): Promise<boolean>;
|
|
36
48
|
/**
|
|
37
49
|
* has all permissions
|
|
38
50
|
*/
|
|
39
|
-
hasAll(modelType: string, modelId: number,
|
|
51
|
+
hasAll(modelType: string, modelId: number, permissions: (string | PermissionInterface)[], entityType: string | null, entityId: number | null): Promise<boolean>;
|
|
40
52
|
/**
|
|
41
53
|
* has any of permissions
|
|
42
54
|
*/
|
|
43
|
-
hasAny(modelType: string, modelId: number,
|
|
55
|
+
hasAny(modelType: string, modelId: number, permission: (string | PermissionInterface)[], entityType: string | null, entityId: number | null): Promise<boolean>;
|
|
44
56
|
/**
|
|
45
57
|
* has all permissions
|
|
46
58
|
*/
|
|
47
|
-
containsAll(modelType: string, modelId: number,
|
|
59
|
+
containsAll(modelType: string, modelId: number, permission: (string | PermissionInterface)[]): Promise<boolean>;
|
|
48
60
|
/**
|
|
49
61
|
* has any of permissions
|
|
50
62
|
*/
|
|
51
|
-
containsAny(modelType: string, modelId: number,
|
|
63
|
+
containsAny(modelType: string, modelId: number, permission: (string | PermissionInterface)[]): Promise<boolean>;
|
|
52
64
|
/**
|
|
53
65
|
* has all permissions
|
|
54
66
|
*/
|
|
55
|
-
containsAllDirect(modelType: string, modelId: number,
|
|
67
|
+
containsAllDirect(modelType: string, modelId: number, permission: (string | PermissionInterface)[]): Promise<boolean>;
|
|
56
68
|
/**
|
|
57
69
|
* has any of permissions
|
|
58
70
|
*/
|
|
59
|
-
containsAnyDirect(modelType: string, modelId: number,
|
|
71
|
+
containsAnyDirect(modelType: string, modelId: number, permission: (string | PermissionInterface)[]): Promise<boolean>;
|
|
60
72
|
/**
|
|
61
73
|
* check if permission is forbidden, if there is same permission with allowed=false then return true;
|
|
62
74
|
*/
|
|
63
|
-
forbidden(modelType: string, modelId: number,
|
|
75
|
+
forbidden(modelType: string, modelId: number, permission: string | PermissionInterface, entityType: string | null, entityId: number | null): boolean;
|
|
64
76
|
/**
|
|
65
77
|
* give permission to model
|
|
66
78
|
*/
|
|
67
|
-
giveAll(modelType: string, modelId: number, slugs: string[], entityType: string | null, entityId: number | null, allowed: boolean): Promise<
|
|
68
|
-
revokeAll(modelType: string, modelId: number, permissions: string[], entityType: string | null, entityId: number | null): ModelQueryBuilderContract<
|
|
69
|
-
flush(modelType: string, modelId: number): ModelQueryBuilderContract<
|
|
79
|
+
giveAll(modelType: string, modelId: number, slugs: string[], entityType: string | null, entityId: number | null, allowed: boolean): Promise<import("@adonisjs/lucid/types/model").LucidRow[]>;
|
|
80
|
+
revokeAll(modelType: string, modelId: number, permissions: string[], entityType: string | null, entityId: number | null): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, any>;
|
|
81
|
+
flush(modelType: string, modelId: number): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, any>;
|
|
70
82
|
/**
|
|
71
83
|
* sync permissions, remove everything outside of the list
|
|
72
84
|
*/
|
|
73
|
-
sync(modelType: string, modelId: number, permissionId: string[]): Promise<
|
|
85
|
+
sync(modelType: string, modelId: number, permissionId: string[]): Promise<import("@adonisjs/lucid/types/model").LucidRow[]>;
|
|
74
86
|
/**
|
|
75
87
|
* forbid permission on model
|
|
76
88
|
*/
|
|
77
|
-
forbid(modelType: string, modelId: number, permissionSlug: string, entityType: string | null, entityId: number | null): Promise<
|
|
89
|
+
forbid(modelType: string, modelId: number, permissionSlug: string, entityType: string | null, entityId: number | null): Promise<import("@adonisjs/lucid/types/model").LucidRow[]>;
|
|
78
90
|
/**
|
|
79
91
|
* forbid permission on model
|
|
80
92
|
*/
|
|
81
|
-
forbidAll(modelType: string, modelId: number, permissionsSlug: string[], entityType: string | null, entityId: number | null): Promise<
|
|
93
|
+
forbidAll(modelType: string, modelId: number, permissionsSlug: string[], entityType: string | null, entityId: number | null): Promise<import("@adonisjs/lucid/types/model").LucidRow[]>;
|
|
82
94
|
/**
|
|
83
95
|
* to remove forbidden permission on model
|
|
84
96
|
*/
|
|
85
97
|
unforbidAll(modelType: string, modelId: number, permissionsSlug: string[], entityType: string | null, entityId: number | null): Promise<any[]>;
|
|
86
|
-
findBySlug(slug: string, allowed?: boolean): Promise<
|
|
98
|
+
findBySlug(slug: string, allowed?: boolean): Promise<PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
87
99
|
private modelPermissionQueryWithForbiddenCheck;
|
|
88
|
-
private
|
|
89
|
-
reverseModelPermissionQuery(conditions: Partial<ModelPermissionsQuery>): ModelQueryBuilderContract<
|
|
90
|
-
findAssignableEntity(
|
|
100
|
+
private modelPermissionQueryBuilder;
|
|
101
|
+
reverseModelPermissionQuery(conditions: Partial<ModelPermissionsQuery>): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, import("../../types.js").ModelPermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
102
|
+
findAssignableEntity(permission: string[], entityClass: string | null, entityId: number | null, allowed: boolean): ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, PermissionModel<import("@adonisjs/lucid/types/model").LucidModel>>;
|
|
91
103
|
private applyTargetRestriction;
|
|
92
104
|
}
|