@firecms/user_management 3.0.0-canary.11 → 3.0.0-canary.111

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.
package/dist/index.umd.js CHANGED
@@ -1,2 +1,1583 @@
1
- (function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react"),require("firebase/firestore"),require("react/jsx-runtime"),require("@firecms/ui"),require("yup"),require("@firecms/core"),require("@firecms/formex"),require("date-fns"),require("date-fns/locale")):typeof define=="function"&&define.amd?define(["exports","react","firebase/firestore","react/jsx-runtime","@firecms/ui","yup","@firecms/core","@firecms/formex","date-fns","date-fns/locale"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.FireCMS={},i.React,i.firestore,i.jsxRuntime,i.ui,i.Yup,i.core,i.formex,i.dateFns,i.locales))})(this,function(i,c,N,e,l,se,S,P,re,ne){"use strict";function z(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const o in s)if(o!=="default"){const d=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(r,o,d.get?d:{enumerable:!0,get:()=>s[o]})}}return r.default=s,Object.freeze(r)}const B=z(se),ae=z(ne),te=["Admin"],ie={read:!1,edit:!1,create:!1,delete:!1};function J({collection:s,user:r}){const o=r?.roles;if(o){if(s.ownerId===r?.uid)return{read:!0,create:!0,edit:!0,delete:!0};{const d={read:!1,create:!1,edit:!1,delete:!1};return o.map(n=>ce(n,s.id)).reduce(Y,d)}}else return ie}function ce(s,r){const o={read:s.isAdmin||s.defaultPermissions?.read,create:s.isAdmin||s.defaultPermissions?.create,edit:s.isAdmin||s.defaultPermissions?.edit,delete:s.isAdmin||s.defaultPermissions?.delete};return s.collectionPermissions&&s.collectionPermissions[r]?Y(s.collectionPermissions[r],o):s.defaultPermissions?Y(s.defaultPermissions,o):o}const Y=(s,r)=>({read:s.read||r.read,create:s.create||r.create,edit:s.edit||r.edit,delete:s.delete||r.delete});function de(s,r){return s?r.roles?r.roles.map(o=>s.find(d=>d.id===o.id)).filter(Boolean):[]:void 0}const H=(s,r)=>{const o=s.map(n=>n.id),d=r.map(n=>n.id);return o.length===r.length&&o.every(n=>d.includes(n))};function he(s,r){if(!r)return;const o=Ce(r),d=new Date(o.exp*1e3);localStorage.setItem(`auth_token::${s}`,JSON.stringify({token:r,expiry:d}))}function fe(s){const r=localStorage.getItem(`auth_token::${s}`);if(r){const o=JSON.parse(r);if(o.expiry=new Date(o.expiry),o.expiry>new Date)return o.token}}function ge(){for(let s=0;s<localStorage.length;s++){const r=localStorage.key(s);r?.startsWith("auth_token::")&&localStorage.removeItem(r)}}function Ce(s){if(!s)throw new Error("No JWT token");const o=s.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),d=decodeURIComponent(window.atob(o).split("").map(function(n){return"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)}).join(""));return JSON.parse(d)}function pe(s,r=10){if(!/^#([0-9A-Fa-f]{3}){1,2}$/.test(s))throw new Error("Invalid color format");let o=s.substring(1).split("");o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]);let d=parseInt(o[0]+o[1],16),n=parseInt(o[2]+o[3],16),g=parseInt(o[4]+o[5],16);return d=Math.floor(d*(1-r/100)),n=Math.floor(n*(1-r/100)),g=Math.floor(g*(1-r/100)),"#"+(d<16?"0":"")+d.toString(16)+(n<16?"0":"")+n.toString(16)+(g<16?"0":"")+g.toString(16)}function me(s,r=10){if(!/^#([0-9A-Fa-f]{3}){1,2}$/.test(s))throw new Error("Invalid color format");let o=s.substring(1).split("");o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]);const d=parseInt(o[0]+o[1],16),n=parseInt(o[2]+o[3],16),g=parseInt(o[4]+o[5],16),u=r/100;return`rgba(${d}, ${n}, ${g}, ${u})`}function be({firebaseApp:s,usersPath:r="__FIRECMS/config/users",rolesPath:o="__FIRECMS/config/roles",usersLimit:d,canEditRoles:n=!0,allowDefaultRolesCreation:g,includeCollectionConfigPermissions:u}){const C=c.useRef(),[U,v]=c.useState(!0),[h,x]=c.useState(!0),[T,t]=c.useState([]),[m,I]=c.useState([]),w=m.map(b=>({...b,roles:T.filter(y=>b.roles?.includes(y.id))})),[q,V]=c.useState(),[p,f]=c.useState(),D=U||h;c.useEffect(()=>{s&&(C.current=N.getFirestore(s))},[s]),c.useEffect(()=>{if(!s||!o)return;const b=N.getFirestore(s);return N.onSnapshot(N.collection(b,o),{next:y=>{V(void 0);try{const k=ve(y.docs);t(k)}catch(k){V(k)}v(!1)},error:y=>{V(y),v(!1)}})},[s,o]),c.useEffect(()=>{if(!s||!r)return;const b=N.getFirestore(s);return N.onSnapshot(N.collection(b,r),{next:y=>{f(void 0);try{const k=ue(y.docs);I(k)}catch(k){f(k)}x(!1)},error:y=>{f(y),x(!1)}})},[s,r]);const F=c.useCallback(async b=>{const y=C.current;if(!y||!r)throw Error("useFirestoreConfigurationPersistence Firestore not initialised");console.debug("Persisting user",b);const k=b.roles?.map(ke=>ke.id),{uid:$,...W}=b;return N.setDoc(N.doc(y,r,$),{...W,roles:k},{merge:!0}).then(()=>b)},[r]),A=c.useCallback(b=>{const y=C.current;if(!y||!o)throw Error("useFirestoreConfigurationPersistence Firestore not initialised");console.debug("Persisting role",b);const{id:k,...$}=b,W=N.doc(y,o,k);return N.setDoc(W,$,{merge:!0})},[o]),a=c.useCallback(async b=>{const y=C.current;if(!y||!r)throw Error("useFirestoreConfigurationPersistence Firestore not initialised");console.debug("Deleting",b);const{uid:k}=b;return N.deleteDoc(N.doc(y,r,k))},[r]),E=c.useCallback(b=>{const y=C.current;if(!y||!o)throw Error("useFirestoreConfigurationPersistence Firestore not initialised");console.debug("Deleting",b);const{id:k}=b,$=N.doc(y,o,k);return N.deleteDoc($)},[o]),L=c.useCallback(({collection:b,user:y})=>J({collection:b,user:y}),[]),M=w.map(b=>b.uid),De=c.useCallback(b=>{if(!w)throw Error("Users not loaded");return w.find(k=>k.email?.toLowerCase()===b?.email?.toLowerCase())?.roles},[M]);return{loading:D,roles:T,users:w,saveUser:F,saveRole:A,deleteUser:a,deleteRole:E,usersLimit:d,canEditRoles:n===void 0?!0:n,allowDefaultRolesCreation:g===void 0?!0:g,includeCollectionConfigPermissions:!!u,collectionPermissions:L,defineRolesFor:De}}const ue=s=>s.map(r=>{const o=r.data();return{uid:r.id,...o,created_on:o?.created_on?.toDate(),updated_on:o?.updated_on?.toDate()}}),ve=s=>s.map(r=>({id:r.id,...r.data()})),j=c.createContext({});function G({children:s,userManagement:r}){return e.jsx(j.Provider,{value:r,children:s})}const _=()=>c.useContext(j);function O({role:s}){let r;return s.isAdmin?r="blueDarker":s.id==="editor"?r="yellowLight":s.id==="viewer"?r="grayLight":r=l.getColorSchemeForSeed(s.id),e.jsx(l.Chip,{colorScheme:r,children:s.name},s.id)}const K=B.object().shape({id:B.string().required("Required"),name:B.string().required("Required")});function Q({open:s,role:r,editable:o,handleClose:d,collections:n}){const{saveRole:g}=_(),u=!r,[C,U]=c.useState(),v=c.useCallback(a=>(U(void 0),g(a)),[g]),h=P.useCreateFormex({initialValues:r??{name:""},onSubmit:(a,E)=>v(a).then(()=>{E.resetForm({values:a}),d()}).catch(L=>U(L)),validation:a=>K.validate(a,{abortEarly:!1}).then(()=>({})).catch(E=>{const L={};return E.inner.forEach(M=>{L[M.path]=M.message}),L})}),{isSubmitting:x,touched:T,values:t,errors:m,handleChange:I,setFieldValue:w,dirty:q,setFieldTouched:V}=h,p=t.isAdmin??!1,f=t.defaultPermissions?.create??!1,D=t.defaultPermissions?.read??!1,F=t.defaultPermissions?.edit??!1,A=t.defaultPermissions?.delete??!1;return c.useEffect(()=>{!P.getIn(T,"id")&&t.name&&w("id",S.toSnakeCase(t.name))},[T,t.name]),e.jsx(l.Dialog,{open:s,maxWidth:"4xl",children:e.jsx(P.Formex,{value:h,children:e.jsxs("form",{noValidate:!0,autoComplete:"off",onSubmit:h.handleSubmit,style:{display:"flex",flexDirection:"column",position:"relative",height:"100%"},children:[e.jsxs(l.DialogContent,{className:"flex-grow",children:[e.jsx("div",{className:"flex flex-row pt-12 pb-8",children:e.jsx(l.Typography,{variant:"h4",className:"flex-grow",children:"Role"})}),e.jsxs("div",{className:"grid grid-cols-12 gap-8",children:[e.jsxs("div",{className:"col-span-12 md:col-span-8",children:[e.jsx(l.TextField,{name:"name",required:!0,error:T.name&&!!m.name,value:t.name,disabled:p||!o,onChange:I,"aria-describedby":"name-helper-text",label:"Name"}),e.jsx(S.FieldCaption,{children:T.name&&m.name?m.name:"Name of this role"})]}),e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsx(l.TextField,{name:"id",required:!0,error:T.id&&!!m.id,value:t.id,disabled:!u||!o,onChange:a=>{I(a),V("id",!0)},"aria-describedby":"id-helper-text",label:"ID"}),e.jsx(S.FieldCaption,{children:T.id&&m.id?m.id:"ID of this role"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(l.Paper,{className:"bg-inherit",children:e.jsxs(l.Table,{children:[e.jsxs(l.TableHeader,{children:[e.jsx(l.TableCell,{}),e.jsx(l.TableCell,{align:"center",children:"Create entities"}),e.jsx(l.TableCell,{align:"center",children:"Read entities"}),e.jsx(l.TableCell,{align:"center",children:"Update entities"}),e.jsx(l.TableCell,{align:"center",children:"Delete entities"})]}),e.jsxs(l.TableBody,{children:[e.jsxs(l.TableRow,{children:[e.jsx(l.TableCell,{scope:"row",children:e.jsx("strong",{children:"All collections"})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Tooltip,{title:"Create entities in collections",children:e.jsx(l.Checkbox,{disabled:p||!o,checked:(p||f)??!1,onCheckedChange:a=>w("defaultPermissions.create",a)})})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Tooltip,{title:"Access all data in every collection",children:e.jsx(l.Checkbox,{disabled:p||!o,checked:(p||D)??!1,onCheckedChange:a=>w("defaultPermissions.read",a)})})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Tooltip,{title:"Update data in any collection",children:e.jsx(l.Checkbox,{disabled:p||!o,checked:(p||F)??!1,onCheckedChange:a=>w("defaultPermissions.edit",a)})})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Tooltip,{title:"Delete data in any collection",children:e.jsx(l.Checkbox,{disabled:p||!o,checked:(p||A)??!1,onCheckedChange:a=>w("defaultPermissions.delete",a)})})})]}),n&&n.map(a=>e.jsxs(l.TableRow,{children:[e.jsx(l.TableCell,{scope:"row",children:a.name}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Checkbox,{disabled:p||f||!o,checked:(p||f||P.getIn(t,`collectionPermissions.${a.path}.create`))??!1,onCheckedChange:E=>w(`collectionPermissions.${a.path}.create`,E)})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Checkbox,{disabled:p||D||!o,checked:(p||D||P.getIn(t,`collectionPermissions.${a.path}.read`))??!1,onCheckedChange:E=>w(`collectionPermissions.${a.path}.read`,E)})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Checkbox,{disabled:p||F||!o,checked:(p||F||P.getIn(t,`collectionPermissions.${a.path}.edit`))??!1,onCheckedChange:E=>w(`collectionPermissions.${a.path}.edit`,E)})}),e.jsx(l.TableCell,{align:"center",children:e.jsx(l.Checkbox,{disabled:p||A||!o,checked:(p||A||P.getIn(t,`collectionPermissions.${a.path}.delete`))??!1,onCheckedChange:E=>w(`collectionPermissions.${a.path}.delete`,E)})})]},a.name))]})]})}),e.jsx(S.FieldCaption,{children:"You can customise the permissions that the users related to this role can perform in the entities of each collection"})]}),e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsxs(l.Select,{error:T.config&&!!m.config,id:"createCollections",name:"createCollections",label:"Create collections",position:"item-aligned",disabled:p||!o,onChange:a=>w("config.createCollections",a.target.value==="true"),value:p||t.config?.createCollections?"true":"false",renderValue:a=>a==="true"?"Yes":"No",children:[e.jsx(l.SelectItem,{value:"true",children:" Yes "}),e.jsx(l.SelectItem,{value:"false",children:" No "})]}),e.jsx(S.FieldCaption,{children:T.config&&m.config?m.config:"Can the user create collections"})]}),e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsxs(l.Select,{error:T.config&&!!m.config,id:"editCollections",name:"editCollections",label:"Edit collections",disabled:p||!o,position:"item-aligned",onChange:a=>w("config.editCollections",a.target.value==="own"?"own":a.target.value==="true"),value:p?"true":t.config?.editCollections==="own"?"own":t.config?.editCollections?"true":"false",renderValue:a=>a==="own"?"Own":a==="true"?"Yes":"No",children:[e.jsx(l.SelectItem,{value:"true",children:" Yes "}),e.jsx(l.SelectItem,{value:"false",children:" No "}),e.jsx(l.SelectItem,{value:"own",children:" Only his/her own "})]}),e.jsx(S.FieldCaption,{children:T.config&&m.config?m.config:"Can the user edit collections"})]}),e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsxs(l.Select,{error:T.config&&!!m.config,id:"deleteCollections",name:"deleteCollections",label:"Delete collections",disabled:p||!o,position:"item-aligned",onChange:a=>w("config.deleteCollections",a.target.value==="own"?"own":a.target.value==="true"),value:p?"true":t.config?.deleteCollections==="own"?"own":t.config?.deleteCollections?"true":"false",renderValue:a=>a==="own"?"Own":a==="true"?"Yes":"No",children:[e.jsx(l.SelectItem,{value:"true",children:" Yes "}),e.jsx(l.SelectItem,{value:"false",children:" No "}),e.jsx(l.SelectItem,{value:"own",children:" Only his/her own "})]}),e.jsx(S.FieldCaption,{children:T.config&&m.config?m.config:"Can the user delete collections"})]})]})]}),e.jsxs(l.DialogActions,{position:"sticky",children:[C&&e.jsx(l.Typography,{className:"text-red-500",children:"There was an error saving this role"}),e.jsx(l.Button,{variant:"text",onClick:()=>{d()},children:"Cancel"}),e.jsx(l.LoadingButton,{variant:"filled",color:"primary",type:"submit",disabled:!q,loading:x,startIcon:e.jsx(l.DoneIcon,{}),children:u?"Create role":"Update"})]})]})})})}const we=[{id:"admin",name:"Admin",isAdmin:!0},{id:"editor",name:"Editor",isAdmin:!1,defaultPermissions:{read:!0,create:!0,edit:!0,delete:!0},config:{createCollections:!0,editCollections:"own",deleteCollections:"own"}},{id:"viewer",name:"Viewer",isAdmin:!1,defaultPermissions:{read:!0,create:!1,edit:!1,delete:!1}}];function X({onRoleClicked:s,editable:r}){const{roles:o,saveRole:d,deleteRole:n,allowDefaultRolesCreation:g}=_(),[u,C]=c.useState(void 0),[U,v]=c.useState(!1);return e.jsxs("div",{className:"w-full overflow-auto",children:[e.jsxs(l.Table,{children:[e.jsxs(l.TableHeader,{children:[e.jsx(l.TableCell,{header:!0,className:"w-16"}),e.jsx(l.TableCell,{header:!0,children:"Role"}),e.jsx(l.TableCell,{header:!0,className:"items-center",children:"Is Admin"}),e.jsx(l.TableCell,{header:!0,children:"Default permissions"})]}),e.jsxs(l.TableBody,{children:[o&&o.map(h=>{const x=h.isAdmin||h.defaultPermissions?.create,T=h.isAdmin||h.defaultPermissions?.read,t=h.isAdmin||h.defaultPermissions?.edit,m=h.isAdmin||h.defaultPermissions?.delete;return e.jsxs(l.TableRow,{onClick:()=>{s(h)},children:[e.jsx(l.TableCell,{style:{width:"64px"},children:!h.isAdmin&&e.jsx(l.Tooltip,{title:"Delete this role",children:e.jsx(l.IconButton,{size:"small",disabled:!r,onClick:I=>(I.stopPropagation(),C(h)),children:e.jsx(l.DeleteIcon,{})})})}),e.jsx(l.TableCell,{children:e.jsx(O,{role:h})}),e.jsx(l.TableCell,{className:"items-center",children:e.jsx(l.Checkbox,{checked:h.isAdmin??!1})}),e.jsx(l.TableCell,{children:e.jsxs("ul",{children:[x&&e.jsx("li",{children:"Create"}),T&&e.jsx("li",{children:"Read"}),t&&e.jsx("li",{children:"Update"}),m&&e.jsx("li",{children:"Delete"})]})})]},h.name)}),(!o||o.length===0)&&e.jsx(l.TableRow,{children:e.jsx(l.TableCell,{colspan:4,children:e.jsxs(l.CenteredView,{className:"flex flex-col gap-4 my-8 items-center",children:[e.jsx(l.Typography,{variant:"label",children:"You don't have any roles yet."}),g&&e.jsx(l.Button,{variant:"outlined",onClick:()=>{we.forEach(h=>{d(h)})},children:"Create default roles"})]})})})]})]}),e.jsx(S.DeleteConfirmationDialog,{open:!!u,loading:U,onAccept:()=>{u&&(v(!0),n(u).then(()=>{C(void 0)}).finally(()=>{v(!1)}))},onCancel:()=>{C(void 0)},title:e.jsx(e.Fragment,{children:"Delete?"}),body:e.jsx(e.Fragment,{children:"Are you sure you want to delete this role?"})})]})}const Z=c.memo(function({children:r}){const{collections:o}=S.useNavigationController(),[d,n]=c.useState(!1),[g,u]=c.useState(),{canEditRoles:C}=_(),U=c.useCallback(h=>{n(!0),u(h)},[]),v=()=>{u(void 0),n(!1)};return e.jsxs(l.Container,{className:"w-full flex flex-col py-4 gap-4",maxWidth:"6xl",children:[r,e.jsxs("div",{className:"flex items-center mt-12",children:[e.jsx(l.Typography,{gutterBottom:!0,variant:"h4",className:"flex-grow",component:"h4",children:"Roles"}),e.jsx(l.Tooltip,{title:C?void 0:"Update plans to customise roles",children:e.jsx(l.Button,{size:"large",disabled:!C,startIcon:e.jsx(l.AddIcon,{}),onClick:()=>n(!0),children:"Add role"})})]}),e.jsx(X,{onRoleClicked:U,editable:!!C}),e.jsx(Q,{open:d,role:g,editable:C,collections:o,handleClose:v},g?.id??"new")]})}),R=B.object().shape({displayName:B.string().required("Required"),email:B.string().email().required("Required"),roles:B.array().min(1)});function ye(s,r,o,d,n){const g=o.filter(v=>v.roles?.map(h=>h.id).includes("admin")),u=s.roles?.map(v=>v.id).includes("admin");if((!n||!H(n.roles??[],r.roles??[]))&&!u)throw new Error("Only admins can change roles");if(n&&n.roles?.map(v=>v.id).includes("admin")&&!r.roles?.map(v=>v.id).includes("admin")&&g.length===1)throw new Error("There must be at least one admin");return!0}function ee({open:s,user:r,handleClose:o}){const d=S.useSnackbarController(),{user:n}=S.useAuthController(),{saveUser:g,users:u,roles:C}=_(),U=!r,v=c.useCallback(f=>{if(!n)throw new Error("Logged user not found");try{return ye(n,f,u,C,r),g(f)}catch(D){return Promise.reject(D)}},[C,g,r,u,n]),h=P.useCreateFormex({initialValues:r??{displayName:"",email:"",roles:C.filter(f=>f.id==="editor")},validation:f=>R.validate(f,{abortEarly:!1}).then(()=>({})).catch(D=>D.inner.reduce((F,A)=>(F[A.path]=A.message,F),{})),onSubmit:(f,D)=>v(f).then(()=>{o(),D.resetForm({values:f})}).catch(F=>{d.open({type:"error",message:F.message})})}),{isSubmitting:x,touched:T,handleChange:t,values:m,errors:I,setFieldValue:w,dirty:q,handleSubmit:V,submitCount:p}=h;return e.jsx(l.Dialog,{open:s,onOpenChange:f=>f?void 0:o(),maxWidth:"4xl",children:e.jsx(P.Formex,{value:h,children:e.jsxs("form",{onSubmit:V,autoComplete:"off",noValidate:!0,style:{display:"flex",flexDirection:"column",position:"relative",height:"100%"},children:[e.jsxs(l.DialogContent,{className:"h-full flex-grow",children:[e.jsx("div",{className:"flex flex-row pt-4 pb-4",children:e.jsx(l.Typography,{variant:"h4",className:"flex-grow",children:"User"})}),e.jsxs("div",{className:"grid grid-cols-12 gap-8",children:[e.jsxs("div",{className:"col-span-12",children:[e.jsx(l.TextField,{name:"displayName",required:!0,error:p>0&&!!I.displayName,value:m.displayName??"",onChange:t,"aria-describedby":"name-helper-text",label:"Name"}),e.jsx(S.FieldCaption,{children:p>0&&I.displayName?I.displayName:"Name of this user"})]}),e.jsxs("div",{className:"col-span-12",children:[e.jsx(l.TextField,{required:!0,error:p>0&&!!I.email,name:"email",value:m.email??"",onChange:t,"aria-describedby":"email-helper-text",label:"Email"}),e.jsx(S.FieldCaption,{children:p>0&&I.email?I.email:"Email of this user"})]}),e.jsx("div",{className:"col-span-12",children:e.jsx(l.MultiSelect,{label:"Roles",value:m.roles?.map(f=>f.id)??[],onMultiValueChange:f=>w("roles",f.map(D=>C.find(F=>F.id===D))),renderValue:f=>{const D=C.find(F=>F.id===f);return D?e.jsx("div",{className:"flex flex-wrap space-x-2 space-y-2",children:e.jsx(O,{role:D},D?.id)}):null},children:C.map(f=>e.jsx(l.MultiSelectItem,{value:f.id,children:e.jsx(O,{role:f},f?.id)},f.id))})})]})]}),e.jsxs(l.DialogActions,{children:[e.jsx(l.Button,{variant:"text",onClick:()=>{o()},children:"Cancel"}),e.jsx(l.LoadingButton,{variant:"filled",color:"primary",type:"submit",disabled:!q,loading:x,startIcon:e.jsx(l.DoneIcon,{}),children:U?"Create user":"Update"})]})]})})})}function le({onUserClicked:s}){const{users:r,saveUser:o,deleteUser:d}=_(),n=S.useAuthController(),g=S.useSnackbarController(),u=S.useCustomizationController(),C=u?.locale?ae[u?.locale]:void 0,U=u?.dateTimeFormat??S.defaultDateFormat,[v,h]=c.useState(void 0),[x,T]=c.useState(!1);return e.jsxs("div",{className:"overflow-auto",children:[e.jsxs(l.Table,{children:[e.jsxs(l.TableHeader,{children:[e.jsx(l.TableCell,{className:"truncate w-16"}),e.jsx(l.TableCell,{children:"ID"}),e.jsx(l.TableCell,{children:"Email"}),e.jsx(l.TableCell,{children:"Name"}),e.jsx(l.TableCell,{children:"Roles"}),e.jsx(l.TableCell,{children:"Created on"})]}),e.jsxs(l.TableBody,{children:[r&&r.map(t=>{const m=t.roles,I=t.created_on?re.format(t.created_on,U,{locale:C}):"";return e.jsxs(l.TableRow,{onClick:()=>{s(t)},children:[e.jsx(l.TableCell,{className:"w-10",children:e.jsx(l.Tooltip,{title:"Delete this user",children:e.jsx(l.IconButton,{size:"small",onClick:w=>(w.stopPropagation(),h(t)),children:e.jsx(l.DeleteIcon,{})})})}),e.jsx(l.TableCell,{children:t.uid}),e.jsx(l.TableCell,{children:t.email}),e.jsx(l.TableCell,{className:"font-medium align-left",children:t.displayName}),e.jsx(l.TableCell,{className:"align-left",children:m?e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(w=>e.jsx(O,{role:w},w?.id))}):null}),e.jsx(l.TableCell,{children:I})]},"row_"+t.uid)}),(!r||r.length===0)&&e.jsx(l.TableRow,{children:e.jsx(l.TableCell,{colspan:6,children:e.jsxs(l.CenteredView,{className:"flex flex-col gap-4 my-8 items-center",children:[e.jsx(l.Typography,{variant:"label",children:"There are no users yet"}),e.jsx(l.Button,{variant:"outlined",onClick:()=>{if(!n.user?.uid)throw Error("UsersTable, authController misconfiguration");o({uid:n.user?.uid,email:n.user?.email,displayName:n.user?.displayName,photoURL:n.user?.photoURL,providerId:n.user?.providerId,isAnonymous:n.user?.isAnonymous,roles:[{id:"admin",name:"Admin"}],created_on:new Date}).then(()=>{g.open({type:"success",message:"User added successfully"})}).catch(t=>{g.open({type:"error",message:"Error adding user: "+t.message})})},children:"Add the logged user as an admin"})]})})})]})]}),e.jsx(S.DeleteConfirmationDialog,{open:!!v,loading:x,onAccept:()=>{v&&(T(!0),d(v).then(()=>{h(void 0)}).catch(t=>{g.open({type:"error",message:"Error deleting user: "+t.message})}).finally(()=>{T(!1)}))},onCancel:()=>{h(void 0)},title:e.jsx(e.Fragment,{children:"Delete?"}),body:e.jsx(e.Fragment,{children:"Are you sure you want to delete this user?"})})]})}const oe=function({children:r}){const[o,d]=c.useState(),[n,g]=c.useState(),{users:u,usersLimit:C}=_(),U=C!==void 0&&u&&u.length>=C,v=c.useCallback(x=>{g(x),d(!0)},[]),h=c.useCallback(()=>{d(!1),g(void 0)},[]);return e.jsxs(l.Container,{className:"w-full flex flex-col py-4 gap-4",maxWidth:"6xl",children:[r,e.jsxs("div",{className:"flex items-center mt-12",children:[e.jsx(l.Typography,{gutterBottom:!0,variant:"h4",className:"flex-grow",component:"h4",children:"Users"}),e.jsx(l.Button,{size:"large",disabled:U,startIcon:e.jsx(l.AddIcon,{}),onClick:()=>d(!0),children:"Add user"})]}),e.jsx(le,{onUserClicked:v}),e.jsx(ee,{open:o??!1,user:n,handleClose:h},n?.uid??"new")]})};function Te({userManagement:s}){return{key:"user_management",loading:s.loading,provider:{Component:G,props:{userManagement:s}}}}const Se=[{path:"users",name:"CMS Users",group:"Admin",icon:"face",view:e.jsx(oe,{})},{path:"roles",name:"Roles",group:"Admin",icon:"gpp_good",view:e.jsx(Z,{})}];i.RESERVED_GROUPS=te,i.RoleChip=O,i.RoleYupSchema=K,i.RolesDetailsForm=Q,i.RolesTable=X,i.RolesView=Z,i.UserDetailsForm=ee,i.UserManagementContext=j,i.UserManagementProvider=G,i.UserYupSchema=R,i.UsersTable=le,i.UsersView=oe,i.areRolesEqual=H,i.cacheDelegatedLoginToken=he,i.clearDelegatedLoginTokensCache=ge,i.darkenColor=pe,i.getDelegatedLoginTokenFromCache=fe,i.getUserRoles=de,i.hexToRgbaWithOpacity=me,i.resolveUserRolePermissions=J,i.useBuildFirestoreUserManagement=be,i.useUserManagement=_,i.useUserManagementPlugin=Te,i.userManagementAdminViews=Se,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react-fast-compare"), require("react/jsx-runtime"), require("@firecms/ui"), require("yup"), require("@firecms/core"), require("@firecms/formex"), require("date-fns"), require("date-fns/locale")) : typeof define === "function" && define.amd ? define(["exports", "react", "react-fast-compare", "react/jsx-runtime", "@firecms/ui", "yup", "@firecms/core", "@firecms/formex", "date-fns", "date-fns/locale"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.FireCMS = {}, global.React, global.equal, global.jsxRuntime, global.ui, global.Yup, global.core, global.formex, global.dateFns, global.locales));
3
+ })(this, function(exports2, React, equal, jsxRuntime, ui, Yup, core, formex, dateFns, locales) {
4
+ "use strict";
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const Yup__namespace = /* @__PURE__ */ _interopNamespaceDefault(Yup);
22
+ const locales__namespace = /* @__PURE__ */ _interopNamespaceDefault(locales);
23
+ const RESERVED_GROUPS = ["Admin"];
24
+ const DEFAULT_PERMISSIONS = {
25
+ read: false,
26
+ edit: false,
27
+ create: false,
28
+ delete: false
29
+ };
30
+ function resolveUserRolePermissions({
31
+ collection,
32
+ user
33
+ }) {
34
+ const roles = user?.roles;
35
+ if (!roles) {
36
+ return DEFAULT_PERMISSIONS;
37
+ } else if (collection.ownerId === user?.uid) {
38
+ return {
39
+ read: true,
40
+ create: true,
41
+ edit: true,
42
+ delete: true
43
+ };
44
+ } else {
45
+ const basePermissions = {
46
+ read: false,
47
+ create: false,
48
+ edit: false,
49
+ delete: false
50
+ };
51
+ return roles.map((role) => resolveCollectionRole(role, collection.id)).reduce(mergePermissions, basePermissions);
52
+ }
53
+ }
54
+ function resolveCollectionRole(role, id) {
55
+ const basePermissions = {
56
+ read: role.isAdmin || role.defaultPermissions?.read,
57
+ create: role.isAdmin || role.defaultPermissions?.create,
58
+ edit: role.isAdmin || role.defaultPermissions?.edit,
59
+ delete: role.isAdmin || role.defaultPermissions?.delete
60
+ };
61
+ if (role.collectionPermissions && role.collectionPermissions[id]) {
62
+ return mergePermissions(role.collectionPermissions[id], basePermissions);
63
+ } else if (role.defaultPermissions) {
64
+ return mergePermissions(role.defaultPermissions, basePermissions);
65
+ } else {
66
+ return basePermissions;
67
+ }
68
+ }
69
+ const mergePermissions = (permA, permB) => {
70
+ return {
71
+ read: permA.read || permB.read,
72
+ create: permA.create || permB.create,
73
+ edit: permA.edit || permB.edit,
74
+ delete: permA.delete || permB.delete
75
+ };
76
+ };
77
+ function getUserRoles(roles, fireCMSUser) {
78
+ return !roles ? void 0 : fireCMSUser.roles ? fireCMSUser.roles.map((role) => roles.find((r) => r.id === role.id)).filter(Boolean) : [];
79
+ }
80
+ const areRolesEqual = (rolesA, rolesB) => {
81
+ const rolesAIds = rolesA.map((r) => r.id);
82
+ const rolesBIds = rolesB.map((r) => r.id);
83
+ return rolesAIds.length === rolesB.length && rolesAIds.every((role) => rolesBIds.includes(role));
84
+ };
85
+ function cacheDelegatedLoginToken(projectId, delegatedToken) {
86
+ if (!delegatedToken) {
87
+ return;
88
+ }
89
+ const data = parseJwt(delegatedToken);
90
+ const expiry = new Date(data.exp * 1e3);
91
+ localStorage.setItem(`auth_token::${projectId}`, JSON.stringify({
92
+ token: delegatedToken,
93
+ expiry
94
+ }));
95
+ }
96
+ function getDelegatedLoginTokenFromCache(projectId) {
97
+ const entry = localStorage.getItem(`auth_token::${projectId}`);
98
+ if (entry) {
99
+ const data = JSON.parse(entry);
100
+ data.expiry = new Date(data.expiry);
101
+ if (data.expiry > /* @__PURE__ */ new Date()) {
102
+ return data.token;
103
+ }
104
+ }
105
+ return void 0;
106
+ }
107
+ function clearDelegatedLoginTokensCache() {
108
+ for (let i = 0; i < localStorage.length; i++) {
109
+ const key = localStorage.key(i);
110
+ if (key?.startsWith("auth_token::")) {
111
+ localStorage.removeItem(key);
112
+ }
113
+ }
114
+ }
115
+ function parseJwt(token) {
116
+ if (!token) {
117
+ throw new Error("No JWT token");
118
+ }
119
+ const base64Url = token.split(".")[1];
120
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
121
+ const jsonPayload = decodeURIComponent(window.atob(base64).split("").map(function(c) {
122
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
123
+ }).join(""));
124
+ return JSON.parse(jsonPayload);
125
+ }
126
+ function darkenColor(hexColor, darkenBy = 10) {
127
+ if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(hexColor)) {
128
+ throw new Error("Invalid color format");
129
+ }
130
+ let color = hexColor.substring(1).split("");
131
+ if (color.length === 3) {
132
+ color = [color[0], color[0], color[1], color[1], color[2], color[2]];
133
+ }
134
+ let r = parseInt(color[0] + color[1], 16);
135
+ let g = parseInt(color[2] + color[3], 16);
136
+ let b = parseInt(color[4] + color[5], 16);
137
+ r = Math.floor(r * (1 - darkenBy / 100));
138
+ g = Math.floor(g * (1 - darkenBy / 100));
139
+ b = Math.floor(b * (1 - darkenBy / 100));
140
+ return "#" + (r < 16 ? "0" : "") + r.toString(16) + (g < 16 ? "0" : "") + g.toString(16) + (b < 16 ? "0" : "") + b.toString(16);
141
+ }
142
+ function hexToRgbaWithOpacity(hexColor, opacity = 10) {
143
+ if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(hexColor)) {
144
+ throw new Error("Invalid color format");
145
+ }
146
+ let color = hexColor.substring(1).split("");
147
+ if (color.length === 3) {
148
+ color = [color[0], color[0], color[1], color[1], color[2], color[2]];
149
+ }
150
+ const r = parseInt(color[0] + color[1], 16);
151
+ const g = parseInt(color[2] + color[3], 16);
152
+ const b = parseInt(color[4] + color[5], 16);
153
+ const alpha = opacity / 100;
154
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
155
+ }
156
+ function useBuildUserManagement({
157
+ dataSourceDelegate,
158
+ usersPath = "__FIRECMS/config/users",
159
+ rolesPath = "__FIRECMS/config/roles",
160
+ usersLimit,
161
+ canEditRoles = true,
162
+ allowDefaultRolesCreation,
163
+ includeCollectionConfigPermissions
164
+ }) {
165
+ const [rolesLoading, setRolesLoading] = React.useState(true);
166
+ const [usersLoading, setUsersLoading] = React.useState(true);
167
+ const [roles, setRoles] = React.useState([]);
168
+ const [usersWithRoleIds, setUsersWithRoleIds] = React.useState([]);
169
+ const users = usersWithRoleIds.map((u) => ({
170
+ ...u,
171
+ roles: roles.filter((r) => u.roles?.includes(r.id))
172
+ }));
173
+ const [rolesError, setRolesError] = React.useState();
174
+ const [usersError, setUsersError] = React.useState();
175
+ const loading = rolesLoading || usersLoading;
176
+ React.useEffect(() => {
177
+ if (!dataSourceDelegate || !rolesPath) return;
178
+ if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
179
+ return dataSourceDelegate.listenCollection?.({
180
+ path: rolesPath,
181
+ onUpdate(entities) {
182
+ setRolesError(void 0);
183
+ try {
184
+ const newRoles = entityToRoles(entities);
185
+ if (!equal(newRoles, roles))
186
+ setRoles(newRoles);
187
+ } catch (e) {
188
+ setRoles([]);
189
+ console.error("Error loading roles", e);
190
+ setRolesError(e);
191
+ }
192
+ setRolesLoading(false);
193
+ },
194
+ onError(e) {
195
+ setRoles([]);
196
+ console.error("Error loading roles", e);
197
+ setRolesError(e);
198
+ setRolesLoading(false);
199
+ }
200
+ });
201
+ }, [dataSourceDelegate?.initialised, rolesPath]);
202
+ React.useEffect(() => {
203
+ if (!dataSourceDelegate || !usersPath) return;
204
+ if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
205
+ return dataSourceDelegate.listenCollection?.({
206
+ path: usersPath,
207
+ onUpdate(entities) {
208
+ setUsersError(void 0);
209
+ try {
210
+ const newUsers = entitiesToUsers(entities);
211
+ if (!equal(newUsers, usersWithRoleIds))
212
+ setUsersWithRoleIds(newUsers);
213
+ } catch (e) {
214
+ setUsersWithRoleIds([]);
215
+ console.error("Error loading users", e);
216
+ setUsersError(e);
217
+ }
218
+ setUsersLoading(false);
219
+ },
220
+ onError(e) {
221
+ setUsersWithRoleIds([]);
222
+ console.error("Error loading users", e);
223
+ setUsersError(e);
224
+ setUsersLoading(false);
225
+ }
226
+ });
227
+ }, [dataSourceDelegate?.initialised, usersPath]);
228
+ const saveUser = React.useCallback(async (user) => {
229
+ if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
230
+ if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
231
+ console.debug("Persisting user", user);
232
+ const roleIds = user.roles?.map((r) => r.id);
233
+ const {
234
+ uid,
235
+ ...userData
236
+ } = user;
237
+ const data = {
238
+ ...userData,
239
+ roles: roleIds
240
+ };
241
+ if (uid) {
242
+ return dataSourceDelegate.saveEntity({
243
+ status: "existing",
244
+ path: usersPath,
245
+ entityId: uid,
246
+ values: data
247
+ }).then(() => user);
248
+ } else {
249
+ return dataSourceDelegate.saveEntity({
250
+ status: "new",
251
+ path: usersPath,
252
+ values: data
253
+ }).then(() => user);
254
+ }
255
+ }, [usersPath, dataSourceDelegate?.initialised]);
256
+ const saveRole = React.useCallback((role) => {
257
+ if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
258
+ if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
259
+ console.debug("Persisting role", role);
260
+ const {
261
+ id,
262
+ ...roleData
263
+ } = role;
264
+ return dataSourceDelegate.saveEntity({
265
+ status: "existing",
266
+ path: rolesPath,
267
+ entityId: id,
268
+ values: roleData
269
+ }).then(() => {
270
+ return;
271
+ });
272
+ }, [rolesPath, dataSourceDelegate?.initialised]);
273
+ const deleteUser = React.useCallback(async (user) => {
274
+ if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
275
+ if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
276
+ console.debug("Deleting", user);
277
+ const { uid } = user;
278
+ const entity = {
279
+ path: usersPath,
280
+ id: uid,
281
+ values: {}
282
+ };
283
+ await dataSourceDelegate.deleteEntity({ entity });
284
+ }, [usersPath, dataSourceDelegate?.initialised]);
285
+ const deleteRole = React.useCallback(async (role) => {
286
+ if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
287
+ if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
288
+ console.debug("Deleting", role);
289
+ const { id } = role;
290
+ const entity = {
291
+ path: usersPath,
292
+ id,
293
+ values: {}
294
+ };
295
+ await dataSourceDelegate.deleteEntity({ entity });
296
+ }, [rolesPath, dataSourceDelegate?.initialised]);
297
+ const collectionPermissions = React.useCallback(({
298
+ collection,
299
+ user
300
+ }) => resolveUserRolePermissions({
301
+ collection,
302
+ user
303
+ }), []);
304
+ const defineRolesFor = React.useCallback((user) => {
305
+ if (!users) throw Error("Users not loaded");
306
+ const mgmtUser = users.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
307
+ return mgmtUser?.roles;
308
+ }, [users]);
309
+ const authenticator = React.useCallback(({ user }) => {
310
+ console.debug("Authenticating user", user);
311
+ if (loading) {
312
+ console.warn("User management is still loading");
313
+ return false;
314
+ }
315
+ if (users.length === 0) {
316
+ return true;
317
+ }
318
+ const mgmtUser = users.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
319
+ if (mgmtUser) {
320
+ return true;
321
+ }
322
+ throw Error("Could not find a user with the provided email in the user management system.");
323
+ }, [loading, users]);
324
+ const isAdmin = roles.some((r) => r.id === "admin");
325
+ return {
326
+ loading,
327
+ roles,
328
+ users,
329
+ saveUser,
330
+ saveRole,
331
+ rolesError,
332
+ deleteUser,
333
+ deleteRole,
334
+ usersLimit,
335
+ usersError,
336
+ isAdmin,
337
+ canEditRoles: canEditRoles === void 0 ? true : canEditRoles,
338
+ allowDefaultRolesCreation: allowDefaultRolesCreation === void 0 ? true : allowDefaultRolesCreation,
339
+ includeCollectionConfigPermissions: Boolean(includeCollectionConfigPermissions),
340
+ collectionPermissions,
341
+ defineRolesFor,
342
+ authenticator
343
+ };
344
+ }
345
+ const entitiesToUsers = (docs) => {
346
+ return docs.map((doc) => {
347
+ const data = doc.values;
348
+ const newVar = {
349
+ uid: doc.id,
350
+ ...data,
351
+ created_on: data?.created_on,
352
+ updated_on: data?.updated_on
353
+ };
354
+ return newVar;
355
+ });
356
+ };
357
+ const entityToRoles = (entities) => {
358
+ return entities.map((doc) => ({
359
+ id: doc.id,
360
+ ...doc.values
361
+ }));
362
+ };
363
+ const UserManagementContext = React.createContext({});
364
+ function UserManagementProvider({
365
+ children,
366
+ userManagement
367
+ }) {
368
+ return /* @__PURE__ */ jsxRuntime.jsx(UserManagementContext.Provider, { value: userManagement, children });
369
+ }
370
+ const useUserManagement = () => React.useContext(UserManagementContext);
371
+ function RoleChip({ role }) {
372
+ let colorScheme;
373
+ if (role.isAdmin) {
374
+ colorScheme = "blueDarker";
375
+ } else if (role.id === "editor") {
376
+ colorScheme = "yellowLight";
377
+ } else if (role.id === "viewer") {
378
+ colorScheme = "grayLight";
379
+ } else {
380
+ colorScheme = ui.getColorSchemeForSeed(role.id);
381
+ }
382
+ return /* @__PURE__ */ jsxRuntime.jsx(
383
+ ui.Chip,
384
+ {
385
+ colorScheme,
386
+ children: role.name
387
+ },
388
+ role.id
389
+ );
390
+ }
391
+ const RoleYupSchema = Yup__namespace.object().shape({
392
+ id: Yup__namespace.string().required("Required"),
393
+ name: Yup__namespace.string().required("Required")
394
+ });
395
+ function RolesDetailsForm({
396
+ open,
397
+ role,
398
+ editable,
399
+ handleClose,
400
+ collections
401
+ }) {
402
+ const { saveRole } = useUserManagement();
403
+ const isNewRole = !role;
404
+ const [savingError, setSavingError] = React.useState();
405
+ const onRoleUpdated = React.useCallback((role2) => {
406
+ setSavingError(void 0);
407
+ return saveRole(role2);
408
+ }, [saveRole]);
409
+ const formex$1 = formex.useCreateFormex({
410
+ initialValues: role ?? {
411
+ name: ""
412
+ },
413
+ onSubmit: (role2, formexController) => {
414
+ return onRoleUpdated(role2).then(() => {
415
+ formexController.resetForm({
416
+ values: role2
417
+ });
418
+ handleClose();
419
+ }).catch((e) => setSavingError(e));
420
+ },
421
+ validation: (values2) => {
422
+ return RoleYupSchema.validate(values2, { abortEarly: false }).then(() => ({})).catch((e) => {
423
+ const errors2 = {};
424
+ e.inner.forEach((error) => {
425
+ errors2[error.path] = error.message;
426
+ });
427
+ return errors2;
428
+ });
429
+ }
430
+ });
431
+ const {
432
+ isSubmitting,
433
+ touched,
434
+ values,
435
+ errors,
436
+ handleChange,
437
+ setFieldValue,
438
+ dirty,
439
+ setFieldTouched
440
+ } = formex$1;
441
+ const isAdmin = values.isAdmin ?? false;
442
+ const defaultCreate = values.defaultPermissions?.create ?? false;
443
+ const defaultRead = values.defaultPermissions?.read ?? false;
444
+ const defaultEdit = values.defaultPermissions?.edit ?? false;
445
+ const defaultDelete = values.defaultPermissions?.delete ?? false;
446
+ React.useEffect(() => {
447
+ const idTouched = formex.getIn(touched, "id");
448
+ if (!idTouched && values.name) {
449
+ setFieldValue("id", core.toSnakeCase(values.name));
450
+ }
451
+ }, [touched, values.name]);
452
+ return /* @__PURE__ */ jsxRuntime.jsx(
453
+ ui.Dialog,
454
+ {
455
+ open,
456
+ maxWidth: "4xl",
457
+ children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
458
+ "form",
459
+ {
460
+ noValidate: true,
461
+ autoComplete: "off",
462
+ onSubmit: formex$1.handleSubmit,
463
+ style: {
464
+ display: "flex",
465
+ flexDirection: "column",
466
+ position: "relative",
467
+ height: "100%"
468
+ },
469
+ children: [
470
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "flex-grow", children: [
471
+ /* @__PURE__ */ jsxRuntime.jsx(
472
+ "div",
473
+ {
474
+ className: "flex flex-row pt-12 pb-8",
475
+ children: /* @__PURE__ */ jsxRuntime.jsx(
476
+ ui.Typography,
477
+ {
478
+ variant: "h4",
479
+ className: "flex-grow",
480
+ children: "Role"
481
+ }
482
+ )
483
+ }
484
+ ),
485
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
486
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-8", children: [
487
+ /* @__PURE__ */ jsxRuntime.jsx(
488
+ ui.TextField,
489
+ {
490
+ name: "name",
491
+ required: true,
492
+ error: touched.name && Boolean(errors.name),
493
+ value: values.name,
494
+ disabled: isAdmin || !editable,
495
+ onChange: handleChange,
496
+ "aria-describedby": "name-helper-text",
497
+ label: "Name"
498
+ }
499
+ ),
500
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.name && Boolean(errors.name) ? errors.name : "Name of this role" })
501
+ ] }),
502
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
503
+ /* @__PURE__ */ jsxRuntime.jsx(
504
+ ui.TextField,
505
+ {
506
+ name: "id",
507
+ required: true,
508
+ error: touched.id && Boolean(errors.id),
509
+ value: values.id,
510
+ disabled: !isNewRole || !editable,
511
+ onChange: (e) => {
512
+ handleChange(e);
513
+ setFieldTouched("id", true);
514
+ },
515
+ "aria-describedby": "id-helper-text",
516
+ label: "ID"
517
+ }
518
+ ),
519
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.id && Boolean(errors.id) ? errors.id : "ID of this role" })
520
+ ] }),
521
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
522
+ /* @__PURE__ */ jsxRuntime.jsx(
523
+ ui.Paper,
524
+ {
525
+ className: "bg-inherit",
526
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
527
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
528
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, {}),
529
+ /* @__PURE__ */ jsxRuntime.jsx(
530
+ ui.TableCell,
531
+ {
532
+ align: "center",
533
+ children: "Create entities"
534
+ }
535
+ ),
536
+ /* @__PURE__ */ jsxRuntime.jsx(
537
+ ui.TableCell,
538
+ {
539
+ align: "center",
540
+ children: "Read entities"
541
+ }
542
+ ),
543
+ /* @__PURE__ */ jsxRuntime.jsx(
544
+ ui.TableCell,
545
+ {
546
+ align: "center",
547
+ children: "Update entities"
548
+ }
549
+ ),
550
+ /* @__PURE__ */ jsxRuntime.jsx(
551
+ ui.TableCell,
552
+ {
553
+ align: "center",
554
+ children: "Delete entities"
555
+ }
556
+ )
557
+ ] }),
558
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
559
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
560
+ /* @__PURE__ */ jsxRuntime.jsx(
561
+ ui.TableCell,
562
+ {
563
+ scope: "row",
564
+ children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "All collections" })
565
+ }
566
+ ),
567
+ /* @__PURE__ */ jsxRuntime.jsx(
568
+ ui.TableCell,
569
+ {
570
+ align: "center",
571
+ children: /* @__PURE__ */ jsxRuntime.jsx(
572
+ ui.Tooltip,
573
+ {
574
+ title: "Create entities in collections",
575
+ children: /* @__PURE__ */ jsxRuntime.jsx(
576
+ ui.Checkbox,
577
+ {
578
+ disabled: isAdmin || !editable,
579
+ checked: (isAdmin || defaultCreate) ?? false,
580
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.create", checked)
581
+ }
582
+ )
583
+ }
584
+ )
585
+ }
586
+ ),
587
+ /* @__PURE__ */ jsxRuntime.jsx(
588
+ ui.TableCell,
589
+ {
590
+ align: "center",
591
+ children: /* @__PURE__ */ jsxRuntime.jsx(
592
+ ui.Tooltip,
593
+ {
594
+ title: "Access all data in every collection",
595
+ children: /* @__PURE__ */ jsxRuntime.jsx(
596
+ ui.Checkbox,
597
+ {
598
+ disabled: isAdmin || !editable,
599
+ checked: (isAdmin || defaultRead) ?? false,
600
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.read", checked)
601
+ }
602
+ )
603
+ }
604
+ )
605
+ }
606
+ ),
607
+ /* @__PURE__ */ jsxRuntime.jsx(
608
+ ui.TableCell,
609
+ {
610
+ align: "center",
611
+ children: /* @__PURE__ */ jsxRuntime.jsx(
612
+ ui.Tooltip,
613
+ {
614
+ title: "Update data in any collection",
615
+ children: /* @__PURE__ */ jsxRuntime.jsx(
616
+ ui.Checkbox,
617
+ {
618
+ disabled: isAdmin || !editable,
619
+ checked: (isAdmin || defaultEdit) ?? false,
620
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.edit", checked)
621
+ }
622
+ )
623
+ }
624
+ )
625
+ }
626
+ ),
627
+ /* @__PURE__ */ jsxRuntime.jsx(
628
+ ui.TableCell,
629
+ {
630
+ align: "center",
631
+ children: /* @__PURE__ */ jsxRuntime.jsx(
632
+ ui.Tooltip,
633
+ {
634
+ title: "Delete data in any collection",
635
+ children: /* @__PURE__ */ jsxRuntime.jsx(
636
+ ui.Checkbox,
637
+ {
638
+ disabled: isAdmin || !editable,
639
+ checked: (isAdmin || defaultDelete) ?? false,
640
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.delete", checked)
641
+ }
642
+ )
643
+ }
644
+ )
645
+ }
646
+ )
647
+ ] }),
648
+ collections && collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
649
+ /* @__PURE__ */ jsxRuntime.jsx(
650
+ ui.TableCell,
651
+ {
652
+ scope: "row",
653
+ children: col.name
654
+ }
655
+ ),
656
+ /* @__PURE__ */ jsxRuntime.jsx(
657
+ ui.TableCell,
658
+ {
659
+ align: "center",
660
+ children: /* @__PURE__ */ jsxRuntime.jsx(
661
+ ui.Checkbox,
662
+ {
663
+ disabled: isAdmin || defaultCreate || !editable,
664
+ checked: (isAdmin || defaultCreate || formex.getIn(values, `collectionPermissions.${col.path}.create`)) ?? false,
665
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.create`, checked)
666
+ }
667
+ )
668
+ }
669
+ ),
670
+ /* @__PURE__ */ jsxRuntime.jsx(
671
+ ui.TableCell,
672
+ {
673
+ align: "center",
674
+ children: /* @__PURE__ */ jsxRuntime.jsx(
675
+ ui.Checkbox,
676
+ {
677
+ disabled: isAdmin || defaultRead || !editable,
678
+ checked: (isAdmin || defaultRead || formex.getIn(values, `collectionPermissions.${col.path}.read`)) ?? false,
679
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.read`, checked)
680
+ }
681
+ )
682
+ }
683
+ ),
684
+ /* @__PURE__ */ jsxRuntime.jsx(
685
+ ui.TableCell,
686
+ {
687
+ align: "center",
688
+ children: /* @__PURE__ */ jsxRuntime.jsx(
689
+ ui.Checkbox,
690
+ {
691
+ disabled: isAdmin || defaultEdit || !editable,
692
+ checked: (isAdmin || defaultEdit || formex.getIn(values, `collectionPermissions.${col.path}.edit`)) ?? false,
693
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.edit`, checked)
694
+ }
695
+ )
696
+ }
697
+ ),
698
+ /* @__PURE__ */ jsxRuntime.jsx(
699
+ ui.TableCell,
700
+ {
701
+ align: "center",
702
+ children: /* @__PURE__ */ jsxRuntime.jsx(
703
+ ui.Checkbox,
704
+ {
705
+ disabled: isAdmin || defaultDelete || !editable,
706
+ checked: (isAdmin || defaultDelete || formex.getIn(values, `collectionPermissions.${col.path}.delete`)) ?? false,
707
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.delete`, checked)
708
+ }
709
+ )
710
+ }
711
+ )
712
+ ] }, col.name))
713
+ ] })
714
+ ] })
715
+ }
716
+ ),
717
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: "You can customise the permissions that the users related to this role can perform in the entities of each collection" })
718
+ ] }),
719
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
720
+ /* @__PURE__ */ jsxRuntime.jsxs(
721
+ ui.Select,
722
+ {
723
+ error: touched.config && Boolean(errors.config),
724
+ id: "createCollections",
725
+ name: "createCollections",
726
+ label: "Create collections",
727
+ position: "item-aligned",
728
+ disabled: isAdmin || !editable,
729
+ onChange: (event) => setFieldValue("config.createCollections", event.target.value === "true"),
730
+ value: isAdmin || values.config?.createCollections ? "true" : "false",
731
+ renderValue: (value) => value === "true" ? "Yes" : "No",
732
+ children: [
733
+ /* @__PURE__ */ jsxRuntime.jsx(
734
+ ui.SelectItem,
735
+ {
736
+ value: "true",
737
+ children: " Yes "
738
+ }
739
+ ),
740
+ /* @__PURE__ */ jsxRuntime.jsx(
741
+ ui.SelectItem,
742
+ {
743
+ value: "false",
744
+ children: " No "
745
+ }
746
+ )
747
+ ]
748
+ }
749
+ ),
750
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user create collections" })
751
+ ] }),
752
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
753
+ /* @__PURE__ */ jsxRuntime.jsxs(
754
+ ui.Select,
755
+ {
756
+ error: touched.config && Boolean(errors.config),
757
+ id: "editCollections",
758
+ name: "editCollections",
759
+ label: "Edit collections",
760
+ disabled: isAdmin || !editable,
761
+ position: "item-aligned",
762
+ onChange: (event) => setFieldValue("config.editCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
763
+ value: isAdmin ? "true" : values.config?.editCollections === "own" ? "own" : values.config?.editCollections ? "true" : "false",
764
+ renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
765
+ children: [
766
+ /* @__PURE__ */ jsxRuntime.jsx(
767
+ ui.SelectItem,
768
+ {
769
+ value: "true",
770
+ children: " Yes "
771
+ }
772
+ ),
773
+ /* @__PURE__ */ jsxRuntime.jsx(
774
+ ui.SelectItem,
775
+ {
776
+ value: "false",
777
+ children: " No "
778
+ }
779
+ ),
780
+ /* @__PURE__ */ jsxRuntime.jsx(
781
+ ui.SelectItem,
782
+ {
783
+ value: "own",
784
+ children: " Only his/her own "
785
+ }
786
+ )
787
+ ]
788
+ }
789
+ ),
790
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user edit collections" })
791
+ ] }),
792
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
793
+ /* @__PURE__ */ jsxRuntime.jsxs(
794
+ ui.Select,
795
+ {
796
+ error: touched.config && Boolean(errors.config),
797
+ id: "deleteCollections",
798
+ name: "deleteCollections",
799
+ label: "Delete collections",
800
+ disabled: isAdmin || !editable,
801
+ position: "item-aligned",
802
+ onChange: (event) => setFieldValue("config.deleteCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
803
+ value: isAdmin ? "true" : values.config?.deleteCollections === "own" ? "own" : values.config?.deleteCollections ? "true" : "false",
804
+ renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
805
+ children: [
806
+ /* @__PURE__ */ jsxRuntime.jsx(
807
+ ui.SelectItem,
808
+ {
809
+ value: "true",
810
+ children: " Yes "
811
+ }
812
+ ),
813
+ /* @__PURE__ */ jsxRuntime.jsx(
814
+ ui.SelectItem,
815
+ {
816
+ value: "false",
817
+ children: " No "
818
+ }
819
+ ),
820
+ /* @__PURE__ */ jsxRuntime.jsx(
821
+ ui.SelectItem,
822
+ {
823
+ value: "own",
824
+ children: " Only his/her own "
825
+ }
826
+ )
827
+ ]
828
+ }
829
+ ),
830
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user delete collections" })
831
+ ] })
832
+ ] })
833
+ ] }),
834
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { position: "sticky", children: [
835
+ savingError && /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { className: "text-red-500", children: "There was an error saving this role" }),
836
+ /* @__PURE__ */ jsxRuntime.jsx(
837
+ ui.Button,
838
+ {
839
+ variant: "text",
840
+ onClick: () => {
841
+ handleClose();
842
+ },
843
+ children: "Cancel"
844
+ }
845
+ ),
846
+ /* @__PURE__ */ jsxRuntime.jsx(
847
+ ui.LoadingButton,
848
+ {
849
+ variant: "filled",
850
+ color: "primary",
851
+ type: "submit",
852
+ disabled: !dirty,
853
+ loading: isSubmitting,
854
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
855
+ children: isNewRole ? "Create role" : "Update"
856
+ }
857
+ )
858
+ ] })
859
+ ]
860
+ }
861
+ ) })
862
+ }
863
+ );
864
+ }
865
+ const DEFAULT_ROLES = [
866
+ {
867
+ id: "admin",
868
+ name: "Admin",
869
+ isAdmin: true
870
+ },
871
+ {
872
+ id: "editor",
873
+ name: "Editor",
874
+ isAdmin: false,
875
+ defaultPermissions: {
876
+ read: true,
877
+ create: true,
878
+ edit: true,
879
+ delete: true
880
+ },
881
+ config: {
882
+ createCollections: true,
883
+ editCollections: "own",
884
+ deleteCollections: "own"
885
+ }
886
+ },
887
+ {
888
+ id: "viewer",
889
+ name: "Viewer",
890
+ isAdmin: false,
891
+ defaultPermissions: {
892
+ read: true,
893
+ create: false,
894
+ edit: false,
895
+ delete: false
896
+ }
897
+ }
898
+ ];
899
+ function RolesTable({
900
+ onRoleClicked,
901
+ editable
902
+ }) {
903
+ const {
904
+ roles,
905
+ saveRole,
906
+ deleteRole,
907
+ allowDefaultRolesCreation
908
+ } = useUserManagement();
909
+ const [roleToBeDeleted, setRoleToBeDeleted] = React.useState(void 0);
910
+ const [deleteInProgress, setDeleteInProgress] = React.useState(false);
911
+ return /* @__PURE__ */ jsxRuntime.jsxs(
912
+ "div",
913
+ {
914
+ className: "w-full overflow-auto",
915
+ children: [
916
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
917
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
918
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "w-16" }),
919
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Role" }),
920
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "items-center", children: "Is Admin" }),
921
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Default permissions" })
922
+ ] }),
923
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
924
+ roles && roles.map((role) => {
925
+ const canCreateAll = role.isAdmin || role.defaultPermissions?.create;
926
+ const canReadAll = role.isAdmin || role.defaultPermissions?.read;
927
+ const canUpdateAll = role.isAdmin || role.defaultPermissions?.edit;
928
+ const canDeleteAll = role.isAdmin || role.defaultPermissions?.delete;
929
+ return /* @__PURE__ */ jsxRuntime.jsxs(
930
+ ui.TableRow,
931
+ {
932
+ onClick: () => {
933
+ onRoleClicked(role);
934
+ },
935
+ children: [
936
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { style: { width: "64px" }, children: !role.isAdmin && /* @__PURE__ */ jsxRuntime.jsx(
937
+ ui.Tooltip,
938
+ {
939
+ asChild: true,
940
+ title: "Delete this role",
941
+ children: /* @__PURE__ */ jsxRuntime.jsx(
942
+ ui.IconButton,
943
+ {
944
+ size: "small",
945
+ disabled: !editable,
946
+ onClick: (event) => {
947
+ event.stopPropagation();
948
+ return setRoleToBeDeleted(role);
949
+ },
950
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
951
+ }
952
+ )
953
+ }
954
+ ) }),
955
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role }) }),
956
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "items-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked: role.isAdmin ?? false }) }),
957
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
958
+ canCreateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Create" }),
959
+ canReadAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Read" }),
960
+ canUpdateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Update" }),
961
+ canDeleteAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Delete" })
962
+ ] }) })
963
+ ]
964
+ },
965
+ role.name
966
+ );
967
+ }),
968
+ (!roles || roles.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
969
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "You don't have any roles yet." }),
970
+ allowDefaultRolesCreation && /* @__PURE__ */ jsxRuntime.jsx(
971
+ ui.Button,
972
+ {
973
+ variant: "outlined",
974
+ onClick: () => {
975
+ DEFAULT_ROLES.forEach((role) => {
976
+ saveRole(role);
977
+ });
978
+ },
979
+ children: "Create default roles"
980
+ }
981
+ )
982
+ ] }) }) })
983
+ ] })
984
+ ] }),
985
+ /* @__PURE__ */ jsxRuntime.jsx(
986
+ core.DeleteConfirmationDialog,
987
+ {
988
+ open: Boolean(roleToBeDeleted),
989
+ loading: deleteInProgress,
990
+ onAccept: () => {
991
+ if (roleToBeDeleted) {
992
+ setDeleteInProgress(true);
993
+ deleteRole(roleToBeDeleted).then(() => {
994
+ setRoleToBeDeleted(void 0);
995
+ }).finally(() => {
996
+ setDeleteInProgress(false);
997
+ });
998
+ }
999
+ },
1000
+ onCancel: () => {
1001
+ setRoleToBeDeleted(void 0);
1002
+ },
1003
+ title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1004
+ body: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this role?" })
1005
+ }
1006
+ )
1007
+ ]
1008
+ }
1009
+ );
1010
+ }
1011
+ const RolesView = React.memo(
1012
+ function RolesView2({ children }) {
1013
+ const { collections } = core.useNavigationController();
1014
+ const [dialogOpen, setDialogOpen] = React.useState(false);
1015
+ const [selectedRole, setSelectedRole] = React.useState();
1016
+ const { canEditRoles } = useUserManagement();
1017
+ const onRoleClicked = React.useCallback((user) => {
1018
+ setDialogOpen(true);
1019
+ setSelectedRole(user);
1020
+ }, []);
1021
+ const handleClose = () => {
1022
+ setSelectedRole(void 0);
1023
+ setDialogOpen(false);
1024
+ };
1025
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1026
+ children,
1027
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mt-12", children: [
1028
+ /* @__PURE__ */ jsxRuntime.jsx(
1029
+ ui.Typography,
1030
+ {
1031
+ gutterBottom: true,
1032
+ variant: "h4",
1033
+ className: "flex-grow",
1034
+ component: "h4",
1035
+ children: "Roles"
1036
+ }
1037
+ ),
1038
+ /* @__PURE__ */ jsxRuntime.jsx(
1039
+ ui.Tooltip,
1040
+ {
1041
+ asChild: true,
1042
+ title: !canEditRoles ? "Update plans to customise roles" : void 0,
1043
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1044
+ ui.Button,
1045
+ {
1046
+ size: "large",
1047
+ disabled: !canEditRoles,
1048
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1049
+ onClick: () => setDialogOpen(true),
1050
+ children: "Add role"
1051
+ }
1052
+ )
1053
+ }
1054
+ )
1055
+ ] }),
1056
+ /* @__PURE__ */ jsxRuntime.jsx(RolesTable, { onRoleClicked, editable: Boolean(canEditRoles) }),
1057
+ /* @__PURE__ */ jsxRuntime.jsx(
1058
+ RolesDetailsForm,
1059
+ {
1060
+ open: dialogOpen,
1061
+ role: selectedRole,
1062
+ editable: canEditRoles,
1063
+ collections,
1064
+ handleClose
1065
+ },
1066
+ selectedRole?.id ?? "new"
1067
+ )
1068
+ ] });
1069
+ }
1070
+ );
1071
+ const UserYupSchema = Yup__namespace.object().shape({
1072
+ displayName: Yup__namespace.string().required("Required"),
1073
+ email: Yup__namespace.string().email().required("Required"),
1074
+ roles: Yup__namespace.array().min(1)
1075
+ });
1076
+ function canUserBeEdited(loggedUser, user, users, roles, prevUser) {
1077
+ const admins = users.filter((u) => u.roles?.map((r) => r.id).includes("admin"));
1078
+ const loggedUserIsAdmin = loggedUser.roles?.map((r) => r.id).includes("admin");
1079
+ const didRolesChange = !prevUser || !areRolesEqual(prevUser.roles ?? [], user.roles ?? []);
1080
+ if (didRolesChange && !loggedUserIsAdmin) {
1081
+ throw new Error("Only admins can change roles");
1082
+ }
1083
+ const adminRoleRemoved = prevUser && prevUser.roles?.map((r) => r.id).includes("admin") && !user.roles?.map((r) => r.id).includes("admin");
1084
+ if (adminRoleRemoved && admins.length === 1) {
1085
+ throw new Error("There must be at least one admin");
1086
+ }
1087
+ return true;
1088
+ }
1089
+ function UserDetailsForm({
1090
+ open,
1091
+ user: userProp,
1092
+ handleClose
1093
+ }) {
1094
+ const snackbarController = core.useSnackbarController();
1095
+ const {
1096
+ user: loggedInUser
1097
+ } = core.useAuthController();
1098
+ const {
1099
+ saveUser,
1100
+ users,
1101
+ roles
1102
+ } = useUserManagement();
1103
+ const isNewUser = !userProp;
1104
+ const onUserUpdated = React.useCallback((savedUser) => {
1105
+ if (!loggedInUser) {
1106
+ throw new Error("Logged user not found");
1107
+ }
1108
+ try {
1109
+ canUserBeEdited(loggedInUser, savedUser, users, roles, userProp);
1110
+ return saveUser(savedUser);
1111
+ } catch (e) {
1112
+ return Promise.reject(e);
1113
+ }
1114
+ }, [roles, saveUser, userProp, users, loggedInUser]);
1115
+ const formex$1 = formex.useCreateFormex({
1116
+ initialValues: userProp ?? {
1117
+ displayName: "",
1118
+ email: "",
1119
+ roles: roles.filter((r) => r.id === "editor")
1120
+ },
1121
+ validation: (values2) => {
1122
+ return UserYupSchema.validate(values2, { abortEarly: false }).then(() => {
1123
+ return {};
1124
+ }).catch((e) => {
1125
+ return e.inner.reduce((acc, error) => {
1126
+ acc[error.path] = error.message;
1127
+ return acc;
1128
+ }, {});
1129
+ });
1130
+ },
1131
+ onSubmit: (user, formexController) => {
1132
+ return onUserUpdated(user).then(() => {
1133
+ handleClose();
1134
+ formexController.resetForm({
1135
+ values: user
1136
+ });
1137
+ }).catch((e) => {
1138
+ snackbarController.open({
1139
+ type: "error",
1140
+ message: e.message
1141
+ });
1142
+ });
1143
+ }
1144
+ });
1145
+ const {
1146
+ isSubmitting,
1147
+ touched,
1148
+ handleChange,
1149
+ values,
1150
+ errors,
1151
+ setFieldValue,
1152
+ dirty,
1153
+ handleSubmit,
1154
+ submitCount
1155
+ } = formex$1;
1156
+ return /* @__PURE__ */ jsxRuntime.jsx(
1157
+ ui.Dialog,
1158
+ {
1159
+ open,
1160
+ onOpenChange: (open2) => !open2 ? handleClose() : void 0,
1161
+ maxWidth: "4xl",
1162
+ children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
1163
+ "form",
1164
+ {
1165
+ onSubmit: handleSubmit,
1166
+ autoComplete: "off",
1167
+ noValidate: true,
1168
+ style: {
1169
+ display: "flex",
1170
+ flexDirection: "column",
1171
+ position: "relative",
1172
+ height: "100%"
1173
+ },
1174
+ children: [
1175
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "h-full flex-grow", children: [
1176
+ /* @__PURE__ */ jsxRuntime.jsx(
1177
+ "div",
1178
+ {
1179
+ className: "flex flex-row pt-4 pb-4",
1180
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1181
+ ui.Typography,
1182
+ {
1183
+ variant: "h4",
1184
+ className: "flex-grow",
1185
+ children: "User"
1186
+ }
1187
+ )
1188
+ }
1189
+ ),
1190
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1192
+ /* @__PURE__ */ jsxRuntime.jsx(
1193
+ ui.TextField,
1194
+ {
1195
+ name: "displayName",
1196
+ required: true,
1197
+ error: submitCount > 0 && Boolean(errors.displayName),
1198
+ value: values.displayName ?? "",
1199
+ onChange: handleChange,
1200
+ "aria-describedby": "name-helper-text",
1201
+ label: "Name"
1202
+ }
1203
+ ),
1204
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.displayName) ? errors.displayName : "Name of this user" })
1205
+ ] }),
1206
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1207
+ /* @__PURE__ */ jsxRuntime.jsx(
1208
+ ui.TextField,
1209
+ {
1210
+ required: true,
1211
+ error: submitCount > 0 && Boolean(errors.email),
1212
+ name: "email",
1213
+ value: values.email ?? "",
1214
+ onChange: handleChange,
1215
+ "aria-describedby": "email-helper-text",
1216
+ label: "Email"
1217
+ }
1218
+ ),
1219
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.email) ? errors.email : "Email of this user" })
1220
+ ] }),
1221
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
1222
+ ui.MultiSelect,
1223
+ {
1224
+ label: "Roles",
1225
+ value: values.roles?.map((r) => r.id) ?? [],
1226
+ onMultiValueChange: (value) => setFieldValue("roles", value.map((id) => roles.find((r) => r.id === id))),
1227
+ renderValue: (value) => {
1228
+ const userRole = roles.find((role) => role.id === value);
1229
+ if (!userRole) return null;
1230
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap space-x-2 space-y-2", children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id) });
1231
+ },
1232
+ children: roles.map((userRole) => /* @__PURE__ */ jsxRuntime.jsx(
1233
+ ui.MultiSelectItem,
1234
+ {
1235
+ value: userRole.id,
1236
+ children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1237
+ },
1238
+ userRole.id
1239
+ ))
1240
+ }
1241
+ ) })
1242
+ ] })
1243
+ ] }),
1244
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { children: [
1245
+ /* @__PURE__ */ jsxRuntime.jsx(
1246
+ ui.Button,
1247
+ {
1248
+ variant: "text",
1249
+ onClick: () => {
1250
+ handleClose();
1251
+ },
1252
+ children: "Cancel"
1253
+ }
1254
+ ),
1255
+ /* @__PURE__ */ jsxRuntime.jsx(
1256
+ ui.LoadingButton,
1257
+ {
1258
+ variant: "filled",
1259
+ color: "primary",
1260
+ type: "submit",
1261
+ disabled: !dirty,
1262
+ loading: isSubmitting,
1263
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
1264
+ children: isNewUser ? "Create user" : "Update"
1265
+ }
1266
+ )
1267
+ ] })
1268
+ ]
1269
+ }
1270
+ ) })
1271
+ }
1272
+ );
1273
+ }
1274
+ function UsersTable({ onUserClicked }) {
1275
+ const {
1276
+ users,
1277
+ saveUser,
1278
+ deleteUser
1279
+ } = useUserManagement();
1280
+ const authController = core.useAuthController();
1281
+ const snackbarController = core.useSnackbarController();
1282
+ const customizationController = core.useCustomizationController();
1283
+ const dateUtilsLocale = customizationController?.locale ? locales__namespace[customizationController?.locale] : void 0;
1284
+ const dateFormat = customizationController?.dateTimeFormat ?? core.defaultDateFormat;
1285
+ const [userToBeDeleted, setUserToBeDeleted] = React.useState(void 0);
1286
+ const [deleteInProgress, setDeleteInProgress] = React.useState(false);
1287
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-auto", children: [
1288
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
1289
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
1290
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "truncate w-16" }),
1291
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "ID" }),
1292
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Email" }),
1293
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Name" }),
1294
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Roles" }),
1295
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Created on" })
1296
+ ] }),
1297
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
1298
+ users && users.map((user) => {
1299
+ const userRoles = user.roles;
1300
+ const formattedDate = user.created_on ? dateFns.format(user.created_on, dateFormat, { locale: dateUtilsLocale }) : "";
1301
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1302
+ ui.TableRow,
1303
+ {
1304
+ onClick: () => {
1305
+ onUserClicked(user);
1306
+ },
1307
+ children: [
1308
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "w-10", children: /* @__PURE__ */ jsxRuntime.jsx(
1309
+ ui.Tooltip,
1310
+ {
1311
+ asChild: true,
1312
+ title: "Delete this user",
1313
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1314
+ ui.IconButton,
1315
+ {
1316
+ size: "small",
1317
+ onClick: (event) => {
1318
+ event.stopPropagation();
1319
+ return setUserToBeDeleted(user);
1320
+ },
1321
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
1322
+ }
1323
+ )
1324
+ }
1325
+ ) }),
1326
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.uid }),
1327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.email }),
1328
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "font-medium align-left", children: user.displayName }),
1329
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "align-left", children: userRoles ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: userRoles.map(
1330
+ (userRole) => /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1331
+ ) }) : null }),
1332
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: formattedDate })
1333
+ ]
1334
+ },
1335
+ "row_" + user.uid
1336
+ );
1337
+ }),
1338
+ (!users || users.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1339
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "There are no users yet" }),
1340
+ /* @__PURE__ */ jsxRuntime.jsx(
1341
+ ui.Button,
1342
+ {
1343
+ variant: "outlined",
1344
+ onClick: () => {
1345
+ if (!authController.user?.uid) {
1346
+ throw Error("UsersTable, authController misconfiguration");
1347
+ }
1348
+ saveUser({
1349
+ uid: authController.user?.uid,
1350
+ email: authController.user?.email,
1351
+ displayName: authController.user?.displayName,
1352
+ photoURL: authController.user?.photoURL,
1353
+ providerId: authController.user?.providerId,
1354
+ isAnonymous: authController.user?.isAnonymous,
1355
+ roles: [{ id: "admin", name: "Admin" }],
1356
+ created_on: /* @__PURE__ */ new Date()
1357
+ }).then(() => {
1358
+ snackbarController.open({
1359
+ type: "success",
1360
+ message: "User added successfully"
1361
+ });
1362
+ }).catch((error) => {
1363
+ snackbarController.open({
1364
+ type: "error",
1365
+ message: "Error adding user: " + error.message
1366
+ });
1367
+ });
1368
+ },
1369
+ children: "Add the logged user as an admin"
1370
+ }
1371
+ )
1372
+ ] }) }) })
1373
+ ] })
1374
+ ] }),
1375
+ /* @__PURE__ */ jsxRuntime.jsx(
1376
+ core.DeleteConfirmationDialog,
1377
+ {
1378
+ open: Boolean(userToBeDeleted),
1379
+ loading: deleteInProgress,
1380
+ onAccept: () => {
1381
+ if (userToBeDeleted) {
1382
+ setDeleteInProgress(true);
1383
+ deleteUser(userToBeDeleted).then(() => {
1384
+ setUserToBeDeleted(void 0);
1385
+ }).catch((error) => {
1386
+ snackbarController.open({
1387
+ type: "error",
1388
+ message: "Error deleting user: " + error.message
1389
+ });
1390
+ }).finally(() => {
1391
+ setDeleteInProgress(false);
1392
+ });
1393
+ }
1394
+ },
1395
+ onCancel: () => {
1396
+ setUserToBeDeleted(void 0);
1397
+ },
1398
+ title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1399
+ body: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this user?" })
1400
+ }
1401
+ )
1402
+ ] });
1403
+ }
1404
+ const UsersView = function UsersView2({ children }) {
1405
+ const [dialogOpen, setDialogOpen] = React.useState();
1406
+ const [selectedUser, setSelectedUser] = React.useState();
1407
+ const { users, usersLimit } = useUserManagement();
1408
+ const reachedUsersLimit = usersLimit !== void 0 && (users && users.length >= usersLimit);
1409
+ const onUserClicked = React.useCallback((user) => {
1410
+ setSelectedUser(user);
1411
+ setDialogOpen(true);
1412
+ }, []);
1413
+ const handleClose = React.useCallback(() => {
1414
+ setDialogOpen(false);
1415
+ setSelectedUser(void 0);
1416
+ }, []);
1417
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1418
+ children,
1419
+ /* @__PURE__ */ jsxRuntime.jsxs(
1420
+ "div",
1421
+ {
1422
+ className: "flex items-center mt-12",
1423
+ children: [
1424
+ /* @__PURE__ */ jsxRuntime.jsx(
1425
+ ui.Typography,
1426
+ {
1427
+ gutterBottom: true,
1428
+ variant: "h4",
1429
+ className: "flex-grow",
1430
+ component: "h4",
1431
+ children: "Users"
1432
+ }
1433
+ ),
1434
+ /* @__PURE__ */ jsxRuntime.jsx(
1435
+ ui.Button,
1436
+ {
1437
+ size: "large",
1438
+ disabled: reachedUsersLimit,
1439
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1440
+ onClick: () => setDialogOpen(true),
1441
+ children: "Add user"
1442
+ }
1443
+ )
1444
+ ]
1445
+ }
1446
+ ),
1447
+ /* @__PURE__ */ jsxRuntime.jsx(UsersTable, { onUserClicked }),
1448
+ /* @__PURE__ */ jsxRuntime.jsx(
1449
+ UserDetailsForm,
1450
+ {
1451
+ open: dialogOpen ?? false,
1452
+ user: selectedUser,
1453
+ handleClose
1454
+ },
1455
+ selectedUser?.uid ?? "new"
1456
+ )
1457
+ ] });
1458
+ };
1459
+ function useUserManagementPlugin({ userManagement }) {
1460
+ const noUsers = userManagement.users.length === 0;
1461
+ const noRoles = userManagement.roles.length === 0;
1462
+ return {
1463
+ key: "user_management",
1464
+ loading: userManagement.loading,
1465
+ homePage: {
1466
+ additionalChildrenStart: noUsers || noRoles ? /* @__PURE__ */ jsxRuntime.jsx(
1467
+ IntroWidget,
1468
+ {
1469
+ noUsers,
1470
+ noRoles,
1471
+ userManagement
1472
+ }
1473
+ ) : void 0
1474
+ },
1475
+ provider: {
1476
+ Component: UserManagementProvider,
1477
+ props: {
1478
+ userManagement
1479
+ }
1480
+ }
1481
+ };
1482
+ }
1483
+ function IntroWidget({
1484
+ noUsers,
1485
+ noRoles,
1486
+ userManagement
1487
+ }) {
1488
+ const authController = core.useAuthController();
1489
+ const snackbarController = core.useSnackbarController();
1490
+ const buttonLabel = noUsers && noRoles ? "Create default roles and add current user as admin" : noUsers ? "Add current user as admin" : noRoles ? "Create default roles" : void 0;
1491
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1492
+ ui.Paper,
1493
+ {
1494
+ className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-slate-800 gap-2",
1495
+ children: [
1496
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" }),
1497
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { children: "You have no users or roles defined. You can create default roles and add the current user as admin." }),
1498
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { onClick: () => {
1499
+ if (!authController.user?.uid) {
1500
+ throw Error("UsersTable, authController misconfiguration");
1501
+ }
1502
+ if (noUsers) {
1503
+ userManagement.saveUser({
1504
+ uid: authController.user?.uid,
1505
+ email: authController.user?.email,
1506
+ displayName: authController.user?.displayName,
1507
+ photoURL: authController.user?.photoURL,
1508
+ providerId: authController.user?.providerId,
1509
+ isAnonymous: authController.user?.isAnonymous,
1510
+ roles: [{
1511
+ id: "admin",
1512
+ name: "Admin"
1513
+ }],
1514
+ created_on: /* @__PURE__ */ new Date()
1515
+ }).then(() => {
1516
+ snackbarController.open({
1517
+ type: "success",
1518
+ message: "User added successfully"
1519
+ });
1520
+ }).catch((error) => {
1521
+ snackbarController.open({
1522
+ type: "error",
1523
+ message: "Error adding user: " + error.message
1524
+ });
1525
+ });
1526
+ }
1527
+ if (noRoles) {
1528
+ DEFAULT_ROLES.forEach((role) => {
1529
+ userManagement.saveRole(role);
1530
+ });
1531
+ }
1532
+ }, children: [
1533
+ /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1534
+ buttonLabel
1535
+ ] })
1536
+ ]
1537
+ }
1538
+ );
1539
+ }
1540
+ const userManagementAdminViews = [
1541
+ {
1542
+ path: "users",
1543
+ name: "CMS Users",
1544
+ group: "Admin",
1545
+ icon: "face",
1546
+ view: /* @__PURE__ */ jsxRuntime.jsx(UsersView, {})
1547
+ },
1548
+ {
1549
+ path: "roles",
1550
+ name: "Roles",
1551
+ group: "Admin",
1552
+ icon: "gpp_good",
1553
+ view: /* @__PURE__ */ jsxRuntime.jsx(RolesView, {})
1554
+ }
1555
+ ];
1556
+ exports2.IntroWidget = IntroWidget;
1557
+ exports2.RESERVED_GROUPS = RESERVED_GROUPS;
1558
+ exports2.RoleChip = RoleChip;
1559
+ exports2.RoleYupSchema = RoleYupSchema;
1560
+ exports2.RolesDetailsForm = RolesDetailsForm;
1561
+ exports2.RolesTable = RolesTable;
1562
+ exports2.RolesView = RolesView;
1563
+ exports2.UserDetailsForm = UserDetailsForm;
1564
+ exports2.UserManagementContext = UserManagementContext;
1565
+ exports2.UserManagementProvider = UserManagementProvider;
1566
+ exports2.UserYupSchema = UserYupSchema;
1567
+ exports2.UsersTable = UsersTable;
1568
+ exports2.UsersView = UsersView;
1569
+ exports2.areRolesEqual = areRolesEqual;
1570
+ exports2.cacheDelegatedLoginToken = cacheDelegatedLoginToken;
1571
+ exports2.clearDelegatedLoginTokensCache = clearDelegatedLoginTokensCache;
1572
+ exports2.darkenColor = darkenColor;
1573
+ exports2.getDelegatedLoginTokenFromCache = getDelegatedLoginTokenFromCache;
1574
+ exports2.getUserRoles = getUserRoles;
1575
+ exports2.hexToRgbaWithOpacity = hexToRgbaWithOpacity;
1576
+ exports2.resolveUserRolePermissions = resolveUserRolePermissions;
1577
+ exports2.useBuildUserManagement = useBuildUserManagement;
1578
+ exports2.useUserManagement = useUserManagement;
1579
+ exports2.useUserManagementPlugin = useUserManagementPlugin;
1580
+ exports2.userManagementAdminViews = userManagementAdminViews;
1581
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1582
+ });
2
1583
  //# sourceMappingURL=index.umd.js.map