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

theme.keycloak.v2.admin.resources.assets.PermissionDetails-D65ccxxC.js Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
import{jsx as s,jsxs as v,Fragment as H}from"react/jsx-runtime";import{a as N}from"./policyRepresentation-LeM_FTje.js";import{u as G,a as _,aj as J,w as $,ae as W,b5 as Q,b6 as B,U as X,g as Y,d as Z,f as ee,b3 as se,B as k,k as j,bB as z,ab as ie,a3 as oe,b2 as ae,D as te,P as re,F as ne,y as E,O as le,ac as C,ad as F,a4 as ce,aq as U,R as pe,A as de,i as K,L as me,b7 as ue}from"./main-C7ps2lmX.js";import{useState as h,useRef as fe}from"react";import{u as he}from"./ConfirmDialog-hx7XKLbN.js";import{F as ge}from"./FormAccess-DyLNkc18.js";import{V as ye}from"./ViewHeader-B7eeFzFA.js";import{u as be}from"./useParams-B67lSY02.js";import{R as M}from"./NewPolicyDialog-DySSrR_B.js";import"react-dom";import"./copy-icon-ACZmDH8e.js";import"./useToggle-K3Kx99tM.js";import"./Td-D2hVFK0Z.js";import"./grip-vertical-icon-BxF7V59o.js";import"./ClientSelect-B9UqjyP6.js";import"./ClientScopeTypes-BnGjMgG5.js";import"./PaginatingTableToolbar-Cjsz5Jh4.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./EmptyStateActions-DWNUFByn.js";import"./KeycloakDataTable-DbY4la1D.js";import"./_baseFlatten-eIEJR-AJ.js";import"./utils-DeGqqWSp.js";import"./filter-icon-DO0QNij3.js";import"./GroupPickerDialog-C09EjRTA.js";import"./DataListItemRow-BC0LurDd.js";import"./CodeEditor-C-nZkUJx.js";import"./SwitchControl-C_9Y74oV.js";import"./AddRoleMappingModal-DW8o4W0z.js";import"./DatePicker-DTJHSI7E.js";import"./FlexItem-BzZfUnQ1.js";import"./debounce-DTNSlfWG.js";const Se=({clientId:c,resourceId:e,preSelected:m})=>{const{adminClient:g}=G(),{t:P}=_(),{control:R,getValues:O,setValue:A,formState:{errors:r}}=J(),[u,n]=h([]),[i,y]=h([]),[d,f]=h(""),[b,D]=h(!1),S=fe(!0),q=O("scopes"),w=l=>l.map(t=>s(X,{value:t,children:t.name},t.id));return $(async()=>e?(e&&!S.current&&A("scopes",[]),S.current=!1,g.clients.listScopesByResource({id:c,resourceName:e})):g.clients.listAllScopes(Object.assign({id:c,deep:!1},d===""?null:{name:d})),l=>{n(l),d||y(l.filter(t=>q?.includes(t.id)))},[e,d]),s(W,{name:"scopes",defaultValue:m?[m]:[],control:R,rules:{validate:l=>l.length>0},render:({field:l})=>s(Q,{toggleId:"scopes",variant:B.typeaheadMulti,onToggle:t=>D(t),onFilter:t=>(f(t),w(u)),onClear:()=>{l.onChange([]),f("")},selections:i.map(t=>t.name),onSelect:t=>{const T=typeof t=="string"?i.find(p=>p.name===t):t,x=i.find(p=>p.id===T.id)?i.filter(p=>p.id!==T.id):[...i,T];l.onChange(x.map(p=>p.id)),y(x),f("")},isOpen:b,"aria-labelledby":P("scopes"),validated:r.scopes?"error":"default",isDisabled:!!m,typeAheadAriaLabel:P("scopes"),children:w(u)})})};function Xe(){const{adminClient:c}=G(),{t:e}=_(),m=Y({mode:"onChange"}),{control:g,reset:P,formState:{errors:R},handleSubmit:O}=m,A=Z(),{id:r,realm:u,permissionType:n,permissionId:i,selectedId:y}=be(),{addAlert:d,addError:f}=ee(),[b,D]=h(),[S,q]=h(!1),{hasAccess:w}=se(),l=!w("manage-authorization");$(async()=>{if(!i)return{};const[o,a,L,V]=await Promise.all([c.clients.findOnePermission({id:r,type:n,permissionId:i}),c.clients.getAssociatedResources({id:r,permissionId:i}),c.clients.getAssociatedPolicies({id:r,permissionId:i}),c.clients.getAssociatedScopes({id:r,permissionId:i})]);if(!o)throw new Error(e("notFound"));return{permission:o,resources:a.map(I=>I._id),policies:L.map(I=>I.id),scopes:V.map(I=>I.id)}},({permission:o,resources:a,policies:L,scopes:V})=>{P({...o,resources:a,policies:L,scopes:V}),o&&"resourceType"in o&&q(!!o.resourceType),D({...o,resources:a,policies:L})},[]);const t=async o=>{try{if(i)await c.clients.updatePermission({id:r,type:n,permissionId:i},o);else{const a=await c.clients.createPermission({id:r,type:n},o);D(a),A(ue({realm:u,id:r,permissionType:n,permissionId:a.id}))}d(e((i?"update":"create")+"PermissionSuccess"),j.success)}catch(a){f("permissionSaveError",a)}},[T,x]=he({titleKey:"deletePermission",messageKey:e("deletePermissionConfirm",{permission:b?.name}),continueButtonVariant:k.danger,continueButtonLabel:"confirm",onConfirm:async()=>{try{await c.clients.delPermission({id:r,type:n,permissionId:i}),d(e("permissionDeletedSuccess"),j.success),A(z({realm:u,clientId:r,tab:"permissions"}))}catch(o){f("permissionDeletedError",o)}}}),p=ie({control:g,name:"resources",defaultValue:[]});return b?v(H,{children:[s(x,{}),s(ye,{titleKey:i?b.name:`create${ae(n)}BasedPermission`,dropdownItems:i?[s(te,{"data-testid":"delete-resource",isDisabled:l,onClick:()=>T(),children:e("delete")},"delete")]:void 0}),s(re,{variant:"light",children:s(ge,{isHorizontal:!0,role:"manage-authorization",onSubmit:O(t),children:v(ne,{...m,children:[s(E,{name:"name",label:e("name"),labelIcon:e("permissionName"),rules:{required:e("required")}}),s(le,{name:"description",label:e("description"),labelIcon:e("permissionDescription"),rules:{maxLength:{value:255,message:e("maxLength",{length:255})}}}),s(C,{label:e("applyToResourceTypeFlag"),fieldId:"applyToResourceTypeFlag",labelIcon:s(F,{helpText:e("applyToResourceTypeFlagHelp"),fieldLabelId:"applyToResourceTypeFlag"}),children:s(ce,{id:"applyToResourceTypeFlag",name:"applyToResourceTypeFlag",label:e("on"),labelOff:e("off"),isChecked:S,onChange:(o,a)=>q(a),"aria-label":e("applyToResourceTypeFlag")})}),S?s(E,{name:"resourceType",label:e("resourceType"),labelIcon:e("resourceTypeHelp"),rules:{required:{value:n==="scope",message:e("required")}}}):v(C,{label:e("resource"),fieldId:"resources",labelIcon:s(F,{helpText:e("permissionResources"),fieldLabelId:"resources"}),isRequired:n!=="scope",children:[s(M,{name:"resources",clientId:r,permissionId:i,preSelected:n==="scope"?void 0:y,variant:n==="scope"?B.typeahead:B.typeaheadMulti,isRequired:n!=="scope"}),R.resources&&s(U,{message:e("required")})]}),n==="scope"&&v(C,{label:e("authorizationScopes"),fieldId:"scopes",labelIcon:s(F,{helpText:e("permissionScopesHelp"),fieldLabelId:"scopesSelect"}),isRequired:!0,children:[s(Se,{clientId:r,resourceId:p?.[0],preSelected:y}),R.scopes&&s(U,{message:e("required")})]}),s(C,{label:e("policies"),fieldId:"policies",labelIcon:s(F,{helpText:e("permissionPoliciesHelp"),fieldLabelId:"policies"}),children:s(M,{name:"policies",clientId:r,permissionId:i})}),s(C,{label:e("decisionStrategy"),labelIcon:s(F,{helpText:e("permissionDecisionStrategyHelp"),fieldLabelId:"decisionStrategy"}),fieldId:"policyEnforcementMode",hasNoPaddingTop:!0,children:s(W,{name:"decisionStrategy","data-testid":"decisionStrategy",defaultValue:N.UNANIMOUS,control:g,render:({field:o})=>s(H,{children:Object.values(N).map(a=>s(pe,{id:a,"data-testid":a,isChecked:o.value===a,isDisabled:l,name:"decisionStrategies",onChange:()=>o.onChange(a),label:e(`decisionStrategies.${a}`),className:"pf-v5-u-mb-md"},a))})})}),s(de,{children:v("div",{className:"pf-v5-u-mt-md",children:[s(K,{variant:k.primary,type:"submit","data-testid":"save",children:e("save")}),s(K,{variant:"link","data-testid":"cancel",component:o=>s(me,{...o,to:z({realm:u,clientId:r,tab:"permissions"})}),children:e("cancel")})]})})]})})})]}):s(oe,{})}export{Xe as default};
//# sourceMappingURL=PermissionDetails-D65ccxxC.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy