@nocobase/plugin-acl 0.21.0-alpha.6 → 0.21.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,4 +6,4 @@
6
6
  }
7
7
  }
8
8
  }
9
- `),Be=(e=[],t=[])=>{for(const n of e)t.push(n.aclSnippet),n.children&&n.children.length&&Be(n.children,t);return t},yi=({active:e})=>{const t=c.useApp(),{styles:n}=We(),{role:r}=h.useContext(F),s=c.useAPIClient(),i=c.useCompile(),o=t.pluginSettingsManager.getList(!1),l=t.pluginSettingsManager.getAclSnippets(),[u,d]=h.useState((r==null?void 0:r.snippets)||[]),y=h.useMemo(()=>ee.flatMap(o,g=>g.children?[g,...g.children]:g),[o]),C=h.useMemo(()=>u.includes("pm.*")&&u.every(g=>!g.startsWith("!pm.")),[u]),{t:b}=T.useTranslation(),{loading:S,refresh:A}=c.useRequest({resource:"roles.snippets",resourceOf:r==null?void 0:r.name,action:"list",params:{paginate:!1}},{ready:!!r&&e,refreshDeps:[r==null?void 0:r.name],manual:!0,onSuccess(g){d((g==null?void 0:g.data.filter(m=>y.find(f=>m.includes(`!${f.aclSnippet}`)||!m.startsWith("!pm."))))||[])}});if(!r)return;const $=s.resource("roles.snippets",r==null?void 0:r.name),I=(g,m)=>w(this,null,function*(){const _=Be(m==null?void 0:m.children,[]).concat(m.aclSnippet);g?(yield $.add({values:_.map(O=>"!"+O)}),A()):(yield $.remove({values:_.map(O=>"!"+O)}),A()),p.message.success(b("Saved successfully"))});return a.jsx(p.Table,{className:n,loading:S,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:b("Plugin name"),render:g=>i(g)},{dataIndex:"accessible",title:a.jsxs(a.Fragment,{children:[a.jsx(p.Checkbox,{checked:C,onChange:()=>w(this,null,function*(){const g=l.map(m=>"!"+m);C?yield $.add({values:g}):yield $.remove({values:g}),A(),p.message.success(b("Saved successfully"))})}),b("Accessible")]}),render:(g,m)=>{const f=!u.includes("!"+m.aclSnippet);return a.jsx(p.Checkbox,{checked:f,onChange:()=>I(f,m)})}}],dataSource:o.filter(g=>g.isTopLevel!==!1).map(g=>g.showTabs!==!1?g:ee.omit(g,"children"))})},_i=E.connect(e=>{const{t}=T.useTranslation();return a.jsxs(p.Checkbox.Group,{style:{width:"100%",display:"block"},value:e.value,onChange:n=>{const r=["ui.*","pm","pm.*","app"],s=r.map(o=>`!${o}`),i=vi([...e.value||[],...n]).filter(o=>o&&!s.includes(o)).map(o=>!r.includes(o)||n!=null&&n.includes(o)?o:`!${o}`);for(const o of r)!i.includes(o)&&!i.includes(`!${o}`)&&i.push(`!${o}`);e.onChange(i)},children:[a.jsx("div",{style:{marginTop:16},children:a.jsx(p.Checkbox,{value:"ui.*",children:t("Allows to configure interface")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"pm",children:t("Allows to install, activate, disable plugins")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"pm.*",children:t("Allows to configure plugins")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"app",children:t("Allows to clear cache, reboot application")})})]})}),bi=({active:e})=>{var u;const{role:t,setRole:n}=h.useContext(F),{t:r}=N(),s=c.useAPIClient(),i=(u=t==null?void 0:t.snippets)==null?void 0:u.includes("pm.*"),o=ge.useMemoizedFn(d=>w(this,null,function*(){yield s.resource("roles").update({filterByTk:t.name,values:d.values}),n(P(P({},t),d.values)),p.message.success(r("Saved successfully"))})),l=h.useMemo(()=>K.createForm({values:t,effects(){K.onFormValuesChange(d=>w(this,null,function*(){yield o(d)}))}}),[t,o]);return a.jsx(c.SchemaComponent,{components:{SnippetCheckboxGroup:_i,StrategyActions:mi,PluginPermissions:yi},scope:{pm:i},schema:{type:"void",name:x.uid(),"x-component":"div",properties:{general:{"x-component":"FormV2","x-component-props":{form:l},properties:{snippets:{title:r("Configure permissions"),type:"boolean","x-decorator":"FormItem","x-component":"SnippetCheckboxGroup"}}},plugins:{"x-component":"FormV2",properties:{pluginSettings:{title:r("Plugin settings"),"x-decorator":"FormItem","x-component":"PluginPermissions","x-visible":"{{pm}}"}}}}}})},ue=h.createContext(null);ue.displayName="MenuItemsContext";const Ye=(e={})=>{const t=[];for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const r=e[n],s={title:r.title,uid:r["x-uid"]};r.properties&&(s.children=Ye(r.properties)),t.push(s)}return t},Ci=()=>h.useContext(ue),Xe=e=>{var i,o;const n={url:`uiSchemas:getProperties/${c.useAdminSchemaUid()}`},r=c.useRequest(n);if(r.loading)return a.jsx(p.Spin,{});const s=Ye((o=(i=r.data)==null?void 0:i.data)==null?void 0:o.properties);return a.jsx(ue.Provider,{value:{service:r,items:s},children:e.children})},Je=e=>{if(!Array.isArray(e))return[];const t=[];for(const n of e)t.push(n.uid),t.push(...Je(n.children));return t},Ze=(e,t,n=[])=>{if(!e)return[];for(const r of e){if(n.push(r.uid),t(r))return n;if(r.children){const s=Ze(r.children,t,n);if(s.length)return s}n.pop()}return[]},Qe=(e=[],t=[])=>{for(const n of e)t.push(n.uid),n.children&&n.children.length&&Qe(n.children,t);return t},$i=({active:e})=>{const{styles:t}=We(),{role:n,setRole:r}=h.useContext(F),s=c.useAPIClient(),{items:i}=Ci(),{t:o}=T.useTranslation(),l=Je(i),[u,d]=h.useState([]),{loading:y,refresh:C}=c.useRequest({resource:"roles.menuUiSchemas",resourceOf:n.name,action:"list",params:{paginate:!1}},{ready:!!n&&e,refreshDeps:[n==null?void 0:n.name],onSuccess(m){var f;d(((f=m==null?void 0:m.data)==null?void 0:f.map(_=>_["x-uid"]))||[])}}),b=s.resource("roles.menuUiSchemas",n.name),S=l.length===u.length,A=(m,f)=>w(this,null,function*(){const _=Ze(i,M=>M.uid===f.uid),O=Qe(f==null?void 0:f.children,[]);if(m){const M=O.concat(f.uid),he=u.filter(Pi=>!M.includes(Pi));d([...he]),yield b.remove({values:M})}else{const M=O.concat(_);d(he=>ee.uniq([...he,...M])),yield b.add({values:M})}p.message.success(o("Saved successfully"))}),$=m=>m.map(f=>{const _=o(f.title);return f.children?D(P({},f),{title:_,children:$(f.children)}):D(P({},f),{title:_})}),I=ge.useMemoizedFn(m=>w(this,null,function*(){yield s.resource("roles").update({filterByTk:n.name,values:m.values}),r(P(P({},n),m.values)),p.message.success(o("Saved successfully"))})),g=h.useMemo(()=>K.createForm({values:n,effects(){K.onFormValuesChange(m=>w(this,null,function*(){yield I(m)}))}}),[n,I]);return a.jsxs(a.Fragment,{children:[a.jsx(c.SchemaComponent,{schema:{type:"void",name:x.uid(),"x-component":"FormV2","x-component-props":{form:g},properties:{allowNewMenu:{title:o("Menu permissions"),"x-decorator":"FormItem","x-component":"Checkbox","x-content":o("New menu items are allowed to be accessed by default.")}}}}),a.jsx(p.Table,{className:t,loading:y,rowKey:"uid",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:o("Menu item title")},{dataIndex:"accessible",title:a.jsxs(a.Fragment,{children:[a.jsx(p.Checkbox,{checked:S,onChange:m=>w(this,null,function*(){S?yield b.set({values:[]}):yield b.set({values:l}),C(),p.message.success(o("Saved successfully"))})})," ",o("Accessible")]}),render:(m,f)=>{const _=u.includes(f.uid);return a.jsx(p.Checkbox,{checked:_,onChange:()=>A(_,f)})}}],dataSource:$(i)})]})},pe=e=>a.jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:e.children}),xi=({active:e})=>{var b;const{t}=N(),[n,r]=h.useState("general"),{role:s,setRole:i}=h.useContext(F),o=(b=s==null?void 0:s.snippets)==null?void 0:b.includes("pm.*"),u=c.useApp().getComponent("DataSourcePermissionManager"),d=h.useMemo(()=>[{key:"general",label:t("System"),children:a.jsx(pe,{children:a.jsx(bi,{active:n==="general"&&e})})},{key:"menu",label:t("Menu"),children:a.jsx(pe,{children:a.jsx(Xe,{children:a.jsx($i,{active:n==="menu"&&e})})})},...u?[{key:"dataSource",label:t("Data sources"),children:a.jsx(pe,{children:a.jsx(Xe,{children:a.jsx(u,{role:s,active:n==="dataSource"&&e})})})}]:[]],[o,n,e,t]),y=c.useAPIClient(),{data:C}=c.useRequest(()=>y.resource("roles").get({filterByTk:s==null?void 0:s.name}).then(S=>{var $,I;const A=($=S==null?void 0:S.data)==null?void 0:$.data;return(I=A.snippets)==null||I.forEach(g=>{A[g]=!0}),A}),{ready:e&&!!s,refreshDeps:[s==null?void 0:s.name]});return h.useEffect(()=>{r("general")},[s==null?void 0:s.name]),h.useEffect(()=>{i(C)},[C]),a.jsx(go,{children:a.jsx(p.Tabs,{type:"card",activeKey:n,onChange:S=>r(S),items:d})})},Si=()=>{const{t:e}=N();return a.jsx(c.SchemaComponent,{scope:{t:e},schema:{type:"void",properties:{newRole:{type:"void",title:e("New role"),"x-component":"Action","x-component-props":{type:"text",icon:"PlusOutlined",style:{width:"100%",textAlign:"left"}},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(t){const n=c.useActionContext();return c.useRequest(()=>Promise.resolve({data:{name:`r_${x.uid()}`,snippets:["!ui.*","!pm","!pm.*"]}}),D(P({},t),{refreshDeps:[n.visible]}))}},title:e("New role"),properties:{title:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem",description:'{{t("Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.")}}'},default:{"x-component":"CollectionField","x-decorator":"FormItem",title:"","x-content":'{{t("Default role")}}'},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}}}}})},Re={name:"roles",filterTargetKey:"name",targetKey:"name",fields:[{type:"string",name:"title",interface:"input",uiSchema:{title:'{{t("Role display name")}}',type:"number","x-component":"Input",required:!0}},{type:"string",name:"name",interface:"input",uiSchema:{title:'{{t("Role UID")}}',type:"string","x-component":"Input"}},{type:"boolean",name:"default",interface:"boolean",uiSchema:{title:'{{t("Default role")}}',type:"boolean","x-component":"Checkbox"}}]},wi=()=>{const{t:e}=N(),t=c.usePlugin(de),[n,r]=h.useState("permissions"),s=Array.from(t.rolesManager.list()).map(([u,d])=>({key:u,label:E.Schema.compile(d.title,{t:e}),children:d.Component?h.createElement(d.Component,{active:n===u}):null})),[i,o]=h.useState(null),l=c.useSchemaComponentContext();return a.jsx(c.SchemaComponentContext.Provider,{value:D(P({},l),{designable:!1}),children:a.jsx(F.Provider,{value:{role:i,setRole:o},children:a.jsx(p.Card,{children:a.jsxs(p.Row,{gutter:24,style:{flexWrap:"nowrap"},children:[a.jsx(p.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"250px"},children:a.jsx(c.ResourceActionProvider,{collection:Re,request:{resource:"roles",action:"list",params:{filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}},children:a.jsxs(c.CollectionProvider_deprecated,{collection:Re,children:[a.jsx(p.Row,{children:a.jsx(Si,{})}),a.jsx(p.Divider,{style:{margin:"12px 0"}}),a.jsx(Q,{})]})})}),a.jsx(p.Col,{flex:"auto",style:{overflow:"hidden"},children:a.jsx(p.Tabs,{activeKey:n,onChange:u=>r(u),items:[{key:"permissions",label:e("Permissions"),children:a.jsx(xi,{active:n==="permissions"})},...s]})})]})})})})};class Ai{constructor(){ve(this,"rolesManager",new j.Registry)}add(t,n){this.rolesManager.register(t,n)}list(){return this.rolesManager.getEntities()}}class de extends c.Plugin{constructor(){super(...arguments);ve(this,"rolesManager",new Ai)}load(){return w(this,null,function*(){this.pluginSettingsManager.add("users-permissions.roles",{title:this.t("Roles & Permissions"),icon:"LockOutlined",Component:wi,aclSnippet:"pm.acl.roles",sort:3})})}}v.PluginACLClient=de,v.RolesManagerContext=F,v.default=de,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
9
+ `),Be=(e=[],t=[])=>{for(const n of e)t.push(n.aclSnippet),n.children&&n.children.length&&Be(n.children,t);return t},yi=({active:e})=>{const t=c.useApp(),{styles:n}=We(),{role:r}=h.useContext(F),s=c.useAPIClient(),i=c.useCompile(),o=t.pluginSettingsManager.getList(!1),l=t.pluginSettingsManager.getAclSnippets(),[u,d]=h.useState((r==null?void 0:r.snippets)||[]),y=h.useMemo(()=>ee.flatMap(o,g=>g.children?[g,...g.children]:g),[o]),C=h.useMemo(()=>u.includes("pm.*")&&u.every(g=>!g.startsWith("!pm.")),[u]),{t:b}=T.useTranslation(),{loading:S,refresh:A}=c.useRequest({resource:"roles.snippets",resourceOf:r==null?void 0:r.name,action:"list",params:{paginate:!1}},{ready:!!r&&e,refreshDeps:[r==null?void 0:r.name],manual:!0,onSuccess(g){d((g==null?void 0:g.data.filter(m=>y.find(f=>m.includes(`!${f.aclSnippet}`)||!m.startsWith("!pm."))))||[])}});if(!r)return;const $=s.resource("roles.snippets",r==null?void 0:r.name),I=(g,m)=>w(this,null,function*(){const _=Be(m==null?void 0:m.children,[]).concat(m.aclSnippet);g?(yield $.add({values:_.map(O=>"!"+O)}),A()):(yield $.remove({values:_.map(O=>"!"+O)}),A()),p.message.success(b("Saved successfully"))});return a.jsx(p.Table,{className:n,loading:S,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:b("Plugin name"),render:g=>i(g)},{dataIndex:"accessible",title:a.jsxs(a.Fragment,{children:[a.jsx(p.Checkbox,{checked:C,onChange:()=>w(this,null,function*(){const g=l.map(m=>"!"+m);C?yield $.add({values:g}):yield $.remove({values:g}),A(),p.message.success(b("Saved successfully"))})}),b("Accessible")]}),render:(g,m)=>{const f=!u.includes("!"+m.aclSnippet);return a.jsx(p.Checkbox,{checked:f,onChange:()=>I(f,m)})}}],dataSource:o.filter(g=>g.isTopLevel!==!1).map(g=>g.showTabs!==!1?g:ee.omit(g,"children"))})},_i=E.connect(e=>{const{t}=T.useTranslation();return a.jsxs(p.Checkbox.Group,{style:{width:"100%",display:"block"},value:e.value,onChange:n=>{const r=["ui.*","pm","pm.*","app"],s=r.map(o=>`!${o}`),i=vi([...e.value||[],...n]).filter(o=>o&&!s.includes(o)).map(o=>!r.includes(o)||n!=null&&n.includes(o)?o:`!${o}`);for(const o of r)!i.includes(o)&&!i.includes(`!${o}`)&&i.push(`!${o}`);e.onChange(i)},children:[a.jsx("div",{style:{marginTop:16},children:a.jsx(p.Checkbox,{value:"ui.*",children:t("Allows to configure interface")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"pm",children:t("Allows to install, activate, disable plugins")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"pm.*",children:t("Allows to configure plugins")})}),a.jsx("div",{style:{marginTop:8},children:a.jsx(p.Checkbox,{value:"app",children:t("Allows to clear cache, reboot application")})})]})}),bi=({active:e})=>{var u;const{role:t,setRole:n}=h.useContext(F),{t:r}=N(),s=c.useAPIClient(),i=(u=t==null?void 0:t.snippets)==null?void 0:u.includes("pm.*"),o=ge.useMemoizedFn(d=>w(this,null,function*(){yield s.resource("roles").update({filterByTk:t.name,values:{snippets:d.values.snippets}}),n(P(P({},t),d.values)),p.message.success(r("Saved successfully"))})),l=h.useMemo(()=>K.createForm({values:t,effects(){K.onFormValuesChange(d=>w(this,null,function*(){yield o(d)}))}}),[t,o]);return a.jsx(c.SchemaComponent,{components:{SnippetCheckboxGroup:_i,StrategyActions:mi,PluginPermissions:yi},scope:{pm:i},schema:{type:"void",name:x.uid(),"x-component":"div",properties:{general:{"x-component":"FormV2","x-component-props":{form:l},properties:{snippets:{title:r("Configure permissions"),type:"boolean","x-decorator":"FormItem","x-component":"SnippetCheckboxGroup"}}},plugins:{"x-component":"FormV2",properties:{pluginSettings:{title:r("Plugin settings"),"x-decorator":"FormItem","x-component":"PluginPermissions","x-visible":"{{pm}}"}}}}}})},ue=h.createContext(null);ue.displayName="MenuItemsContext";const Ye=(e={})=>{const t=[];for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const r=e[n],s={title:r.title,uid:r["x-uid"]};r.properties&&(s.children=Ye(r.properties)),t.push(s)}return t},Ci=()=>h.useContext(ue),Xe=e=>{var i,o;const n={url:`uiSchemas:getProperties/${c.useAdminSchemaUid()}`},r=c.useRequest(n);if(r.loading)return a.jsx(p.Spin,{});const s=Ye((o=(i=r.data)==null?void 0:i.data)==null?void 0:o.properties);return a.jsx(ue.Provider,{value:{service:r,items:s},children:e.children})},Je=e=>{if(!Array.isArray(e))return[];const t=[];for(const n of e)t.push(n.uid),t.push(...Je(n.children));return t},Ze=(e,t,n=[])=>{if(!e)return[];for(const r of e){if(n.push(r.uid),t(r))return n;if(r.children){const s=Ze(r.children,t,n);if(s.length)return s}n.pop()}return[]},Qe=(e=[],t=[])=>{for(const n of e)t.push(n.uid),n.children&&n.children.length&&Qe(n.children,t);return t},$i=({active:e})=>{const{styles:t}=We(),{role:n,setRole:r}=h.useContext(F),s=c.useAPIClient(),{items:i}=Ci(),{t:o}=T.useTranslation(),l=Je(i),[u,d]=h.useState([]),{loading:y,refresh:C}=c.useRequest({resource:"roles.menuUiSchemas",resourceOf:n.name,action:"list",params:{paginate:!1}},{ready:!!n&&e,refreshDeps:[n==null?void 0:n.name],onSuccess(m){var f;d(((f=m==null?void 0:m.data)==null?void 0:f.map(_=>_["x-uid"]))||[])}}),b=s.resource("roles.menuUiSchemas",n.name),S=l.length===u.length,A=(m,f)=>w(this,null,function*(){const _=Ze(i,M=>M.uid===f.uid),O=Qe(f==null?void 0:f.children,[]);if(m){const M=O.concat(f.uid),he=u.filter(Pi=>!M.includes(Pi));d([...he]),yield b.remove({values:M})}else{const M=O.concat(_);d(he=>ee.uniq([...he,...M])),yield b.add({values:M})}p.message.success(o("Saved successfully"))}),$=m=>m.map(f=>{const _=o(f.title);return f.children?D(P({},f),{title:_,children:$(f.children)}):D(P({},f),{title:_})}),I=ge.useMemoizedFn(m=>w(this,null,function*(){yield s.resource("roles").update({filterByTk:n.name,values:m.values}),r(P(P({},n),m.values)),p.message.success(o("Saved successfully"))})),g=h.useMemo(()=>K.createForm({values:n,effects(){K.onFormValuesChange(m=>w(this,null,function*(){yield I(m)}))}}),[n,I]);return a.jsxs(a.Fragment,{children:[a.jsx(c.SchemaComponent,{schema:{type:"void",name:x.uid(),"x-component":"FormV2","x-component-props":{form:g},properties:{allowNewMenu:{title:o("Menu permissions"),"x-decorator":"FormItem","x-component":"Checkbox","x-content":o("New menu items are allowed to be accessed by default.")}}}}),a.jsx(p.Table,{className:t,loading:y,rowKey:"uid",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:o("Menu item title")},{dataIndex:"accessible",title:a.jsxs(a.Fragment,{children:[a.jsx(p.Checkbox,{checked:S,onChange:m=>w(this,null,function*(){S?yield b.set({values:[]}):yield b.set({values:l}),C(),p.message.success(o("Saved successfully"))})})," ",o("Accessible")]}),render:(m,f)=>{const _=u.includes(f.uid);return a.jsx(p.Checkbox,{checked:_,onChange:()=>A(_,f)})}}],dataSource:$(i)})]})},pe=e=>a.jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:e.children}),xi=({active:e})=>{var b;const{t}=N(),[n,r]=h.useState("general"),{role:s,setRole:i}=h.useContext(F),o=(b=s==null?void 0:s.snippets)==null?void 0:b.includes("pm.*"),u=c.useApp().getComponent("DataSourcePermissionManager"),d=h.useMemo(()=>[{key:"general",label:t("System"),children:a.jsx(pe,{children:a.jsx(bi,{active:n==="general"&&e})})},{key:"menu",label:t("Menu"),children:a.jsx(pe,{children:a.jsx(Xe,{children:a.jsx($i,{active:n==="menu"&&e})})})},...u?[{key:"dataSource",label:t("Data sources"),children:a.jsx(pe,{children:a.jsx(Xe,{children:a.jsx(u,{role:s,active:n==="dataSource"&&e})})})}]:[]],[o,n,e,t]),y=c.useAPIClient(),{data:C}=c.useRequest(()=>y.resource("roles").get({filterByTk:s==null?void 0:s.name}).then(S=>{var $,I;const A=($=S==null?void 0:S.data)==null?void 0:$.data;return(I=A.snippets)==null||I.forEach(g=>{A[g]=!0}),A}),{ready:e&&!!s,refreshDeps:[s==null?void 0:s.name]});return h.useEffect(()=>{r("general")},[s==null?void 0:s.name]),h.useEffect(()=>{i(C)},[C]),a.jsx(go,{children:a.jsx(p.Tabs,{type:"card",activeKey:n,onChange:S=>r(S),items:d})})},Si=()=>{const{t:e}=N();return a.jsx(c.SchemaComponent,{scope:{t:e},schema:{type:"void",properties:{newRole:{type:"void",title:e("New role"),"x-component":"Action","x-component-props":{type:"text",icon:"PlusOutlined",style:{width:"100%",textAlign:"left"}},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(t){const n=c.useActionContext();return c.useRequest(()=>Promise.resolve({data:{name:`r_${x.uid()}`,snippets:["!ui.*","!pm","!pm.*"]}}),D(P({},t),{refreshDeps:[n.visible]}))}},title:e("New role"),properties:{title:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem",description:'{{t("Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.")}}'},default:{"x-component":"CollectionField","x-decorator":"FormItem",title:"","x-content":'{{t("Default role")}}'},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}}}}})},Re={name:"roles",filterTargetKey:"name",targetKey:"name",fields:[{type:"string",name:"title",interface:"input",uiSchema:{title:'{{t("Role display name")}}',type:"number","x-component":"Input",required:!0}},{type:"string",name:"name",interface:"input",uiSchema:{title:'{{t("Role UID")}}',type:"string","x-component":"Input"}},{type:"boolean",name:"default",interface:"boolean",uiSchema:{title:'{{t("Default role")}}',type:"boolean","x-component":"Checkbox"}}]},wi=()=>{const{t:e}=N(),t=c.usePlugin(de),[n,r]=h.useState("permissions"),s=Array.from(t.rolesManager.list()).map(([u,d])=>({key:u,label:E.Schema.compile(d.title,{t:e}),children:d.Component?h.createElement(d.Component,{active:n===u}):null})),[i,o]=h.useState(null),l=c.useSchemaComponentContext();return a.jsx(c.SchemaComponentContext.Provider,{value:D(P({},l),{designable:!1}),children:a.jsx(F.Provider,{value:{role:i,setRole:o},children:a.jsx(p.Card,{children:a.jsxs(p.Row,{gutter:24,style:{flexWrap:"nowrap"},children:[a.jsx(p.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"250px"},children:a.jsx(c.ResourceActionProvider,{collection:Re,request:{resource:"roles",action:"list",params:{filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}},children:a.jsxs(c.CollectionProvider_deprecated,{collection:Re,children:[a.jsx(p.Row,{children:a.jsx(Si,{})}),a.jsx(p.Divider,{style:{margin:"12px 0"}}),a.jsx(Q,{})]})})}),a.jsx(p.Col,{flex:"auto",style:{overflow:"hidden"},children:a.jsx(p.Tabs,{activeKey:n,onChange:u=>r(u),items:[{key:"permissions",label:e("Permissions"),children:a.jsx(xi,{active:n==="permissions"})},...s]})})]})})})})};class Ai{constructor(){ve(this,"rolesManager",new j.Registry)}add(t,n){this.rolesManager.register(t,n)}list(){return this.rolesManager.getEntities()}}class de extends c.Plugin{constructor(){super(...arguments);ve(this,"rolesManager",new Ai)}load(){return w(this,null,function*(){this.pluginSettingsManager.add("users-permissions.roles",{title:this.t("Roles & Permissions"),icon:"LockOutlined",Component:wi,aclSnippet:"pm.acl.roles",sort:3})})}}v.PluginACLClient=de,v.RolesManagerContext=F,v.default=de,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,22 +1,22 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.21.0-alpha.6",
2
+ "@nocobase/client": "0.21.0-alpha.8",
3
3
  "react": "18.2.0",
4
4
  "@formily/shared": "2.3.0",
5
5
  "antd": "5.12.8",
6
6
  "@formily/react": "2.3.0",
7
7
  "@ant-design/icons": "5.2.6",
8
8
  "react-i18next": "11.18.6",
9
- "@nocobase/utils": "0.21.0-alpha.6",
10
- "@nocobase/actions": "0.21.0-alpha.6",
11
- "@nocobase/cache": "0.21.0-alpha.6",
12
- "@nocobase/database": "0.21.0-alpha.6",
13
- "@nocobase/server": "0.21.0-alpha.6",
9
+ "@nocobase/utils": "0.21.0-alpha.8",
10
+ "@nocobase/actions": "0.21.0-alpha.8",
11
+ "@nocobase/cache": "0.21.0-alpha.8",
12
+ "@nocobase/database": "0.21.0-alpha.8",
13
+ "@nocobase/server": "0.21.0-alpha.8",
14
14
  "async-mutex": "0.3.2",
15
15
  "lodash": "4.17.21",
16
- "@nocobase/test": "0.21.0-alpha.6",
16
+ "@nocobase/test": "0.21.0-alpha.8",
17
17
  "@formily/core": "2.3.0",
18
18
  "ahooks": "3.7.8",
19
19
  "@formily/antd-v5": "1.1.9",
20
20
  "antd-style": "3.4.5",
21
- "@nocobase/acl": "0.21.0-alpha.6"
21
+ "@nocobase/acl": "0.21.0-alpha.8"
22
22
  };
@@ -47,7 +47,7 @@ function createWithACLMetaMiddleware() {
47
47
  if (!ctx.action || !ctx.get("X-With-ACL-Meta") || ctx.status !== 200) {
48
48
  return;
49
49
  }
50
- const { resourceName, actionName } = ctx.action;
50
+ const { resourceName, actionName } = ctx.permission;
51
51
  if (!["list", "get"].includes(actionName)) {
52
52
  return;
53
53
  }
@@ -84,6 +84,7 @@ function createWithACLMetaMiddleware() {
84
84
  return db;
85
85
  }
86
86
  },
87
+ getCurrentRepository: ctx.getCurrentRepository,
87
88
  action: {
88
89
  actionName: action,
89
90
  name: action,
@@ -17,7 +17,7 @@ export declare class GrantHelper {
17
17
  targetActionResourceMap: Map<string, string[]>;
18
18
  constructor();
19
19
  }
20
- export declare class PluginACL extends Plugin {
20
+ export declare class PluginACLServer extends Plugin {
21
21
  associationFieldsActions: AssociationFieldsActions;
22
22
  grantHelper: GrantHelper;
23
23
  get acl(): import("@nocobase/acl").ACL;
@@ -31,4 +31,4 @@ export declare class PluginACL extends Plugin {
31
31
  install(): Promise<void>;
32
32
  load(): Promise<void>;
33
33
  }
34
- export default PluginACL;
34
+ export default PluginACLServer;
@@ -28,7 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var server_exports = {};
29
29
  __export(server_exports, {
30
30
  GrantHelper: () => GrantHelper,
31
- PluginACL: () => PluginACL,
31
+ PluginACLServer: () => PluginACLServer,
32
32
  default: () => server_default
33
33
  });
34
34
  module.exports = __toCommonJS(server_exports);
@@ -53,7 +53,7 @@ class GrantHelper {
53
53
  constructor() {
54
54
  }
55
55
  }
56
- class PluginACL extends import_server.Plugin {
56
+ class PluginACLServer extends import_server.Plugin {
57
57
  // association field actions config
58
58
  associationFieldsActions = {};
59
59
  grantHelper = new GrantHelper();
@@ -173,7 +173,11 @@ class PluginACL extends import_server.Plugin {
173
173
  "roles.resources:*",
174
174
  "uiSchemas:getProperties",
175
175
  "roles.menuUiSchemas:*",
176
- "roles.users:*"
176
+ "roles.users:*",
177
+ "dataSources.roles:*",
178
+ "dataSources:list",
179
+ "roles.dataSourcesCollections:*",
180
+ "roles.dataSourceResources:*"
177
181
  ]
178
182
  });
179
183
  this.app.acl.beforeGrantAction((ctx) => {
@@ -198,7 +202,6 @@ class PluginACL extends import_server.Plugin {
198
202
  };
199
203
  }
200
204
  });
201
- this.registerAssociationFieldsActions();
202
205
  this.app.resourcer.define(import_available_actions.availableActionResource);
203
206
  this.app.resourcer.define(import_role_collections.roleCollectionsResource);
204
207
  this.app.resourcer.registerActionHandler("roles:check", import_role_check.checkAction);
@@ -530,42 +533,6 @@ class PluginACL extends import_server.Plugin {
530
533
  }
531
534
  }
532
535
  });
533
- this.app.acl.use(
534
- async (ctx, next) => {
535
- var _a, _b, _c;
536
- const { actionName, resourceName, resourceOf } = ctx.action;
537
- if (resourceName.includes(".") && resourceOf) {
538
- if (!((_b = (_a = ctx == null ? void 0 : ctx.permission) == null ? void 0 : _a.can) == null ? void 0 : _b.params)) {
539
- return next();
540
- }
541
- delete ctx.permission.can.params.filter;
542
- const [collectionName] = resourceName.split(".");
543
- const action = ctx.can({ resource: collectionName, action: actionName });
544
- const availableAction = this.app.acl.getAvailableAction(actionName);
545
- if ((_c = availableAction == null ? void 0 : availableAction.options) == null ? void 0 : _c.onNewRecord) {
546
- if (action) {
547
- ctx.permission.skip = true;
548
- } else {
549
- ctx.permission.can = false;
550
- }
551
- } else {
552
- const filteredParams = this.app.acl.filterParams(ctx, collectionName, (action == null ? void 0 : action.params) || {});
553
- const params = await parseJsonTemplate(filteredParams, ctx);
554
- const sourceInstance = await ctx.db.getRepository(collectionName).findOne({
555
- filterByTk: resourceOf,
556
- filter: params.filter || {}
557
- });
558
- if (!sourceInstance) {
559
- ctx.permission.can = false;
560
- }
561
- }
562
- }
563
- await next();
564
- },
565
- {
566
- before: "core"
567
- }
568
- );
569
536
  this.app.acl.use(
570
537
  async (ctx, next) => {
571
538
  var _a, _b;
@@ -617,9 +584,9 @@ class PluginACL extends import_server.Plugin {
617
584
  });
618
585
  }
619
586
  }
620
- var server_default = PluginACL;
587
+ var server_default = PluginACLServer;
621
588
  // Annotate the CommonJS export names for ESM import in node:
622
589
  0 && (module.exports = {
623
590
  GrantHelper,
624
- PluginACL
591
+ PluginACLServer
625
592
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "权限控制",
5
5
  "description": "Based on roles, resources, and actions, access control can precisely manage interface configuration permissions, data operation permissions, menu access permissions, and plugin permissions.",
6
6
  "description.zh-CN": "基于角色、资源和操作的权限控制,可以精确控制界面配置权限、数据操作权限、菜单访问权限、插件权限。",
7
- "version": "0.21.0-alpha.6",
7
+ "version": "0.21.0-alpha.8",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -34,5 +34,5 @@
34
34
  "url": "git+https://github.com/nocobase/nocobase.git",
35
35
  "directory": "packages/plugins/acl"
36
36
  },
37
- "gitHead": "25eaaf1bdf44d2b457a3a3742532db9d2008216b"
37
+ "gitHead": "bed69485709bc8e268285b50debfc1ebfd7a30c7"
38
38
  }