@nocobase/plugin-acl 0.20.0-alpha.8 → 0.20.0-alpha.9

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
- `),Ve=e=>{if(!Array.isArray(e))return[];const t=[];for(const r of e)t.push(r.uid),t.push(...Ve(r.children));return t},We=(e,t,r=[])=>{if(!e)return[];for(const n of e){if(r.push(n.uid),t(n))return r;if(n.children){const a=We(n.children,t,r);if(a.length)return a}r.pop()}return[]},Be=(e=[],t=[])=>{for(const r of e)t.push(r.uid),r.children&&r.children.length&&Be(r.children,t);return t},yi=({active:e})=>{const{styles:t}=Le(),{role:r}=g.useContext(A),n=u.useAPIClient(),{items:a}=mi(),{t:i}=S.useTranslation(),o=Ve(a),[c,l]=g.useState([]),{loading:f,refresh:v}=u.useRequest({resource:"roles.menuUiSchemas",resourceOf:r.name,action:"list",params:{paginate:!1}},{ready:!!r&&e,refreshDeps:[r==null?void 0:r.name],onSuccess(b){var y;l(((y=b==null?void 0:b.data)==null?void 0:y.map(h=>h["x-uid"]))||[])}}),m=n.resource("roles.menuUiSchemas",r.name),C=o.length===c.length,le=(b,y)=>w(this,null,function*(){const h=We(a,$=>$.uid===y.uid),_=Be(y==null?void 0:y.children,[]);if(b){const $=_.concat(y.uid),N=c.filter(H=>!$.includes(H));l([...N]),yield m.remove({values:$})}else{const $=_.concat(h);l(N=>Z.uniq([...N,...$])),yield m.add({values:$})}p.message.success(i("Saved successfully"))}),D=b=>b.map(y=>{const h=i(y.title);return y.children?E(P({},y),{title:h,children:D(y.children)}):E(P({},y),{title:h})});return s.jsx(p.Table,{className:t,loading:f,rowKey:"uid",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:i("Menu item title")},{dataIndex:"accessible",title:s.jsxs(s.Fragment,{children:[s.jsx(p.Checkbox,{checked:C,onChange:b=>w(this,null,function*(){C?yield m.set({values:[]}):yield m.set({values:o}),v(),p.message.success(i("Saved successfully"))})})," ",i("Accessible")]}),render:(b,y)=>{const h=c.includes(y.uid);return s.jsx(p.Checkbox,{checked:h,onChange:()=>le(h,y)})}}],dataSource:D(a)})},Ye=(e=[],t=[])=>{for(const r of e)t.push(r.aclSnippet),r.children&&r.children.length&&Ye(r.children,t);return t},_i=({active:e})=>{const t=u.useApp(),{styles:r}=Le(),{role:n}=g.useContext(A),a=u.useAPIClient(),i=u.useCompile(),o=t.pluginSettingsManager.getList(!1),c=t.pluginSettingsManager.getAclSnippets(),[l,f]=g.useState([]),v=g.useMemo(()=>Z.flatMap(o,h=>h.children?[h,...h.children]:h),[o]),m=g.useMemo(()=>l.includes("pm.*")&&l.every(h=>!h.startsWith("!pm.")),[l]),{t:C}=S.useTranslation(),{loading:le,refresh:D}=u.useRequest({resource:"roles.snippets",resourceOf:n.name,action:"list",params:{paginate:!1}},{ready:!!n&&e,refreshDeps:[n==null?void 0:n.name],onSuccess(h){f((h==null?void 0:h.data.filter(_=>v.find($=>_.includes(`!${$.aclSnippet}`)||!_.startsWith("!pm."))))||[])}}),b=a.resource("roles.snippets",n.name),y=(h,_)=>w(this,null,function*(){const N=Ye(_==null?void 0:_.children,[]).concat(_.aclSnippet);h?(yield b.add({values:N.map(H=>"!"+H)}),D()):(yield b.remove({values:N.map(H=>"!"+H)}),D()),p.message.success(C("Saved successfully"))});return s.jsx(p.Table,{className:r,loading:le,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:C("Plugin name"),render:h=>i(h)},{dataIndex:"accessible",title:s.jsxs(s.Fragment,{children:[s.jsx(p.Checkbox,{checked:m,onChange:()=>w(this,null,function*(){const h=c.map(_=>"!"+_);m?yield b.add({values:h}):yield b.remove({values:h}),D(),p.message.success(C("Saved successfully"))})})," ",C("Accessible")]}),render:(h,_)=>{const $=!l.includes("!"+_.aclSnippet);return s.jsx(p.Checkbox,{checked:$,onChange:()=>y($,_)})}}],dataSource:o.filter(h=>h.isTopLevel!==!1).map(h=>h.showTabs!==!1?h:Z.omit(h,"children"))})},J=e=>s.jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:e.children}),bi=({active:e})=>{var f;const{t}=T(),[r,n]=g.useState("general"),{role:a}=g.useContext(A),i=(f=a==null?void 0:a.snippets)==null?void 0:f.includes("pm.*"),c=u.useApp().getComponent("DataSourcePermissionManager"),l=g.useMemo(()=>[{key:"general",label:t("General"),children:s.jsx(J,{children:s.jsx(gi,{active:r==="general"&&e})})},{key:"menu",label:t("Menu"),children:s.jsx(J,{children:s.jsx(ze,{children:s.jsx(yi,{active:r==="menu"&&e})})})},...i?[{key:"plugin",label:t("Plugin settings"),children:s.jsx(J,{children:s.jsx(_i,{active:r==="plugin"&&e})})}]:[],...c?[{key:"dataSource",label:t("Data sources"),children:s.jsx(J,{children:s.jsx(ze,{children:s.jsx(c,{role:a,active:r==="dataSource"&&e})})})}]:[]],[i,r,e,t]);return g.useEffect(()=>{n("general")},[a==null?void 0:a.name]),s.jsx(ho,{children:s.jsx(p.Tabs,{type:"card",activeKey:r,onChange:v=>n(v),items:l})})},$i=()=>{const{t:e}=T();return s.jsx(u.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 r=u.useActionContext();return u.useRequest(()=>Promise.resolve({data:{name:`r_${x.uid()}`,snippets:["!ui.*","!pm","!pm.*"]}}),E(P({},t),{refreshDeps:[r.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 }}"}}}}}}}}}}})},Xe={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"}}]},Ci=()=>{const{t:e}=T(),t=u.usePlugin(Je),[r,n]=g.useState("permissions"),a=Array.from(t.rolesManager.list()).map(([c,l])=>({key:c,label:I.Schema.compile(l.title,{t:e}),children:l.Component?g.createElement(l.Component,{active:r===c}):null})),[i,o]=g.useState(null);return s.jsx(A.Provider,{value:{role:i,setRole:o},children:s.jsx(p.Card,{children:s.jsxs(p.Row,{gutter:24,style:{flexWrap:"nowrap"},children:[s.jsx(p.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"250px"},children:s.jsx(u.ResourceActionProvider,{collection:Xe,request:{resource:"roles",action:"list",params:{pagination:!1,filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}},children:s.jsxs(u.CollectionProvider_deprecated,{collection:Xe,children:[s.jsx(p.Row,{children:s.jsx($i,{})}),s.jsx(p.Divider,{style:{margin:"12px 0"}}),s.jsx(se,{})]})})}),s.jsx(p.Col,{flex:"auto",style:{overflow:"hidden"},children:s.jsx(p.Tabs,{activeKey:r,onChange:c=>n(c),items:[{key:"permissions",label:e("Permissions"),children:s.jsx(bi,{active:r==="permissions"})},...a]})})]})})})};class xi{constructor(){pe(this,"rolesManager",new k.Registry)}add(t,r){this.rolesManager.register(t,r)}list(){return this.rolesManager.getEntities()}}class Je extends u.Plugin{constructor(){super(...arguments);pe(this,"rolesManager",new xi)}load(){return w(this,null,function*(){this.app.pluginSettingsManager.add("users-permissions.roles",{title:'{{t("Roles & Permissions")}}',icon:"LockOutlined",Component:Ci,aclSnippet:"pm.roles",sort:3})})}}d.RolesManagerContext=A,d.default=Je,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
9
+ `),Ve=e=>{if(!Array.isArray(e))return[];const t=[];for(const r of e)t.push(r.uid),t.push(...Ve(r.children));return t},We=(e,t,r=[])=>{if(!e)return[];for(const n of e){if(r.push(n.uid),t(n))return r;if(n.children){const a=We(n.children,t,r);if(a.length)return a}r.pop()}return[]},Be=(e=[],t=[])=>{for(const r of e)t.push(r.uid),r.children&&r.children.length&&Be(r.children,t);return t},yi=({active:e})=>{const{styles:t}=Le(),{role:r}=g.useContext(A),n=u.useAPIClient(),{items:a}=mi(),{t:i}=S.useTranslation(),o=Ve(a),[c,l]=g.useState([]),{loading:f,refresh:v}=u.useRequest({resource:"roles.menuUiSchemas",resourceOf:r.name,action:"list",params:{paginate:!1}},{ready:!!r&&e,refreshDeps:[r==null?void 0:r.name],onSuccess(b){var y;l(((y=b==null?void 0:b.data)==null?void 0:y.map(h=>h["x-uid"]))||[])}}),m=n.resource("roles.menuUiSchemas",r.name),C=o.length===c.length,le=(b,y)=>w(this,null,function*(){const h=We(a,$=>$.uid===y.uid),_=Be(y==null?void 0:y.children,[]);if(b){const $=_.concat(y.uid),N=c.filter(H=>!$.includes(H));l([...N]),yield m.remove({values:$})}else{const $=_.concat(h);l(N=>Z.uniq([...N,...$])),yield m.add({values:$})}p.message.success(i("Saved successfully"))}),D=b=>b.map(y=>{const h=i(y.title);return y.children?E(P({},y),{title:h,children:D(y.children)}):E(P({},y),{title:h})});return s.jsx(p.Table,{className:t,loading:f,rowKey:"uid",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:i("Menu item title")},{dataIndex:"accessible",title:s.jsxs(s.Fragment,{children:[s.jsx(p.Checkbox,{checked:C,onChange:b=>w(this,null,function*(){C?yield m.set({values:[]}):yield m.set({values:o}),v(),p.message.success(i("Saved successfully"))})})," ",i("Accessible")]}),render:(b,y)=>{const h=c.includes(y.uid);return s.jsx(p.Checkbox,{checked:h,onChange:()=>le(h,y)})}}],dataSource:D(a)})},Ye=(e=[],t=[])=>{for(const r of e)t.push(r.aclSnippet),r.children&&r.children.length&&Ye(r.children,t);return t},_i=({active:e})=>{const t=u.useApp(),{styles:r}=Le(),{role:n}=g.useContext(A),a=u.useAPIClient(),i=u.useCompile(),o=t.pluginSettingsManager.getList(!1),c=t.pluginSettingsManager.getAclSnippets(),[l,f]=g.useState([]),v=g.useMemo(()=>Z.flatMap(o,h=>h.children?[h,...h.children]:h),[o]),m=g.useMemo(()=>l.includes("pm.*")&&l.every(h=>!h.startsWith("!pm.")),[l]),{t:C}=S.useTranslation(),{loading:le,refresh:D}=u.useRequest({resource:"roles.snippets",resourceOf:n.name,action:"list",params:{paginate:!1}},{ready:!!n&&e,refreshDeps:[n==null?void 0:n.name],onSuccess(h){f((h==null?void 0:h.data.filter(_=>v.find($=>_.includes(`!${$.aclSnippet}`)||!_.startsWith("!pm."))))||[])}}),b=a.resource("roles.snippets",n.name),y=(h,_)=>w(this,null,function*(){const N=Ye(_==null?void 0:_.children,[]).concat(_.aclSnippet);h?(yield b.add({values:N.map(H=>"!"+H)}),D()):(yield b.remove({values:N.map(H=>"!"+H)}),D()),p.message.success(C("Saved successfully"))});return s.jsx(p.Table,{className:r,loading:le,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:C("Plugin name"),render:h=>i(h)},{dataIndex:"accessible",title:s.jsxs(s.Fragment,{children:[s.jsx(p.Checkbox,{checked:m,onChange:()=>w(this,null,function*(){const h=c.map(_=>"!"+_);m?yield b.add({values:h}):yield b.remove({values:h}),D(),p.message.success(C("Saved successfully"))})})," ",C("Accessible")]}),render:(h,_)=>{const $=!l.includes("!"+_.aclSnippet);return s.jsx(p.Checkbox,{checked:$,onChange:()=>y($,_)})}}],dataSource:o.filter(h=>h.isTopLevel!==!1).map(h=>h.showTabs!==!1?h:Z.omit(h,"children"))})},J=e=>s.jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:e.children}),bi=({active:e})=>{var f;const{t}=T(),[r,n]=g.useState("general"),{role:a}=g.useContext(A),i=(f=a==null?void 0:a.snippets)==null?void 0:f.includes("pm.*"),c=u.useApp().getComponent("DataSourcePermissionManager"),l=g.useMemo(()=>[{key:"general",label:t("General"),children:s.jsx(J,{children:s.jsx(gi,{active:r==="general"&&e})})},{key:"menu",label:t("Menu"),children:s.jsx(J,{children:s.jsx(ze,{children:s.jsx(yi,{active:r==="menu"&&e})})})},...i?[{key:"plugin",label:t("Plugin settings"),children:s.jsx(J,{children:s.jsx(_i,{active:r==="plugin"&&e})})}]:[],...c?[{key:"dataSource",label:t("Data sources"),children:s.jsx(J,{children:s.jsx(ze,{children:s.jsx(c,{role:a,active:r==="dataSource"&&e})})})}]:[]],[i,r,e,t]);return g.useEffect(()=>{n("general")},[a==null?void 0:a.name]),s.jsx(ho,{children:s.jsx(p.Tabs,{type:"card",activeKey:r,onChange:v=>n(v),items:l})})},$i=()=>{const{t:e}=T();return s.jsx(u.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 r=u.useActionContext();return u.useRequest(()=>Promise.resolve({data:{name:`r_${x.uid()}`,snippets:["!ui.*","!pm","!pm.*"]}}),E(P({},t),{refreshDeps:[r.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 }}"}}}}}}}}}}})},Xe={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"}}]},Ci=()=>{const{t:e}=T(),t=u.usePlugin(Je),[r,n]=g.useState("permissions"),a=Array.from(t.rolesManager.list()).map(([c,l])=>({key:c,label:I.Schema.compile(l.title,{t:e}),children:l.Component?g.createElement(l.Component,{active:r===c}):null})),[i,o]=g.useState(null);return s.jsx(A.Provider,{value:{role:i,setRole:o},children:s.jsx(p.Card,{children:s.jsxs(p.Row,{gutter:24,style:{flexWrap:"nowrap"},children:[s.jsx(p.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"250px"},children:s.jsx(u.ResourceActionProvider,{collection:Xe,request:{resource:"roles",action:"list",params:{pagination:!1,filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}},children:s.jsxs(u.CollectionProvider_deprecated,{collection:Xe,children:[s.jsx(p.Row,{children:s.jsx($i,{})}),s.jsx(p.Divider,{style:{margin:"12px 0"}}),s.jsx(se,{})]})})}),s.jsx(p.Col,{flex:"auto",style:{overflow:"hidden"},children:s.jsx(p.Tabs,{activeKey:r,onChange:c=>n(c),items:[{key:"permissions",label:e("Permissions"),children:s.jsx(bi,{active:r==="permissions"})},...a]})})]})})})};class xi{constructor(){pe(this,"rolesManager",new k.Registry)}add(t,r){this.rolesManager.register(t,r)}list(){return this.rolesManager.getEntities()}}class Je extends u.Plugin{constructor(){super(...arguments);pe(this,"rolesManager",new xi)}load(){return w(this,null,function*(){this.app.pluginSettingsManager.add("users-permissions.roles",{title:'{{t("Roles & Permissions")}}',icon:"LockOutlined",Component:Ci,aclSnippet:"pm.acl.roles",sort:3})})}}d.RolesManagerContext=A,d.default=Je,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,22 +1,22 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.20.0-alpha.8",
2
+ "@nocobase/client": "0.20.0-alpha.9",
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.20.0-alpha.8",
10
- "@nocobase/actions": "0.20.0-alpha.8",
11
- "@nocobase/cache": "0.20.0-alpha.8",
12
- "@nocobase/database": "0.20.0-alpha.8",
13
- "@nocobase/server": "0.20.0-alpha.8",
9
+ "@nocobase/utils": "0.20.0-alpha.9",
10
+ "@nocobase/actions": "0.20.0-alpha.9",
11
+ "@nocobase/cache": "0.20.0-alpha.9",
12
+ "@nocobase/database": "0.20.0-alpha.9",
13
+ "@nocobase/server": "0.20.0-alpha.9",
14
14
  "async-mutex": "0.3.2",
15
15
  "lodash": "4.17.21",
16
- "@nocobase/test": "0.20.0-alpha.8",
16
+ "@nocobase/test": "0.20.0-alpha.9",
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.20.0-alpha.8"
21
+ "@nocobase/acl": "0.20.0-alpha.9"
22
22
  };
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.20.0-alpha.8",
7
+ "version": "0.20.0-alpha.9",
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": "39ebc1cefe5a826aecf0b14d73530dfa5f9c2b1c"
37
+ "gitHead": "5473d9039cfdb649a8c8c625edefc9a3ac464be5"
38
38
  }