@nocobase/plugin-acl 1.7.0-beta.9 → 1.7.1

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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).push([["787"],{761:function(e,t,n){n.r(t),n.d(t,{RolesManagement:function(){return q}});var r=n(505),o=n(772),l=n(721),a=n(156),i=n.n(a),c=n(371),u=n(888),s=n(875),f=function(){var e=(0,u.g)().t;return i().createElement(o.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:{textAlign:"left"}},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:function(e){var t,n,r=(0,o.useActionContext)();return(0,o.useRequest)(function(){return Promise.resolve({data:{name:"r_".concat((0,s.uid)()),snippets:["!ui.*","!pm","!pm.*"]}})},(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},e),n=n={refreshDeps:[r.visible]},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t))}},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 }}"}}}}}}}}}}})},m=n(746),p=n(482),y=n(467);function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var b={type:"object",properties:d({},(0,s.uid)(),{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:function(e){var t,n,r=(0,o.useRecord)(),l=(0,o.useRequest)(function(){return Promise.resolve({data:(0,y.pick)(r,["title","name","default"])})},(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){d(e,t,n[t])})}return e}({},e),n=n={manual:!0},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t)),i=(0,o.useActionContext)();return(0,a.useEffect)(function(){i.visible&&l.run()},[i.visible]),l}},title:'{{t("Edit role")}}',properties:{title:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem","x-disabled":!0},default:{title:"","x-component":"CollectionField","x-decorator":"FormItem","x-content":'{{t("Default role")}}',"x-reactions":function(e){e.initialValue?e.disabled=!0:e.disabled=!1}},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.useUpdateAction }}"}}}}}})};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var h=function(e){var t,n=e.loadMore,r=(t=(0,a.useState)(null),function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(t,2)||function(e,t){if(e){if("string"==typeof e)return v(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),o=r[0],l=r[1],i=(0,a.useRef)(null),c=(0,a.useCallback)(function(e){e&&(i.current&&i.current.disconnect(),i.current=new IntersectionObserver(function(t){t.forEach(function(t){t.target===e.current&&t.isIntersecting&&(i.current&&i.current.unobserve(e.current),n())})}),e.current&&i.current&&i.current.observe(e.current))},[n]);return(0,a.useEffect)(function(){return c(o),function(){i.current&&i.current.disconnect()}},[o,c]),{lastItem:o,setLastItem:l}};function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function w(e,t,n,r,o,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}function E(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var l=e.apply(t,n);function a(e){w(l,r,o,a,i,"next",e)}function i(e){w(l,r,o,a,i,"throw",e)}a(void 0)})}}function O(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(e,t)||x(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e){return function(e){if(Array.isArray(e))return g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||x(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}function S(e,t){var n,r,o,l,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){var c=[l,i];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var j=function(){var e=(0,u.g)().t,t=(0,o.useResourceActionContext)(),n=t.data,r=t.mutate,c=O((0,a.useState)(!1),2),s=c[0],f=c[1],p=O((0,a.useState)(null),2),y=p[0],d=p[1],v=(0,a.useContext)(m.T),g=v.role,w=v.setRole,x=O((0,a.useState)([]),2),P=x[0],C=x[1],I=O((0,a.useState)(!1),2),R=I[0],k=I[1],D=(0,o.useAPIClient)(),T=h({loadMore:(0,a.useCallback)(E(function(){var e,t;return S(this,function(o){switch(o.label){case 0:if(!(e=null==n?void 0:n.meta)||e.page>=e.totalPage)return[2];return k(!0),[4,D.resource("roles").list({page:e.page+1,pageSize:e.pageSize,filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]})];case 1:return r((null==(t=o.sent())?void 0:t.data)||{}),k(!1),[2]}})}),[n])}),M=T.lastItem,F=T.setLastItem;(0,a.useEffect)(function(){P[0]&&w(P[0])},[P,w]),(0,a.useEffect)(function(){if(null==n||null==(e=n.data)?void 0:e.length){var e,t;F(i().createRef()),(null==(t=n.meta)?void 0:t.page)>1?C(function(e){return e.concat(n.data)}):C(n.data)}},[n,F]);var U=(0,a.useMemo)(function(){return P.map(function(e,t){return{key:e.name,label:t===P.length-1?i().createElement("div",{ref:M},i().createElement(j.Item,{item:e,onEdit:function(){f(!0),d(e)}})):i().createElement(j.Item,{item:e,onEdit:function(){f(!0),d(e)}})}})},[P,M]);return i().createElement(i().Fragment,null,P.length?i().createElement(l.Menu,{style:{border:"none",maxHeight:"65vh",overflowY:"auto"},items:A(U).concat(A(R?[{key:"loading",label:i().createElement(l.Spin,null)}]:[])),selectedKeys:[null==g?void 0:g.name],onSelect:function(e){var t=e.key;w(P.find(function(e){return e.name===t}))}}):i().createElement(l.Empty,{image:l.Empty.PRESENTED_IMAGE_SIMPLE}),i().createElement(o.ActionContextProvider,{value:{visible:s,setVisible:f}},i().createElement(o.RecordProvider,{record:y,collectionName:"departments"},i().createElement(o.SchemaComponent,{scope:{t:e},schema:b}))))};j.Item=function(e){var t=e.item,n=e.onEdit,a=(0,u.g)().t,c=(0,o.useResourceActionContext)().refreshAsync,s=l.App.useApp(),f=s.modal,m=s.message,y=(0,o.useAPIClient)(),d=function(){f.confirm({title:a("Delete"),content:a("Are you sure you want to delete it?"),onOk:E(function(){return S(this,function(e){switch(e.label){case 0:return[4,y.resource("roles").destroy({filterByTk:t.name})];case 1:return e.sent(),m.success(a("Deleted successfully")),[4,c()];case 2:return e.sent(),[2]}})})})},b=r.Schema.compile(t.title,{t:a});return i().createElement(l.Row,null,i().createElement(l.Col,{flex:3,style:{display:"inline-flex",alignItems:"center"}},i().createElement("span",{style:{whiteSpace:"nowrap",width:"120px",overflow:"hidden",textOverflow:"ellipsis"}},i().createElement(p.TagOutlined,null),i().createElement("span",{style:{marginLeft:"10px"},title:b},b))),i().createElement(l.Col,null,t.default?i().createElement(l.Tag,{color:"success",bordered:!1},a("Default")):null,i().createElement(l.Dropdown,{menu:{items:[{label:a("Edit"),key:"edit"},{label:a("Delete"),key:"delete"}],onClick:function(e){var t=e.key;switch(e.domEvent.stopPropagation(),t){case"edit":n();break;case"delete":d()}}}},i().createElement(p.MoreOutlined,null))))};var P=n(844);function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var I=function(e){return i().createElement("div",{style:{maxHeight:"60vh",overflowY:"auto"}},e.children)},R=function(e){var t,n=e.active,r=(0,u.g)().t,s=(t=i().useState("general"),function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(t,2)||function(e,t){if(e){if("string"==typeof e)return C(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return C(e,t)}}(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),f=s[0],p=s[1],y=(0,a.useContext)(m.T),d=y.role,b=y.setRole,v=(0,o.usePlugin)(c.default),h=(0,o.useACLRoleContext)(),g=(0,a.useMemo)(function(){return v.settingsUI.getPermissionsTabs({t:r,activeKey:f,TabLayout:I,activeRole:d,currentUserRole:h}).filter(Boolean)},[f,v.settingsUI,d,r,h]),w=(0,o.useAPIClient)(),E=(0,o.useRequest)(function(){return w.resource("roles").get({filterByTk:null==d?void 0:d.name}).then(function(e){var t,n,r=null==e||null==(t=e.data)?void 0:t.data;return null==(n=r.snippets)||n.forEach(function(e){r[e]=!0}),r})},{ready:n&&!!d,refreshDeps:[null==d?void 0:d.name]}).data;return(0,a.useEffect)(function(){p("general")},[null==d?void 0:d.name]),(0,a.useEffect)(function(){b(E)},[E,b]),i().createElement(P.U,null,i().createElement(l.Tabs,{type:"card",activeKey:f,onChange:function(e){return p(e)},items:g}))},k=n(749);function D(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var T=function(){var e,t=(0,u.g)().t,n=(0,o.useAPIClient)(),r=(0,o.useCurrentRoleMode)(),c=(e=(0,a.useState)(r||"default"),function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(e,2)||function(e,t){if(e){if("string"==typeof e)return D(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return D(e,t)}}(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),s=c[0],f=c[1],m=(0,k.useRequest)(function(e){return n.resource("roles").setSystemRoleMode({values:{roleMode:e}})},{manual:!0,onSuccess:function(e,n){f(n[0]),l.message.success(t("Saved successfully")),window.location.reload()}}).run;return i().createElement("div",null,i().createElement(l.Select,{value:s,onChange:function(e){return m(e)},options:[{value:"default",label:t("Independent roles"),desc:t("Do not use role union. Users need to switch between their roles individually.")},{value:"allow-use-union",label:t("Allow roles union"),desc:t("Allow users to use role union, which means they can use permissions from all their roles simultaneously, or switch between individual roles.")},{value:"only-use-union",label:t("Roles union only"),desc:t("Force users to use only role union. They cannot switch between individual roles.")}],optionRender:function(e){return i().createElement(l.Tooltip,{placement:"right",title:i().createElement("div",null,e.data.desc)},i().createElement(l.Flex,{justify:"space-between"},i().createElement("span",{style:{display:"inline-flex",paddingRight:8}},e.data.label)))}}))};function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function F(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(e,t)||U(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e,t){if(e){if("string"==typeof e)return M(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return M(e,t)}}var _={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"}}]},q=function(){var e=(0,u.g)().t,t=(0,o.usePlugin)(c.default),n=F(i().useState("permissions"),2),s=n[0],p=n[1],y=Array.from(t.rolesManager.list()).map(function(t){var n=F(t,2),o=n[0],l=n[1];return{key:o,label:r.Schema.compile(l.title,{t:e}),children:l.Component?i().createElement(l.Component,{active:s===o}):null}}),d=F((0,a.useState)(null),2),b=d[0],v=d[1],h=(0,o.useSchemaComponentContext)(),g=(0,a.useMemo)(function(){var e,t;return e=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},h),t=t={designable:!1},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e},[h]);return i().createElement(o.SchemaComponentContext.Provider,{value:g},i().createElement(m.T.Provider,{value:{role:b,setRole:v}},i().createElement(l.Card,null,i().createElement(l.Row,{gutter:24,style:{flexWrap:"nowrap"}},i().createElement(l.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"350px"}},i().createElement(o.ResourceActionProvider,{collection:_,request:{resource:"roles",action:"list",params:{filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}}},i().createElement(o.CollectionProvider_deprecated,{collection:_},i().createElement(l.Row,{justify:"space-between",align:"middle",style:{width:"100%"}},i().createElement(f,null),i().createElement(T,null)),i().createElement(l.Divider,{style:{margin:"12px 0"}}),i().createElement(j,null)))),i().createElement(l.Col,{flex:"auto",style:{overflow:"hidden"}},i().createElement(l.Tabs,{activeKey:s,onChange:function(e){return p(e)},items:[{key:"permissions",label:e("Permissions"),children:i().createElement(R,{active:"permissions"===s})}].concat(function(e){if(Array.isArray(e))return M(e)}(y)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(y)||U(y)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())}))))))}},844:function(e,t,n){n.d(t,{U:function(){return c},r:function(){return u}});var r=n(772),o=n(721),l=n(156),a=n.n(l),i=(0,l.createContext)([]);i.displayName="AvailableActionsContext";var c=function(e){var t=(0,r.useRequest)({resource:"availableActions",action:"list"}),n=t.data;return t.loading?a().createElement(o.Spin,null):a().createElement(i.Provider,{value:null==n?void 0:n.data},e.children)},u=function(){return(0,l.useContext)(i)}},888:function(e,t,n){n.d(t,{g:function(){return o}});var r=n(238);function o(){return(0,r.useTranslation)(["@nocobase/plugin-acl","client"],{nsMode:"fallback"})}}}]);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).push([["837"],{844:function(e,n,t){t.d(n,{U:function(){return u},r:function(){return c}});var r=t(772),o=t(721),a=t(156),l=t.n(a),i=(0,a.createContext)([]);i.displayName="AvailableActionsContext";var u=function(e){var n=(0,r.useRequest)({resource:"availableActions",action:"list"}),t=n.data;return n.loading?l().createElement(o.Spin,null):l().createElement(i.Provider,{value:null==t?void 0:t.data},e.children)},c=function(){return(0,a.useContext)(i)}},784:function(e,n,t){t.r(n),t.d(n,{GeneralPermissions:function(){return z}});var r=t(563),o=t(505),a=t(875),l=t(772),i=t(749),u=t(721),c=t(467),s=t.n(c),f=t(156),p=t.n(f),d=t(238),m=t(888),y=t(746);function b(){var e,n,t=(e=["\n .ant-table-cell {\n > .ant-space-horizontal {\n .ant-space-item-split:has(+ .ant-space-item:empty) {\n display: none;\n }\n }\n }\n "],n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}})));return b=function(){return t},t}var v=(0,t(202).createStyles)(function(e){return(0,e.css)(b())});function h(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function g(e,n,t,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){t(e);return}i.done?n(u):Promise.resolve(u).then(r,o)}function w(e){return function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function l(e){g(a,r,o,l,i,"next",e)}function i(e){g(a,r,o,l,i,"throw",e)}l(void 0)})}}function S(e,n){if(e){if("string"==typeof e)return h(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return h(e,n)}}function x(e,n){var t,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(t)throw TypeError("Generator is already executing.");for(;l;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){l.label=u[1];break}if(6===u[0]&&l.label<o[1]){l.label=o[1],o=u;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(u);break}o[2]&&l.ops.pop(),l.trys.pop();continue}u=n.call(e,l)}catch(e){u=[6,e],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var O=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=!0,r=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(t=(a=l.next()).done);t=!0){var i=a.value;n.push(i.aclSnippet),i.children&&i.children.length&&O(i.children,n)}}catch(e){r=!0,o=e}finally{try{t||null==l.return||l.return()}finally{if(r)throw o}}return n},A=function(e){var n=e.active,t=(0,l.useApp)(),r=v().styles,o=(0,f.useContext)(y.T).role,a=(0,l.useAPIClient)(),i=(0,l.useCompile)(),m=t.pluginSettingsManager.getList(!1),b=t.pluginSettingsManager.getAclSnippets(),g=(M=(0,f.useState)((null==o?void 0:o.snippets)||[]),function(e){if(Array.isArray(e))return e}(M)||function(e,n){var t,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(t=o.next()).done)&&(a.push(t.value),a.length!==n);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(M,2)||S(M,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),A=g[0],k=g[1],C=(0,f.useMemo)(function(){return(0,c.flatMap)(m,function(e){var n;return e.children?[e].concat(function(e){if(Array.isArray(e))return h(e)}(n=e.children)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(n)||S(n)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()):e})},[m]),j=(0,f.useMemo)(function(){return A.includes("pm.*")&&A.every(function(e){return!e.startsWith("!pm.")})},[A]),E=(0,d.useTranslation)().t,P=(0,l.useRequest)({resource:"roles.snippets",resourceOf:null==o?void 0:o.name,action:"list",params:{paginate:!1}},{ready:!!o&&n,refreshDeps:[null==o?void 0:o.name],manual:!0,onSuccess:function(e){k((null==e?void 0:e.data.filter(function(e){return C.find(function(n){return e.includes("!".concat(n.aclSnippet))||!e.startsWith("!pm.")})}))||[])}}),T=P.loading,I=P.refresh;if(o){var M,F,D=a.resource("roles.snippets",null==o?void 0:o.name),_=(F=w(function(e,n){var t;return x(this,function(r){switch(r.label){case 0:if(t=O(null==n?void 0:n.children,[]).concat(n.aclSnippet),e)return[3,2];return[4,D.remove({values:t.map(function(e){return"!"+e})})];case 1:return r.sent(),I(),[3,4];case 2:return[4,D.add({values:t.map(function(e){return"!"+e})})];case 3:r.sent(),I(),r.label=4;case 4:return u.message.success(E("Saved successfully")),[2]}})}),function(e,n){return F.apply(this,arguments)});return p().createElement(u.Table,{className:r,loading:T,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:E("Plugin name"),render:function(e){return i(e)}},{dataIndex:"accessible",title:p().createElement(p().Fragment,null,p().createElement(u.Checkbox,{checked:j,onChange:w(function(){var e;return x(this,function(n){switch(n.label){case 0:if(e=b.map(function(e){return"!"+e}),j)return[3,2];return[4,D.remove({values:e})];case 1:return n.sent(),[3,4];case 2:return[4,D.add({values:e})];case 3:n.sent(),n.label=4;case 4:return I(),u.message.success(E("Saved successfully")),[2]}})})}),E("Accessible")),render:function(e,n){var t=!A.includes("!"+n.aclSnippet);return p().createElement(u.Checkbox,{checked:t,onChange:function(){return _(t,n)}})}}],dataSource:m.filter(function(e){return!1!==e.isTopLevel}).map(function(e){return!1!==e.showTabs?e:s().omit(e,"children")})})}},k=t(844);function C(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}var j=function(e){if(!e)return{};var n,t={};return null==e||null==(n=e.forEach)||n.call(e,function(e){var n,r=(n=e.split(":"),function(e){if(Array.isArray(e))return e}(n)||function(e,n){var t,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(t=o.next()).done)&&(a.push(t.value),a.length!==n);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw r}}return a}}(n,2)||function(e,n){if(e){if("string"==typeof e)return C(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return C(e,n)}}(n,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),o=r[0],a=r[1];t[o]=a||"all"}),t},E=function(e){var n=[];for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t)){var r=e[t];"all"===r?n.push(t):n.push("".concat(t,":").concat(r))}return n},P=(0,o.connect)(function(e){var n=e.onChange,t=(0,k.r)(),r=(0,l.useCompile)(),a=(0,d.useTranslation)().t,i=j((0,o.useField)().value);return p().createElement("div",null,p().createElement(u.Table,{rowKey:"name",size:"small",pagination:!1,columns:[{dataIndex:"displayName",title:a("Action display name"),render:function(e){return r(e)}},{dataIndex:"onNewRecord",title:a("Action type"),render:function(e){return e?p().createElement(u.Tag,{color:"green"},a("Action on new records")):p().createElement(u.Tag,{color:"geekblue"},a("Action on existing records"))}},{dataIndex:"enabled",title:a("Allow"),render:function(e,t){return p().createElement(u.Checkbox,{checked:e,"aria-label":"".concat(t.name,"_checkbox"),onChange:function(r){e?delete i[t.name]:i[t.name]="all",n(E(i))}})}},{dataIndex:"scope",title:a("Data scope"),render:function(e,t){return!t.onNewRecord&&p().createElement(u.Select,{"data-testid":"select-data-scope",popupMatchSelectWidth:!1,size:"small",value:e,options:[{label:a("All records"),value:"all"},{label:a("Own records"),value:"own"}],onChange:function(e){i[t.name]=e,n(E(i))}})}}],dataSource:null==t?void 0:t.map(function(e){var n,t,r="all",o=!1;return i[e.name]&&(o=!0,r=i[e.name]),n=function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r;r=t[n],n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r})}return e}({},e),t=t={enabled:o,scope:r},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):(function(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))}),n})}))});function T(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function I(e,n,t,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){t(e);return}i.done?n(u):Promise.resolve(u).then(r,o)}function M(e){return function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function l(e){I(a,r,o,l,i,"next",e)}function i(e){I(a,r,o,l,i,"throw",e)}l(void 0)})}}function F(e){return function(e){if(Array.isArray(e))return T(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,n){if(e){if("string"==typeof e)return T(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return T(e,n)}}(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e,n){var t,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(t)throw TypeError("Generator is already executing.");for(;l;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){l.label=u[1];break}if(6===u[0]&&l.label<o[1]){l.label=o[1],o=u;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(u);break}o[2]&&l.ops.pop(),l.trys.pop();continue}u=n.call(e,l)}catch(e){u=[6,e],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var _=(0,o.connect)(function(e){var n=(0,d.useTranslation)().t;return p().createElement(u.Checkbox.Group,{style:{width:"100%",display:"block"},value:e.value,onChange:function(n){var t=["ui.*","pm","pm.*","app"],r=t.map(function(e){return"!".concat(e)}),o=(0,c.uniq)(F(e.value||[]).concat(F(n))).filter(function(e){return e&&!r.includes(e)}).map(function(e){return!t.includes(e)||(null==n?void 0:n.includes(e))?e:"!".concat(e)}),a=!0,l=!1,i=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;o.includes(f)||o.includes("!".concat(f))||o.push("!".concat(f))}}catch(e){l=!0,i=e}finally{try{a||null==s.return||s.return()}finally{if(l)throw i}}e.onChange(o)}},p().createElement("div",{style:{marginTop:16}},p().createElement(u.Checkbox,{value:"ui.*"},n("Allows to configure interface"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"pm"},n("Allows to install, activate, disable plugins"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"pm.*"},n("Allows to configure plugins"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"app"},n("Allows to clear cache, reboot application"))))}),z=function(){var e,n,t=(0,f.useContext)(y.T),o=t.role,c=t.setRole,s=(0,m.g)().t,d=(0,l.useAPIClient)(),b=null==o||null==(n=o.snippets)?void 0:n.includes("pm.*"),v=(0,i.useMemoizedFn)((e=M(function(e){return D(this,function(n){switch(n.label){case 0:return[4,d.resource("roles").update({filterByTk:o.name,values:{snippets:e.values.snippets}})];case 1:return n.sent(),c(function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r;r=t[n],n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r})}return e}({},o,e.values)),u.message.success(s("Saved successfully")),[2]}})}),function(n){return e.apply(this,arguments)})),h=(0,f.useMemo)(function(){return(0,r.createForm)({values:o,effects:function(){var e;(0,r.onFormValuesChange)((e=M(function(e){return D(this,function(n){switch(n.label){case 0:return[4,v(e)];case 1:return n.sent(),[2]}})}),function(n){return e.apply(this,arguments)}))}})},[o,v]);return p().createElement(l.SchemaComponent,{components:{SnippetCheckboxGroup:_,StrategyActions:P,PluginPermissions:A},scope:{pm:b},schema:{type:"void",name:(0,a.uid)(),"x-component":"div",properties:{general:{"x-component":"FormV2","x-component-props":{form:h},properties:{snippets:{title:s("Configure permissions"),type:"boolean","x-decorator":"FormItem","x-component":"SnippetCheckboxGroup"}}},plugins:{"x-component":"FormV2",properties:{pluginSettings:{title:s("Plugin settings"),"x-decorator":"FormItem","x-component":"PluginPermissions","x-visible":"{{pm}}"}}}}}})}},888:function(e,n,t){t.d(n,{g:function(){return o}});var r=t(238);function o(){return(0,r.useTranslation)(["@nocobase/plugin-acl","client"],{nsMode:"fallback"})}}}]);
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react-i18next"),require("@formily/shared"),require("@nocobase/utils/client"),require("@formily/core"),require("@nocobase/client"),require("lodash"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("antd-style"),require("react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-acl",["react-i18next","@formily/shared","@nocobase/utils/client","@formily/core","@nocobase/client","lodash","ahooks","antd","@ant-design/icons","@formily/react","antd-style","react"],t):"object"==typeof exports?exports["@nocobase/plugin-acl"]=t(require("react-i18next"),require("@formily/shared"),require("@nocobase/utils/client"),require("@formily/core"),require("@nocobase/client"),require("lodash"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("antd-style"),require("react")):e["@nocobase/plugin-acl"]=t(e["react-i18next"],e["@formily/shared"],e["@nocobase/utils/client"],e["@formily/core"],e["@nocobase/client"],e.lodash,e.ahooks,e.antd,e["@ant-design/icons"],e["@formily/react"],e["antd-style"],e.react)}(self,function(e,t,n,r,o,i,u,a,c,l,s,f){return function(){var p,d,b,h,y,m,v={746:function(e,t,n){"use strict";n.d(t,{T:function(){return r}});var r=(0,n(156).createContext)({role:null});r.displayName="RolesManagerContext"},509:function(e,t,n){"use strict";n.r(t),n.d(t,{DesktopAllRoutesProvider:function(){return E},MenuPermissions:function(){return C}});var r=n(563),o=n(875),i=n(772),u=n(749),a=n(721),c=n(467),l=n(156),s=n.n(l),f=n(238),p=n(746);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function b(e,t,n,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){n(e);return}a.done?t(c):Promise.resolve(c).then(r,o)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){b(i,r,o,u,a,"next",e)}function a(e){b(i,r,o,u,a,"throw",e)}u(void 0)})}}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}function m(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function v(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}}function w(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function x(){var e,t,n=(e=["\n .ant-table-cell {\n > .ant-space-horizontal {\n .ant-space-item-split:has(+ .ant-space-item:empty) {\n display: none;\n }\n }\n }\n"],!t&&(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return x=function(){return n},n}var k=function(e,t){return Array.isArray(e)?e.map(function(e){var n,r=k(e.children,e),o=0===r.length;return{title:e.title,id:e.id,children:o?null:r,hideChildren:o,firstTabId:null===(n=r[0])||void 0===n?void 0:n.id,parent:t}}):[]},O=function(e){if(!Array.isArray(e))return[];var t=[],n=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var a=i.value;t.push(a.id),t.push.apply(t,v(O(a.children)))}}catch(e){r=!0,o=e}finally{try{!n&&null!=u.return&&u.return()}finally{if(r)throw o}}return t},P=(0,i.css)(x()),j=function(e,t,n){return e.map(function(e){var r,o=((null===(r=e.title)||void 0===r?void 0:r.match(/^\s*\{\{\s*.+?\s*\}\}\s*$/))?n(e.title):t(e.title))||t("Unnamed");return e.children?m(y({},e),{title:o,children:j(e.children,t,n)}):m(y({},e),{title:o})})},S=(0,l.createContext)({routeList:[]}),_=function(e){var t=e.children,n=e.refreshRef,r=(0,i.useAPIClient)(),o=(0,l.useMemo)(function(){return r.resource("desktopRoutes")},[r]),u=(0,i.useRequest)(function(){return o.list({tree:!0,sort:"sort",paginate:!1,filter:{hidden:{$ne:!0}}}).then(function(e){return e.data})},{manual:!0}),a=u.data,c=u.runAsync;n&&(n.current=c);var f=(0,l.useMemo)(function(){return(null==a?void 0:a.data)||[]},[a]),p=(0,l.useMemo)(function(){return{routeList:f}},[f]);return s().createElement(S.Provider,{value:p},t)},E=function(e){var t=e.children,n=e.active,r=s().useRef(function(){});return(0,l.useEffect)(function(){if(n){var e;null===(e=r.current)||void 0===e||e.call(r)}},[n]),s().createElement(_,{refreshRef:r},t)},C=function(e){var t,n,d,b,m,x=e.active,_=k((0,l.useContext)(S).routeList),E=(0,l.useContext)(p.T),C=E.role,R=E.setRole,T=(0,i.useAPIClient)(),q=(0,f.useTranslation)().t,A=O(_);var M=(t=(0,l.useState)([]),n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(e);!(u=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);u=!0);}catch(e){a=!0,r=e}finally{try{!u&&null!=o.return&&o.return()}finally{if(a)throw r}}return i}}(t,2)||g(t,n)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),I=M[0],D=M[1],F=(0,i.useRequest)({resource:"roles.desktopRoutes",resourceOf:C.name,action:"list",params:{paginate:!1,filter:{hidden:{$ne:!0}}}},{ready:!!C&&x,refreshDeps:[null==C?void 0:C.name],onSuccess:function(e){var t;D((null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.map(function(e){return e.id}))||[])}}),z=F.loading,L=F.refresh,N=T.resource("roles.desktopRoutes",C.name),G=A.length===I.length,U=(0,i.useAllAccessDesktopRoutes)().refresh;var B=(d=h(function(e,t){var n,r,o,i,u,l,s,f;return w(this,function(p){switch(p.label){case 0:if(!e)return[3,2];return n=I.filter(function(e){return e!==t.id}),r=[t.id],t.parent&&0===t.parent.children.filter(function(e){return n.includes(e.id)}).length&&(n=n.filter(function(e){return e!==t.parent.id}),r.push(t.parent.id)),t.children&&(n=n.filter(function(e){return!O(t.children).includes(e)}),(o=r).push.apply(o,v(O(t.children)))),D(n),[4,N.remove({values:r})];case 1:return p.sent(),[3,4];case 2:return i=v(I).concat([t.id]),u=[t.id],t.parent&&!i.includes(t.parent.id)&&(i.push(t.parent.id),u.push(t.parent.id)),t.children&&(f=O(t.children),(l=i).push.apply(l,v(f)),(s=u).push.apply(s,v(f))),D((0,c.uniq)(i)),[4,N.add({values:u})];case 3:p.sent(),p.label=4;case 4:return U(),a.message.success(q("Saved successfully")),[2]}})}),function(e,t){return d.apply(this,arguments)});var $=(0,u.useMemoizedFn)((b=h(function(e){return w(this,function(t){switch(t.label){case 0:return[4,T.resource("roles").update({filterByTk:C.name,values:e.values})];case 1:return t.sent(),R(y({},C,e.values)),a.message.success(q("Saved successfully")),[2]}})}),function(e){return b.apply(this,arguments)})),K=(0,l.useMemo)(function(){return(0,r.createForm)({values:C,effects:function(){var e;(0,r.onFormValuesChange)((e=h(function(e){return w(this,function(t){switch(t.label){case 0:return[4,$(e)];case 1:return t.sent(),[2]}})}),function(t){return e.apply(this,arguments)}))}})},[C,$]),V=(0,i.useCompile)();return s().createElement(s().Fragment,null,s().createElement(i.SchemaComponent,{schema:{type:"void",name:(0,o.uid)(),"x-component":"FormV2","x-component-props":{form:K},properties:{allowNewMenu:{title:q("Route permissions"),"x-decorator":"FormItem","x-component":"Checkbox","x-content":q("New routes are allowed to be accessed by default")}}}}),s().createElement(a.Table,{className:P,loading:z,rowKey:"id",pagination:!1,expandable:{defaultExpandAllRows:!1},columns:[{dataIndex:"title",title:q("Route name")},{dataIndex:"accessible",title:s().createElement(s().Fragment,null,s().createElement(a.Checkbox,{checked:G,onChange:(m=h(function(e){return w(this,function(e){switch(e.label){case 0:if(!G)return[3,2];return[4,N.set({values:[]})];case 1:return e.sent(),[3,4];case 2:return[4,N.set({values:A})];case 3:e.sent(),e.label=4;case 4:return L(),U(),a.message.success(q("Saved successfully")),[2]}})}),function(e){return m.apply(this,arguments)})})," ",q("Accessible")),render:function(e,t){var n=I.includes(t.id);return s().createElement(a.Checkbox,{checked:n,onChange:function(){return B(n,t)}})}}],dataSource:j(_,q,V)}))}},371:function(e,t,n){"use strict";n.r(t),n.d(t,{PluginACLClient:function(){return C},default:function(){return R},RolesManagerContext:function(){return v.T}});var r=n("772"),o=n("156"),i=n.n(o),u=n("509"),a=n(581);function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=(0,r.lazy)(function(){return a("imported_-1r1jup3_component",n.e("837").then(n.bind(n,784)))},"GeneralPermissions").GeneralPermissions,s=(0,r.lazy)(function(){return a("imported_1qalbop_component",Promise.resolve().then(n.bind(n,509)))},"MenuPermissions").MenuPermissions,f=function(){var e,t,n;function r(){var e,t,n;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,r),e=this,t="permissionsTabs",n=[function(e){var t=e.t,n=e.TabLayout;return{key:"general",label:t("System"),sort:10,children:i().createElement(n,null,i().createElement(l,null))}},function(e){var t=e.activeKey,n=e.t,r=e.TabLayout;return{key:"menu",label:n("Desktop routes"),sort:20,children:i().createElement(r,null,i().createElement(u.DesktopAllRoutesProvider,{active:"menu"===t},i().createElement(s,{active:"menu"===t})))}}],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}return e=r,t=[{key:"addPermissionsTab",value:function(e){this.permissionsTabs.push(e)}},{key:"getPermissionsTabs",value:function(e){return this.permissionsTabs.map(function(t){return"function"==typeof t?t(e):t}).sort(function(e,t){var n,r;return(null!==(n=null==e?void 0:e.sort)&&void 0!==n?n:100)-(null!==(r=null==t?void 0:t.sort)&&void 0!==r?r:100)})}}],c(e.prototype,t),r}(),p=n("584");function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var b=function(){var e,t,n;function r(){var e,t,n;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,r),e=this,t="rolesManager",n=new p.Registry,t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}return e=r,t=[{key:"add",value:function(e,t){this.rolesManager.register(e,t)}},{key:"list",value:function(){return this.rolesManager.getEntities()}}],d(e.prototype,t),r}(),h=n("238");function y(e,t,n,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){n(e);return}a.done?t(c):Promise.resolve(c).then(r,o)}var m=function(){var e,t,n,o=(0,h.useTranslation)().t,u=(0,r.useAPIClient)(),a=(0,r.useCurrentRoles)(),c=(0,r.useCurrentRoleMode)(),l=null===(n=a.find(function(e){return e.name===u.auth.role}))||void 0===n?void 0:n.name;if(a.length<=1||"only-use-union"===c)return null;return i().createElement(r.SchemaSettingsItem,{eventKey:"SwitchRole",title:"SwitchRole"},i().createElement(r.SelectWithTitle,{title:o("Switch role"),fieldNames:{label:"title",value:"name"},options:a,defaultValue:l||a[0].name,onChange:(t=(e=function(e){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}(this,function(t){switch(t.label){case 0:return u.auth.setRole(e),[4,u.resource("users").setDefaultRole({values:{roleName:e}})];case 1:return t.sent(),location.reload(),window.location.reload(),[2]}})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){y(i,r,o,u,a,"next",e)}function a(e){y(i,r,o,u,a,"throw",e)}u(void 0)})}),function(e){return t.apply(this,arguments)})}))},v=n("746"),g=n(581);function w(e,t,n,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){n(e);return}a.done?t(c):Promise.resolve(c).then(r,o)}function x(e,t,n){return(x=_()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&j(o,n.prototype),o}).apply(null,arguments)}function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e){return(P=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function j(e,t){return(j=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function S(e){var t="function"==typeof Map?new Map:void 0;return(S=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return x(e,arguments,P(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),j(r,e)})(e)}function _(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_=function(){return!!e})()}var E=(0,r.lazy)(function(){return g("imported_-1obaqk_component",n.e("787").then(n.bind(n,761)))},"RolesManagement").RolesManagement,C=function(e){var t,n,r;function o(){var e,t,n,r;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),t=this,n=o,r=arguments,n=P(n),O(e=function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(t,_()?Reflect.construct(n,r||[],P(t).constructor):n.apply(t,r)),"rolesManager",new b),O(e,"settingsUI",new f),e}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&j(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}(this,function(e){return t.pluginSettingsManager.add("users-permissions.roles",{title:t.t("Roles & Permissions"),icon:"LockOutlined",Component:E,aclSnippet:"pm.acl.roles",sort:3}),t.app.addUserCenterSettingsItem({name:"divider_switchRole",type:"divider",sort:200}),t.app.addUserCenterSettingsItem({name:"switchRole",Component:m,sort:300}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){w(i,r,o,u,a,"next",e)}function a(e){w(i,r,o,u,a,"throw",e)}u(void 0)})})()}}],k(t.prototype,n),o}(S(r.Plugin)),R=C},581:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=c},563:function(e){"use strict";e.exports=r},505:function(e){"use strict";e.exports=l},875:function(e){"use strict";e.exports=t},772:function(e){"use strict";e.exports=o},584:function(e){"use strict";e.exports=n},749:function(e){"use strict";e.exports=u},721:function(e){"use strict";e.exports=a},202:function(e){"use strict";e.exports=s},467:function(e){"use strict";e.exports=i},156:function(e){"use strict";e.exports=f},238:function(t){"use strict";t.exports=e}},g={};function w(e){var t=g[e];if(void 0!==t)return t.exports;var n=g[e]={exports:{}};return v[e](n,n.exports,w),n.exports}return w.m=v,w.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return w.d(t,{a:t}),t},w.d=function(e,t){for(var n in t)w.o(t,n)&&!w.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},w.f={},w.e=function(e){return Promise.all(Object.keys(w.f).reduce(function(t,n){return w.f[n](e,t),t},[]))},w.u=function(e){return""+({787:"521fd10515e7f9e6",837:"de199341733ccf37"})[e]+".js"},w.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),w.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p={},d="@nocobase/plugin-acl:",w.l=function(e,t,n,r){if(p[e]){p[e].push(t);return}if(void 0!==n){for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var c=u[a];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")==d+n){o=c;break}}}!o&&(i=!0,(o=document.createElement("script")).charset="utf-8",o.timeout=120,w.nc&&o.setAttribute("nonce",w.nc),o.setAttribute("data-webpack",d+n),o.src=e),p[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},w.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},w.p=(!(b=window.__nocobase_public_path__||"/").endsWith("/")&&(b+="/"),b+"static/plugins/@nocobase/plugin-acl/dist/client/"),h={909:0},w.f.j=function(e,t){var n=w.o(h,e)?h[e]:void 0;if(0!==n){if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=h[e]=[t,r]});t.push(n[2]=r);var o=w.p+w.u(e),i=Error();w.l(o,function(t){if(w.o(h,e)&&(0!==(n=h[e])&&(h[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}}},y=function(e,t){var n=t[0],r=t[1],o=t[2],i,u,a=0;if(n.some(function(e){return 0!==h[e]})){for(i in r)w.o(r,i)&&(w.m[i]=r[i]);o&&o(w)}for(e&&e(t);a<n.length;a++)u=n[a],w.o(h,u)&&h[u]&&h[u][0](),h[u]=0},(m=self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).forEach(y.bind(null,0)),m.push=y.bind(null,m.push.bind(m)),w("371")}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@formily/core"),require("ahooks"),require("@formily/shared"),require("@nocobase/client"),require("react"),require("@formily/react"),require("lodash"),require("@nocobase/utils/client"),require("@ant-design/icons"),require("antd"),require("antd-style"),require("react-i18next")):"function"==typeof define&&define.amd?define("@nocobase/plugin-acl",["@formily/core","ahooks","@formily/shared","@nocobase/client","react","@formily/react","lodash","@nocobase/utils/client","@ant-design/icons","antd","antd-style","react-i18next"],t):"object"==typeof exports?exports["@nocobase/plugin-acl"]=t(require("@formily/core"),require("ahooks"),require("@formily/shared"),require("@nocobase/client"),require("react"),require("@formily/react"),require("lodash"),require("@nocobase/utils/client"),require("@ant-design/icons"),require("antd"),require("antd-style"),require("react-i18next")):e["@nocobase/plugin-acl"]=t(e["@formily/core"],e.ahooks,e["@formily/shared"],e["@nocobase/client"],e.react,e["@formily/react"],e.lodash,e["@nocobase/utils/client"],e["@ant-design/icons"],e.antd,e["antd-style"],e["react-i18next"])}(self,function(e,t,n,r,o,i,u,a,l,c,s,f){return function(){var p,d,h,b,y,m,v={746:function(e,t,n){"use strict";n.d(t,{T:function(){return r}});var r=(0,n(156).createContext)({role:null});r.displayName="RolesManagerContext"},509:function(e,t,n){"use strict";n.r(t),n.d(t,{DesktopAllRoutesProvider:function(){return E},MenuPermissions:function(){return C}});var r=n(563),o=n(875),i=n(772),u=n(749),a=n(721),l=n(467),c=n(156),s=n.n(c),f=n(238),p=n(746);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function h(e,t,n,r,o,i,u){try{var a=e[i](u),l=a.value}catch(e){n(e);return}a.done?t(l):Promise.resolve(l).then(r,o)}function b(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){h(i,r,o,u,a,"next",e)}function a(e){h(i,r,o,u,a,"throw",e)}u(void 0)})}}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function m(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function v(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}}function w(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){var l=[i,a];if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return u.label++,{value:l[1],done:!1};case 5:u.label++,r=l[1],l=[0];continue;case 7:l=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){u=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){u.label=l[1];break}if(6===l[0]&&u.label<o[1]){u.label=o[1],o=l;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(l);break}o[2]&&u.ops.pop(),u.trys.pop();continue}l=t.call(e,u)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}function x(){var e,t,n=(e=["\n .ant-table-cell {\n > .ant-space-horizontal {\n .ant-space-item-split:has(+ .ant-space-item:empty) {\n display: none;\n }\n }\n }\n"],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return x=function(){return n},n}var k=function(e,t){return Array.isArray(e)?e.map(function(e){var n,r=k(e.children,e),o=0===r.length;return{title:e.title,id:e.id,children:o?null:r,hideChildren:o,firstTabId:null==(n=r[0])?void 0:n.id,parent:t}}):[]},O=function(e){if(!Array.isArray(e))return[];var t=[],n=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var a=i.value;t.push(a.id),t.push.apply(t,v(O(a.children)))}}catch(e){r=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(r)throw o}}return t},P=(0,i.css)(x()),_=function(e,t,n){return e.map(function(e){var r,o=((null==(r=e.title)?void 0:r.match(/^\s*\{\{\s*.+?\s*\}\}\s*$/))?n(e.title):t(e.title))||t("Unnamed");return e.children?m(y({},e),{title:o,children:_(e.children,t,n)}):m(y({},e),{title:o})})},j=(0,c.createContext)({routeList:[]}),S=function(e){var t=e.children,n=e.refreshRef,r=(0,i.useAPIClient)(),o=(0,c.useMemo)(function(){return r.resource("desktopRoutes")},[r]),u=(0,i.useRequest)(function(){return o.list({tree:!0,sort:"sort",paginate:!1,filter:{hidden:{$ne:!0}}}).then(function(e){return e.data})},{manual:!0}),a=u.data,l=u.runAsync;n&&(n.current=l);var f=(0,c.useMemo)(function(){return(null==a?void 0:a.data)||[]},[a]),p=(0,c.useMemo)(function(){return{routeList:f}},[f]);return s().createElement(j.Provider,{value:p},t)},E=function(e){var t=e.children,n=e.active,r=s().useRef(function(){});return(0,c.useEffect)(function(){if(n){var e;null==(e=r.current)||e.call(r)}},[n]),s().createElement(S,{refreshRef:r},t)},C=function(e){var t,n,d,h,m=e.active,x=k((0,c.useContext)(j).routeList),S=(0,c.useContext)(p.T),E=S.role,C=S.setRole,R=(0,i.useAPIClient)(),T=(0,f.useTranslation)().t,q=O(x),A=(t=(0,c.useState)([]),function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],u=!0,a=!1;try{for(o=o.call(e);!(u=(n=o.next()).done)&&(i.push(n.value),i.length!==t);u=!0);}catch(e){a=!0,r=e}finally{try{u||null==o.return||o.return()}finally{if(a)throw r}}return i}}(t,2)||g(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),M=A[0],I=A[1],D=(0,i.useRequest)({resource:"roles.desktopRoutes",resourceOf:E.name,action:"list",params:{paginate:!1,filter:{hidden:{$ne:!0}}}},{ready:!!E&&m,refreshDeps:[null==E?void 0:E.name],onSuccess:function(e){var t;I((null==e||null==(t=e.data)?void 0:t.map(function(e){return e.id}))||[])}}),F=D.loading,z=D.refresh,L=R.resource("roles.desktopRoutes",E.name),N=q.length===M.length,G=(0,i.useAllAccessDesktopRoutes)().refresh,U=(n=b(function(e,t){var n,r,o,i,u,c,s,f;return w(this,function(p){switch(p.label){case 0:if(!e)return[3,2];return n=M.filter(function(e){return e!==t.id}),r=[t.id],t.parent&&0===t.parent.children.filter(function(e){return n.includes(e.id)}).length&&(n=n.filter(function(e){return e!==t.parent.id}),r.push(t.parent.id)),t.children&&(n=n.filter(function(e){return!O(t.children).includes(e)}),(o=r).push.apply(o,v(O(t.children)))),I(n),[4,L.remove({values:r})];case 1:return p.sent(),[3,4];case 2:return i=v(M).concat([t.id]),u=[t.id],t.parent&&!i.includes(t.parent.id)&&(i.push(t.parent.id),u.push(t.parent.id)),t.children&&(f=O(t.children),(c=i).push.apply(c,v(f)),(s=u).push.apply(s,v(f))),I((0,l.uniq)(i)),[4,L.add({values:u})];case 3:p.sent(),p.label=4;case 4:return G(),a.message.success(T("Saved successfully")),[2]}})}),function(e,t){return n.apply(this,arguments)}),B=(0,u.useMemoizedFn)((d=b(function(e){return w(this,function(t){switch(t.label){case 0:return[4,R.resource("roles").update({filterByTk:E.name,values:e.values})];case 1:return t.sent(),C(y({},E,e.values)),a.message.success(T("Saved successfully")),[2]}})}),function(e){return d.apply(this,arguments)})),$=(0,c.useMemo)(function(){return(0,r.createForm)({values:E,effects:function(){var e;(0,r.onFormValuesChange)((e=b(function(e){return w(this,function(t){switch(t.label){case 0:return[4,B(e)];case 1:return t.sent(),[2]}})}),function(t){return e.apply(this,arguments)}))}})},[E,B]),K=(0,i.useCompile)();return s().createElement(s().Fragment,null,s().createElement(i.SchemaComponent,{schema:{type:"void",name:(0,o.uid)(),"x-component":"FormV2","x-component-props":{form:$},properties:{allowNewMenu:{title:T("Route permissions"),"x-decorator":"FormItem","x-component":"Checkbox","x-content":T("New routes are allowed to be accessed by default")}}}}),s().createElement(a.Table,{className:P,loading:F,rowKey:"id",pagination:!1,expandable:{defaultExpandAllRows:!1},columns:[{dataIndex:"title",title:T("Route name")},{dataIndex:"accessible",title:s().createElement(s().Fragment,null,s().createElement(a.Checkbox,{checked:N,onChange:(h=b(function(e){return w(this,function(e){switch(e.label){case 0:if(!N)return[3,2];return[4,L.set({values:[]})];case 1:return e.sent(),[3,4];case 2:return[4,L.set({values:q})];case 3:e.sent(),e.label=4;case 4:return z(),G(),a.message.success(T("Saved successfully")),[2]}})}),function(e){return h.apply(this,arguments)})})," ",T("Accessible")),render:function(e,t){var n=M.includes(t.id);return s().createElement(a.Checkbox,{checked:n,onChange:function(){return U(n,t)}})}}],dataSource:_(x,T,K)}))}},371:function(e,t,n){"use strict";n.r(t),n.d(t,{PluginACLClient:function(){return C},RolesManagerContext:function(){return g.T},default:function(){return R}});var r=n(772),o=n(156),i=n.n(o),u=n(509),a=n(581),l=(0,r.lazy)(function(){return a("imported_-1r1jup3_component",n.e("837").then(n.bind(n,784)))},"GeneralPermissions").GeneralPermissions,c=(0,r.lazy)(function(){return a("imported_1qalbop_component",Promise.resolve().then(n.bind(n,509)))},"MenuPermissions").MenuPermissions,s=function(){var e;function t(){var e,n;if(!(this instanceof t))throw TypeError("Cannot call a class as a function");e="permissionsTabs",n=[function(e){var t=e.t,n=e.TabLayout;return{key:"general",label:t("System"),sort:10,children:i().createElement(n,null,i().createElement(l,null))}},function(e){var t=e.activeKey,n=e.t,r=e.TabLayout;return{key:"menu",label:n("Desktop routes"),sort:20,children:i().createElement(r,null,i().createElement(u.DesktopAllRoutesProvider,{active:"menu"===t},i().createElement(c,{active:"menu"===t})))}}],e in this?Object.defineProperty(this,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):this[e]=n}return e=[{key:"addPermissionsTab",value:function(e){this.permissionsTabs.push(e)}},{key:"getPermissionsTabs",value:function(e){return this.permissionsTabs.map(function(t){return"function"==typeof t?t(e):t}).sort(function(e,t){var n,r;return(null!=(n=null==e?void 0:e.sort)?n:100)-(null!=(r=null==t?void 0:t.sort)?r:100)})}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,e),t}(),f=n(584),p=function(){var e;function t(){var e,n;if(!(this instanceof t))throw TypeError("Cannot call a class as a function");e="rolesManager",n=new f.Registry,e in this?Object.defineProperty(this,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):this[e]=n}return e=[{key:"add",value:function(e,t){this.rolesManager.register(e,t)}},{key:"list",value:function(){return this.rolesManager.getEntities()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,e),t}(),d=n(238),h=n(721),b=n(467),y=n.n(b);function m(e,t,n,r,o,i,u){try{var a=e[i](u),l=a.value}catch(e){n(e);return}a.done?t(l):Promise.resolve(l).then(r,o)}var v=function(){var e,t,n,o=(0,d.useTranslation)().t,u=(0,r.useAPIClient)(),a=y().cloneDeep((0,r.useCurrentRoles)()),l=(0,r.useCurrentRoleMode)(),c=null==(n=a.find(function(e){return e.name===u.auth.role}))?void 0:n.name;return("allow-use-union"===l&&a.unshift({name:"__union__",title:o("Full permissions",{ns:"acl"})}),a.length<=1||"only-use-union"===l)?null:i().createElement(r.SchemaSettingsItem,{eventKey:"SwitchRole",title:"SwitchRole"},i().createElement(r.SelectWithTitle,{title:o("Switch role"),fieldNames:{label:"title",value:"name"},options:a.reduce(function(e,t){return e.push(t),"__union__"===t.name&&e.push({name:"divider",title:i().createElement(h.Divider,{style:{margin:"2px 1px"}}),disabled:!0,style:{minHeight:0,height:"auto",padding:0}}),e},[]),defaultValue:c||a[0].name,onChange:(e=function(e){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){var l=[i,a];if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return u.label++,{value:l[1],done:!1};case 5:u.label++,r=l[1],l=[0];continue;case 7:l=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){u=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){u.label=l[1];break}if(6===l[0]&&u.label<o[1]){u.label=o[1],o=l;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(l);break}o[2]&&u.ops.pop(),u.trys.pop();continue}l=t.call(e,u)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(t){switch(t.label){case 0:return u.auth.setRole(e),[4,u.resource("users").setDefaultRole({values:{roleName:e}})];case 1:return t.sent(),location.reload(),window.location.reload(),[2]}})},t=function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){m(i,r,o,u,a,"next",e)}function a(e){m(i,r,o,u,a,"throw",e)}u(void 0)})},function(e){return t.apply(this,arguments)})}))},g=n(746),w=n(581);function x(e,t,n,r,o,i,u){try{var a=e[i](u),l=a.value}catch(e){n(e);return}a.done?t(l):Promise.resolve(l).then(r,o)}function k(e,t,n){return(k=S()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&_(o,n.prototype),o}).apply(null,arguments)}function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e){return(P=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _(e,t){return(_=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function j(e){var t="function"==typeof Map?new Map:void 0;return(j=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,P(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)})(e)}function S(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(S=function(){return!!e})()}var E=(0,r.lazy)(function(){return w("imported_-1obaqk_component",n.e("787").then(n.bind(n,761)))},"RolesManagement").RolesManagement,C=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function n(){var e,t,r;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");return t=n,r=arguments,t=P(t),O(e=function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,S()?Reflect.construct(t,r||[],P(this).constructor):t.apply(this,r)),"rolesManager",new p),O(e,"settingsUI",new s),e}return n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&_(n,e),t=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){var l=[i,a];if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return u.label++,{value:l[1],done:!1};case 5:u.label++,r=l[1],l=[0];continue;case 7:l=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){u=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){u.label=l[1];break}if(6===l[0]&&u.label<o[1]){u.label=o[1],o=l;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(l);break}o[2]&&u.ops.pop(),u.trys.pop();continue}l=t.call(e,u)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return t.pluginSettingsManager.add("users-permissions.roles",{title:t.t("Roles & Permissions"),icon:"LockOutlined",Component:E,aclSnippet:"pm.acl.roles",sort:3}),t.app.addUserCenterSettingsItem({name:"divider_switchRole",type:"divider",sort:200}),t.app.addUserCenterSettingsItem({name:"switchRole",Component:v,sort:300}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){x(i,r,o,u,a,"next",e)}function a(e){x(i,r,o,u,a,"throw",e)}u(void 0)})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,t),n}(j(r.Plugin)),R=C},581:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=l},563:function(t){"use strict";t.exports=e},505:function(e){"use strict";e.exports=i},875:function(e){"use strict";e.exports=n},772:function(e){"use strict";e.exports=r},584:function(e){"use strict";e.exports=a},749:function(e){"use strict";e.exports=t},721:function(e){"use strict";e.exports=c},202:function(e){"use strict";e.exports=s},467:function(e){"use strict";e.exports=u},156:function(e){"use strict";e.exports=o},238:function(e){"use strict";e.exports=f}},g={};function w(e){var t=g[e];if(void 0!==t)return t.exports;var n=g[e]={exports:{}};return v[e](n,n.exports,w),n.exports}return w.m=v,w.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return w.d(t,{a:t}),t},w.d=function(e,t){for(var n in t)w.o(t,n)&&!w.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},w.f={},w.e=function(e){return Promise.all(Object.keys(w.f).reduce(function(t,n){return w.f[n](e,t),t},[]))},w.u=function(e){return""+({787:"01bfb9fae6388d2f",837:"348ddf634e6b8533"})[e]+".js"},w.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),w.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p={},d="@nocobase/plugin-acl:",w.l=function(e,t,n,r){if(p[e])return void p[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var l=u[a];if(l.getAttribute("src")==e||l.getAttribute("data-webpack")==d+n){o=l;break}}o||(i=!0,(o=document.createElement("script")).charset="utf-8",o.timeout=120,w.nc&&o.setAttribute("nonce",w.nc),o.setAttribute("data-webpack",d+n),o.src=e),p[e]=[t];var c=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),i&&document.head.appendChild(o)},w.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(h=window.__nocobase_public_path__||"/").endsWith("/")||(h+="/"),w.p=h+"static/plugins/@nocobase/plugin-acl/dist/client/",b={909:0},w.f.j=function(e,t){var n=w.o(b,e)?b[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=b[e]=[t,r]});t.push(n[2]=r);var o=w.p+w.u(e),i=Error();w.l(o,function(t){if(w.o(b,e)&&(0!==(n=b[e])&&(b[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},y=function(e,t){var n,r,o=t[0],i=t[1],u=t[2],a=0;if(o.some(function(e){return 0!==b[e]})){for(n in i)w.o(i,n)&&(w.m[n]=i[n]);u&&u(w)}for(e&&e(t);a<o.length;a++)r=o[a],w.o(b,r)&&b[r]&&b[r][0](),b[r]=0},(m=self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).forEach(y.bind(null,0)),m.push=y.bind(null,m.push.bind(m)),w(371)}()});
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.7.0-beta.9",
11
+ "@nocobase/client": "1.7.1",
12
12
  "antd": "5.24.2",
13
13
  "react": "18.2.0",
14
14
  "react-i18next": "11.18.6",
@@ -16,15 +16,15 @@ module.exports = {
16
16
  "ahooks": "3.7.8",
17
17
  "@formily/react": "2.3.0",
18
18
  "@ant-design/icons": "5.6.1",
19
- "@nocobase/utils": "1.7.0-beta.9",
20
- "@nocobase/actions": "1.7.0-beta.9",
21
- "@nocobase/cache": "1.7.0-beta.9",
22
- "@nocobase/database": "1.7.0-beta.9",
23
- "@nocobase/server": "1.7.0-beta.9",
24
19
  "lodash": "4.17.21",
25
- "@nocobase/test": "1.7.0-beta.9",
20
+ "@nocobase/utils": "1.7.1",
21
+ "@nocobase/actions": "1.7.1",
22
+ "@nocobase/cache": "1.7.1",
23
+ "@nocobase/database": "1.7.1",
24
+ "@nocobase/server": "1.7.1",
25
+ "@nocobase/test": "1.7.1",
26
26
  "@formily/core": "2.3.0",
27
27
  "@formily/antd-v5": "1.2.3",
28
28
  "antd-style": "3.7.1",
29
- "@nocobase/acl": "1.7.0-beta.9"
29
+ "@nocobase/acl": "1.7.1"
30
30
  };
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "The current user has no roles. Please try another account.": "De huidige gebruiker heeft geen rol. Probeer een andere gebruikersaccount.",
3
3
  "The user role does not exist. Please try signing in again": "De gebruikersrol bestaat niet. Probeer opnieuw in te loggen.",
4
+ "Roles & Permissions": "Rollen & Permissies",
5
+ "General": "Algemeen",
4
6
  "New role": "Nieuwe rol",
5
7
  "Permissions": "Permissies",
6
- "Desktop menu": "Desktop menu"
8
+ "Desktop menu": "Desktop menu",
9
+ "Plugin settings": "Plugin instellingen",
10
+ "Data sources": "Data bronnen"
7
11
  }
@@ -45,25 +45,44 @@ async function setDefaultRole(ctx, next) {
45
45
  }
46
46
  const repository = db.getRepository("rolesUsers");
47
47
  await db.sequelize.transaction(async (transaction) => {
48
- await repository.update({
48
+ const currentUserDefaultRole = await repository.findOne({
49
49
  filter: {
50
- userId: currentUser.id
51
- },
52
- values: {
53
- default: false
50
+ userId: currentUser.id,
51
+ default: true
54
52
  },
55
53
  transaction
56
54
  });
57
- await repository.update({
55
+ if ((currentUserDefaultRole == null ? void 0 : currentUserDefaultRole.roleName) === roleName) {
56
+ return;
57
+ }
58
+ if (currentUserDefaultRole) {
59
+ await repository.model.update(
60
+ { default: false },
61
+ { where: { userId: currentUser.id, roleName: currentUserDefaultRole.roleName }, transaction }
62
+ );
63
+ }
64
+ const targetUserRole = await repository.findOne({
58
65
  filter: {
59
66
  userId: currentUser.id,
60
67
  roleName
61
68
  },
62
- values: {
63
- default: true
64
- },
65
69
  transaction
66
70
  });
71
+ let model;
72
+ if (targetUserRole) {
73
+ await repository.model.update({ default: true }, { where: { userId: currentUser.id, roleName }, transaction });
74
+ model = targetUserRole.set("default", true);
75
+ } else {
76
+ model = await repository.create({
77
+ values: {
78
+ userId: currentUser.id,
79
+ roleName,
80
+ default: true
81
+ },
82
+ transaction
83
+ });
84
+ }
85
+ db.emitAsync("rolesUsers.afterSave", model);
67
86
  });
68
87
  ctx.body = "ok";
69
88
  await next();
@@ -32,8 +32,8 @@ module.exports = __toCommonJS(setCurrentRole_exports);
32
32
  var import_constants = require("../constants");
33
33
  var import_enum = require("../enum");
34
34
  async function setCurrentRole(ctx, next) {
35
- var _a, _b;
36
- const currentRole = ctx.get("X-Role");
35
+ var _a, _b, _c;
36
+ let currentRole = ctx.get("X-Role");
37
37
  if (currentRole === "anonymous") {
38
38
  ctx.state.currentRole = currentRole;
39
39
  return next();
@@ -62,9 +62,13 @@ async function setCurrentRole(ctx, next) {
62
62
  roles.forEach((role2) => rolesMap.set(role2.name, role2));
63
63
  const userRoles = Array.from(rolesMap.values());
64
64
  ctx.state.currentUser.roles = userRoles;
65
- const systemSettings = await ctx.db.getRepository("systemSettings").findOne();
66
- const roleMode = (systemSettings == null ? void 0 : systemSettings.get("roleMode")) || import_enum.SystemRoleMode.default;
67
- if (ctx.state.currentRole === import_constants.UNION_ROLE_KEY && roleMode === import_enum.SystemRoleMode.default) {
65
+ const systemSettings = await cache.wrap(
66
+ `app:systemSettings`,
67
+ () => ctx.db.getRepository("systemSettings").findOne({ raw: true })
68
+ );
69
+ const roleMode = (systemSettings == null ? void 0 : systemSettings.roleMode) || import_enum.SystemRoleMode.default;
70
+ if ([currentRole, ctx.state.currentRole].includes(import_constants.UNION_ROLE_KEY) && roleMode === import_enum.SystemRoleMode.default) {
71
+ currentRole = userRoles[0].name;
68
72
  ctx.state.currentRole = userRoles[0].name;
69
73
  ctx.headers["x-role"] = userRoles[0].name;
70
74
  } else if (roleMode === import_enum.SystemRoleMode.onlyUseUnion) {
@@ -72,11 +76,6 @@ async function setCurrentRole(ctx, next) {
72
76
  ctx.headers["x-role"] = import_constants.UNION_ROLE_KEY;
73
77
  ctx.state.currentRoles = userRoles.map((role2) => role2.name);
74
78
  return next();
75
- } else if (roleMode === import_enum.SystemRoleMode.allowUseUnion) {
76
- ctx.state.currentUser.roles = userRoles.concat({
77
- name: import_constants.UNION_ROLE_KEY,
78
- title: ctx.t("Full permissions", { ns: "acl" })
79
- });
80
79
  }
81
80
  if (currentRole === import_constants.UNION_ROLE_KEY) {
82
81
  ctx.state.currentRole = import_constants.UNION_ROLE_KEY;
@@ -94,14 +93,14 @@ async function setCurrentRole(ctx, next) {
94
93
  }
95
94
  }
96
95
  if (!role) {
97
- const defaultRole = userRoles.find((role2) => {
98
- var _a2;
99
- return (_a2 = role2 == null ? void 0 : role2.rolesUsers) == null ? void 0 : _a2.default;
100
- });
101
- role = (_b = defaultRole || userRoles[0]) == null ? void 0 : _b.name;
96
+ const defaultRoleModel = await cache.wrap(
97
+ `roles:${ctx.state.currentUser.id}:defaultRole`,
98
+ () => ctx.db.getRepository("rolesUsers").findOne({ where: { userId: ctx.state.currentUser.id, default: true } })
99
+ );
100
+ role = (defaultRoleModel == null ? void 0 : defaultRoleModel.roleName) || ((_b = userRoles[0]) == null ? void 0 : _b.name);
102
101
  }
103
102
  ctx.state.currentRole = role;
104
- ctx.state.currentRoles = [role];
103
+ ctx.state.currentRoles = role === import_constants.UNION_ROLE_KEY ? [(_c = userRoles[0]) == null ? void 0 : _c.name] : [role];
105
104
  if (!ctx.state.currentRoles.length) {
106
105
  return ctx.throw(401, {
107
106
  code: "ROLE_NOT_FOUND_ERR",
@@ -316,10 +316,16 @@ class PluginACLServer extends import_server.Plugin {
316
316
  this.app.db.on("rolesUsers.afterSave", async (model) => {
317
317
  const cache = this.app.cache;
318
318
  await cache.del(`roles:${model.get("userId")}`);
319
+ await cache.del(`roles:${model.get("userId")}:defaultRole`);
320
+ });
321
+ this.app.db.on("systemSettings.afterSave", async (model) => {
322
+ const cache = this.app.cache;
323
+ await cache.del(`app:systemSettings`);
319
324
  });
320
325
  this.app.db.on("rolesUsers.afterDestroy", async (model) => {
321
326
  const cache = this.app.cache;
322
327
  await cache.del(`roles:${model.get("userId")}`);
328
+ await cache.del(`roles:${model.get("userId")}:defaultRole`);
323
329
  });
324
330
  const writeRolesToACL = async (app, options) => {
325
331
  const exists = await this.app.db.collectionExistsInDb("roles");
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": "1.7.0-beta.9",
7
+ "version": "1.7.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -13,8 +13,8 @@
13
13
  "Users & permissions"
14
14
  ],
15
15
  "devDependencies": {
16
- "@types/jsonwebtoken": "^8.5.8",
17
- "jsonwebtoken": "^8.5.1",
16
+ "@types/jsonwebtoken": "^9.0.9",
17
+ "jsonwebtoken": "^9.0.2",
18
18
  "react": "^18.2.0",
19
19
  "react-dom": "^18.2.0"
20
20
  },
@@ -33,5 +33,5 @@
33
33
  "url": "git+https://github.com/nocobase/nocobase.git",
34
34
  "directory": "packages/plugins/acl"
35
35
  },
36
- "gitHead": "7013a5080f3695d7750ab21005c90d2172c16480"
36
+ "gitHead": "8324f0fcc37d68f1e37fbdad70dea1bdce81866c"
37
37
  }
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- "use strict";(self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).push([["787"],{761:function(e,t,n){n.r(t),n.d(t,{RolesManagement:function(){return q}});var r=n("505"),o=n("772"),l=n("721"),a=n("156"),i=n.n(a),c=n("371"),u=n("888"),s=n("875"),f=function(){var e=(0,u.g)().t;return i().createElement(o.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:{textAlign:"left"}},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:function(e){var t,n,r=(0,o.useActionContext)();return(0,o.useRequest)(function(){return Promise.resolve({data:{name:"r_".concat((0,s.uid)()),snippets:["!ui.*","!pm","!pm.*"]}})},(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,l;r=e,o=t,l=n[t],o in r?Object.defineProperty(r,o,{value:l,enumerable:!0,configurable:!0,writable:!0}):r[o]=l})}return e}({},e),n=(n={refreshDeps:[r.visible]},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t))}},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 }}"}}}}}}}}}}})},m=n("746"),p=n("482"),d=n("467");function y(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var b={type:"object",properties:y({},(0,s.uid)(),{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:function(e){var t,n,r=(0,o.useRecord)();var l=(0,o.useRequest)(function(){return Promise.resolve({data:(0,d.pick)(r,["title","name","default"])})},(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){y(e,t,n[t])})}return e}({},e),n=(n={manual:!0},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t)),i=(0,o.useActionContext)();return(0,a.useEffect)(function(){i.visible&&l.run()},[i.visible]),l}},title:'{{t("Edit role")}}',properties:{title:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem","x-disabled":!0},default:{title:"","x-component":"CollectionField","x-decorator":"FormItem","x-content":'{{t("Default role")}}',"x-reactions":function(e){e.initialValue?e.disabled=!0:e.disabled=!1}},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.useUpdateAction }}"}}}}}})};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var h=function(e){var t,n,r=e.loadMore;var o=(t=(0,a.useState)(null),n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(i)throw r}}return l}}(t,2)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}(t,n)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),l=o[0],i=o[1],c=(0,a.useRef)(null),u=(0,a.useCallback)(function(e){if(!!e)c.current&&c.current.disconnect(),c.current=new IntersectionObserver(function(t){t.forEach(function(t){if(t.target===e.current)t.isIntersecting&&(c.current&&c.current.unobserve(e.current),r())})}),e.current&&c.current&&c.current.observe(e.current)},[r]);return(0,a.useEffect)(function(){return u(l),function(){c.current&&c.current.disconnect()}},[l,u]),{lastItem:l,setLastItem:i}};function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function w(e,t,n,r,o,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}function E(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var l=e.apply(t,n);function a(e){w(l,r,o,a,i,"next",e)}function i(e){w(l,r,o,a,i,"throw",e)}a(void 0)})}}function O(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(i)throw r}}return l}}(e,t)||x(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e){return function(e){if(Array.isArray(e))return g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||x(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(e,t){if(e){if("string"==typeof e)return g(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return g(e,t)}}function S(e,t){var n,r,o,l,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){return function(l){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,i])}}}var j=function(){var e=(0,u.g)().t,t=(0,o.useResourceActionContext)(),n=t.data,r=t.mutate,c=O((0,a.useState)(!1),2),s=c[0],f=c[1],p=O((0,a.useState)(null),2),d=p[0],y=p[1],v=(0,a.useContext)(m.T),g=v.role,w=v.setRole,x=O((0,a.useState)([]),2),P=x[0],C=x[1],I=O((0,a.useState)(!1),2),R=I[0],k=I[1],D=(0,o.useAPIClient)(),T=h({loadMore:(0,a.useCallback)(E(function(){var e,t;return S(this,function(o){switch(o.label){case 0:if(!(e=null==n?void 0:n.meta)||e.page>=e.totalPage)return[2];return k(!0),[4,D.resource("roles").list({page:e.page+1,pageSize:e.pageSize,filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]})];case 1:return r((null==(t=o.sent())?void 0:t.data)||{}),k(!1),[2]}})}),[n])}),M=T.lastItem,F=T.setLastItem;(0,a.useEffect)(function(){if(!!P[0])w(P[0])},[P,w]),(0,a.useEffect)(function(){var e,t;if(!!(null==n?void 0:null===(e=n.data)||void 0===e?void 0:e.length))F(i().createRef()),(null===(t=n.meta)||void 0===t?void 0:t.page)>1?C(function(e){return e.concat(n.data)}):C(n.data)},[n,F]);var U=(0,a.useMemo)(function(){return P.map(function(e,t){return{key:e.name,label:t===P.length-1?i().createElement("div",{ref:M},i().createElement(j.Item,{item:e,onEdit:function(){f(!0),y(e)}})):i().createElement(j.Item,{item:e,onEdit:function(){f(!0),y(e)}})}})},[P,M]);return i().createElement(i().Fragment,null,P.length?i().createElement(l.Menu,{style:{border:"none",maxHeight:"65vh",overflowY:"auto"},items:A(U).concat(A(R?[{key:"loading",label:i().createElement(l.Spin,null)}]:[])),selectedKeys:[null==g?void 0:g.name],onSelect:function(e){var t=e.key;w(P.find(function(e){return e.name===t}))}}):i().createElement(l.Empty,{image:l.Empty.PRESENTED_IMAGE_SIMPLE}),i().createElement(o.ActionContextProvider,{value:{visible:s,setVisible:f}},i().createElement(o.RecordProvider,{record:d,collectionName:"departments"},i().createElement(o.SchemaComponent,{scope:{t:e},schema:b}))))};j.Item=function(e){var t=e.item,n=e.onEdit,a=(0,u.g)().t,c=(0,o.useResourceActionContext)().refreshAsync,s=l.App.useApp(),f=s.modal,m=s.message,d=(0,o.useAPIClient)(),y=function(){f.confirm({title:a("Delete"),content:a("Are you sure you want to delete it?"),onOk:E(function(){return S(this,function(e){switch(e.label){case 0:return[4,d.resource("roles").destroy({filterByTk:t.name})];case 1:return e.sent(),m.success(a("Deleted successfully")),[4,c()];case 2:return e.sent(),[2]}})})})},b=r.Schema.compile(t.title,{t:a});return i().createElement(l.Row,null,i().createElement(l.Col,{flex:3,style:{display:"inline-flex",alignItems:"center"}},i().createElement("span",{style:{whiteSpace:"nowrap",width:"120px",overflow:"hidden",textOverflow:"ellipsis"}},i().createElement(p.TagOutlined,null),i().createElement("span",{style:{marginLeft:"10px"},title:b},b))),i().createElement(l.Col,null,t.default?i().createElement(l.Tag,{color:"success",bordered:!1},a("Default")):null,i().createElement(l.Dropdown,{menu:{items:[{label:a("Edit"),key:"edit"},{label:a("Delete"),key:"delete"}],onClick:function(e){var t=e.key;switch(e.domEvent.stopPropagation(),t){case"edit":n();break;case"delete":y()}}}},i().createElement(p.MoreOutlined,null))))};var P=n("844");function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var I=function(e){return i().createElement("div",{style:{maxHeight:"60vh",overflowY:"auto"}},e.children)},R=function(e){var t,n,r=e.active,s=(0,u.g)().t;var f=(t=i().useState("general"),n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(i)throw r}}return l}}(t,2)||function(e,t){if(e){if("string"==typeof e)return C(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return C(e,t)}}(t,n)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),p=f[0],d=f[1],y=(0,a.useContext)(m.T),b=y.role,v=y.setRole,h=(0,o.usePlugin)(c.default),g=(0,o.useACLRoleContext)(),w=(0,a.useMemo)(function(){return h.settingsUI.getPermissionsTabs({t:s,activeKey:p,TabLayout:I,activeRole:b,currentUserRole:g}).filter(Boolean)},[p,h.settingsUI,b,s,g]),E=(0,o.useAPIClient)(),O=(0,o.useRequest)(function(){return E.resource("roles").get({filterByTk:null==b?void 0:b.name}).then(function(e){var t,n,r=null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.data;return null===(n=r.snippets)||void 0===n||n.forEach(function(e){r[e]=!0}),r})},{ready:r&&!!b,refreshDeps:[null==b?void 0:b.name]}).data;return(0,a.useEffect)(function(){d("general")},[null==b?void 0:b.name]),(0,a.useEffect)(function(){v(O)},[O,v]),i().createElement(P.U,null,i().createElement(l.Tabs,{type:"card",activeKey:p,onChange:function(e){return d(e)},items:w}))},k=n("749");function D(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var T=function(){var e,t,n=(0,u.g)().t,r=(0,o.useAPIClient)(),c=(0,o.useCurrentRoleMode)();var s=(e=(0,a.useState)(c||"default"),t=2,function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(i)throw r}}return l}}(e,2)||function(e,t){if(e){if("string"==typeof e)return D(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return D(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),f=s[0],m=s[1],p=(0,k.useRequest)(function(e){return r.resource("roles").setSystemRoleMode({values:{roleMode:e}})},{manual:!0,onSuccess:function(e,t){m(t[0]),l.message.success(n("Saved successfully")),window.location.reload()}}).run;return i().createElement("div",null,i().createElement(l.Select,{value:f,onChange:function(e){return p(e)},options:[{value:"default",label:n("Independent roles"),desc:n("Do not use role union. Users need to switch between their roles individually.")},{value:"allow-use-union",label:n("Allow roles union"),desc:n("Allow users to use role union, which means they can use permissions from all their roles simultaneously, or switch between individual roles.")},{value:"only-use-union",label:n("Roles union only"),desc:n("Force users to use only role union. They cannot switch between individual roles.")}],optionRender:function(e){return i().createElement(l.Tooltip,{placement:"right",title:i().createElement("div",null,e.data.desc)},i().createElement(l.Flex,{justify:"space-between"},i().createElement("span",{style:{display:"inline-flex",paddingRight:8}},e.data.label)))}}))};function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function F(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(i)throw r}}return l}}(e,t)||U(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e,t){if(e){if("string"==typeof e)return M(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return M(e,t)}}var _={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"}}]},q=function(){var e,t=(0,u.g)().t,n=(0,o.usePlugin)(c.default),s=F(i().useState("permissions"),2),p=s[0],d=s[1],y=Array.from(n.rolesManager.list()).map(function(e){var n=F(e,2),o=n[0],l=n[1];return{key:o,label:r.Schema.compile(l.title,{t:t}),children:l.Component?i().createElement(l.Component,{active:p===o}):null}}),b=F((0,a.useState)(null),2),v=b[0],h=b[1],g=(0,o.useSchemaComponentContext)(),w=(0,a.useMemo)(function(){var e,t;return e=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,l;r=e,o=t,l=n[t],o in r?Object.defineProperty(r,o,{value:l,enumerable:!0,configurable:!0,writable:!0}):r[o]=l})}return e}({},g),t=(t={designable:!1},t),Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e},[g]);return i().createElement(o.SchemaComponentContext.Provider,{value:w},i().createElement(m.T.Provider,{value:{role:v,setRole:h}},i().createElement(l.Card,null,i().createElement(l.Row,{gutter:24,style:{flexWrap:"nowrap"}},i().createElement(l.Col,{flex:"280px",style:{borderRight:"1px solid #eee",minWidth:"350px"}},i().createElement(o.ResourceActionProvider,{collection:_,request:{resource:"roles",action:"list",params:{filter:{"name.$ne":"root"},showAnonymous:!0,sort:["createdAt"],appends:[]}}},i().createElement(o.CollectionProvider_deprecated,{collection:_},i().createElement(l.Row,{justify:"space-between",align:"middle",style:{width:"100%"}},i().createElement(f,null),i().createElement(T,null)),i().createElement(l.Divider,{style:{margin:"12px 0"}}),i().createElement(j,null)))),i().createElement(l.Col,{flex:"auto",style:{overflow:"hidden"}},i().createElement(l.Tabs,{activeKey:p,onChange:function(e){return d(e)},items:[{key:"permissions",label:t("Permissions"),children:i().createElement(R,{active:"permissions"===p})}].concat(function(e){if(Array.isArray(e))return M(e)}(e=y)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||U(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())}))))))}},844:function(e,t,n){n.d(t,{U:function(){return c},r:function(){return u}});var r=n(772),o=n(721),l=n(156),a=n.n(l),i=(0,l.createContext)([]);i.displayName="AvailableActionsContext";var c=function(e){var t=(0,r.useRequest)({resource:"availableActions",action:"list"}),n=t.data;return t.loading?a().createElement(o.Spin,null):a().createElement(i.Provider,{value:null==n?void 0:n.data},e.children)},u=function(){return(0,l.useContext)(i)}},888:function(e,t,n){n.d(t,{g:function(){return o}});var r=n(238);function o(){return(0,r.useTranslation)(["@nocobase/plugin-acl","client"],{nsMode:"fallback"})}}}]);
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- "use strict";(self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).push([["837"],{844:function(e,n,t){t.d(n,{U:function(){return u},r:function(){return c}});var r=t(772),o=t(721),a=t(156),l=t.n(a),i=(0,a.createContext)([]);i.displayName="AvailableActionsContext";var u=function(e){var n=(0,r.useRequest)({resource:"availableActions",action:"list"}),t=n.data;return n.loading?l().createElement(o.Spin,null):l().createElement(i.Provider,{value:null==t?void 0:t.data},e.children)},c=function(){return(0,a.useContext)(i)}},784:function(e,n,t){t.r(n),t.d(n,{GeneralPermissions:function(){return G}});var r=t("563"),o=t("505"),a=t("875"),l=t("772"),i=t("749"),u=t("721"),c=t("467"),s=t.n(c),f=t("156"),p=t.n(f),d=t("238"),m=t("888"),y=t("746"),v=t("202");function b(){var e,n,t=(e=["\n .ant-table-cell {\n > .ant-space-horizontal {\n .ant-space-item-split:has(+ .ant-space-item:empty) {\n display: none;\n }\n }\n }\n "],!n&&(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}})));return b=function(){return t},t}var h=(0,v.createStyles)(function(e){return(0,e.css)(b())});function g(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function w(e,n,t,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){t(e);return}i.done?n(u):Promise.resolve(u).then(r,o)}function S(e){return function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function l(e){w(a,r,o,l,i,"next",e)}function i(e){w(a,r,o,l,i,"throw",e)}l(void 0)})}}function x(e,n){if(e){if("string"==typeof e)return g(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return g(e,n)}}function O(e,n){var t,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(t)throw TypeError("Generator is already executing.");for(;l;)try{if(t=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=n.call(e,l)}catch(e){a=[6,e],r=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}var A=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=!0,r=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(t=(a=l.next()).done);t=!0){var i=a.value;n.push(i.aclSnippet),i.children&&i.children.length&&A(i.children,n)}}catch(e){r=!0,o=e}finally{try{!t&&null!=l.return&&l.return()}finally{if(r)throw o}}return n},k=function(e){var n,t,r,o=e.active,a=(0,l.useApp)(),i=h().styles,m=(0,f.useContext)(y.T).role,v=(0,l.useAPIClient)(),b=(0,l.useCompile)(),w=a.pluginSettingsManager.getList(!1),k=a.pluginSettingsManager.getAclSnippets();var C=(n=(0,f.useState)((null==m?void 0:m.snippets)||[]),t=2,function(e){if(Array.isArray(e))return e}(n)||function(e,n){var t,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(t=o.next()).done)&&(a.push(t.value),!n||a.length!==n);l=!0);}catch(e){i=!0,r=e}finally{try{!l&&null!=o.return&&o.return()}finally{if(i)throw r}}return a}}(n,2)||x(n,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),j=C[0],E=C[1],P=(0,f.useMemo)(function(){return(0,c.flatMap)(w,function(e){var n;if(!e.children)return e;return[e].concat(function(e){if(Array.isArray(e))return g(e)}(n=e.children)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(n)||x(n)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())})},[w]),T=(0,f.useMemo)(function(){return j.includes("pm.*")&&j.every(function(e){return!e.startsWith("!pm.")})},[j]),I=(0,d.useTranslation)().t,M=(0,l.useRequest)({resource:"roles.snippets",resourceOf:null==m?void 0:m.name,action:"list",params:{paginate:!1}},{ready:!!m&&o,refreshDeps:[null==m?void 0:m.name],manual:!0,onSuccess:function(e){E((null==e?void 0:e.data.filter(function(e){return P.find(function(n){return e.includes("!".concat(n.aclSnippet))||!e.startsWith("!pm.")})}))||[])}}),F=M.loading,D=M.refresh;if(!!m){var _=v.resource("roles.snippets",null==m?void 0:m.name);var z=(r=S(function(e,n){var t;return O(this,function(r){switch(r.label){case 0:if(t=A(null==n?void 0:n.children,[]).concat(n.aclSnippet),e)return[3,2];return[4,_.remove({values:t.map(function(e){return"!"+e})})];case 1:return r.sent(),D(),[3,4];case 2:return[4,_.add({values:t.map(function(e){return"!"+e})})];case 3:r.sent(),D(),r.label=4;case 4:return u.message.success(I("Saved successfully")),[2]}})}),function(e,n){return r.apply(this,arguments)});return p().createElement(u.Table,{className:i,loading:F,rowKey:"key",pagination:!1,expandable:{defaultExpandAllRows:!0},columns:[{dataIndex:"title",title:I("Plugin name"),render:function(e){return b(e)}},{dataIndex:"accessible",title:p().createElement(p().Fragment,null,p().createElement(u.Checkbox,{checked:T,onChange:S(function(){var e;return O(this,function(n){switch(n.label){case 0:if(e=k.map(function(e){return"!"+e}),T)return[3,2];return[4,_.remove({values:e})];case 1:return n.sent(),[3,4];case 2:return[4,_.add({values:e})];case 3:n.sent(),n.label=4;case 4:return D(),u.message.success(I("Saved successfully")),[2]}})})}),I("Accessible")),render:function(e,n){var t=!j.includes("!"+n.aclSnippet);return p().createElement(u.Checkbox,{checked:t,onChange:function(){return z(t,n)}})}}],dataSource:w.filter(function(e){return!1!==e.isTopLevel}).map(function(e){return!1!==e.showTabs?e:s().omit(e,"children")})})}},C=t("844");function j(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}var E=function(e){if(!e)return{};var n,t={};return null==e||null===(n=e.forEach)||void 0===n||n.call(e,function(e){var n,r,o=(n=e.split(":"),r=2,function(e){if(Array.isArray(e))return e}(n)||function(e,n){var t,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(t=o.next()).done)&&(a.push(t.value),!n||a.length!==n);l=!0);}catch(e){i=!0,r=e}finally{try{!l&&null!=o.return&&o.return()}finally{if(i)throw r}}return a}}(n,2)||function(e,n){if(e){if("string"==typeof e)return j(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return j(e,n)}}(n,r)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=o[0],l=o[1];t[a]=l||"all"}),t},P=function(e){var n=[];for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t)){var r=e[t];"all"===r?n.push(t):n.push("".concat(t,":").concat(r))}return n},T=(0,o.connect)(function(e){var n=e.onChange,t=(0,C.r)(),r=(0,l.useCompile)(),a=(0,d.useTranslation)().t,i=E((0,o.useField)().value);return p().createElement("div",null,p().createElement(u.Table,{rowKey:"name",size:"small",pagination:!1,columns:[{dataIndex:"displayName",title:a("Action display name"),render:function(e){return r(e)}},{dataIndex:"onNewRecord",title:a("Action type"),render:function(e){return e?p().createElement(u.Tag,{color:"green"},a("Action on new records")):p().createElement(u.Tag,{color:"geekblue"},a("Action on existing records"))}},{dataIndex:"enabled",title:a("Allow"),render:function(e,t){return p().createElement(u.Checkbox,{checked:e,"aria-label":"".concat(t.name,"_checkbox"),onChange:function(r){e?delete i[t.name]:i[t.name]="all",n(P(i))}})}},{dataIndex:"scope",title:a("Data scope"),render:function(e,t){return!t.onNewRecord&&p().createElement(u.Select,{"data-testid":"select-data-scope",popupMatchSelectWidth:!1,size:"small",value:e,options:[{label:a("All records"),value:"all"},{label:a("Own records"),value:"own"}],onChange:function(e){i[t.name]=e,n(P(i))}})}}],dataSource:null==t?void 0:t.map(function(e){var n,t,r="all",o=!1;return i[e.name]&&(o=!0,r=i[e.name]),n=function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r,o,a;r=e,o=n,a=t[n],o in r?Object.defineProperty(r,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[o]=a})}return e}({},e),t=(t={enabled:o,scope:r},t),Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):(function(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))}),n})}))});function I(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function M(e,n,t,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){t(e);return}i.done?n(u):Promise.resolve(u).then(r,o)}function F(e){return function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function l(e){M(a,r,o,l,i,"next",e)}function i(e){M(a,r,o,l,i,"throw",e)}l(void 0)})}}function D(e){return function(e){if(Array.isArray(e))return I(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,n){if(e){if("string"==typeof e)return I(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return I(e,n)}}(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _(e,n){var t,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(t)throw TypeError("Generator is already executing.");for(;l;)try{if(t=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=n.call(e,l)}catch(e){a=[6,e],r=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}var z=(0,o.connect)(function(e){var n=(0,d.useTranslation)().t;return p().createElement(u.Checkbox.Group,{style:{width:"100%",display:"block"},value:e.value,onChange:function(n){var t=["ui.*","pm","pm.*","app"],r=t.map(function(e){return"!".concat(e)}),o=(0,c.uniq)(D(e.value||[]).concat(D(n))).filter(function(e){return e&&!r.includes(e)}).map(function(e){return!t.includes(e)||(null==n?void 0:n.includes(e))?e:"!".concat(e)}),a=!0,l=!1,i=void 0;try{for(var u,s=t[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;!o.includes(f)&&!o.includes("!".concat(f))&&o.push("!".concat(f))}}catch(e){l=!0,i=e}finally{try{!a&&null!=s.return&&s.return()}finally{if(l)throw i}}e.onChange(o)}},p().createElement("div",{style:{marginTop:16}},p().createElement(u.Checkbox,{value:"ui.*"},n("Allows to configure interface"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"pm"},n("Allows to install, activate, disable plugins"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"pm.*"},n("Allows to configure plugins"))),p().createElement("div",{style:{marginTop:8}},p().createElement(u.Checkbox,{value:"app"},n("Allows to clear cache, reboot application"))))}),G=function(){var e,n,t=(0,f.useContext)(y.T),o=t.role,c=t.setRole,s=(0,m.g)().t,d=(0,l.useAPIClient)(),v=null==o?void 0:null===(n=o.snippets)||void 0===n?void 0:n.includes("pm.*");var b=(0,i.useMemoizedFn)((e=F(function(e){return _(this,function(n){switch(n.label){case 0:return[4,d.resource("roles").update({filterByTk:o.name,values:{snippets:e.values.snippets}})];case 1:return n.sent(),c(function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r,o,a;r=e,o=n,a=t[n],o in r?Object.defineProperty(r,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[o]=a})}return e}({},o,e.values)),u.message.success(s("Saved successfully")),[2]}})}),function(n){return e.apply(this,arguments)})),h=(0,f.useMemo)(function(){return(0,r.createForm)({values:o,effects:function(){var e;(0,r.onFormValuesChange)((e=F(function(e){return _(this,function(n){switch(n.label){case 0:return[4,b(e)];case 1:return n.sent(),[2]}})}),function(n){return e.apply(this,arguments)}))}})},[o,b]);return p().createElement(l.SchemaComponent,{components:{SnippetCheckboxGroup:z,StrategyActions:T,PluginPermissions:k},scope:{pm:v},schema:{type:"void",name:(0,a.uid)(),"x-component":"div",properties:{general:{"x-component":"FormV2","x-component-props":{form:h},properties:{snippets:{title:s("Configure permissions"),type:"boolean","x-decorator":"FormItem","x-component":"SnippetCheckboxGroup"}}},plugins:{"x-component":"FormV2",properties:{pluginSettings:{title:s("Plugin settings"),"x-decorator":"FormItem","x-component":"PluginPermissions","x-visible":"{{pm}}"}}}}}})}},888:function(e,n,t){t.d(n,{g:function(){return o}});var r=t(238);function o(){return(0,r.useTranslation)(["@nocobase/plugin-acl","client"],{nsMode:"fallback"})}}}]);