permissions licenses and plans, user validations handling for whole app
npm install @zohodesk/permissionsjavascrript
import { READ_ONLY, SHOW, HIDE } from '@zohodesk/permissions'
const restrictionRules = {
: {
: {
: [SHOW, READ_ONLY], //In array 1th position meant can we show ?, 2st position meant to can we readOnly ?
: [SHOW, READ_ONLY],
: [HIDE]
}
}
}
};
const readyOnlyMessages = {
: {
: {
: message ,
: message ,
: message
}
}
};
`
$3
`
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]
}
}
}
};
`
$3
`
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'
}
};
`
$3
`javascript
const permission = {
"tickets" : {
create: true,
delete: true,
edit: true,
export: true,
import: true,
view: true
}
}
`
$3
`
const license = {
agentAllowed: true,
agentMaxCount: "100",
manualTimeTrackingAllowed: true,
ticketTemplateAllowed: true,
timeTrackingAllowed: true,
twilioAllowed: true,
webFormsAllowed: true
}
`
$3
`javascript
import { PermissionProvider } from '@zohodesk/permissions'
{permission}
{license}
{restrictionRules}
{lockMessages}
>
{component}
`
$3
##### How to use the it.
`javascript
import { restrictionProviderUtils } from '@zohodesk/permissions';
restrictionProviderUtils.getRestriction(features=[...], group-name , feature-action-1);
restrictionProviderUtils.getRestriction(['isSpam','bluePrintApplied'],'tickets','edit')
restrictionProviderUtils.getRestriction('isSpam','tickets','edit')
`
$3
##### How to use the it.
`javascript
import { RestrictionValidator } from '@zohodesk/permissions';
features={features [] or feature string}
action={feature or action}>
{({isReadOnly,readOnlyMessage})=>{
return (
Add product
)
}}
`
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.
`javascript
features={features [] or feature string}
action={feature or action}>
`
handleShowHide - you can handle the show/hide 'isShow' into you component, simply passing props
handleShowHide={false}
`javascript
features={features [] or feature string}
action={feature or action}>
{({isShow,isReadOnly,readOnlyMessage})=>{
if(!isShow){
return (Add Contact)
}
return (
Add product
)
}}
`
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.
$3
`javascrript
import { connect } from 'react-redux';
import { compose } from 'redux';
import { getPermission } from 'provider';
import { ALL , licensePermissionCheckHOC } from '@zohodesk/permissions';
export defult compose(connect(...),
licensePermissionCheckHOC({
validation : {
license : ALL,
permission : getPermission("tickets", "create")
},
customValdation : {...},
Fallback : func..
})
)(YourComponent);
`
$3
`javascrript
import { connect } from 'react-redux';
import { compose } from 'redux';
import { getPermission } from 'provider';
import { ALL , licensePermissionCheckHOC } from '@zohodesk/permissions';
export defult compose(connect(...),
licensePermissionCheckHOC({
validation : {
license : ALL,
permission : getPermission("tickets", "create") + "&&"+ getPermission("tickets", "edit")
},
customValdation : {...},
Fallback : func..
})
)(YourComponent);
`
$3
`javascrript
let YourComponentNew = licensePermissionCheckHOC({
validation : {
license : ALL,
permission : 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);
`
$3
`javascript
import { licensePermissionProviderUtils } from '@zohodesk/permissions';
let {licenseSuccess, permissionSuccess, permissionProps, failedCases} = licensePermissionProviderUtils.getLicensePermissionCheck({
license : ALL,
permission : ALL
});
if(licenseSuccess && permissionSuccess){
return
}
`
$3
`javascrript
import { LicensePermissionHandler } from '@zohodesk/permissions';
SuccessComponent={YourComponent}
FallbackComponent={null}
validationProps={{
license : ALL,
permission : ALL
}}
/>
``