baasic-sdk-angularjs
Version:
AngularJS SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
199 lines (132 loc) • 5.37 kB
Markdown
# baasicPermissionsService
Baasic Permissions Service provides an easy way to consume Baasic Application Permissions REST API end-points. In order to obtain needed routes `baasicPermissionsService` uses `baasicPermissionsRouteService`.
* * *
### baasicPermissionsService.find()
Returns a promise that is resolved once the find action has been performed. Success response returns a list of access policies that match the specified search parameters.
**Example**:
```js
baasicPermissionsService.find('<section-name>', {
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicPermissionsService.getActions()
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.
**Example**:
```js
baasicPermissionsService.getActions({
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicPermissionsService.getPermissionSubjects()
Returns a promise that is resolved once the getPermissionSubjects action has been performed. Success response returns a list of matching user and role resources.
**Example**:
```js
baasicPermissionsService.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
});
```
### baasicPermissionsService.create()
Returns a promise that is resolved once the create action has been performed; this action creates a new permission resource.
**Example**:
```js
// readAction and updateActions are resources previously fetched using getActions.
baasicPermissionsService.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
});
```
### baasicPermissionsService.remove()
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. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicPermissionsService` route template. Here is an example of how a route can be obtained from HAL enabled objects:
```
var params = baasicApiService.removeParams(permission);
var uri = params['model'].links('delete').href;
```
**Example**:
```js
// permission is a resource previously fetched using get action.
baasicPermissionsService.remove(permission)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
```
### baasicPermissionsService.createPermission()
Creates a new in-memory permission object.
**Example**:
```js
// action collection are lookup items fetched using baasicLookupService.get action.
var actionCollection;
return baasicLookupService.get()
.success(function (data) {
actionCollection = data;
})
.error(function (data, status, headers, config) {});
// subjectItem is an item fetched using baasicPermissionsService.getPermissionSubjects action.
baasicPermissionsService.createPermission('<section-Name>', actionCollection, subjectItem);
```
### baasicPermissionsService.findPermission()
Finds a permission in a given permission collection.
**Example**:
```js
baasicPermissionsService.findPermission(permissionObj, permissionCollection);
```
### baasicPermissionsService.exists()
Checks if a permission object exists in a given permission collection.
**Example**:
```js
baasicPermissionsService.exists(permissionObj, permissionCollection);
```
### baasicPermissionsService.togglePermission()
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.
**Example**:
```js
baasicPermissionsService.togglePermission(permissionObj, action);
```
### baasicPermissionsService.getModulePermissions()
Fetches and returns and object containing all existing module permissions.
**Example**:
```js
baasicPermissionsService.getModulePermissions('<section-name>');
```
### baasicPermissionsService.routeService()
Provides direct access to `baasicPermissionsRouteService`.
**Example**:
```js
baasicPermissionsService.routeService.get(expandObject);
```
* * *
**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 service.
*(c) 2017 Mono Ltd*
**Author:** Mono Ltd
**License:** MIT