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