All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.EditUser-abefe270.js Maven / Gradle / Ivy

There is a newer version: 25.0.1
Show newest version
import{bp as Ve,c1 as as,c2 as ns,c5 as Re,c4 as is,c3 as os,bk as ds,c6 as Ee,bj as ls,cv as cs,bh as us,dq as ms,dr as ps,ds as hs,dt as fs,du as gs,dv as xs,u as F,d as q,r as y,e as ne,j as e,P as se,bF as be,b5 as bs,aD as ys,g as b,A as U,l as Z,a8 as O,a1 as qe,B as L,D as js,bH as ws,a7 as Cs,G as ye,F as J,dw as vs,dx as Is,a as ks,h as we,C as He,Q as Ps,f as _e,V as G,S as Ts,q as ue,K as ze,X as Ss,at as Ae,Y as Ds,au as We,M as Ls,bG as Fs,c as pe,W as Rs,N as de,a$ as Es,L as As,bL as Ns,o as Ne,b as Us,dy as Ks,aO as Bs}from"./index-f33eb656.js";import{u as te,C as $e}from"./ConfirmDialog-cc2aa7b4.js";import{R as Ms,u as Os}from"./RoutableTabs-8ba6475e.js";import{V as Gs}from"./ViewHeader-5aaa6ccc.js";import{u as Vs,U as qs}from"./UserProfileContext-80d88abf.js";import{u as Hs,F as _s}from"./useIsFeatureEnabled-4167e6f3.js";import{u as Ce}from"./useParams-74754a7c.js";import{u as zs}from"./useUpdateEffect-149a036b.js";import{A as Ws}from"./AttributeForm-71f684c4.js";import{L as ve}from"./PaginatingTableToolbar-2e41cd99.js";import{K as me,T as $s,m as Qs,n as Xs,P as Ys}from"./KeycloakDataTable-82a4b6c2.js";import{u as Js}from"./useFormatDate-0368aa03.js";import{X as Zs,N,Y as et,S as R,T as Ue,O as Ke,P as ie,Q as _,R as Be,V as xe}from"./Td-137060bd.js";import{C as st,S as tt}from"./SessionsTable-fa5aca93.js";import{C as rt,c as at}from"./Select-802cd710.js";import{R as nt,F as it,U as ot,i as dt,u as lt}from"./UserForm-954f441f.js";import{u as je}from"./useToggle-d322044d.js";import{u as ct}from"./useLocaleSort-22b9cad8.js";import{M as Qe,a as Ie}from"./Modal-e76dd76f.js";import{K as ce}from"./KeycloakTextInput-e2751b88.js";import{F as he}from"./Form-6c170f69.js";import{T as ut}from"./TimeSelector-6a5d1719.js";import{P as Me}from"./PasswordInput-3397c9bf.js";import{G as mt,a as pt}from"./GroupPickerDialog-1f4cdfaa.js";import{C as ht}from"./Checkbox-8826c1eb.js";import{Q as ft}from"./question-circle-icon-096c9b7f.js";import{F as Oe}from"./FormPanel-dcdadf01.js";import{c as oe}from"./capitalize-33229820.js";import{T as le}from"./Text-83f5a4d7.js";import{R as gt}from"./AddRoleMappingModal-d36df11e.js";import"./user-section-12ab98ea.js";import{a as X,b as Y}from"./Tabs-5aebe4ec.js";import"./ToolbarContent-f1a19b22.js";import"./FormAccess-29b78a4e.js";import"./copy-icon-c00ff2e0.js";import"./GridItem-8422f423.js";import"./KeyValueInput-7823c1d9.js";import"./minus-icon-9eecb50c.js";import"./minus-circle-icon-cb05a6be.js";import"./ActionListItem-96f54559.js";import"./plus-circle-icon-2ea0b4ed.js";import"./EmptyStateBody-de699127.js";import"./EmptyStateSecondaryActions-7a33984f.js";import"./TableToolbar-8e38cfad.js";import"./star-icon-d7615f00.js";import"./check-fc57dbe1.js";import"./grip-vertical-icon-90ec69d5.js";import"./ListItem-a3eaabf7.js";import"./ScrollForm-c201dcc9.js";import"./admin-ui-endpoint-9ec5dfbd.js";import"./getAuthorizationHeaders-f2376d1a.js";import"./DataListItemRow-c0c554d3.js";import"./data-list-7d55714c.js";import"./CardHeader-8937fd16.js";import"./Card-1b46a6d0.js";import"./CardTitle-f50befe6.js";import"./CardBody-a335088c.js";import"./resource-db8462e3.js";import"./filter-icon-16b4a4ff.js";import"./plus-icon-6a98b80b.js";import"./MenuList-b32c7668.js";var xt=Math.min;function bt(s,t,n){for(var o=n?is:os,a=s[0].length,g=s.length,l=g,u=Array(g),c=1/0,h=[];l--;){var i=s[l];l&&t&&(i=Ve(i,as(t))),c=xt(i.length,c),u[l]=!n&&(t||a>=120&&i.length>=120)?new ns(l&&i):void 0}i=s[0];var m=-1,j=u[0];e:for(;++m{const{t}=F("users"),{addAlert:n,addError:o}=q(),[a,g]=y.useState(s),l=ne({mode:"onChange"}),{config:u}=Vs(),c=()=>bs(a.attributes);y.useEffect(()=>{l.setValue("attributes",c())},[a,u]);const h=async i=>{try{const m=ys(i.attributes);await b.users.update({id:a.id},{...a,attributes:m}),g({...a,attributes:m}),n(t("userSaved"),U.success)}catch(m){o("groups:groupUpdateError",m)}};return e.jsx(se,{variant:be.light,children:e.jsx(Ws,{form:l,save:h,fineGrainedAccess:a.access?.manage,reset:()=>l.reset({attributes:c()})})})},Tt=()=>{const[s,t]=y.useState(),{t:n}=F("roles"),{addAlert:o,addError:a}=q(),g=Js(),[l,u]=y.useState(0),{id:c}=Ce(),h=f=>qe(f,E=>E.clientId?.toUpperCase()),i=()=>u(new Date().getTime()),m=async()=>{const f=await b.users.listConsents({id:c});return h(f)},j=({grantedClientScopes:f})=>e.jsx(rt,{className:"kc-consents-chip-group",children:f.map(E=>e.jsx(at,{isReadOnly:!0,className:"kc-consents-chip",children:E},E))}),[p,P]=te({titleKey:"users:revokeClientScopesTitle",messageKey:n("users:revokeClientScopes",{clientId:s?.clientId}),continueButtonLabel:"common:revoke",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.revokeConsent({id:c,clientId:s.clientId}),i(),o(n("deleteGrantsSuccess"),U.success)}catch(f){a("roles:deleteGrantsError",f)}}});return e.jsxs(e.Fragment,{children:[e.jsx(P,{}),e.jsx(me,{loader:m,ariaLabelKey:"roles:roleList",searchPlaceholderKey:" ",columns:[{name:"clientId",displayKey:"clients:Client",cellFormatters:[O()],transforms:[N(20)]},{name:"grantedClientScopes",displayKey:"client-scopes:grantedClientScopes",cellFormatters:[O()],cellRenderer:j,transforms:[N(30)]},{name:"createDate",displayKey:"clients:created",transforms:[N(20)],cellRenderer:({createDate:f})=>f?g(new Date(f)):"—"},{name:"lastUpdatedDate",displayKey:"clients:lastUpdated",transforms:[N(10)],cellRenderer:({lastUpdatedDate:f})=>f?g(new Date(f)):"—"}],actions:[{title:n("users:revoke"),onRowClick:f=>{t(f),p()}}],emptyState:e.jsx(ve,{hasIcon:!0,icon:st,message:n("users:noConsents"),instructions:n("users:noConsentsText")})},l)]})},St=({credentialData:s,onClose:t})=>{const{t:n}=F("users");return e.jsx(Qe,{variant:Ie.medium,title:n("passwordDataTitle"),"data-testid":"passwordDataDialog",isOpen:!0,onClose:t,children:e.jsxs($s,{"aria-label":n("passwordDataTitle"),"data-testid":"password-data-dialog",variant:et.compact,cells:[n("showPasswordDataName"),n("showPasswordDataValue")],rows:s,children:[e.jsx(Qs,{}),e.jsx(Xs,{})]})})},Dt=({credential:s,resetPassword:t,toggleDelete:n,children:o})=>{const{t:a}=F("users"),[g,l]=je(),[u,c]=je(),h=ct(),i=y.useMemo(()=>{if(!s.credentialData)return[];const m=JSON.parse(s.credentialData);return h(Object.entries(m),([j])=>j).map(([j,p])=>typeof p=="string"?[j,p]:[j,JSON.stringify(p)])},[s.credentialData]);return e.jsxs(e.Fragment,{children:[g&&Object.keys(s).length!==0&&e.jsx(St,{credentialData:i,onClose:()=>{l()}}),e.jsx(R,{children:o}),e.jsx(R,{children:e.jsx(L,{className:"kc-showData-btn",variant:"link","data-testid":"showDataBtn",onClick:l,children:a("showDataBtn")})}),s.type==="password"?e.jsx(R,{isActionCell:!0,children:e.jsx(L,{variant:"secondary","data-testid":"resetPasswordBtn",onClick:t,children:a("resetPasswordBtn")})}):e.jsx(R,{}),e.jsx(R,{isActionCell:!0,children:e.jsx(js,{isPlain:!0,position:ws.right,toggle:e.jsx(Cs,{onToggle:c}),isOpen:u,dropdownItems:[e.jsx(ye,{"data-testid":"deleteDropdownItem",component:"button",onClick:()=>{n(),c()},children:a("deleteBtn")},s.id)]})})]})},Lt=({userId:s,credential:t,isEditable:n,toggle:o})=>{const{t:a}=F("users"),{register:g,handleSubmit:l}=ne(),{addAlert:u,addError:c}=q(),h=async i=>{try{await b.users.updateCredentialLabel({id:s,credentialId:t.id},i.userLabel||""),u(a("updateCredentialUserLabelSuccess"),U.success),o()}catch(m){c("users:updateCredentialUserLabelError",m)}};return e.jsx(he,{isHorizontal:!0,className:"kc-form-userLabel",onSubmit:l(h),children:e.jsx(J,{fieldId:"kc-userLabel",className:"kc-userLabel-row",children:e.jsx("div",{className:"kc-form-group-userLabel",children:n?e.jsxs(e.Fragment,{children:[e.jsx(ce,{"data-testid":"userLabelFld",defaultValue:t.userLabel,className:"kc-userLabel","aria-label":a("userLabel"),...g("userLabel")}),e.jsxs("div",{className:"kc-userLabel-actionBtns",children:[e.jsx(L,{"data-testid":"editUserLabelAcceptBtn",variant:"link",className:"kc-editUserLabelAcceptBtn",type:"submit",icon:e.jsx(vs,{})}),e.jsx(L,{"data-testid":"editUserLabelCancelBtn",variant:"link",className:"kc-editUserLabel-cancelBtn",onClick:o,icon:e.jsx(Is,{})})]})]}):e.jsxs(e.Fragment,{children:[t.userLabel,e.jsx(L,{"aria-label":a("editUserLabel"),variant:"link",className:"kc-editUserLabel-btn",onClick:o,"data-testid":"editUserLabelBtn",icon:e.jsx(Ys,{})})]})})})})},Ft=()=>{const{t:s}=F("users"),{control:t}=ks();return e.jsx(J,{fieldId:"lifespan",label:s("lifespan"),isStack:!0,labelIcon:e.jsx(we,{helpText:s("clients-help:lifespan"),fieldLabelId:"lifespan"}),children:e.jsx(He,{name:"lifespan",defaultValue:Xe.lifespan,control:t,render:({field:n})=>e.jsx(ut,{value:n.value,units:["minute","hour","day"],onChange:n.onChange,menuAppendTo:"parent"})})})},Xe={actions:[],lifespan:43200},Rt=({userId:s,onClose:t})=>{const{t:n}=F("users"),o=ne({defaultValues:Xe}),{handleSubmit:a,control:g}=o,l=Ps({control:g,name:"actions"}),u=!Ge(l),{addAlert:c,addError:h}=q(),i=async({actions:m,lifespan:j})=>{if(!Ge(m))try{await b.users.executeActionsEmail({id:s,actions:m,lifespan:j}),c(n("credentialResetEmailSuccess"),U.success),t()}catch(p){h("users:credentialResetEmailError",p)}};return e.jsx($e,{variant:Ie.medium,titleKey:"users:credentialReset",open:!0,onCancel:t,toggleDialog:t,continueButtonLabel:"users:credentialResetConfirm",onConfirm:()=>{a(i)()},confirmButtonDisabled:!u,children:e.jsx(he,{id:"userCredentialsReset-form",isHorizontal:!0,"data-testid":"credential-reset-modal",children:e.jsxs(_e,{...o,children:[e.jsx(nt,{name:"actions",label:"resetActions",help:"clients-help:resetActions"}),e.jsx(Ft,{})]})})})},Et={password:"",passwordConfirmation:"",temporaryPassword:!0},At=({user:s,isResetPassword:t,refresh:n,onClose:o})=>{const{t:a}=F("users"),{register:g,control:l,formState:{isValid:u,errors:c},watch:h,handleSubmit:i,clearErrors:m,setError:j}=ne({defaultValues:Et,mode:"onChange"}),[p,P]=je(!0),f=h("password",""),E=h("passwordConfirmation",""),{addAlert:z,addError:W}=q(),[K,H]=te({titleKey:t?"users:resetPasswordConfirm":"users:setPasswordConfirm",messageKey:t?a("resetPasswordConfirmText",{username:s.username}):a("setPasswordConfirmText",{username:s.username}),continueButtonLabel:t?"users:resetPassword":"users:savePassword",continueButtonVariant:Z.danger,onConfirm:()=>i(S)()}),S=async({password:x,temporaryPassword:d})=>{try{await b.users.resetPassword({id:s.id,credential:{temporary:d,type:"password",value:x}});const B=(await b.users.getCredentials({id:s.id})).find($=>$.type==="password");B&&await b.users.updateCredentialLabel({id:s.id,credentialId:B.id},a("defaultPasswordLabel")),z(a(t?"resetCredentialsSuccess":"savePasswordSuccess"),U.success),n()}catch(k){W(t?"users:resetPasswordError":"users:savePasswordError",k)}o()},{onChange:D,...A}=g("password",{required:!0});return e.jsxs(e.Fragment,{children:[e.jsx(H,{}),e.jsx($e,{titleKey:t?a("resetPasswordFor",{username:s.username}):a("setPasswordFor",{username:s.username}),open:p,onCancel:o,toggleDialog:P,onConfirm:K,confirmButtonDisabled:!u,continueButtonLabel:"common:save",children:e.jsxs(he,{id:"userCredentials-form",isHorizontal:!0,className:"keycloak__user-credentials__reset-form",children:[e.jsx(J,{name:"password",label:a("password"),fieldId:"password",helperTextInvalid:a("common:required"),validated:c.password?G.error:G.default,isRequired:!0,children:e.jsx(Me,{"data-testid":"passwordField",id:"password",onChange:x=>{D(x),E!==x.currentTarget.value?j("passwordConfirmation",{message:a("confirmPasswordDoesNotMatch").toString()}):m("passwordConfirmation")},...A})}),e.jsx(J,{name:"passwordConfirmation",label:a(t?"resetPasswordConfirmation":"passwordConfirmation"),fieldId:"passwordConfirmation",helperTextInvalid:c.passwordConfirmation?.message,validated:c.passwordConfirmation?G.error:G.default,isRequired:!0,children:e.jsx(Me,{"data-testid":"passwordConfirmationField",id:"passwordConfirmation",...g("passwordConfirmation",{required:!0,validate:x=>x===f||a("confirmPasswordDoesNotMatch").toString()})})}),e.jsx(J,{label:a("common:temporaryPassword"),labelIcon:e.jsx(we,{helpText:a("temporaryPasswordHelpText"),fieldLabelId:"temporaryPassword"}),fieldId:"kc-temporaryPassword",children:e.jsx(He,{name:"temporaryPassword",defaultValue:!0,control:l,render:({field:x})=>e.jsx(Ts,{className:"kc-temporaryPassword",onChange:x.onChange,isChecked:x.value,label:a("common:on"),labelOff:a("common:off"),"aria-label":a("common:temporaryPassword")})})})]})})]})};const Nt=({user:s})=>{const{t}=F("users"),{addAlert:n,addError:o}=q(),[a,g]=y.useState(0),l=()=>g(a+1),[u,c]=y.useState(!1),[h,i]=y.useState(!1),[m,j]=y.useState([]),[p,P]=y.useState([]),[f,E]=y.useState({}),[z,W]=y.useState(!1),[K,H]=y.useState(),S=y.useRef(null),[D,A]=y.useState({draggedItemId:"",draggingToItemIndex:-1,dragging:!1,tempItemOrder:[""]});ue(()=>b.users.getCredentials({id:s.id}),r=>{j(r);const C=r.reduce((I,T)=>(I[T.type]=I[T.type]||[],I[T.type].push(T),I),Object.create(null)),w=Object.keys(C).map(I=>({key:I,value:C[I]}));P(w.map(I=>({...I,isExpanded:!1})))},[a]);const x=m.find(r=>r.type==="password"),d=()=>c(!u),k=()=>{i(!h)},B=()=>{W(!0),d()},[$,v]=te({titleKey:t("deleteCredentialsConfirmTitle"),messageKey:t("deleteCredentialsConfirm"),continueButtonLabel:t("common:delete"),continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.deleteCredential({id:s.id,credentialId:f.id}),n(t("deleteCredentialsSuccess"),U.success),g(r=>r+1)}catch(r){o("users:deleteCredentialsError",r)}}}),V=({credential:r})=>e.jsx(Dt,{credential:r,toggleDelete:()=>{E(r),$()},resetPassword:B,children:e.jsx(Lt,{credential:r,userId:s.id,isEditable:K?.status&&K.rowKey===r.id||!1,toggle:()=>{H({status:!K?.status,rowKey:r.id}),K?.status&&l()}})},r.id),ee=y.useMemo(()=>p.flatMap(r=>[r.value.map(({id:C})=>C).toString(),...r.isExpanded?r.value.map(C=>C.id):[]]),[p]),re=r=>{r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",r.currentTarget.id);const C=r.currentTarget.id;r.currentTarget.classList.add(xe.modifiers.ghostRow),r.currentTarget.setAttribute("aria-pressed","true"),A({...D,draggedItemId:C,dragging:!0})},fe=(r,C,w)=>{const I=r.indexOf(C);if(I===w)return r;const T=[...r];return T.splice(w,0,T.splice(I,1)[0]),T},ae=r=>{if(!S.current)return;const C=S.current,w=Array.from(C.children);w.every(({id:I},T)=>I===r[T])||(C.replaceChildren(),r.forEach(I=>{C.appendChild(w.find(({id:T})=>T===I))}))},Ye=()=>{S.current&&(Array.from(S.current.children).forEach(r=>{r.classList.remove(xe.modifiers.ghostRow),r.setAttribute("aria-pressed","false")}),A({...D,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},Je=r=>{ke(r)||(ae(ee),A({...D,draggingToItemIndex:-1}))},ke=r=>{if(!S.current)return!1;const C=S.current.getBoundingClientRect();return r.clientX>C.x&&r.clientXC.y&&r.clientY{ke(r)?Ze(D.draggedItemId,D.tempItemOrder):Ye()},Te=r=>{r.preventDefault();const w=r.target.closest("tr");if(!(!w||S.current&&!S.current.contains(w)||w.id===D.draggedItemId)){const I=w.id,T=Array.from(S.current?.children||[]).findIndex(M=>M.id===I);if(T===D.draggingToItemIndex)return;const Q=fe(ee,D.draggedItemId,T);ae(Q),A({...D,draggingToItemIndex:T,tempItemOrder:Q})}},Se=({target:r})=>{r instanceof HTMLTableRowElement&&(r.classList.remove(xe.modifiers.ghostRow),r.setAttribute("aria-pressed","false"),A({...D,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},Ze=async(r,C)=>{const w=ee.findIndex(M=>M===r),I=C.findIndex(M=>M===r),T=I-w,Q=r.split(",");try{for(const M of Q)for(let Fe=0;Fe0?await b.users.moveCredentialPositionDown({id:s.id,credentialId:M,newPreviousCredentialId:ee[I]}):await b.users.moveCredentialPositionUp({id:s.id,credentialId:M});l(),n(t("users:updatedCredentialMoveSuccess"),U.success)}catch(M){o("users:updatedCredentialMoveError",M)}},es=s.federationLink||s.origin,[ge,ss]=y.useState([]);if(ue(()=>b.users.getUserStorageCredentialTypes({id:s.id}),ss,[]),!ge)return e.jsx(ze,{});const De=ge.length>0,ts=p.length===0,rs=!s.credentials||s.credentials.length===0,Le=ts&&rs&&!De;return e.jsxs(e.Fragment,{children:[u&&e.jsx(At,{user:s,isResetPassword:z,refresh:l,onClose:()=>c(!1)}),h&&e.jsx(Rt,{userId:s.id,onClose:()=>i(!1)}),e.jsx(v,{}),s.email&&!Le&&e.jsx(L,{className:"kc-resetCredentialBtn-header",variant:"primary","data-testid":"credentialResetBtn",onClick:()=>i(!0),children:t("credentialResetBtn")}),m.length!==0&&x===void 0&&e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"kc-setPasswordBtn-tbl","data-testid":"setPasswordBtn-table",variant:"primary",form:"userCredentials-form",onClick:()=>{c(!0)},children:t("setPassword")}),e.jsx(Ss,{})]}),p.length!==0&&e.jsx(se,{variant:be.light,children:e.jsxs(Ue,{variant:"compact",children:[e.jsx(Ke,{children:e.jsxs(ie,{className:"kc-table-header",children:[e.jsx(_,{children:e.jsx(we,{helpText:t("users:userCredentialsHelpText"),fieldLabelId:"users:userCredentialsHelpTextLabel"})}),e.jsx(_,{"aria-hidden":"true"}),e.jsx(_,{children:t("type")}),e.jsx(_,{children:t("userLabel")}),e.jsx(_,{children:t("data")}),e.jsx(_,{"aria-hidden":"true"}),e.jsx(_,{"aria-hidden":"true"})]})}),e.jsx(Be,{ref:S,onDragOver:Te,onDrop:Te,onDragLeave:Je,children:p.map((r,C)=>e.jsxs(y.Fragment,{children:[e.jsxs(ie,{id:r.value.map(({id:w})=>w).toString(),draggable:p.length>1,onDrop:Pe,onDragEnd:Se,onDragStart:re,children:[e.jsx(R,{className:p.length===1?"one-row":"",draggableRow:{id:`draggable-row-${r.value.map(({id:w})=>w)}`}}),r.value.length>1?e.jsx(R,{className:"kc-expandRow-btn",expand:{rowIndex:C,isExpanded:r.isExpanded,onToggle:(w,I)=>{const T=p.map((Q,M)=>M===I?{...Q,isExpanded:!Q.isExpanded}:Q);P(T)}}}):e.jsx(R,{}),e.jsx(R,{dataLabel:`columns-${r.key}`,className:"kc-notExpandableRow-credentialType","data-testid":"credentialType",children:Ae(r.key)}),r.value.length<=1&&r.value.map(w=>e.jsx(V,{credential:w},w.id))]}),r.isExpanded&&r.value.map(w=>e.jsxs(ie,{id:w.id,draggable:!0,onDrop:Pe,onDragEnd:Se,onDragStart:re,children:[e.jsx(R,{}),e.jsx(R,{className:"kc-draggable-dropdown-type-icon",draggableRow:{id:`draggable-row-${r.value.map(({id:I})=>I)}`}}),e.jsx(R,{dataLabel:`child-columns-${w.id}`,className:"kc-expandableRow-credentialType",children:Ae(w.type)}),e.jsx(V,{credential:w})]},w.id))]},r.key))})]})}),es&&De&&e.jsx(se,{variant:be.light,children:e.jsxs(Ue,{variant:"compact",children:[e.jsx(Ke,{children:e.jsxs(ie,{children:[e.jsx(_,{children:t("type")}),e.jsx(_,{children:t("providedBy")}),e.jsx(_,{"aria-hidden":"true"})]})}),e.jsx(Be,{children:ge.map(r=>e.jsxs(ie,{children:[e.jsx(R,{children:e.jsx("b",{children:r})}),e.jsx(R,{children:e.jsx(it,{user:s})}),r==="password"&&e.jsx(R,{modifier:"fitContent",children:e.jsx(L,{variant:"secondary",onClick:d,children:t("setPassword")})})]},r))})]})}),Le&&e.jsx(ve,{hasIcon:!0,message:t("noCredentials"),instructions:t("noCredentialsText"),primaryActionText:t("setPassword"),onPrimaryAction:d,secondaryActions:s.email?[{text:t("credentialResetBtn"),onClick:k,type:Z.link}]:void 0})]})},Ut=({user:s})=>{const{t}=F("users"),{addAlert:n,addError:o}=q(),[a,g]=y.useState(0),l=()=>g(a+1),[u,c]=y.useState([]),[h,i]=y.useState(!0),[m,j]=y.useState([]),[p,P]=y.useState(!1),{enabled:f}=Ds(),{hasAccess:E}=We(),z=E("manage-users"),W=d=>qe(d,k=>k.path?.toUpperCase()),K=async(d,k,B)=>{const $={first:d,max:k},v=B||"";v&&($.search=v);const V=await b.users.listGroups({...$,id:s.id});j([...V]);const ee=[];return h||V.forEach(re=>{const fe=re.path?.substring(1).split("/").slice(0,-1)||[];ee.push(...fe.map(ae=>({name:ae,path:re.path?.substring(0,re.path.indexOf(ae)+ae.length)})))}),W(Fs([...V,...ee],"path"))},H=()=>{P(!p)},[S,D]=te({titleKey:t("leaveGroup",{count:u.length,name:u[0]?.name}),messageKey:t("leaveGroupConfirmDialog",{count:u.length,groupname:u[0]?.name,username:s.username}),continueButtonLabel:"leave",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await Promise.all(u.map(d=>b.users.delFromGroup({id:s.id,groupId:d.id}))),n(t("removedGroupMembership"),U.success)}catch(d){o("users:removedGroupMembershipError",d)}l()}}),A=d=>{c(d),S()},x=async d=>{try{await Promise.all(d.map(k=>b.users.addToGroup({id:s.id,groupId:k.id}))),n(t("addedGroupMembership"),U.success)}catch(k){o("users:addedGroupMembershipError",k)}l()};return e.jsxs(e.Fragment,{children:[e.jsx(D,{}),p&&e.jsx(mt,{id:s.id,type:"selectMany",text:{title:t("joinGroupsFor",{username:s.username}),ok:"users:join"},canBrowse:z,onClose:()=>P(!1),onConfirm:async(d=[])=>{await x(d),P(!1)}}),e.jsx(me,{loader:K,className:"keycloak_user-section_groups-table",isPaginated:!0,ariaLabelKey:"roles:roleList",searchPlaceholderKey:"groups:searchGroup",canSelectAll:!0,onSelect:d=>c(h?d:wt(d,m,"id")),isRowDisabled:d=>!h&&m.every(k=>k.id!==d.id),toolbarItem:e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"kc-join-group-button",onClick:H,"data-testid":"add-group-button",isDisabled:!s.access?.manageGroupMembership,children:t("joinGroup")}),e.jsx(ht,{label:t("directMembership"),id:"kc-direct-membership-checkbox",onChange:()=>{i(!h),l()},isChecked:h,className:"direct-membership-check"},"direct-membership-check"),e.jsx(L,{onClick:()=>A(u),"data-testid":"leave-group-button",variant:"link",isDisabled:u.length===0,children:t("leave")}),f&&e.jsx(Ls,{"aria-label":"Basic popover",position:"bottom",bodyContent:e.jsx("div",{children:t("whoWillAppearPopoverText")}),children:e.jsx(L,{variant:"link",className:"kc-who-will-appear-button",icon:e.jsx(ft,{}),children:t("whoWillAppearLinkText")},"who-will-appear-button")})]}),columns:[{name:"groupMembership",displayKey:"users:groupMembership",cellRenderer:d=>d.name||"",cellFormatters:[O()],transforms:[N(40)]},{name:"path",displayKey:"users:path",cellRenderer:d=>e.jsx(pt,{group:d}),transforms:[N(45)]},{name:"",cellRenderer:d=>m.some(B=>B.id===d.id)||m.length===0||h?e.jsx(L,{"data-testid":`leave-${d.name}`,onClick:()=>A([d]),variant:"link",isDisabled:!s.access?.manageGroupMembership,children:t("leave")}):"",cellFormatters:[O()],transforms:[N(20)]}],emptyState:e.jsx(ve,{hasIcon:!0,message:t("noGroups"),instructions:t("noGroupsText"),primaryActionText:t("joinGroup"),onPrimaryAction:H})},a)]})},Kt=({userId:s,federatedId:t,onClose:n,onRefresh:o})=>{const{t:a}=F("users"),{addAlert:g,addError:l}=q(),{register:u,handleSubmit:c,formState:{isValid:h,errors:i}}=ne({mode:"onChange"}),m=async j=>{try{await b.users.addToFederatedIdentity({id:s,federatedIdentityId:t,federatedIdentity:j}),g(a("users:idpLinkSuccess"),U.success),n(),o()}catch(p){l("users:couldNotLinkIdP",p)}};return e.jsx(Qe,{variant:Ie.small,title:a("users:linkAccountTitle",{provider:oe(t)}),onClose:n,actions:[e.jsx(L,{"data-testid":"confirm",variant:"primary",type:"submit",form:"group-form",isDisabled:!h,children:a("link")},"confirm"),e.jsx(L,{"data-testid":"cancel",variant:Z.link,onClick:n,children:a("common:cancel")},"cancel")],isOpen:!0,children:e.jsxs(he,{id:"group-form",onSubmit:c(m),children:[e.jsx(J,{label:a("users:identityProvider"),fieldId:"identityProvider",children:e.jsx(ce,{id:"identityProvider","data-testid":"idpNameInput",value:oe(t),isReadOnly:!0})}),e.jsx(J,{label:a("users:userID"),fieldId:"userID",helperText:a("users-help:userIdHelperText"),helperTextInvalid:a("common:required"),validated:i.userId?G.error:G.default,isRequired:!0,children:e.jsx(ce,{id:"userID","data-testid":"userIdInput",validated:i.userId?G.error:G.default,autoFocus:!0,...u("userId",{required:!0})})}),e.jsx(J,{label:a("users:username"),fieldId:"username",helperText:a("users-help:usernameHelperText"),helperTextInvalid:a("common:required"),validated:i.userName?G.error:G.default,isRequired:!0,children:e.jsx(ce,{id:"username","data-testid":"usernameInput",validated:i.userName?G.error:G.default,...u("userName",{required:!0})})})]})})},Bt=({userId:s})=>{const[t,n]=y.useState(0),[o,a]=y.useState(""),[g,l]=y.useState(!1),{realm:u}=pe(),{addAlert:c,addError:h}=q(),{t:i}=F("users"),m=()=>n(new Date().getTime()),j=Rs().identityProviders,p=async()=>{const x=await b.identityProviders.find(),d=await b.users.listFederatedIdentities({id:s});for(const k of d)k.providerId=x.find(B=>B.alias===k.identityProvider)?.providerId;return d},P=async()=>(await b.realms.findOne({realm:u})).identityProviders,f=async()=>p(),E=async()=>{const x=(await p()).map(d=>d.identityProvider);return(await P())?.filter(d=>!x.includes(d.alias))},[z,W]=te({titleKey:i("users:unlinkAccountTitle",{provider:oe(o)}),messageKey:i("users:unlinkAccountConfirm",{provider:oe(o)}),continueButtonLabel:"users:unlink",continueButtonVariant:Z.primary,onConfirm:async()=>{try{await b.users.delFromFederatedIdentity({id:s,federatedIdentityId:o}),c(i("users:idpUnlinkSuccess"),U.success),m()}catch(x){h("common:mappingDeletedError",x)}}}),K=x=>e.jsx(As,{to:Ns({realm:u,providerId:x.providerId,alias:x.identityProvider,tab:"settings"}),children:oe(x.identityProvider)}),H=x=>{const d=j?.find(k=>k.id===x.identityProvider)?.groupName;return e.jsx(Ne,{color:d==="Social"?"blue":"orange",children:i(d==="Social"?"users:idpType.social":"users:idpType.custom")})},S=x=>{const d=j?.find(k=>k.id===x.providerId)?.groupName;return e.jsx(Ne,{color:d==="User-defined"?"orange":"blue",children:d==="User-defined"?"Custom":d==="Social"?i("users:idpType.social"):d})},D=x=>e.jsx(L,{variant:"link",onClick:()=>{a(x.identityProvider),z()},children:i("unlinkAccount")}),A=x=>e.jsx(L,{variant:"link",onClick:()=>{a(x.alias),l(!0)},children:i("linkAccount")});return e.jsxs(e.Fragment,{children:[g&&e.jsx(Kt,{userId:s,federatedId:o,onClose:()=>l(!1),onRefresh:m}),e.jsx(W,{}),e.jsxs(se,{variant:"light",className:"pf-u-p-0",children:[e.jsxs(Oe,{title:i("linkedIdPs"),className:"kc-linked-idps",children:[e.jsx(de,{children:e.jsx(le,{className:"kc-available-idps-text",children:i("linkedIdPsText")})}),e.jsx(me,{loader:f,isPaginated:!1,ariaLabelKey:"users:LinkedIdPs",className:"kc-linked-IdPs-table",columns:[{name:"identityProvider",displayKey:"common:name",cellFormatters:[O()],cellRenderer:K,transforms:[N(20)]},{name:"type",displayKey:"common:type",cellFormatters:[O()],cellRenderer:H,transforms:[N(10)]},{name:"userId",displayKey:"users:userID",cellFormatters:[O()],transforms:[N(30)]},{name:"userName",displayKey:"users:username",cellFormatters:[O()],transforms:[N(20)]},{name:"",cellFormatters:[O()],cellRenderer:D,transforms:[N(20)]}],emptyState:e.jsx(de,{className:"kc-no-providers-text",children:e.jsx(le,{children:i("users:noProvidersLinked")})})},t)]}),e.jsxs(Oe,{className:"kc-available-idps",title:i("availableIdPs"),children:[e.jsx(de,{children:e.jsx(le,{className:"kc-available-idps-text",children:i("availableIdPsText")})}),e.jsx(me,{loader:E,isPaginated:!1,ariaLabelKey:"users:LinkedIdPs",className:"kc-linked-IdPs-table",columns:[{name:"alias",displayKey:"common:name",cellFormatters:[O(),Es()],transforms:[N(20)]},{name:"type",displayKey:"common:type",cellFormatters:[O()],cellRenderer:S,transforms:[N(60)]},{name:"",cellFormatters:[O()],cellRenderer:A}],emptyState:e.jsx(de,{className:"kc-no-providers-text",children:e.jsx(le,{children:i("users:noAvailableIdentityProviders")})})},t)]})]})]})},Mt=({id:s,name:t})=>{const{t:n}=F("users"),{addAlert:o,addError:a}=q(),g=async l=>{try{const u=l.filter(c=>c.client===void 0).map(c=>c.role).flat();await b.users.addRealmRoleMappings({id:s,roles:u}),await Promise.all(l.filter(c=>c.client!==void 0).map(c=>b.users.addClientRoleMappings({id:s,clientUniqueId:c.client.id,roles:[c.role]}))),o(n("roleMappingUpdatedSuccess"),U.success)}catch(u){a("clients:roleMappingUpdatedError",u)}};return e.jsx(gt,{name:t,id:s,type:"users",save:g})},Ot=()=>{const{id:s}=Ce(),{realm:t}=pe(),{t:n}=F("sessions"),o=()=>b.users.listSessions({id:s,realm:t});return e.jsx(se,{variant:"light",className:"pf-u-p-0",children:e.jsx(tt,{loader:o,hiddenColumns:["username","type"],emptyInstructions:n("noSessionsForUser"),logoutUser:s})})};function Qr(){const{realm:s}=pe(),{id:t}=Ce(),{t:n}=F("users"),[o,a]=y.useState(),[g,l]=y.useState(),[u,c]=y.useState(0),h=()=>c(i=>i+1);return ue(async()=>{const[i,m,j]=await Promise.all([b.users.findOne({id:t}),b.realms.findOne({realm:s}),b.attackDetection.findOne({id:t})]);if(!i||!m||!j)throw new Error(n("common:notFound"));const p=m.bruteForceProtected,P=p&&j.disabled;return{user:i,bruteForced:{isBruteForceProtected:p,isLocked:P}}},({user:i,bruteForced:m})=>{a(i),l(m)},[u]),!o||!g?e.jsx(ze,{}):e.jsx(Gt,{user:o,bruteForced:g,refresh:h})}const Gt=({user:s,bruteForced:t,refresh:n})=>{const{t:o}=F("users"),{realm:a}=pe(),{addAlert:g,addError:l}=q(),u=Us(),{hasAccess:c}=We(),h=ne({mode:"onChange",defaultValues:s}),[i,m]=y.useState();ue(()=>b.realms.findOne({realm:a}),v=>{if(!v)throw new Error(o("common:notFound"));m(v)},[]);const p=Hs()(_s.DeclarativeUserProfile)&&i?.attributes?.userProfileEnabled==="true",P=v=>Bs({realm:a,id:s.id,tab:v}),f=v=>Os(P(v)),E=f("settings"),z=f("attributes"),W=f("credentials"),K=f("role-mapping"),H=f("groups"),S=f("consents"),D=f("identity-provider-links"),A=f("sessions");zs(()=>h.reset(s),[s]);const x=async v=>{try{await b.users.update({id:s.id},{...v,username:v.username?.trim(),attributes:{...s.attributes,...v.attributes}}),g(o("userSaved"),U.success),n()}catch(V){dt(V)?l(lt(V),V):l("users:userCreateError",V)}},[d,k]=te({titleKey:"users:deleteConfirm",messageKey:"users:deleteConfirmCurrentUser",continueButtonLabel:"common:delete",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.del({id:s.id}),g(o("userDeletedSuccess"),U.success),u(Ks({realm:a}))}catch(v){l("users:userDeletedError",v)}}}),[B,$]=te({titleKey:"users:impersonateConfirm",messageKey:"users:impersonateConfirmDialog",continueButtonLabel:"users:impersonate",onConfirm:async()=>{try{const v=await b.users.impersonation({id:s.id},{user:s.id,realm:a});v.sameRealm?window.location=v.redirect:window.open(v.redirect,"_blank")}catch(v){l("users:impersonateError",v)}}});return e.jsxs(e.Fragment,{children:[e.jsx($,{}),e.jsx(k,{}),e.jsx(Gs,{titleKey:s.username,className:"kc-username-view-header",divider:!1,dropdownItems:[e.jsx(ye,{isDisabled:!s.access?.impersonate,onClick:()=>B(),children:o("impersonate")},"impersonate"),e.jsx(ye,{isDisabled:!s.access?.manage,onClick:()=>d(),children:o("common:delete")},"delete")],onToggle:v=>x({...s,enabled:v}),isEnabled:s.enabled}),e.jsx(se,{variant:"light",className:"pf-u-p-0",children:e.jsx(qs,{children:e.jsx(_e,{...h,children:e.jsxs(Ms,{isBox:!0,mountOnEnter:!0,defaultLocation:P("settings"),children:[e.jsx(X,{"data-testid":"user-details-tab",title:e.jsx(Y,{children:o("common:details")}),...E,children:e.jsx(se,{variant:"light",children:e.jsx(ot,{save:x,user:s,bruteForce:t,realm:i})})}),!p&&e.jsx(X,{"data-testid":"attributes",title:e.jsx(Y,{children:o("common:attributes")}),...z,children:e.jsx(Pt,{user:s})}),e.jsx(X,{"data-testid":"credentials",isHidden:!s.access?.view,title:e.jsx(Y,{children:o("common:credentials")}),...W,children:e.jsx(Nt,{user:s})}),e.jsx(X,{"data-testid":"role-mapping-tab",isHidden:!s.access?.mapRoles,title:e.jsx(Y,{children:o("roleMapping")}),...K,children:e.jsx(Mt,{id:s.id,name:s.username})}),c("query-groups")&&e.jsx(X,{"data-testid":"user-groups-tab",title:e.jsx(Y,{children:o("common:groups")}),...H,children:e.jsx(Ut,{user:s})}),e.jsx(X,{"data-testid":"user-consents-tab",title:e.jsx(Y,{children:o("consents")}),...S,children:e.jsx(Tt,{})}),c("view-identity-providers")&&e.jsx(X,{"data-testid":"identity-provider-links-tab",title:e.jsx(Y,{children:o("identityProviderLinks")}),...D,children:e.jsx(Bt,{userId:s.id})}),e.jsx(X,{"data-testid":"user-sessions-tab",title:e.jsx(Y,{children:o("sessions")}),...A,children:e.jsx(Ot,{})})]})})})})]})};export{Qr as default};
//# sourceMappingURL=EditUser-abefe270.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy