Package Exports
- @zohodesk/permissions
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@zohodesk/permissions) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Restriction validation for your app
Creating Restriction Rules/ Read only messages for your app
import { READ_ONLY, SHOW, HIDE } from '@zohodesk/permissions'
const restrictionRules = {
<group-name>: {
<features>: {
<feature-action-1>: [SHOW, READ_ONLY], //In array 1th position meant can we show ?, 2st position meant to can we readOnly ?
<feature-action-2>: [SHOW, READ_ONLY],
<feature-action-3>: [HIDE]
}
}
}
};
const readyOnlyMessages = {
<group-name>: {
<features>: {
<feature-action-1>: message ,
<feature-action-2>: message ,
<feature-action-3>: message
}
}
};
Restriction Rules
const restrictionRules = {
tickets: {
isSpam: {
secondaryContact: [SHOW, READ_ONLY],
timeline: [HIDE],
mergeTicket: [SHOW, READ_ONLY],
edit : [SHOW]
}
},
bluePrintApplied: {
status: [SHOW, READ_ONLY],
move: [HIDE],
edit : [HIDE]
}
},
contacts: {
anonymous_users : {
edit: [HIDE],
follow: [HIDE],
add_tickets: [SHOW, READ_ONLY],
add_products: [SHOW]
}
}
}
};Read Only Messages
const readOnlyMessages = {
contacts: {
anonymous_users: {
edit: 'support.contacts.edit.field.locked',
add_tickets: 'support.add_tickets.field.locked',
add_products: 'support.add_products.field.locked'
}
};
Restriction handling into your app using util methods
Write an file and exports it.
import { createGetRestriction } from '@zohodesk/permissions';
const getRestriction = createGetRestriction(restrictionRules,lockMessages);
export default getRestriction;How to use the it.
import getRestriction from '../written-file';
getRestriction(features=[...], group-name , feature-action-1);
getRestriction(['isSpam','bluePrintApplied'],'tickets','edit')
getRestriction('isSpam','tickets','edit')
Restriction handling into your app using components
Write an file and exports it.
import { createRestrictionValidator } from '@zohodesk/permissions';
const RestrictionValidator = createRestrictionValidator(restrictionRules,lockMessages);
export default RestrictionValidator;How to use the it.
import RestrictionValidator from 'written-file';
<RestrictionValidator module={group-name}
features={features [] or feature string}
action={feature or action}>
{({isReadOnly,readOnlyMessage})=>{
return (<span>
<Icon name='ZD-addNew' iconClass={iconClass} /> Add product
</span>)
}}
</RestrictionValidator>YourComponent - we will add few props based on the restriction values - ReadOnly, readOnlyMessage
isShow : false - By default, we will return null. In this case children won't be rendered.
<RestrictionValidator module={group-name}
features={features [] or feature string}
action={feature or action}>
<YourComponent />
</RestrictionValidator>
handleShowHide - you can handle the show/hide 'isShow' into you component, simply passing props
handleShowHide={false}
<RestrictionValidator module={group-name} handleShowHide={false}
features={features [] or feature string}
action={feature or action}>
{({isShow,isReadOnly,readOnlyMessage})=>{
if(!isShow){
return (<span>Add Contact</span>)
}
return (<span>
<Icon name='ZD-addNew' iconClass={iconClass} /> Add product
</span>)
}}
</RestrictionValidator>License and Permission validation for your app
import { licensePermissionCheckHOC } from '@zohodesk/permissions';
licensePermissionCheckHOC({
validation : {
license : ... ,
permission : ...
},
customValdation : {...},
Fallback : func..
})(YourComponent);
license - used to verify with user license. * , Any other
permission - used to verify with user permissions. * , Any other
* - Means all.
License Permission validation in connected components
import { connect } from 'react-redux';
import { compose } from 'redux';
import { permissions, licenses } from 'provider';
import { ALL , licensePermissionCheckHOC , } from '@zohodesk/permissions';
export defult compose(connect(...),
licensePermissionCheckHOC({
validation : {
license : ALL,
permissions : permissions.TICKETS_CREATE
},
customValdation : {...},
Fallback : func..
})
)(YourComponent);
License Permission validation with custom permission checks.
let YourComponentNew = licensePermissionCheckHOC({
validation : {
license : ALL,
permissions : ALL
},
customValdation : {
canMove :(props)=>{
let { module , checkMoveOption } = props;
let permission = `${module}_view`;
if(crossDepartmentsMove){
permission += `&&${module}_crossDepartmentMove`
}
return {
permission ,
obj : true,
falseObj : false
}
}
},
Fallback : func..
})(YourComponent);
<YourComponentNew module="tickets" checkMoveOption={true} />
<YourComponentNew module="tasks" checkMoveOption={true} />