/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/PermissionIdentities-Cblgbc38.js
import{j as e,d as n,d5 as H,aj as G,r as N,l as E,d6 as ne,d7 as oe,d8 as ae,d9 as ie,q as v,R as re,da as le,e as Q,b as q,db as de,dc as z,n as M,dd as ce,y as ue,m as me,f as pe,g as he,i as ge,de as fe,df as ye,aJ as Se,dg as xe,aW as je,G as Ie,dh as _}from"./index-B3cgCbnJ.js";import{S as be}from"./SelectableMainTable-CTM3_-pn.js";import{S as Ne}from"./SelectedTableNotification-BBOESV7i.js";import{u as Ce}from"./useSortTableData-DogFPcVj.js";import{u as R,G as ve,L as V,S as Ge,A as Te,Q as Pe,i as we,T as Le,P as Ae}from"./GroupOrIdentityChangesTable-BR7xFl1a.js";import{u as w,p as J}from"./usePanelParams-CZsrUgz_.js";import{P as B}from"./PageHeader-CCfZuT9z.js";import{H as De}from"./HelpLink-D9xEWgz5.js";import{u as X,a as Z}from"./useAuthGroups-sO_2YynQ.js";import{G as ee}from"./GroupSelection-DeSbcBFI.js";import{G as Fe,N as ke}from"./NameWithGroupForm-C6XxSQWh.js";import{B as Be}from"./BulkDeleteButton-CR5M7boY.js";import{C as Me}from"./CodeSnippetWithCopyButton-BMlK7djB.js";import"./searchAndFilter-B29FrImZ.js";import"./PermissionGroupsFilter-7ey2euXS.js";const Ee=({identities:s,className:i,...r})=>{const{canEditIdentity:h}=R(),d=w(),u=s.length>1?`Modify groups for ${s.length} identities`:"Modify groups",l=s.filter(c=>!h(c)),o=()=>{const c=l.map(m=>` - ${H(m)}`).join("");return`You do not have permission to modify ${l.length>1?"some of the selected":"the selected"} ${G("identity",l.length)}:${c}`};return e.jsx(e.Fragment,{children:e.jsxs(n.Button,{onClick:()=>{d.openIdentityGroups()},"aria-label":"Modify groups",title:l.length?o():"Modify groups",className:i,disabled:!!l.length||!s.length||!!d.panel,hasIcon:!0,...r,children:[e.jsx(n.Icon,{name:"user-group"}),e.jsx("span",{children:u})]})})},Re=({onConfirm:s,close:i,addedGroups:r,removedGroups:h,selectedIdentities:d})=>{const[u,l]=N.useState(!1),o=n.useNotify(),c=w(),m=E(),f=n.useToastNotification(),S=ne(d,r,h),x=oe(S),y=()=>{l(!0);const j=ae(r,h,d),a=d.map(p=>({...p,groups:j[p.id]}));ie(a).then(()=>{m.invalidateQueries({predicate:L=>[v.identities,v.authGroups].includes(L.queryKey[0])});const p=Object.keys(S),T=p.length>1?`Updated groups for ${p.length} identities`:e.jsxs(e.Fragment,{children:["Updated groups for"," ",e.jsx(re,{type:"oidc-identity",value:p[0],to:"/ui/permissions/identities"})]});f.success(T),c.clear(),o.clear()}).catch(p=>{o.failure("Update groups failed",p)}).finally(()=>{l(!1),s()})};return e.jsx(n.ConfirmationModal,{confirmButtonLabel:"Confirm changes",confirmButtonAppearance:"positive",onConfirm:y,close:i,title:"Confirm modification",className:"permission-confirm-modal",confirmButtonLoading:u,children:e.jsx(ve,{identityGroupsChangeSummary:S,groupIdentitiesChangeSummary:x,identities:d,initialGroupBy:"identity"})})},$e=({identities:s,onClose:i})=>{var C;const r=w(),h=n.useNotify(),[d,u]=N.useState(!1),{data:l=[],error:o,isLoading:c}=X(),{desiredState:m,save:f,undo:S}=Z({initialState:{groupsAdded:new Set,groupsRemoved:new Set}});o&&h.failure("Loading panel details failed",o),N.useEffect(()=>{if(!s.length){r.clear();return}},[s]);const{groupsForAllIdentities:x,groupsForSomeIdentities:y,groupsForNoIdentities:j}=le(l,s),a=new Set(m.groupsAdded);for(const g of x)m.groupsRemoved.has(g)||a.add(g);const p=new Set(y.filter(g=>!a.has(g)&&!m.groupsRemoved.has(g))),T=()=>{const g=new Set;for(const I of x)a.has(I)||g.add(I);for(const I of y)p.has(I)||g.add(I);for(const I of j)a.has(I)&&g.add(I);return g},L=(g,I)=>{f(I?{groupsAdded:new Set,groupsRemoved:new Set(l.map(F=>F.name))}:{groupsAdded:new Set(g),groupsRemoved:new Set})},A=g=>{const I=a.has(g),F=p.has(g),P=new Set(m.groupsAdded),k=new Set(m.groupsRemoved);I||F?(P.delete(g),k.add(g)):(P.add(g),k.delete(g)),f({groupsAdded:P,groupsRemoved:k})},$=()=>{r.clear(),h.clear(),u(!1),i()},D=()=>{h.clear(),u(!1)},t=T(),b=s.length>1?`Change auth groups for ${s.length} identities`:`Change auth groups for ${(C=s[0])==null?void 0:C.name}`;return e.jsxs(e.Fragment,{children:[e.jsxs(n.SidePanel,{loading:c,hasError:!l,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{className:"u-truncate",children:b})}),e.jsx(Q,{className:"u-no-padding"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(ee,{groups:l,modifiedGroups:t,parentItemName:"identity",parentItems:s,selectedGroups:a,setSelectedGroups:L,indeterminateGroups:p,toggleGroup:A,scrollDependencies:[t.size,h.notification]})}),e.jsx(n.SidePanel.Footer,{className:"u-align--right",children:e.jsx(Fe,{modifiedGroups:t,undoChange:S,closePanel:$,onSubmit:()=>{u(!0)},disabled:t.size===0,isEdit:!0})})]}),d&&e.jsx(Re,{close:D,onConfirm:D,selectedIdentities:s,addedGroups:m.groupsAdded,removedGroups:m.groupsRemoved})]})},_e=({identities:s})=>{const i=E(),r=n.useNotify(),h=n.useToastNotification(),d=`Delete ${G("identity",s.length)}`,[u,l]=N.useState(!1),{canDeleteIdentity:o}=R(),{data:c}=q(),m=(c==null?void 0:c.auth_user_name)??"",f=s.some(a=>a.id===m),S=[],x=[];s.forEach(a=>{o(a)?x.push(a):S.push(a)});const y=()=>{l(!0);const a=`${x.length} ${G("identity",x.length)} successfully deleted`;de(x).then(()=>{if(f&&(c==null?void 0:c.auth_user_method)==="oidc"){z();return}i.invalidateQueries({predicate:p=>[v.identities,v.authGroups,v.settings].includes(p.queryKey[0])}),h.success(a),l(!1)}).catch(p=>{r.failure("Identity deletion failed",p),l(!1)})},j=()=>{if(S.length)return[`${x.length} ${G("identity",x.length)} will be deleted.`,`${S.length} ${G("identity",S.length)} that you do not have permission to delete will be ignored.`]};return e.jsx(Be,{entities:s,deletableEntities:x,entityType:"identity",onDelete:y,disabledReason:x.length?void 0:`You do not have permission to delete the selected ${G("identity",s.length)}`,className:"u-no-margin--bottom",confirmationButtonProps:{loading:u},buttonLabel:d,bulkDeleteBreakdown:j(),modalContentPrefix:e.jsx(V,{isVisible:f})})},He=({identity:s})=>{const i=E(),r=n.useNotify(),h=n.useToastNotification(),[d,u]=N.useState(!1),{canDeleteIdentity:l}=R(),{data:o}=q(),c=(o==null?void 0:o.auth_user_name)??"",m=s.id===c,f=()=>{u(!0),ce(s).then(()=>{if(m&&(o==null?void 0:o.auth_user_method)==="oidc"){z();return}i.invalidateQueries({predicate:S=>[v.identities,v.authGroups,v.settings].includes(S.queryKey[0])}),h.success(e.jsxs(e.Fragment,{children:["Identity"," ",e.jsx(M,{type:"certificate",value:s.name,bold:!0,truncate:!0})," ","deleted."]})),u(!1),close()}).catch(S=>{u(!1),r.failure("Identity deletion failed",S,e.jsx(M,{type:"certificate",value:s.name,bold:!0,truncate:!0}))})};return e.jsx(n.ConfirmationButton,{onHoverText:l(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:m}),e.jsxs("p",{children:["This will permanently delete identity"," ",e.jsx(M,{type:"certificate",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]})]}),confirmButtonLabel:"Delete",onConfirm:f},shiftClickEnabled:!0,showShiftClickHint:!0,loading:d,disabled:!l(s)||d,children:e.jsx(n.Icon,{name:"delete"})})},qe=({openPanel:s})=>{const i=ue(),{canCreateIdentities:r}=me();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:r()?"":"You do not have permission to create identities",disabled:!r(),children:[!i&&e.jsx(n.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create TLS Identity"})]})})},Ke=({onClose:s,token:i,identityName:r})=>e.jsx(n.Modal,{close:s,className:"create-tls-identity",title:"Identity created",children:i&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["The identity trust token below can be used to log in with the newly created identity"," ",e.jsx(M,{type:"certificate",value:r})," ."," ",e.jsx("b",{children:"Once this modal is closed, the identity trust token can’t be generated again."})]}),e.jsx(Me,{code:i})]})}),Oe=({onSuccess:s})=>{const i=w(),r=n.useNotify(),h=E(),{data:d=[],error:u,isLoading:l}=X(),{desiredState:o,save:c}=Z({initialState:{groupsAdded:new Set}});u&&r.failure("Loading panel details failed",u);const m=(j,a)=>{c(a?{groupsAdded:new Set}:{groupsAdded:new Set(j)})},f=()=>{i.clear(),r.clear()},S=j=>{fe(j.name,Array.from(o.groupsAdded)).then(a=>{const p=ye(a);s(j.name,p),h.invalidateQueries({queryKey:[v.identities]}),f()}).catch(a=>{r.failure("TLS Identity failed to be created",a)})},x=pe().shape({name:he().required("Identity name is required")}),y=ge({initialValues:{name:"",groups:[]},validationSchema:x,onSubmit:S});return e.jsx(e.Fragment,{children:e.jsxs(n.SidePanel,{loading:l,hasError:!d,children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{children:"Create identity"})}),e.jsx(Q,{className:"u-no-padding"}),e.jsx(ke,{formik:y}),e.jsx("p",{children:"Auth groups"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(ee,{groups:d,modifiedGroups:o.groupsAdded,parentItemName:"",selectedGroups:o.groupsAdded,setSelectedGroups:m,toggleGroup:j=>{const a=new Set([...o.groupsAdded]);a.has(j)?a.delete(j):a.add(j),m([...a],a.size===0)},scrollDependencies:[d,o.groupsAdded.size,r.notification,y]})}),e.jsxs(n.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(n.Button,{appearance:"base",onClick:f,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"})]})]})})},Ue=()=>{const s=w(),{openPortal:i,closePortal:r,isOpen:h,Portal:d}=n.usePortal({programmaticallyOpen:!0}),[u,l]=N.useState(""),[o,c]=N.useState("");return e.jsxs(e.Fragment,{children:[h&&e.jsx(d,{children:e.jsx(Ke,{onClose:r,token:u,identityName:o})}),s.panel===J.createTLSIdentity&&e.jsx(Oe,{onSuccess:(m,f)=>{c(m),l(f),i()}})]})},We=()=>!!localStorage.getItem("ssoNotificationClosed"),Ye=()=>{localStorage.setItem("ssoNotificationClosed","yes")},Qe=({hasOidc:s})=>{const[i,r]=N.useState(We());if(i||s)return null;const h=()=>{Ye(),r(!0)};return e.jsx(e.Fragment,{children:e.jsx(n.Notification,{severity:"information",title:"Did you know?",onDismiss:h,actions:[e.jsx(Se,{docPath:"/howto/oidc/",children:"Show me how"},"sso-doc-link")],children:"LXD can be configured to log in using a single sign-on provider."})})},ct=()=>{var D;const s=n.useNotify(),{data:i=[],error:r,isLoading:h}=xe(),{data:d}=q(),u=w(),[l]=je(),[o,c]=N.useState([]),{hasAccessManagementTLS:m}=Ie(),{canEditIdentity:f}=R(),S=(D=d==null?void 0:d.auth_methods)==null?void 0:D.includes("oidc");N.useEffect(()=>{const t=new Set(i.map(C=>C.id)),b=o.filter(C=>t.has(C));b.length!==o.length&&c(b)},[i]),r&&s.failure("Loading identities failed",r);const x=[{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:l.getAll(Pe),authMethod:l.getAll(Te),systemIdentities:l.get(Ge)},j=i.filter(t=>!(y.systemIdentities==="hide"&&we(t)||!y.queries.every(b=>H(t).toLowerCase().includes(b)||t.id.toLowerCase().includes(b))||y.authMethod.length>0&&!y.authMethod.includes(t.authentication_method))),a=i.filter(t=>o.includes(t.id)),p=j.map(t=>{var P;const b=(d==null?void 0:d.auth_user_name)===t.id,C=()=>{u.openIdentityGroups(t.id),c([t.id])},g=()=>{var K,O,U,W,Y;if(f(t))return e.jsx(n.Button,{appearance:"link",dense:!0,onClick:C,children:((K=t.groups)==null?void 0:K.length)||0});const k=G("group",((O=t.groups)==null?void 0:O.length)??0),te=(U=t.groups)==null?void 0:U.join(` - `),se=`Assigned ${k}: - ${te}`;return e.jsx("div",{title:(W=t.groups)!=null&&W.length?se:"",children:((Y=t.groups)==null?void 0:Y.length)||0})},I=H(t),F=()=>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(M,{type:F(),value:I})," ",e.jsx(Le,{isVisible:b,children:"You"})]}),role:"rowheader","aria-label":"Name",className:"u-truncate",title:I},{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:g(),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:C,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"})}),m&&e.jsx(He,{identity:t})]}),className:"actions u-align--right",role:"cell","aria-label":"Actions"}],sortData:{id:t.id,name:I.toLowerCase(),authentication_method:t.authentication_method,type:t.type,groups:((P=t.groups)==null?void 0:P.length)||0}}}),{rows:T,updateSort:L}=Ce({rows:p,defaultSort:"name"}),A=i.filter(t=>!_(t));if(h)return e.jsx(n.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const $=()=>{const t=p.length>1?`Showing all ${p.length} identities`:"Showing 1 out of 1 identity";return o.length>0?e.jsx(Ne,{totalCount:A.length??0,itemName:"identity",selectedNames:o,setSelectedNames:c,filteredNames:A.map(b=>b.id),hideActions:!!u.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(De,{docPath:"/explanation/authorization",title:"Learn more about permissions",children:"Identities"})}),!o.length&&!u.panel&&e.jsx(B.Search,{children:e.jsx(Ae,{})}),!!o.length&&e.jsx(Ee,{identities:a,className:"u-no-margin--bottom"}),!!o.length&&m&&e.jsx(_e,{identities:a})]}),e.jsx(B.BaseActions,{children:e.jsx(qe,{openPanel:u.openCreateTLSIdentity})})]}),children:[!u.panel&&e.jsxs("div",{className:"row",children:[e.jsx(n.NotificationConsumer,{}),e.jsx(Qe,{hasOidc:S??!1})]}),e.jsx(n.Row,{children:e.jsx(n.ScrollableTable,{dependencies:[i],tableId:"identities-table",belowIds:["status-bar"],children:e.jsx(n.TablePagination,{data:T,id:"pagination",itemName:"identity",className:"u-no-margin--top","aria-label":"Table pagination control",description:$(),children:e.jsx(be,{id:"identities-table",className:"permission-identities-table",headers:x,rows:T,sortable:!0,emptyStateMsg:"No identities found matching this search",onUpdateSort:L,itemName:"identity",parentName:"",selectedNames:o,setSelectedNames:c,disabledNames:[],filteredNames:A.map(t=>t.id),disableSelect:!!u.panel})})})})]}),e.jsx(Ue,{}),u.panel===J.identityGroups&&e.jsx($e,{identities:a,onClose:()=>{c([])}})]})};export{ct as default};
Copyright ©2k19 -
Hexid
|
Tex7ure