/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/PermissionIdpGroups-koye6BlE.js
import{C as A,d4 as oe,bM as ie,u as _,ah as O,l as F,d as n,r as v,Y as re,j as e,n as Q,q as B,aj as w,f as V,g as J,i as W,e as q,R as X,A as le,b as de,m as ce,y as ue,L as pe,aJ as me}from"./index-B3cgCbnJ.js";import{S as ge}from"./SelectableMainTable-CTM3_-pn.js";import{S as he}from"./SelectedTableNotification-BBOESV7i.js";import{u as fe}from"./useSortTableData-DogFPcVj.js";import{u as M,p as U}from"./usePanelParams-CZsrUgz_.js";import{P as E}from"./PageHeader-CCfZuT9z.js";import{H as Ie}from"./HelpLink-D9xEWgz5.js";import{P as ye}from"./PermissionGroupsFilter-7ey2euXS.js";import{G as Z}from"./GroupSelection-DeSbcBFI.js";import{u as ee,a as te}from"./useAuthGroups-sO_2YynQ.js";import{N as se,G as Se}from"./NameWithGroupForm-C6XxSQWh.js";import{B as be}from"./BulkDeleteButton-CR5M7boY.js";const xe=["can_delete","can_edit"],je=async t=>{const s=new URLSearchParams;return s.set("recursion","1"),ie(s,t,xe),fetch(`/1.0/auth/identity-provider-groups?${s.toString()}`).then(A).then(d=>d.metadata)},Pe=async t=>{await fetch("/1.0/auth/identity-provider-groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,groups:t.groups})}).then(A)},De=async t=>{await fetch(`/1.0/auth/identity-provider-groups/${encodeURIComponent(t.name)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(A)},Ne=async(t,s)=>{await fetch(`/1.0/auth/identity-provider-groups/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s})}).then(A)},ve=async t=>{await fetch(`/1.0/auth/identity-provider-groups/${encodeURIComponent(t)}`,{method:"DELETE"}).then(A)},Ce=async t=>Promise.allSettled(t.map(async s=>ve(s))).then(oe),H=()=>{const{isFineGrained:t}=_();return{canDeleteIdpGroup:i=>O(t,"can_delete",i==null?void 0:i.access_entitlements),canEditIdpGroup:i=>O(t,"can_edit",i==null?void 0:i.access_entitlements)}},ne=(t,s)=>["deduplicate","An identity provider group with this name already exists",async d=>s&&d===s||re(d,"",t,"auth/identity-provider-groups")],ae=t=>{const s=F(),d=n.useNotify(),i=n.useToastNotification(),[o,m]=v.useState(!1),{canDeleteIdpGroup:P}=H(),c=[],r=[];t.forEach(p=>{P(p)?r.push(p):c.push(p)});const j=r.length===1;return{deleteIdpGroups:()=>{m(!0);const p=j?e.jsxs(e.Fragment,{children:["IDP group"," ",e.jsx(Q,{bold:!0,type:"idp-group",value:r[0].name})," ","deleted."]}):`${r.length} IDP groups deleted.`;Ce(r.map(b=>b.name)).then(()=>{s.invalidateQueries({queryKey:[B.idpGroups]}),i.success(p)}).catch(b=>{d.failure(`${w("IDP group",r.length)} deletion failed`,b)}).finally(()=>{m(!1)})},isDeleting:o,restrictedIdpGroups:c,deletableIdpGroups:r}},Ge=()=>{const t=M(),s=n.useNotify(),d=n.useToastNotification(),i=F(),o=v.useState(null),{data:m=[],error:P,isLoading:c}=ee(),{desiredState:r,save:j}=te({initialState:{groupsAdded:new Set}});P&&s.failure("Loading panel details failed",P);const I=(h,g)=>{j(g?{groupsAdded:new Set}:{groupsAdded:new Set(h)})},p=()=>{t.clear(),s.clear()},b=h=>{const g={name:h.name,groups:Array.from(r.groupsAdded)};f.setSubmitting(!0),Pe(g).then(()=>{d.success(e.jsxs(e.Fragment,{children:["IDP group"," ",e.jsx(X,{type:"idp-group",value:h.name,to:"/ui/permissions/idp-groups"})," ","created."]})),i.invalidateQueries({queryKey:[B.idpGroups]}),p()}).catch(C=>{s.failure("IDP group creation failed",C)}).finally(()=>{f.setSubmitting(!1)})},y=V().shape({name:J().test(...ne(o)).required("IDP group name is required")}),f=W({initialValues:{name:""},validationSchema:y,onSubmit:b});return e.jsxs(n.SidePanel,{loading:c,hasError:!m,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{children:"Create IDP group"})}),e.jsx(q,{className:"u-no-padding"}),e.jsx(se,{formik:f}),e.jsx("p",{children:"Groups"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(Z,{groups:m,modifiedGroups:r.groupsAdded,parentItemName:"",selectedGroups:r.groupsAdded,setSelectedGroups:I,toggleGroup:h=>{const g=new Set([...r.groupsAdded]);g.has(h)?g.delete(h):g.add(h),I([...g],g.size===0)},scrollDependencies:[m,r.groupsAdded.size,s.notification,f]})}),e.jsxs(n.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(n.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(n.ActionButton,{appearance:"positive",onClick:()=>void f.submitForm(),className:"u-no-margin--bottom",disabled:!f.isValid||f.isSubmitting||!f.values.name,loading:f.isSubmitting,children:"Create IDP group"})]})]})},we=({idpGroups:t})=>{const{deletableIdpGroups:s,restrictedIdpGroups:d,deleteIdpGroups:i}=ae(t),o=()=>{if(d.length)return[`${s.length} ${w("IDP group",s.length)} will be deleted.`,`${d.length} ${w("IDP group",d.length)} that you do not have permission to delete will be ignored.`]};return e.jsx(be,{entities:t,deletableEntities:s,entityType:"IDP group",onDelete:i,disabledReason:s.length?void 0:`You do not have permission to delete the selected ${w("idp group",t.length)}`,className:"u-no-margin--bottom",buttonLabel:`Delete ${t.length} ${w("IDP group",t.length)}`,bulkDeleteBreakdown:o()})},Ee=({idpGroup:t,onClose:s})=>{const d=M(),i=n.useNotify(),o=n.useToastNotification(),m=F(),P=v.useState(null),{data:c=[],error:r,isLoading:j}=ee(),{desiredState:I,save:p,undo:b}=te({initialState:{groupsAdded:new Set,groupsRemoved:new Set}});r&&i.failure("Loading panel details failed",r);const y=new Set(I.groupsAdded);for(const l of t.groups)I.groupsRemoved.has(l)||y.add(l);const f=()=>{const l=new Set;for(const u of t.groups)y.has(u)||l.add(u);for(const u of c)!t.groups.includes(u.name)&&y.has(u.name)&&l.add(u.name);return l},h=(l,u)=>{p(u?{groupsAdded:new Set,groupsRemoved:new Set(c.map(x=>x.name))}:{groupsAdded:new Set(l),groupsRemoved:new Set})},g=l=>{const u=y.has(l),x=new Set(I.groupsAdded),G=new Set(I.groupsRemoved);u?(x.delete(l),G.add(l)):(x.add(l),G.delete(l)),p({groupsAdded:x,groupsRemoved:G})},C=()=>{d.clear(),i.clear(),s==null||s()},L=l=>{const u=new Set(t.groups);for(const N of I.groupsAdded)u.add(N);for(const N of I.groupsRemoved)u.delete(N);let x=De({...t,groups:Array.from(u)});t.name!==l.name&&(x=x.then(async()=>Ne((t==null?void 0:t.name)??"",l.name))),S.setSubmitting(!0),x.then(()=>{o.success(e.jsxs(e.Fragment,{children:["IDP group"," ",e.jsx(X,{type:"idp-group",value:l.name,to:"/ui/permissions/idp-groups"})," ","updated."]})),m.invalidateQueries({queryKey:[B.idpGroups]}),C()}).catch(N=>{i.failure("IDP group update failed",N)}).finally(()=>{S.setSubmitting(!1)})},$=V().shape({name:J().test(...ne(P,d.idpGroup??"")).required("IDP group name is required")}),S=W({initialValues:{name:(t==null?void 0:t.name)??""},enableReinitialize:!0,validationSchema:$,onSubmit:L}),D=f(),T=!!S.touched.name,k=S.isValid&&S.values.name,R=!!D.size,a=T&&k||k&&R;return e.jsxs(n.SidePanel,{loading:j,hasError:!c,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{className:"u-truncate",children:`Edit IDP group ${t==null?void 0:t.name}`})}),e.jsx(q,{className:"u-no-padding"}),e.jsx(se,{formik:S}),e.jsx("p",{children:"Map groups to this idp group"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(Z,{groups:c,modifiedGroups:D,parentItemName:"IDP group",parentItems:[t],selectedGroups:y,setSelectedGroups:h,toggleGroup:g,scrollDependencies:[c,D.size,i.notification,S]})}),e.jsx(n.SidePanel.Footer,{className:"u-align--right",children:e.jsx(Se,{modifiedGroups:D,undoChange:b,closePanel:C,onSubmit:()=>void S.submitForm(),loading:S.isSubmitting,disabled:!a||S.isSubmitting,isEdit:!0})})]})},Ae=({idpGroup:t})=>{var m;const{canDeleteIdpGroup:s}=H(),{isDeleting:d,deletableIdpGroups:i,deleteIdpGroups:o}=ae([t]);return e.jsx(n.ConfirmationButton,{onHoverText:s(t)?"Delete IDP group":"You do not have permission to delete this IDP group",appearance:"base",className:"has-icon is-dense","aria-label":"Delete IDP group",type:"button",disabled:!s(t),shiftClickEnabled:!0,showShiftClickHint:!0,confirmationModalProps:{title:"Confirm IDP group deletion",confirmButtonLabel:"Delete",confirmButtonLoading:d,onConfirm:o,className:"permission-confirm-modal",children:e.jsxs("p",{children:["Are you sure you want to delete the IDP group"," ",e.jsx(Q,{type:"idp-group",value:(m=i[0])==null?void 0:m.name,bold:!0}),"?"]})},children:e.jsx(n.Icon,{name:"delete"})})},Le=()=>{const{isFineGrained:t}=_();return le({queryKey:[B.idpGroups],queryFn:async()=>je(t),enabled:t!==null})},Oe=()=>{var R;const t=n.useNotify(),{data:s=[],error:d,isLoading:i}=Le(),o=M(),[m,P]=v.useState(""),[c,r]=v.useState([]),{data:j}=de(),I=(R=j==null?void 0:j.config)==null?void 0:R["oidc.groups.claim"],{canCreateIdpGroups:p}=ce(),{canEditIdpGroup:b}=H(),y=ue();d&&t.failure("Loading provider groups failed",d),v.useEffect(()=>{const a=c.filter(l=>s.some(u=>u.name===l));a.length!==c.length&&r(a)},[s]),v.useEffect(()=>{o.idpGroup&&r([o.idpGroup])},[o.idpGroup,s]);const f=[{content:"Name",className:"name",sortKey:"name"},{content:"Mapped groups",sortKey:"groups",className:"u-align--right mapped-groups"},{"aria-label":"Actions",className:"u-align--right actions"}],h=s.filter(a=>!m||a.name.toLowerCase().includes(m)),g=s.filter(a=>c.includes(a.name)),C=h.map(a=>{const l=()=>{var N,z,K,Y;if(b(a))return e.jsx(n.Button,{appearance:"link",dense:!0,onClick:()=>{o.openEditIdpGroup(a.name)},children:a.groups.length});const u=w("group",((N=a.groups)==null?void 0:N.length)??0),x=(z=a.groups)==null?void 0:z.join(` - `),G=`Assigned ${u}: - ${x}`;return e.jsx("div",{title:(K=a.groups)!=null&&K.length?G:"",children:((Y=a.groups)==null?void 0:Y.length)||0})};return{key:a.name,name:a.name,className:"u-row",columns:[{content:a.name,role:"rowheader","aria-label":"Name",className:"u-truncate",title:a.name},{content:l(),role:"cell",className:"u-align--right mapped-groups","aria-label":"Number of mapped groups"},{className:"actions u-align--right",content:e.jsx(n.List,{inline:!0,className:"u-no-margin--bottom actions-list",items:[e.jsx(n.Button,{appearance:"base",hasIcon:!0,dense:!0,onClick:()=>{o.openEditIdpGroup(a.name)},type:"button","aria-label":"Edit IDP group details",title:b(a)?"Edit details":"You do not have permission to modify this IDP group",disabled:!b(a),children:e.jsx(n.Icon,{name:"edit"})},`edit-${a.name}`),e.jsx(Ae,{idpGroup:a},`delete-${a.name}`)]}),role:"cell","aria-label":"Actions"}],sortData:{name:a.name.toLowerCase(),groups:a.groups.length}}}),{rows:L,updateSort:$}=fe({rows:C});if(i)return e.jsx(n.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const S=()=>c.length>0?e.jsx(he,{totalCount:s.length??0,itemName:"IDP group",parentName:"",selectedNames:c,setSelectedNames:r,filteredNames:h.map(a=>a.name),hideActions:!!o.panel}):null,D=s.length>0,T=e.jsxs(e.Fragment,{children:[e.jsx(e.Fragment,{children:"Identity provider groups map authentication entities from your identity provider to groups within LXD."}),!I&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"You need to set your server"," ",e.jsxs(pe,{to:"/ui/settings",children:["configuration (",e.jsx("code",{children:"oidc.groups.claim"}),")"]})," ","to the name of the custom claim that provides the IDP groups."]}),e.jsx("br",{}),e.jsx(me,{docPath:"/explanation/authorization/#use-groups-defined-by-the-identity-provider",children:"Learn more about IDP groups"})]}),k=D?e.jsxs(e.Fragment,{children:[e.jsx(n.Notification,{severity:"information",children:T}),e.jsx(n.ScrollableTable,{dependencies:[s],tableId:"idp-groups-table",belowIds:["status-bar"],children:e.jsx(n.TablePagination,{data:L,id:"pagination",itemName:"IDP group",className:"u-no-margin--top","aria-label":"Table pagination control",description:S(),children:e.jsx(ge,{id:"idp-groups-table",className:"permission-idp-group-table",headers:f,rows:L,sortable:!0,emptyStateMsg:"No identity provider groups found matching this search",onUpdateSort:$,itemName:"IDP group",parentName:"",selectedNames:c,setSelectedNames:r,disabledNames:[],filteredNames:h.map(a=>a.name),disableSelect:!!o.panel})})})]}):e.jsxs(n.EmptyState,{className:"empty-state",image:e.jsx(n.Icon,{name:"user-group",className:"empty-state-icon"}),title:"No IDP group mappings",children:[e.jsx("p",{children:T}),e.jsxs(n.Button,{className:"empty-state-button",appearance:"positive",onClick:o.openCreateIdpGroup,disabled:!p(),title:p()?"":"You do not have permission to create IDP groups",hasIcon:!y,children:[!y&&e.jsx(n.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create IDP group"})]})]});return e.jsxs(e.Fragment,{children:[e.jsxs(n.CustomLayout,{mainClassName:"permission-idp-groups-list",contentClassName:"u-no-padding--bottom",header:e.jsxs(E,{children:[e.jsxs(E.Left,{children:[e.jsx(E.Title,{children:e.jsx(Ie,{docPath:"/explanation/authorization",title:"Learn more about permissions",children:"IDP groups"})}),!c.length&&D?e.jsx(E.Search,{children:e.jsx(ye,{onChange:P,value:m,disabled:!!o.idpGroup})}):null,c.length>0&&!o.panel&&e.jsx(e.Fragment,{children:e.jsx(we,{idpGroups:g})})]}),D&&e.jsx(E.BaseActions,{children:!c.length&&e.jsxs(n.Button,{appearance:"positive",className:"u-no-margin--bottom u-float-right",onClick:o.openCreateIdpGroup,disabled:!p(),title:p()?"":"You do not have permission to create IDP groups",hasIcon:!y,children:[!y&&e.jsx(n.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create IDP group"})]})})]}),children:[!o.panel&&e.jsx(q,{}),e.jsx(n.Row,{children:k})]}),o.panel===U.createIdpGroup&&e.jsx(Ge,{}),o.panel===U.editIdpGroup&&g.length>0&&e.jsx(Ee,{idpGroup:g[0],onClose:()=>{r([])}})]})};export{Oe as default};
Copyright ©2k19 -
Hexid
|
Tex7ure