forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-permission.d.ts
181 lines (158 loc) · 5.01 KB
/
angular-permission.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Type definitions for angular-permission 2.3.6
// Project: https://github.com/Narzerus/angular-permission
// Definitions by: Voislav Mishevski <https://github.com/vmishevski>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../angular-ui-router/angular-ui-router.d.ts" />
declare namespace angular.permission {
/**
* Used as optional parameter provided on definitions of permissions and roles
*/
export interface TransitionProperties {
fromState?: angular.ui.IState;
fromParams?: angular.ui.IStateParamsService;
toState?: angular.ui.IState;
toParams?: angular.ui.IStateParamsService;
options?: angular.ui.IStateOptions;
}
export interface PermissionStore {
/**
* Allows to define permission on application configuration
* @method
*
* @param permissionName {String} Name of defined permission
* @param validationFunction {Function} Function used to validate if permission is valid
*/
definePermission(
name: string,
validationFunction: (permission?: string, transitionProperties?: TransitionProperties) => boolean | angular.IPromise<any>
): void;
/**
* Allows to define set of permissionNames with shared validation function on application configuration
* @method
* @throws {TypeError}
*
* @param permissionNames {Array} Set of permission names
* @param validationFunction {Function} Function used to validate if permission is valid
*/
defineManyPermissions(
permissions: string[],
validationFunction: (permission?: string, transitionProperties?: TransitionProperties) => boolean | angular.IPromise<any>
): void;
clearStore(): void;
/**
* Deletes permission
* @method
*
* @param permissionName {String} Name of defined permission
*/
removePermissionDefinition(permission: string): void;
/**
* Checks if permission exists
* @method
*
* @param permissionName {String} Name of defined permission
* @returns {Boolean}
*/
hasPermissionDefinition(permissionName: string): boolean;
/**
* Returns all permissions
* @method
*
* @returns {Object} Permissions collection
*/
getStore(): Permission[];
}
export interface RoleStore {
/**
* Allows to define role
* @method
*
* @param roleName {String} Name of defined role
* @param permissions {Array} Set of permission names
* @param [validationFunction] {Function} Function used to validate if permissions in role are valid
*/
defineRole(
role: string,
permissions: Array<string>,
validationFunction: RoleValidationFunction
): void;
/**
* Allows to define role
* @method
*
* @param roleName {String} Name of defined role
* @param permissions {Array} Set of permission names
*/
defineRole(role: string, permissions: Array<string>): void;
/**
* Checks if role is defined in store
* @method
*
* @param roleName {String} Name of role
* @returns {Boolean}
*/
hasRoleDefinition(role: string): boolean;
/**
* Returns role definition object by it's name
* @method
*
* @returns {permission.Role} Role definition object
*/
getRoleDefinition(roleName: string): Role;
/**
* Removes all role definitions
* @method
*/
clearStore(): void;
/**
* Deletes role from store
* @method
*
* @param roleName {String} Name of defined permission
*/
removeRoleDefinition(roleName: string): void;
/**
* Returns all role definitions
* @method
*
* @returns {Object} Defined roles collection
*/
getStore(): Role[];
}
export interface Role {
roleName: string;
permissionNames: string[];
validationFunction?: RoleValidationFunction;
}
export interface Permission {
permissionName: string;
validationFunction?: PermissionValidationFunction;
}
interface RoleValidationFunction {
(permission?: string, transitionProperties?: TransitionProperties): boolean | angular.IPromise<any>;
}
interface PermissionValidationFunction {
(permission?: string, transitionProperties?: TransitionProperties): boolean | angular.IPromise<any>;
}
export interface IPermissionState extends angular.ui.IState {
data?: any | DataWithPermissions;
}
export interface DataWithPermissions {
permissions?: {
only?: (() => void) | Array<string> | angular.IPromise<any>;
except?: (() => void) | Array<string> | angular.IPromise<any>;
redirectTo: string | (() => string) | (() => PermissionRedirectConfigation) | {[index: string]: PermissionRedirectConfigation}
};
}
export interface PermissionRedirectConfigation {
state: string;
params?: {};
options?: angular.ui.IStateOptions;
}
}
declare module "angular-permission" {
export var permission: string;
export var ngPermission: string;
export var uiPermission: string;
}