theme.keycloak.v2.admin.resources.assets.AddRoleMappingModal-DW8o4W0z.js Maven / Gradle / Ivy
import{jsxs as B,Fragment as T,jsx as l}from"react/jsx-runtime";import{useState as R}from"react";import{cq as j,u as _,a as G,f as W,B as z,k as X,a2 as D,bS as Y,i as x,bK as Z,aC as U,bG as ee,b3 as te,s as se,M as ne,q as ie,J as le,K as oe,N as ae,D as re}from"./main-C7ps2lmX.js";import{L as H}from"./PaginatingTableToolbar-Cjsz5Jh4.js";import{K as J}from"./KeycloakDataTable-DbY4la1D.js";import{u as ce}from"./ConfirmDialog-hx7XKLbN.js";import{F as de}from"./filter-icon-DO0QNij3.js";import{T as pe}from"./Td-D2hVFK0Z.js";const V={delete:["delClientRoleMappings","delRealmRoleMappings"],listEffective:["listRoleMappings","listCompositeRealmRoleMappings","listCompositeClientRoleMappings"],listAvailable:["listAvailableClientRoleMappings","listAvailableRealmRoleMappings"]},N={delete:["delClientScopeMappings","delRealmScopeMappings"],listEffective:["listScopeMappings","listCompositeRealmScopeMappings","listCompositeClientScopeMappings"],listAvailable:["listAvailableClientScopeMappings","listAvailableRealmScopeMappings"]},E={groups:V,users:V,clientScopes:N,clients:N,roles:{delete:["delCompositeRoles","delCompositeRoles"],listEffective:["getCompositeRoles","getCompositeRoles","getCompositeRolesForClient"],listAvailable:["listRoles","find"]}},me=(t,e)=>t[e],S=(t,e,n,...i)=>me(t,e)[n](...i),ge=(t,e,n,i)=>i.map(o=>{const a={id:o.role.id,name:o.role.name},s=E[e]?.delete[o.client?0:1];return S(t,e,s,{id:n,clientUniqueId:o.client?.id,client:o.client?.id,roles:[a]},[a])}),fe=async(t,e,n)=>{const i=E[e].listEffective[0],o=S(t,e,i,{id:n});if(e!=="roles")return o;const a=await o;return{clientMappings:await Promise.all(a.filter(m=>m.clientRole).map(async m=>{const r=await t.clients.findOne({id:m.containerId});return m.containerId=r?.clientId,{...r,mappings:[m]}})),realmMappings:a.filter(m=>!m.clientRole)}},ue=async(t,e,n)=>{const i=E[e].listEffective[1];if(e!=="roles")return(await S(t,e,i,{id:n})).map(s=>({role:s}));const o=await S(t,e,i,{id:n}),a=await Promise.all(o.filter(s=>s.composite).map(s=>S(t,e,i,{id:s.id})));return[...o,...a.flat()].map(s=>({role:s}))},Re=async(t,e,n)=>{const i=E[e].listAvailable[1];return(await S(t,e,i,n)).map(o=>({role:o}))},q=async(t,{id:e,type:n,first:i,max:o,search:a,endpoint:s})=>j(t,`/ui-ext/${s}/${n}/${e}`,{first:(i||0).toString(),max:(o||10).toString(),search:a||""}),he=(t,e)=>q(t,{...e,endpoint:"available-roles"}),ye=(t,e)=>q(t,{...e,endpoint:"effective-roles"}),Be=(t,e)=>j(t,"ui-ext/brute-force-user",e),Te=(t,e)=>q(t,{...e,endpoint:"authentication-management"}),Ce=(t,e,n)=>[...n?t.map(i=>({...i,role:{...i.role,isInherited:!1}})):e.map(i=>({...i,role:{...i.role,isInherited:t.find(o=>o.role.id===i.role.id)===void 0}}))],Q=({role:t,client:e})=>B(T,{children:[e?.clientId&&l(ee,{isRead:!0,className:"keycloak-admin--role-mapping__client-name",children:e.clientId}),t.name]}),De=({name:t,id:e,type:n,isManager:i=!0,save:o})=>{const{adminClient:a}=_(),{t:s}=G(),{addAlert:m,addError:r}=W(),[M,F]=R(0),u=()=>F(M+1),[h,f]=R(!0),[k,C]=R(!1),[b,y]=R([]),L=async d=>{await o(d),u()},K=async()=>{let d=[],v=[];h||(d=await ue(a,n,e),v=(await ye(a,{type:n,id:e})).map(c=>({client:{clientId:c.client,id:c.clientId},role:{id:c.id,name:c.role,description:c.description}})));const p=await fe(a,n,e),w=p.realmMappings?.map(c=>({role:c}))||[],A=Object.values(p.clientMappings||{}).map(c=>c.mappings.map(g=>({client:{clientId:c.client,...c},role:g}))).flat();return[...Ce([...w,...A],[...v,...d],h)]},[I,$]=ce({titleKey:"removeMappingTitle",messageKey:s("removeMappingConfirm",{count:b.length}),continueButtonLabel:"remove",continueButtonVariant:z.danger,onCancel:()=>{y([]),u()},onConfirm:async()=>{try{await Promise.all(ge(a,n,e,b)),m(s("clientScopeRemoveSuccess"),X.success),y([]),u()}catch(d){r("clientScopeRemoveError",d)}}});return B(T,{children:[k&&l(ve,{id:e,type:n,name:t,onAssign:L,onClose:()=>C(!1)}),l($,{}),l(J,{"data-testid":"assigned-roles",loader:K,canSelectAll:!0,onSelect:d=>y(d),searchPlaceholderKey:"searchByName",ariaLabelKey:"clientScopeList",isRowDisabled:d=>d.role.isInherited||!1,toolbarItem:B(T,{children:[l(D,{children:l(Y,{label:s("hideInheritedRoles"),id:"hideInheritedRoles","data-testid":"hideInheritedRoles",isChecked:h,onChange:(d,v)=>{f(v),u()}})}),i&&B(T,{children:[l(D,{children:l(x,{"data-testid":"assignRole",onClick:()=>C(!0),children:s("assignRole")})}),l(D,{children:l(x,{variant:"link","data-testid":"unAssignRole",onClick:I,isDisabled:b.length===0,children:s("unAssignRole")})})]})]}),actions:i?[{title:s("unAssignRole"),onRowClick:async d=>(y([d]),I(),!1)}]:[],columns:[{name:"role.name",displayKey:s("name"),transforms:[pe(30)],cellRenderer:Q},{name:"role.isInherited",displayKey:s("inherent"),cellFormatters:[Z(),U()]},{name:"role.description",displayKey:s("description"),cellFormatters:[U()]}],emptyState:l(H,{message:s(`noRoles-${n}`),instructions:s(`noRolesInstructions-${n}`),primaryActionText:s("assignRole"),onPrimaryAction:()=>C(!0),secondaryActions:[{text:s("showInheritedRoles"),onClick:()=>{f(!1),u()}}]})},`${e}${M}`)]})},ve=({id:t,name:e,type:n,isRadio:i=!1,isLDAPmapper:o,onAssign:a,onClose:s})=>{const{adminClient:m}=_(),{t:r}=G(),{hasAccess:M}=te(),F=M("view-realm")||M("query-users"),[u,h]=R(!1),[f,k]=R("clients"),[C,b]=R([]),[y,L]=R(0),K=()=>L(y+1),I=se(),$=({role:{name:p}})=>p?.toUpperCase(),d=async(p,w,A)=>{const c={first:p,max:w};A&&(c.search=A);const g=await Re(m,n,{...c,id:t});return I(g,$).map(O=>({role:O.role,id:O.role.id}))},v=async(p,w,A)=>{const c=await he(m,{id:t,type:n,first:p||0,max:w||10,search:A});return I(c.map(g=>({client:{clientId:g.client,id:g.clientId},role:{id:g.id,name:g.role,description:g.description},id:g.id})),({client:{clientId:g},role:{name:P}})=>`${g}${P}`)};return l(ne,{variant:ie.large,title:o?r("assignRole"):r("assignRolesTo",{client:e}),isOpen:!0,onClose:s,actions:[l(x,{"data-testid":"assign",isDisabled:C.length===0,variant:"primary",onClick:()=>{a(C),s()},children:r("assign")},"confirm"),l(x,{"data-testid":"cancel",variant:"link",onClick:s,children:r("cancel")},"cancel")],children:l(J,{onSelect:p=>b([...p]),searchPlaceholderKey:"searchByRoleName",isPaginated:!(f==="roles"&&n!=="roles"),searchTypeComponent:F&&l(D,{children:l(le,{onOpenChange:p=>h(p),onSelect:()=>{k(f==="roles"?"clients":"roles"),h(!1),K()},toggle:p=>l(oe,{"data-testid":"filter-type-dropdown",ref:p,onClick:()=>h(!u),icon:l(de,{}),children:r(f==="roles"?"filterByRoles":"filterByClients")}),isOpen:u,children:l(ae,{children:l(re,{"data-testid":f,children:r(f==="roles"?"filterByClients":"filterByRoles")},"filter-type")})})}),canSelectAll:!0,isRadio:i,loader:f==="roles"?d:v,ariaLabelKey:"roles",columns:[{name:"name",cellRenderer:Q},{name:"role.description",displayKey:"description"}],emptyState:l(H,{message:r("noRoles"),instructions:r("noRealmRolesToAssign"),secondaryActions:[{text:r("filterByClients"),onClick:()=>{k("clients"),K()}}]})},y)})};export{ve as A,De as R,Q as S,Be as a,Te as f};
//# sourceMappingURL=AddRoleMappingModal-DW8o4W0z.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy