@agendize/vue-acl
Advanced tools
Comparing version 0.0.2-beta01 to 0.0.2
@@ -12,2 +12,4 @@ import { reactive, computed } from "vue"; | ||
rules: defaultRules, | ||
router: null, | ||
onDeniedRoute: "/", | ||
debug: false | ||
@@ -60,2 +62,45 @@ }; | ||
registerDirective(app, `can`); | ||
if (pluginOptions.router) { | ||
const routerRedirectHandler = (to, from, next, granted) => { | ||
if (granted) { | ||
next(); | ||
} else { | ||
let onDeniedRoute = pluginOptions.onDeniedRoute; | ||
if (to.meta && to.meta.onDeniedRoute) { | ||
onDeniedRoute = to.meta.onDeniedRoute; | ||
} | ||
if (typeof onDeniedRoute === "object") { | ||
next(onDeniedRoute); | ||
} else { | ||
if (onDeniedRoute === "$from") { | ||
next(from); | ||
} else { | ||
next({ path: `${onDeniedRoute}`, replace: true }); | ||
} | ||
} | ||
} | ||
}; | ||
const evaluateRouterAcl = (to, from, next) => { | ||
if (to.meta && to.meta.can) { | ||
const abilities = to.meta.can; | ||
let granted = canHelperHandler(abilities); | ||
routerRedirectHandler(to, from, next, granted); | ||
} else if (to.meta && to.meta.canNot) { | ||
const abilities = to.meta.canNot; | ||
let granted = notCanHelperHandler(abilities); | ||
routerRedirectHandler(to, from, next, granted); | ||
} else if (to.meta && to.meta.canAny) { | ||
const abilities = to.meta.canAny; | ||
let granted = anyCanHelperHandler(abilities); | ||
routerRedirectHandler(to, from, next, granted); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
pluginOptions.router.beforeEach((to, from, next) => { | ||
evaluateRouterAcl(to, from, next); | ||
}); | ||
} else { | ||
console.error(`:::VueACL::: Instance of vue-router is required.`); | ||
} | ||
}; | ||
@@ -62,0 +107,0 @@ const createAcl = (userDefinedOptions) => { |
@@ -1,1 +0,1 @@ | ||
(function(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u(l.VueACL={},l.Vue))})(this,function(l,u){"use strict";const r=u.reactive({registeredUser:{},registeredRights:{},registeredRules:{},options:{}}),A=(e,t)=>{const n={...{user:Object.create(null),rules:v,debug:!1},...t};w(n);const i=(o,d)=>{const f=d.arg,g=d.value,a=d.modifiers,_=!!a.any,S=!!a.not,D=!!a.readonly,$=!!(a.disable||a.disabled),q=!!(a.hide||a.hidden);m({abilities:f,args:g,any:_})?S?o.style.display="none":o.style.display="":S?o.style.display="":$?o.disabled=!0:D?o.readOnly=!0:o.style.display="none"};((o,d)=>{o.directive(`${d}`,{mounted(f,g){i(f,g)},updated(f,g){i(f,g)}})})(e,"can")},b=e=>({install:(t,s={})=>{A(t,{...s,...e})}}),y=e=>{typeof e=="function"&&e(L)},C=()=>{const e={};return e.user=u.computed(()=>r.registeredUser).value,e.getUser=()=>r.registeredUser,e.setUser=t=>r.registeredUser=t,e.rights=u.computed(()=>r.registeredRights).value,e.getRights=()=>r.registeredRights,e.setRights=t=>r.registeredRights=t,e.fetchRights=(t,s,n)=>T(t,s,n),e.can=U,e.can.not=V,e.can.any=N,u.reactive(e)},v=()=>y(e=>{["companySettings","servicesSettings","staffsSettings","resourcesSettings","appointmentsNew","appointmentsAccept","appointmentsReschedule","appointmentsStatusChange","appointmentsModeFree"].forEach(s=>{e(s,(n,i)=>H(n,s,i))})}),w=e=>{const t=e.user;if(r.registeredUser=t,e.rights){const s=e.rights;r.registeredRights=s}e.rules&&typeof e.rules=="function"&&e.rules(),r.options=e},L=(e,t)=>{typeof e=="string"&&M(e,t)},M=(e,t)=>{Object.prototype.hasOwnProperty.call(r.registeredRules,e)?console.warn(`:::VueACL::: Duplicate ACL Rule '${e}' defined. Only the first defined rule will be evaluated.`):r.registeredRules[e]=t},U=(e,t)=>p({abilities:e,args:t,any:!1}),V=(e,t)=>!p({abilities:e,args:t,any:!1}),N=(e,t)=>p({abilities:e,args:t,any:!0}),p=({abilities:e,args:t,any:s=!1})=>e&&typeof e=="string"?m({abilities:e,args:t,any:s}):(console.warn(":::VueACL::: Invalid ACL arguments specified."),!1),m=({abilities:e,args:t,any:s=!1})=>{const n=e,i=t;let c=!1;return n&&(i?c=R({abilities:n,args:i}):c=R({abilities:n})),c},R=({abilities:e,args:t,any:s=!1})=>{if(e&&typeof e=="string"&&Object.prototype.hasOwnProperty.call(r.registeredRules,e)){const n=r.registeredRules[e];return P(n,e,t)}return!1},P=(e,t,s)=>{try{return typeof e=="function"?typeof s=="object"&&!Array.isArray(s)?e(r.registeredUser,s):typeof s=="object"&&Array.isArray(s)?e(r.registeredUser,...s):e(r.registeredUser):!1}catch(n){const i=j(e);i&&Array.isArray(i)&&i.shift();let c=':::VueACL::: The defined ACL Rule for "'+t+'" require some argument(s) or data object to be specified for matching.';return console.error(c),console.error(n),!1}},j=e=>{let t=null;const s=/\(([a-z0-9 ,$_+*\-/]+)\)/im,i=e.toString().match(s);if(i&&Array.isArray(i)&&i[0]){let c=i[0];c=c.replace(/\(|\)|[ ]/g,"");const o=c.split(",");o.length>0&&(t=o)}return t},H=(e,t,s)=>{if(s&&s.id&&s.owner&&s.owner.userName){const n=O(e,s.id);if(n)if(r.registeredRights){const i=r.registeredRights.find(c=>c.owner===s.owner.userName);if(i){const c=i.rights[n];if(c){const o=c[t];return r.options.debug&&console.debug(":::VueACL::: Ability ["+t+"] on ["+s.id+"]: "+o),o}else r.options.debug&&console.debug(":::VueACL::: No ability found for this role ["+n+"] on ["+s.id+"]")}else r.options.debug&&console.debug(":::VueACL::: No company ["+s.id+"] rights founded ["+s.owner.userName+"]")}else r.options.debug&&console.debug(":::VueACL::: No registeredRights");else r.options.debug&&console.debug(":::VueACL::: User has no role on this company ["+s.id+"]",e)}return!1},O=(e,t)=>{if(e&&e.roles&&t){const s=e.roles.find(n=>n.companyId===t);if(s)return s.role}},T=async(e,t,s)=>{var n;((n=r.registeredRights)==null?void 0:n.length)>0&&!s||(r.registeredRights=[],await Promise.all([...t].map(i=>e.getAccountSettings(i).then(c=>{const o=c.result;if(o){const d=h(o.adminRights),f=h(o.schedulerRights),g=h(o.readerRights),a={owner:i,rights:{admin:d,scheduler:f,reader:g}};r.registeredRights.push(a)}}))),r.options.debug&&console.info(":::VueACL::: Registered rights:",r.registeredRights))},h=e=>({companySettings:e.companySettings,servicesSettings:e.servicesSettings,staffsSettings:e.staffsSettings,resourcesSettings:e.resourcesSettings,appointmentsNew:e.appointmentsNew,appointmentsReschedule:e.appointmentsReschedule,appointmentsStatusChange:e.appointmentsStatusChange,appointmentsModeFree:e.appointmentsModeFree,appointmentsAccept:e.appointmentsAccept}),F={install:(e,t)=>A(e,t)};l.createAcl=b,l.default=F,l.defineAclRules=y,l.useAcl=C,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(f,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],h):(f=typeof globalThis!="undefined"?globalThis:f||self,h(f.VueACL={},f.Vue))})(this,function(f,h){"use strict";const r=h.reactive({registeredUser:{},registeredRights:{},registeredRules:{},options:{}}),y=(e,t)=>{const n={...{user:Object.create(null),rules:V,router:null,onDeniedRoute:"/",debug:!1},...t};M(n);const a=(o,g)=>{const i=g.arg,u=g.value,c=g.modifiers,p=!!c.any,d=!!c.not,F=!!c.readonly,_=!!(c.disable||c.disabled),q=!!(c.hide||c.hidden);v({abilities:i,args:u,any:p})?d?o.style.display="none":o.style.display="":d?o.style.display="":_?o.disabled=!0:F?o.readOnly=!0:o.style.display="none"};if(((o,g)=>{o.directive(`${g}`,{mounted(i,u){a(i,u)},updated(i,u){a(i,u)}})})(e,"can"),n.router){const o=(i,u,c,p)=>{if(p)c();else{let d=n.onDeniedRoute;i.meta&&i.meta.onDeniedRoute&&(d=i.meta.onDeniedRoute),c(typeof d=="object"?d:d==="$from"?u:{path:`${d}`,replace:!0})}},g=(i,u,c)=>{if(i.meta&&i.meta.can){const p=i.meta.can;let d=b(p);o(i,u,c,d)}else if(i.meta&&i.meta.canNot){const p=i.meta.canNot;let d=S(p);o(i,u,c,d)}else if(i.meta&&i.meta.canAny){const p=i.meta.canAny;let d=C(p);o(i,u,c,d)}else c()};n.router.beforeEach((i,u,c)=>{g(i,u,c)})}else console.error(":::VueACL::: Instance of vue-router is required.")},w=e=>({install:(t,s={})=>{y(t,{...s,...e})}}),R=e=>{typeof e=="function"&&e(U)},N=()=>{const e={};return e.user=h.computed(()=>r.registeredUser).value,e.getUser=()=>r.registeredUser,e.setUser=t=>r.registeredUser=t,e.rights=h.computed(()=>r.registeredRights).value,e.getRights=()=>r.registeredRights,e.setRights=t=>r.registeredRights=t,e.fetchRights=(t,s,n)=>T(t,s,n),e.can=b,e.can.not=S,e.can.any=C,h.reactive(e)},V=()=>R(e=>{["companySettings","servicesSettings","staffsSettings","resourcesSettings","appointmentsNew","appointmentsAccept","appointmentsReschedule","appointmentsStatusChange","appointmentsModeFree"].forEach(s=>{e(s,(n,a)=>D(n,s,a))})}),M=e=>{const t=e.user;if(r.registeredUser=t,e.rights){const s=e.rights;r.registeredRights=s}e.rules&&typeof e.rules=="function"&&e.rules(),r.options=e},U=(e,t)=>{typeof e=="string"&&j(e,t)},j=(e,t)=>{Object.prototype.hasOwnProperty.call(r.registeredRules,e)?console.warn(`:::VueACL::: Duplicate ACL Rule '${e}' defined. Only the first defined rule will be evaluated.`):r.registeredRules[e]=t},b=(e,t)=>A({abilities:e,args:t,any:!1}),S=(e,t)=>!A({abilities:e,args:t,any:!1}),C=(e,t)=>A({abilities:e,args:t,any:!0}),A=({abilities:e,args:t,any:s=!1})=>e&&typeof e=="string"?v({abilities:e,args:t,any:s}):(console.warn(":::VueACL::: Invalid ACL arguments specified."),!1),v=({abilities:e,args:t,any:s=!1})=>{const n=e,a=t;let l=!1;return n&&(a?l=L({abilities:n,args:a}):l=L({abilities:n})),l},L=({abilities:e,args:t,any:s=!1})=>{if(e&&typeof e=="string"&&Object.prototype.hasOwnProperty.call(r.registeredRules,e)){const n=r.registeredRules[e];return H(n,e,t)}return!1},H=(e,t,s)=>{try{return typeof e=="function"?typeof s=="object"&&!Array.isArray(s)?e(r.registeredUser,s):typeof s=="object"&&Array.isArray(s)?e(r.registeredUser,...s):e(r.registeredUser):!1}catch(n){const a=P(e);a&&Array.isArray(a)&&a.shift();let l=':::VueACL::: The defined ACL Rule for "'+t+'" require some argument(s) or data object to be specified for matching.';return console.error(l),console.error(n),!1}},P=e=>{let t=null;const s=/\(([a-z0-9 ,$_+*\-/]+)\)/im,a=e.toString().match(s);if(a&&Array.isArray(a)&&a[0]){let l=a[0];l=l.replace(/\(|\)|[ ]/g,"");const o=l.split(",");o.length>0&&(t=o)}return t},D=(e,t,s)=>{if(s&&s.id&&s.owner&&s.owner.userName){const n=O(e,s.id);if(n)if(r.registeredRights){const a=r.registeredRights.find(l=>l.owner===s.owner.userName);if(a){const l=a.rights[n];if(l){const o=l[t];return r.options.debug&&console.debug(":::VueACL::: Ability ["+t+"] on ["+s.id+"]: "+o),o}else r.options.debug&&console.debug(":::VueACL::: No ability found for this role ["+n+"] on ["+s.id+"]")}else r.options.debug&&console.debug(":::VueACL::: No company ["+s.id+"] rights founded ["+s.owner.userName+"]")}else r.options.debug&&console.debug(":::VueACL::: No registeredRights");else r.options.debug&&console.debug(":::VueACL::: User has no role on this company ["+s.id+"]",e)}return!1},O=(e,t)=>{if(e&&e.roles&&t){const s=e.roles.find(n=>n.companyId===t);if(s)return s.role}},T=async(e,t,s)=>{var n;((n=r.registeredRights)==null?void 0:n.length)>0&&!s||(r.registeredRights=[],await Promise.all([...t].map(a=>e.getAccountSettings(a).then(l=>{const o=l.result;if(o){const g=m(o.adminRights),i=m(o.schedulerRights),u=m(o.readerRights),c={owner:a,rights:{admin:g,scheduler:i,reader:u}};r.registeredRights.push(c)}}))),r.options.debug&&console.info(":::VueACL::: Registered rights:",r.registeredRights))},m=e=>({companySettings:e.companySettings,servicesSettings:e.servicesSettings,staffsSettings:e.staffsSettings,resourcesSettings:e.resourcesSettings,appointmentsNew:e.appointmentsNew,appointmentsReschedule:e.appointmentsReschedule,appointmentsStatusChange:e.appointmentsStatusChange,appointmentsModeFree:e.appointmentsModeFree,appointmentsAccept:e.appointmentsAccept}),$={install:(e,t)=>y(e,t)};f.createAcl=w,f.default=$,f.defineAclRules=R,f.useAcl=N,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@agendize/vue-acl", | ||
"private": false, | ||
"version": "0.0.2-beta01", | ||
"version": "0.0.2", | ||
"description": "Vue agendize's ACL management", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19775
366
0