/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/PermissionIdentities-sAtbiIbs.js
import{j as e,d as n,cN as H,ah as G,r as N,l as M,cO as se,cP as ne,cQ as oe,cR as ae,q as C,R as ie,cS as re,e as q,b as K,cT as le,cU as z,m as D,cV as de,x as ce,E as ue,f as me,g as pe,i as he,cW as ge,cX as fe,cY as ye,n as xe,aS as Se,G as be,cZ as _}from"./index-dL2n30-Z.js";import{S as je}from"./ScrollableTable-CQDmfMtz.js";import{S as Ie}from"./SelectableMainTable-DeGTWeiA.js";import{S as Ne}from"./SelectedTableNotification-BHmDbErh.js";import{u as Ce}from"./useSortTableData-8PACcjA7.js";import{u as R,G as Te,L as V,S as Ge,A as ve,Q as Pe,i as we,T as Le,P as Ae}from"./GroupOrIdentityChangesTable-DJ_UDqXA.js";import{u as w,p as X}from"./usePanelParams-BJBr0ywH.js";import{P as B}from"./PageHeader-5dI4zJHr.js";import{H as ke}from"./HelpLink-C3KAssP1.js";import{u as Z,a as J}from"./useAuthGroups-BOHrDGa-.js";import{G as ee}from"./GroupSelection-FgXPdk2y.js";import{G as Fe,N as Be}from"./NameWithGroupForm-kQ6dnhAt.js";import{B as De}from"./BulkDeleteButton-DzyTAjHk.js";import"./searchAndFilter-B29FrImZ.js";import"./PermissionGroupsFilter-LHLrXwA4.js";import"./ScrollableContainer-ceiHesUW.js";const Ee=({identities:s,className:i,...l})=>{const{canEditIdentity:p}=R(),u=w(),h=s.length>1?`Modify groups for ${s.length} identities`:"Modify groups",o=s.filter(r=>!p(r)),d=()=>{const r=o.map(c=>` - ${H(c)}`).join("");return`You do not have permission to modify ${o.length>1?"some of the selected":"the selected"} ${G("identity",o.length)}:${r}`};return e.jsx(e.Fragment,{children:e.jsxs(n.Button,{onClick:()=>{u.openIdentityGroups()},"aria-label":"Modify groups",title:o.length?d():"Modify groups",className:i,disabled:!!o.length||!s.length||!!u.panel,hasIcon:!0,...l,children:[e.jsx(n.Icon,{name:"user-group"}),e.jsx("span",{children:h})]})})},Me=({onConfirm:s,close:i,addedGroups:l,removedGroups:p,selectedIdentities:u})=>{const[h,o]=N.useState(!1),d=n.useNotify(),r=w(),c=M(),x=n.useToastNotification(),f=se(u,l,p),S=ne(f),y=()=>{o(!0);const b=oe(l,p,u),a=u.map(g=>({...g,groups:b[g.id]}));ae(a).then(()=>{c.invalidateQueries({predicate:L=>[C.identities,C.authGroups].includes(L.queryKey[0])});const g=Object.keys(f),v=g.length>1?`Updated groups for ${g.length} identities`:e.jsxs(e.Fragment,{children:["Updated groups for"," ",e.jsx(ie,{type:"oidc-identity",value:g[0],to:"/ui/permissions/identities"})]});x.success(v),r.clear(),d.clear()}).catch(g=>{d.failure("Update groups failed",g)}).finally(()=>{o(!1),s()})};return e.jsx(n.ConfirmationModal,{confirmButtonLabel:"Confirm changes",confirmButtonAppearance:"positive",onConfirm:y,close:i,title:"Confirm modification",className:"permission-confirm-modal",confirmButtonLoading:h,children:e.jsx(Te,{identityGroupsChangeSummary:f,groupIdentitiesChangeSummary:S,identities:u,initialGroupBy:"identity"})})},Re=({identities:s,onClose:i})=>{var E;const l=w(),p=n.useNotify(),[u,h]=N.useState(!1),{data:o=[],error:d,isLoading:r}=Z(),{desiredState:c,save:x,undo:f}=J({initialState:{groupsAdded:new Set,groupsRemoved:new Set}});d&&p.failure("Loading panel details failed",d),N.useEffect(()=>{if(!s.length){l.clear();return}},[s]);const{groupsForAllIdentities:S,groupsForSomeIdentities:y,groupsForNoIdentities:b}=re(o,s),a=new Set(c.groupsAdded);for(const m of S)c.groupsRemoved.has(m)||a.add(m);const g=new Set(y.filter(m=>!a.has(m)&&!c.groupsRemoved.has(m))),v=()=>{const m=new Set;for(const I of S)a.has(I)||m.add(I);for(const I of y)g.has(I)||m.add(I);for(const I of b)a.has(I)&&m.add(I);return m},L=(m,I)=>{x(I?{groupsAdded:new Set,groupsRemoved:new Set(o.map(P=>P.name))}:{groupsAdded:new Set(m),groupsRemoved:new Set})},A=m=>{const I=a.has(m),P=g.has(m),k=new Set(c.groupsAdded),F=new Set(c.groupsRemoved);I||P?(k.delete(m),F.add(m)):(k.add(m),F.delete(m)),x({groupsAdded:k,groupsRemoved:F})},$=()=>{l.clear(),p.clear(),h(!1),i()},t=()=>{p.clear(),h(!1)},j=v(),T=s.length>1?`Change auth groups for ${s.length} identities`:`Change auth groups for ${(E=s[0])==null?void 0:E.name}`;return e.jsxs(e.Fragment,{children:[e.jsxs(n.SidePanel,{loading:r,hasError:!o,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{className:"u-truncate",children:T})}),e.jsx(q,{className:"u-no-padding"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(ee,{groups:o,modifiedGroups:j,parentItemName:"identity",parentItems:s,selectedGroups:a,setSelectedGroups:L,indeterminateGroups:g,toggleGroup:A,scrollDependencies:[j.size,p.notification]})}),e.jsx(n.SidePanel.Footer,{className:"u-align--right",children:e.jsx(Fe,{modifiedGroups:j,undoChange:f,closePanel:$,onSubmit:()=>{h(!0)},disabled:j.size===0,isEdit:!0})})]}),u&&e.jsx(Me,{close:t,onConfirm:t,selectedIdentities:s,addedGroups:c.groupsAdded,removedGroups:c.groupsRemoved})]})},$e=({identities:s})=>{const i=M(),l=n.useNotify(),p=n.useToastNotification(),u=`Delete ${G("identity",s.length)}`,[h,o]=N.useState(!1),{canDeleteIdentity:d}=R(),{data:r}=K(),c=(r==null?void 0:r.auth_user_name)??"",x=s.some(a=>a.id===c),f=[],S=[];s.forEach(a=>{d(a)?S.push(a):f.push(a)});const y=()=>{o(!0);const a=`${S.length} ${G("identity",S.length)} successfully deleted`;le(S).then(()=>{if(x&&(r==null?void 0:r.auth_user_method)==="oidc"){z();return}i.invalidateQueries({predicate:g=>[C.identities,C.authGroups,C.settings].includes(g.queryKey[0])}),p.success(a),o(!1)}).catch(g=>{l.failure("Identity deletion failed",g),o(!1)})},b=()=>{if(f.length)return[`${S.length} ${G("identity",S.length)} will be deleted.`,`${f.length} ${G("identity",f.length)} that you do not have permission to delete will be ignored.`]};return e.jsx(De,{entities:s,deletableEntities:S,entityType:"identity",onDelete:y,disabledReason:S.length?void 0:`You do not have permission to delete the selected ${G("identity",s.length)}`,className:"u-no-margin--bottom",confirmationButtonProps:{loading:h},buttonLabel:u,bulkDeleteBreakdown:b(),modalContentPrefix:e.jsx(V,{isVisible:x})})},_e=({identity:s})=>{const i=M(),l=n.useNotify(),p=n.useToastNotification(),[u,h]=N.useState(!1),{canDeleteIdentity:o}=R(),{data:d}=K(),r=(d==null?void 0:d.auth_user_name)??"",c=s.id===r,x=()=>{h(!0),de(s).then(()=>{if(c&&(d==null?void 0:d.auth_user_method)==="oidc"){z();return}i.invalidateQueries({predicate:f=>[C.identities,C.authGroups,C.settings].includes(f.queryKey[0])}),p.success(e.jsxs(e.Fragment,{children:["Identity"," ",e.jsx(D,{type:"certificate",value:s.name,bold:!0,truncate:!0})," ","deleted."]})),h(!1),close()}).catch(f=>{h(!1),l.failure("Identity deletion failed",f,e.jsx(D,{type:"certificate",value:s.name,bold:!0,truncate:!0}))})};return e.jsx(n.ConfirmationButton,{onHoverText:o(s)?"Delete identity":"You do not have permission to delete this identity",appearance:"base","aria-label":"Delete identity",className:"has-icon u-no-margin--bottom is-dense",confirmationModalProps:{title:"Confirm delete",children:e.jsxs(e.Fragment,{children:[e.jsx(V,{isVisible:c}),e.jsxs("p",{children:["This will permanently delete identity"," ",e.jsx(D,{type:"certificate",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]})]}),confirmButtonLabel:"Delete",onConfirm:x},shiftClickEnabled:!0,showShiftClickHint:!0,loading:u,disabled:!o(s)||u,children:e.jsx(n.Icon,{name:"delete"})})},He=({openPanel:s})=>{const i=ce(),{canCreateIdentities:l}=ue();return e.jsx(e.Fragment,{children:e.jsxs(n.Button,{appearance:"positive",className:"u-float-right u-no-margin--bottom",onClick:s,hasIcon:!i,title:l()?"":"You do not have permission to create identities",disabled:!l(),children:[!i&&e.jsx(n.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create TLS Identity"})]})})},qe=({label:s,text:i})=>{const[l,p]=N.useState(!1),u=async()=>{if(i)try{await navigator.clipboard.writeText(i),p(!0),setTimeout(()=>{p(!1)},5e3)}catch(h){console.error(h)}};return e.jsxs(n.Button,{"aria-label":l?"Copied to clipboard":"Copy to clipboard",className:"u-no-margin--bottom",onClick:u,type:"button",hasIcon:!0,children:[e.jsx(n.Icon,{name:l?"task-outstanding":"copy"}),e.jsx("span",{children:s})]})},Ke=({onClose:s,token:i,identityName:l})=>e.jsx(n.Modal,{close:s,className:"create-tls-identity",title:"Identity created",buttonRow:e.jsx(e.Fragment,{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Copy trust token",text:i}),e.jsx(n.Button,{"aria-label":"Close",className:"u-no-margin--bottom",onClick:s,type:"button",children:"Close"})]})}),children:i&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["The trust token below can be used to log in with the newly created identity ",e.jsx(D,{type:"certificate",value:l})," ."," ",e.jsx("b",{children:"Once this modal is closed, the trust token can’t be generated again."})]}),e.jsx("div",{className:"token-code-block",children:e.jsx("code",{children:i})})]})}),Ue=({onSuccess:s})=>{const i=w(),l=n.useNotify(),p=M(),{data:u=[],error:h,isLoading:o}=Z(),{desiredState:d,save:r}=J({initialState:{groupsAdded:new Set}});h&&l.failure("Loading panel details failed",h);const c=(b,a)=>{r(a?{groupsAdded:new Set}:{groupsAdded:new Set(b)})},x=()=>{i.clear(),l.clear()},f=b=>{ge(b.name,Array.from(d.groupsAdded)).then(a=>{const g=fe(a);s(b.name,g),p.invalidateQueries({queryKey:[C.identities]}),x()}).catch(a=>{l.failure("TLS Identity failed to be created",a)})},S=me().shape({name:pe().required("Identity name is required")}),y=he({initialValues:{name:"",groups:[]},validationSchema:S,onSubmit:f});return e.jsx(e.Fragment,{children:e.jsxs(n.SidePanel,{loading:o,hasError:!u,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{children:"Create identity"})}),e.jsx(q,{className:"u-no-padding"}),e.jsx(Be,{formik:y}),e.jsx("p",{children:"Auth groups"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(ee,{groups:u,modifiedGroups:d.groupsAdded,parentItemName:"",selectedGroups:d.groupsAdded,setSelectedGroups:c,toggleGroup:b=>{const a=new Set([...d.groupsAdded]);a.has(b)?a.delete(b):a.add(b),c([...a],a.size===0)},scrollDependencies:[u,d.groupsAdded.size,l.notification,y]})}),e.jsxs(n.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(n.Button,{appearance:"base",onClick:x,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(n.ActionButton,{appearance:"positive",onClick:()=>void y.submitForm(),className:"u-no-margin--bottom",disabled:!y.isValid||y.isSubmitting||!y.values.name,loading:y.isSubmitting,children:"Create identity"})]})]})})},Oe=()=>{const s=w(),{openPortal:i,closePortal:l,isOpen:p,Portal:u}=n.usePortal({programmaticallyOpen:!0}),[h,o]=N.useState(""),[d,r]=N.useState("");return e.jsxs(e.Fragment,{children:[p&&e.jsx(u,{children:e.jsx(Ke,{onClose:l,token:h,identityName:d})}),s.panel===X.createTLSIdentity&&e.jsx(Ue,{onSuccess:(c,x)=>{r(c),o(x),i()}})]})},lt=()=>{const s=n.useNotify(),{data:i=[],error:l,isLoading:p}=ye(),{data:u}=K(),h=xe(),o=w(),[d]=Se(),[r,c]=N.useState([]),{hasAccessManagementTLS:x}=be(),{canEditIdentity:f}=R();N.useEffect(()=>{const t=new Set(i.map(T=>T.id)),j=r.filter(T=>t.has(T));j.length!==r.length&&c(j)},[i]),l&&s.failure("Loading identities failed",l);const S=[{content:"Name",className:"name",sortKey:"name"},{content:"ID",sortKey:"id",className:"identity-id"},{content:"Auth method",sortKey:"authmethod",className:"auth-method"},{content:"Type",sortKey:"type",className:"identity-type"},{content:"Groups",sortKey:"groups",className:"u-align--right group-count"},{"aria-label":"Actions",className:"u-align--right actions"}],y={queries:d.getAll(Pe),authMethod:d.getAll(ve),systemIdentities:d.get(Ge)},b=i.filter(t=>!(y.systemIdentities==="hide"&&we(t)||!y.queries.every(j=>H(t).toLowerCase().includes(j)||t.id.toLowerCase().includes(j))||y.authMethod.length>0&&!y.authMethod.includes(t.authentication_method))),a=i.filter(t=>r.includes(t.id)),g=b.map(t=>{var P;const j=(u==null?void 0:u.auth_user_name)===t.id,T=()=>{o.openIdentityGroups(t.id),c([t.id])},E=()=>{var U,O,Y,Q,W;if(f(t))return e.jsx(n.Button,{appearance:"link",dense:!0,onClick:T,children:((U=t.groups)==null?void 0:U.length)||0});const k=G("group",((O=t.groups)==null?void 0:O.length)??0),F=(Y=t.groups)==null?void 0:Y.join(` - `),te=`Assigned ${k}: - ${F}`;return e.jsx("div",{title:(Q=t.groups)!=null&&Q.length?te:"",children:((W=t.groups)==null?void 0:W.length)||0})},m=H(t),I=()=>t.type.startsWith("Client certificate")?"certificate":t.type.startsWith("OIDC client")?"oidc-identity":t.type.startsWith("Server certificate")?"cluster-member":t.type.startsWith("Metrics certificate")?"metric":"certificate";return{key:t.id,name:_(t)?"":t.id,className:"u-row",columns:[{content:e.jsxs(e.Fragment,{children:[e.jsx(D,{type:I(),value:m})," ",e.jsx(Le,{isVisible:j,children:"You"})]}),role:"rowheader","aria-label":"Name",className:"u-truncate",title:m},{content:t.id,role:"cell","aria-label":"ID",className:"u-truncate identity-id",title:t.id},{content:t.authentication_method.toUpperCase(),role:"cell","aria-label":"Auth method",className:"auth-method"},{content:t.type,role:"cell","aria-label":"Type",className:"u-truncate identity-type"},{content:E(),role:"cell",className:"u-align--right group-count","aria-label":"Groups for this identity"},{content:!_(t)&&e.jsxs(e.Fragment,{children:[e.jsx(n.Button,{appearance:"base",className:"u-no-margin--bottom",hasIcon:!0,dense:!0,onClick:T,type:"button","aria-label":"Manage groups",title:f()?"Manage groups":"You do not have permission to modify this identity",disabled:!f(t),children:e.jsx(n.Icon,{name:"user-group"})}),x&&e.jsx(_e,{identity:t})]}),className:"actions u-align--right",role:"cell","aria-label":"Actions"}],sortData:{id:t.id,name:m.toLowerCase(),authentication_method:t.authentication_method,type:t.type,groups:((P=t.groups)==null?void 0:P.length)||0}}}),{rows:v,updateSort:L}=Ce({rows:g,defaultSort:"name"}),A=i.filter(t=>!_(t));if(p)return e.jsx(n.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const $=()=>{const t=g.length>1?`Showing all ${g.length} identities`:"Showing 1 out of 1 identity";return r.length>0?e.jsx(Ne,{totalCount:A.length??0,itemName:"identity",selectedNames:r,setSelectedNames:c,filteredNames:A.map(j=>j.id),hideActions:!!o.panel}):t};return e.jsxs(e.Fragment,{children:[e.jsxs(n.CustomLayout,{mainClassName:"permission-identities-list",contentClassName:"u-no-padding--bottom",header:e.jsxs(B,{children:[e.jsxs(B.Left,{children:[e.jsx(B.Title,{children:e.jsx(ke,{href:`${h}/explanation/authorization`,title:"Learn more about permissions",children:"Identities"})}),!r.length&&!o.panel&&e.jsx(B.Search,{children:e.jsx(Ae,{})}),!!r.length&&e.jsx(Ee,{identities:a,className:"u-no-margin--bottom"}),!!r.length&&x&&e.jsx($e,{identities:a})]}),e.jsx(B.BaseActions,{children:e.jsx(He,{openPanel:o.openCreateTLSIdentity})})]}),children:[!o.panel&&e.jsx(q,{}),e.jsx(n.Row,{children:e.jsx(je,{dependencies:[i],tableId:"identities-table",belowIds:["status-bar"],children:e.jsx(n.TablePagination,{data:v,id:"pagination",itemName:"identity",className:"u-no-margin--top","aria-label":"Table pagination control",description:$(),children:e.jsx(Ie,{id:"identities-table",className:"permission-identities-table",headers:S,rows:v,sortable:!0,emptyStateMsg:"No identities found matching this search",onUpdateSort:L,itemName:"identity",parentName:"",selectedNames:r,setSelectedNames:c,disabledNames:[],filteredNames:A.map(t=>t.id),disableSelect:!!o.panel})})})})]}),e.jsx(Oe,{}),o.panel===X.identityGroups&&e.jsx(Re,{identities:a,onClose:()=>{c([])}})]})};export{lt as default};
Copyright ©2k19 -
Hexid
|
Tex7ure