@nocobase/plugin-acl 1.7.0-beta.13 → 1.7.0-beta.15

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.
@@ -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,l,c,s,f){return function(){var p,d,h,y,b,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 y(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 b(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(b({},e),{title:o,children:j(e.children,t,n)}):m(b({},e),{title:o})})},S=(0,c.createContext)({routeList:[]}),_=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(S.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)||void 0===e||e.call(r)}},[n]),s().createElement(_,{refreshRef:r},t)},C=function(e){var t,n,d,h,m,x=e.active,_=k((0,c.useContext)(S).routeList),E=(0,c.useContext)(p.T),C=E.role,R=E.setRole,T=(0,i.useAPIClient)(),q=(0,f.useTranslation)().t,A=O(_);var M=(t=(0,c.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=y(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=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),(c=i).push.apply(c,v(f)),(s=u).push.apply(s,v(f))),D((0,l.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)((h=y(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(b({},C,e.values)),a.message.success(q("Saved successfully")),[2]}})}),function(e){return h.apply(this,arguments)})),K=(0,c.useMemo)(function(){return(0,r.createForm)({values:C,effects:function(){var e;(0,r.onFormValuesChange)((e=y(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=y(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 R},default:function(){return T},RolesManagerContext:function(){return g.T}});var r=n("772"),o=n("156"),i=n.n(o),u=n("509"),a=n(581);function l(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 c=(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(c,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)})}}],l(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 h=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}(),y=n("238"),b=n("721");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,y.useTranslation)().t,u=(0,r.useAPIClient)(),a=(0,r.useCurrentRoles)(),l=(0,r.useCurrentRoleMode)(),c=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"===l)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.reduce(function(e,t){return e.push(t),"__union__"===t.name&&e.push({name:"divider",title:i().createElement(b.Divider,{style:{margin:"2px 1px"}}),disabled:!0,style:{minHeight:0,height:"auto",padding:0}}),e},[]),defaultValue:c||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){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=E()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&S(o,n.prototype),o}).apply(null,arguments)}function O(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 P(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function S(e,t){return(S=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _(e){var t="function"==typeof Map?new Map:void 0;return(_=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 k(e,arguments,j(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),S(r,e)})(e)}function E(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(E=function(){return!!e})()}var C=(0,r.lazy)(function(){return w("imported_-1obaqk_component",n.e("787").then(n.bind(n,761)))},"RolesManagement").RolesManagement,R=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=j(n),P(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,E()?Reflect.construct(n,r||[],j(t).constructor):n.apply(t,r)),"rolesManager",new h),P(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&&S(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:C,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)})})()}}],O(t.prototype,n),o}(_(r.Plugin)),T=R},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(e){"use strict";e.exports=r},505:function(e){"use strict";e.exports=c},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 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})},w.p=(!(h=window.__nocobase_public_path__||"/").endsWith("/")&&(h+="/"),h+"static/plugins/@nocobase/plugin-acl/dist/client/"),y={909:0},w.f.j=function(e,t){var n=w.o(y,e)?y[e]:void 0;if(0!==n){if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=y[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(y,e)&&(0!==(n=y[e])&&(y[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)}}},b=function(e,t){var n=t[0],r=t[1],o=t[2],i,u,a=0;if(n.some(function(e){return 0!==y[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(y,u)&&y[u]&&y[u][0](),y[u]=0},(m=self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).forEach(b.bind(null,0)),m.push=b.bind(null,m.push.bind(m)),w("371")}()});
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,l,c,s,f){return function(){var p,d,h,y,b,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 y(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 b(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()),_=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(b({},e),{title:o,children:_(e.children,t,n)}):m(b({},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)||void 0===e||e.call(r)}},[n]),s().createElement(S,{refreshRef:r},t)},C=function(e){var t,n,d,h,m,x=e.active,S=k((0,c.useContext)(j).routeList),E=(0,c.useContext)(p.T),C=E.role,R=E.setRole,T=(0,i.useAPIClient)(),q=(0,f.useTranslation)().t,A=O(S);var M=(t=(0,c.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=y(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=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),(c=i).push.apply(c,v(f)),(s=u).push.apply(s,v(f))),D((0,l.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)((h=y(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(b({},C,e.values)),a.message.success(q("Saved successfully")),[2]}})}),function(e){return h.apply(this,arguments)})),K=(0,c.useMemo)(function(){return(0,r.createForm)({values:C,effects:function(){var e;(0,r.onFormValuesChange)((e=y(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=y(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:_(S,q,V)}))}},371:function(e,t,n){"use strict";n.r(t),n.d(t,{PluginACLClient:function(){return q},default:function(){return A},RolesManagerContext:function(){return x.T}});var r=n("772"),o=n("156"),i=n.n(o),u=n("509"),a=n(581);function l(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 c=(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(c,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)})}}],l(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 h=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}(),y=n("238"),b=n("721"),m=n("467"),v=n.n(m);function g(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 w=function(){var e,t,n,o=(0,y.useTranslation)().t,u=(0,r.useAPIClient)(),a=v().cloneDeep((0,r.useCurrentRoles)()),l=(0,r.useCurrentRoleMode)(),c=null===(n=a.find(function(e){return e.name===u.auth.role}))||void 0===n?void 0:n.name;if("allow-use-union"===l&&a.unshift({name:"__union__",title:o("Full permissions",{ns:"acl"})}),a.length<=1||"only-use-union"===l)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.reduce(function(e,t){return e.push(t),"__union__"===t.name&&e.push({name:"divider",title:i().createElement(b.Divider,{style:{margin:"2px 1px"}}),disabled:!0,style:{minHeight:0,height:"auto",padding:0}}),e},[]),defaultValue:c||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){g(i,r,o,u,a,"next",e)}function a(e){g(i,r,o,u,a,"throw",e)}u(void 0)})}),function(e){return t.apply(this,arguments)})}))},x=n("746"),k=n(581);function O(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 P(e,t,n){return(P=R()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&E(o,n.prototype),o}).apply(null,arguments)}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)}}function j(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e){return(S=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function E(e,t){return(E=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function C(e){var t="function"==typeof Map?new Map:void 0;return(C=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 P(e,arguments,S(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),E(r,e)})(e)}function R(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(R=function(){return!!e})()}var T=(0,r.lazy)(function(){return k("imported_-1obaqk_component",n.e("787").then(n.bind(n,761)))},"RolesManagement").RolesManagement,q=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=S(n),j(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,R()?Reflect.construct(n,r||[],S(t).constructor):n.apply(t,r)),"rolesManager",new h),j(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&&E(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:T,aclSnippet:"pm.acl.roles",sort:3}),t.app.addUserCenterSettingsItem({name:"divider_switchRole",type:"divider",sort:200}),t.app.addUserCenterSettingsItem({name:"switchRole",Component:w,sort:300}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){O(i,r,o,u,a,"next",e)}function a(e){O(i,r,o,u,a,"throw",e)}u(void 0)})})()}}],_(t.prototype,n),o}(C(r.Plugin)),A=q},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(e){"use strict";e.exports=r},505:function(e){"use strict";e.exports=c},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 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})},w.p=(!(h=window.__nocobase_public_path__||"/").endsWith("/")&&(h+="/"),h+"static/plugins/@nocobase/plugin-acl/dist/client/"),y={909:0},w.f.j=function(e,t){var n=w.o(y,e)?y[e]:void 0;if(0!==n){if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=y[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(y,e)&&(0!==(n=y[e])&&(y[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)}}},b=function(e,t){var n=t[0],r=t[1],o=t[2],i,u,a=0;if(n.some(function(e){return 0!==y[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(y,u)&&y[u]&&y[u][0](),y[u]=0},(m=self.webpackChunk_nocobase_plugin_acl=self.webpackChunk_nocobase_plugin_acl||[]).forEach(b.bind(null,0)),m.push=b.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.13",
11
+ "@nocobase/client": "1.7.0-beta.15",
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.13",
20
- "@nocobase/actions": "1.7.0-beta.13",
21
- "@nocobase/cache": "1.7.0-beta.13",
22
- "@nocobase/database": "1.7.0-beta.13",
23
- "@nocobase/server": "1.7.0-beta.13",
24
19
  "lodash": "4.17.21",
25
- "@nocobase/test": "1.7.0-beta.13",
20
+ "@nocobase/utils": "1.7.0-beta.15",
21
+ "@nocobase/actions": "1.7.0-beta.15",
22
+ "@nocobase/cache": "1.7.0-beta.15",
23
+ "@nocobase/database": "1.7.0-beta.15",
24
+ "@nocobase/server": "1.7.0-beta.15",
25
+ "@nocobase/test": "1.7.0-beta.15",
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.13"
29
+ "@nocobase/acl": "1.7.0-beta.15"
30
30
  };
@@ -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,7 +32,7 @@ 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;
35
+ var _a, _b, _c;
36
36
  let currentRole = ctx.get("X-Role");
37
37
  if (currentRole === "anonymous") {
38
38
  ctx.state.currentRole = currentRole;
@@ -62,7 +62,10 @@ 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();
65
+ const systemSettings = await cache.wrap(
66
+ `app:systemSettings`,
67
+ () => ctx.db.getRepository("systemSettings").findOne()
68
+ );
66
69
  const roleMode = (systemSettings == null ? void 0 : systemSettings.get("roleMode")) || import_enum.SystemRoleMode.default;
67
70
  if ([currentRole, ctx.state.currentRole].includes(import_constants.UNION_ROLE_KEY) && roleMode === import_enum.SystemRoleMode.default) {
68
71
  currentRole = userRoles[0].name;
@@ -73,12 +76,6 @@ async function setCurrentRole(ctx, next) {
73
76
  ctx.headers["x-role"] = import_constants.UNION_ROLE_KEY;
74
77
  ctx.state.currentRoles = userRoles.map((role2) => role2.name);
75
78
  return next();
76
- } else if (roleMode === import_enum.SystemRoleMode.allowUseUnion) {
77
- userRoles.unshift({
78
- name: import_constants.UNION_ROLE_KEY,
79
- title: ctx.t("Full permissions", { ns: "acl" })
80
- });
81
- ctx.state.currentUser.roles = userRoles;
82
79
  }
83
80
  if (currentRole === import_constants.UNION_ROLE_KEY) {
84
81
  ctx.state.currentRole = import_constants.UNION_ROLE_KEY;
@@ -96,14 +93,14 @@ async function setCurrentRole(ctx, next) {
96
93
  }
97
94
  }
98
95
  if (!role) {
99
- const defaultRole = userRoles.find((role2) => {
100
- var _a2;
101
- return (_a2 = role2 == null ? void 0 : role2.rolesUsers) == null ? void 0 : _a2.default;
102
- });
103
- role = (_b = defaultRole || userRoles.find((x) => x.name !== import_constants.UNION_ROLE_KEY)) == 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);
104
101
  }
105
102
  ctx.state.currentRole = role;
106
- ctx.state.currentRoles = [role];
103
+ ctx.state.currentRoles = role === import_constants.UNION_ROLE_KEY ? [(_c = userRoles[0]) == null ? void 0 : _c.name] : [role];
107
104
  if (!ctx.state.currentRoles.length) {
108
105
  return ctx.throw(401, {
109
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.13",
7
+ "version": "1.7.0-beta.15",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/acl",
@@ -33,5 +33,5 @@
33
33
  "url": "git+https://github.com/nocobase/nocobase.git",
34
34
  "directory": "packages/plugins/acl"
35
35
  },
36
- "gitHead": "e5c152b727dbedd54b67e450b11523df5acc51c6"
36
+ "gitHead": "b0792740852a55981b2f23ad622faeee332cf678"
37
37
  }