baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
186 lines (185 loc) • 8.42 kB
TypeScript
/**
* @module permissionClient
* @description Role Client provides an easy way to consume Role REST API end-points. In order to obtain needed routes `permissionClient` uses `permissionRoute`.
*/
import { ApiClient, IHttpResponse } from '../../httpApi';
import { PermissionRoute } from './';
import { IAccessPolicy, IAccessSection, IAccessAction } from './contracts';
import { IBaasicApp } from '../../core/contracts';
export declare class PermissionClient {
protected permissionRoute: PermissionRoute;
protected apiClient: ApiClient;
private application;
private utility;
private permissionHash;
/**
* Provides direct access to `permissionRoute`.
* @method
* @example permissionClient.routeDefinition.get().expand(expandObject);
**/
readonly routeDefinition: PermissionRoute;
constructor(permissionRoute: PermissionRoute, apiClient: ApiClient, application: IBaasicApp);
/**
* Returns a promise that is resolved once the findAll action has been performed. Success response returns a list of access sections matching the given criteria.
* @method
* @param options Query resource options object.
* @returns A promise that is resolved once the find action has been performed.
* @example permissionClient.findAll({
searchQuery : '<search-phrase>'
})
.then(function (collection) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
findAll(options?: any): PromiseLike<IHttpResponse<IAccessSection[]>>;
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of role resources matching the given criteria.
* @method
* @param options Query resource options object.
* @returns A promise that is resolved once the find action has been performed.
* @example permissionClient.find({
section : '<access-section>',
search : '<search-phrase>'
})
.then(function (collection) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
find(section: string, options?: any): PromiseLike<IHttpResponse<IAccessPolicy[]>>;
/**
* Returns a promise that is resolved once the getActions action has been performed. Success response returns a list of access policies that match the specified search parameters.
* @method
* @example
permissionClient.getActions({
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
getActions(options?: any): PromiseLike<IHttpResponse<IAccessAction[]>>;
/**
* Returns a promise that is resolved once the getSectionPolicies action has beed preformed. Success response returns a list of requested access policies that match the specified search parameters
*/
getSectionsPolicies(sectionAbrvs: string, options?: any): PromiseLike<IHttpResponse<IAccessPolicy[]>>;
/**
* Returns a promise that is resolved once the getPermissionSubjects action has been performed. Success response returns a list of matching user and role resources.
* @method
* @example
permissionClient.getPermissionSubjects({
orderBy : '<field>',
orderDirection : '<asc|desc>',
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
getPermissionSubjects(options: any): PromiseLike<any>;
/**
* Returns a promise that is resolved once the create action has been performed; this action creates a new permission resource.
* @method
* @example
// readAction and updateActions are resources previously fetched using getActions.
permissionClient.create({
actions : [readAction, updateAction],
section : '<section-name>',
userName : '<userName>'
})
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
create(data: IAccessPolicy): PromiseLike<IHttpResponse<IAccessPolicy[]>>;
/**
* Returns a promise that is resolved once the remove action has been performed. If the action is successfully complete, an access policy assigned to the specified role and section will be removed.
* @method
* @example
// permission is a resource previously fetched using get action.
permissionClient.remove(permission)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
remove(data: IAccessPolicy): PromiseLike<IHttpResponse<any>>;
/**
* Creates a new in-memory permission object.
* @method
* @example
// action collection are lookup items fetched using lookupClient.get action.
var actionCollection;
return lookupClient.get()
.success(function (data) {
actionCollection = data;
})
.error(function (data, status, headers, config) {});
// subjectItem is an item fetched using permissionClient.getPermissionSubjects action.
permissionClient.createPermission('<section-Name>', actionCollection, subjectItem);
**/
createPermission(section: string, actions: IAccessAction[], membershipItem: any): any;
/**
* Finds a permission in a given permission collection.
* @method
* @example permissionClient.findPermission(permissionObj, permissionCollection);
**/
findPermission(permission: any, permissionCollection: any): any;
/**
* Checks if a permission object exists in a given permission collection.
* @method
* @example permissionClient.exists(permissionObj, permissionCollection);
**/
exists(permission: any, permissionCollection: any): boolean;
/**
* Returns a promise that is resolved once the togglePermission action has been completed. The action will internally either call a `remove` or `create` action based on given criteria.
* @method
* @example permissionClient.togglePermission(permissionObj, action);
**/
togglePermission(permission: any, action: any): any;
/**
* Fetches and returns and object containing all existing module permissions.
* @method
* @example permissionClient.getModulePermissions('<section-name>');
**/
getModulePermissions(section: any): {
update: boolean;
create: boolean;
remove: boolean;
read: boolean;
full: boolean;
};
resetPermissions(): void;
/**
* Checks if current user has permissions to perform a certain action. To optimize performance this information is cached and can be reset using the resetPermissions action. Permissions cache should be reset when updated user information is set.
* @method
* @example baasicAuthorizationService.hasPermission("<baasic-Section>.<action>");
**/
hasPermission(authorization: string): boolean;
private isEmpty;
private getRoles;
private getUsers;
private firstCharToLowerCase;
}
/**
* @overview
***Notes:**
- Refer to the [Baasic REST API](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points.
- All end-point objects are transformed by the associated route definition.
*/