@spotify/backstage-plugin-rbac 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @spotify/backstage-plugin-rbac
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Minor accessibility improvements.
8
+ - Upgraded to Backstage `v1.14.0`
9
+ - RBAC policy authors can now choose how authorization is resolved for users matching multiple roles. This `Decision resolution strategy` can be set from a new policy options page.
10
+ - Minor UI tweaks and improvements.
11
+ - Set the default Resolution Strategy to be 'any-allow' for new policy drafts that are created.
12
+ - Updated dependency `vanilla-jsoneditor` to `^0.17.0`.
13
+ - Updated dependencies
14
+ - @spotify/backstage-plugin-rbac-common@0.5.2
15
+ - @spotify/backstage-plugin-core@0.5.2
16
+
17
+ ## 0.5.2
18
+
19
+ ### Patch Changes
20
+
21
+ - Fixed the permission decision dialog showing no options when any plugin returned invalid permission metadata.
22
+ - Moved the action buttons on the Policy page into a context menu.
23
+ - Upgraded Backstage to `v1.13.0`.
24
+ - Updated dependencies
25
+ - @spotify/backstage-plugin-rbac-common@0.5.1
26
+ - @spotify/backstage-plugin-core@0.5.1
27
+
3
28
  ## 0.5.1
4
29
 
5
30
  ### Patch Changes
package/README.md CHANGED
@@ -197,3 +197,14 @@ permission:
197
197
  fallbackPolicy:
198
198
  $include: ./fallback-rbac-policy.yaml
199
199
  ```
200
+
201
+ ### Decision resolution strategy
202
+
203
+ Multiple decisions from multiple roles could be applicable to a single user when authorizing a permission request. By default, the `any-allow` strategy will be selected for a new policy.
204
+
205
+ You can change the decision resolution strategy for a policy and read more about the options by following the steps below:
206
+
207
+ 1. Go to the draft policy page and click the `more options` icon on the top right.
208
+ 2. Select `Options`.
209
+ 3. Select which resolution strategy makes sense for your policy.
210
+ 4. Click `Back to Policy` when you are done. Your policy will be automatically updated with your selection, and it will be saved and/or published when save and publish your policy.
@@ -0,0 +1,2 @@
1
+ import{useApi as u}from"@backstage/core-plugin-api";import e from"react";import i from"react-use/lib/useAsync";import{r as m}from"./index-b4653372.esm.js";function p({children:n,loading:l=null,unauthorized:o=null}){var r;const a=u(m),t=i(()=>a.authorize(),[]);return t.loading?e.createElement(e.Fragment,null,l):(r=t.value)!=null&&r.authorized?e.createElement(e.Fragment,null,n):e.createElement(e.Fragment,null,o)}export{p as A};
2
+ //# sourceMappingURL=Authorized-636e7b48.esm.js.map
@@ -1,2 +1,2 @@
1
- import t from"react";import e from"@material-ui/icons/Lock";import{SidebarItem as m}from"@backstage/core-components";import{A as i}from"./Authorized-93283dff.esm.js";import"@backstage/core-plugin-api";import"react-use/lib/useAsync";import"./index-e1e7669d.esm.js";import"@backstage/errors";function p({text:r="RBAC",...o}){return t.createElement(i,null,t.createElement(m,{icon:e,to:"rbac",text:r,...o}))}export{p as RBACSidebarItem};
2
- //# sourceMappingURL=RBACSidebarItem-cdefd88c.esm.js.map
1
+ import t from"react";import e from"@material-ui/icons/Lock";import{SidebarItem as m}from"@backstage/core-components";import{A as i}from"./Authorized-636e7b48.esm.js";import"@backstage/core-plugin-api";import"react-use/lib/useAsync";import"./index-b4653372.esm.js";import"@backstage/errors";function p({text:r="RBAC",...o}){return t.createElement(i,null,t.createElement(m,{icon:e,to:"rbac",text:r,...o}))}export{p as RBACSidebarItem};
2
+ //# sourceMappingURL=RBACSidebarItem-7f1b6ef3.esm.js.map
@@ -0,0 +1,3 @@
1
+ import e,{createContext as He,useState as k,useCallback as R,useMemo as L,useContext as We,useEffect as V,Fragment as Pe,useRef as ae,useReducer as Tn,useLayoutEffect as An}from"react";import{useNavigate as _,Link as Sn,useParams as ze,Routes as kn,Route as De}from"react-router-dom";import{useApi as I,configApiRef as Rn,alertApiRef as re,useRouteRef as $n,useApp as Ge}from"@backstage/core-plugin-api";import ue from"react-use/lib/useAsync";import{isResourcePermission as Ue}from"@backstage/plugin-permission-common";import{r as G,a as In}from"./index-b4653372.esm.js";import{forEach as On,mapValues as Bn,groupBy as Mn,uniq as Ln}from"lodash";import{Breadcrumbs as Fn,Link as de,Page as jn,Header as Hn,Content as Wn,EmptyState as Ne,Progress as we,ErrorPanel as gt,Table as zn,ContentHeader as Te}from"@backstage/core-components";import ht from"react-use/lib/useMount";import{makeStyles as N,Typography as b,Container as Gn,Grid as F,Button as T,Card as Y,CardContent as pe,Box as f,Chip as Ae,Tooltip as fe,List as Un,ListItem as vt,ListItemIcon as K,ListItemText as Q,CardActions as Vn,Dialog as oe,DialogContent as X,DialogTitle as Se,TextField as Ee,DialogActions as Ve,CircularProgress as bt,IconButton as j,Checkbox as _e,TableRow as U,TableCell as D,debounce as _n,Table as Ye,TableHead as Je,TableBody as qe,Tabs as Yn,Tab as Jn,FormControl as Ke,InputLabel as ke,Select as Qe,MenuItem as z,Menu as Ct,FormControlLabel as xt,FormHelperText as Pt,Popper as qn,Paper as Kn,Divider as Xe,DialogContentText as Qn,ButtonBase as Xn,CardHeader as Dt,MenuList as Ze,ListItemSecondaryAction as Zn,CardActionArea as el,Radio as tl}from"@material-ui/core";import{SpotifyLicenseBanner as nl,useAutoUpdatingRelativeTime as ll,invariant as Re}from"@spotify/backstage-plugin-core";import ie from"react-use/lib/useAsyncFn";import al,{dump as rl}from"js-yaml";import{PolicyConfigParser as $e,isConditionalDecision as et,isAllOfPermissionCriteria as ol,isAnyOfPermissionCriteria as il,isNotPermissionCriteria as cl,isMatchingPermission as sl,BackstageUserPlaceholder as ye,RoleParser as ml,UpdateDraftRequestParser as ul}from"@spotify/backstage-plugin-rbac-common";import{v4 as ce}from"uuid";import Nt from"lodash/keyBy";import dl from"lodash/isEqual";import wt from"@material-ui/icons/ReportProblemOutlined";import pl from"@material-ui/icons/CalendarToday";import Tt from"@material-ui/icons/Person";import fl from"@material-ui/icons/FiberManualRecord";import{DateTime as Ie}from"luxon";import El from"react-use/lib/useLocalStorage";import{saveAs as yl}from"file-saver";import At from"lodash/omit";import gl from"lodash/pickBy";import tt from"@material-ui/icons/Close";import hl from"@material-ui/icons/Publish";import vl from"@material-ui/icons/FilterNone";import{parseEntityRef as Z,DEFAULT_NAMESPACE as bl}from"@backstage/catalog-model";import{humanizeEntityRef as Cl,catalogApiRef as xl}from"@backstage/plugin-catalog-react";import{Autocomplete as nt,ToggleButton as Pl,ToggleButtonGroup as Dl}from"@material-ui/lab";import ge from"@material-ui/icons/Delete";import Nl from"@material-ui/icons/Group";import wl from"@material-ui/icons/GroupWork";import St from"@material-ui/icons/Info";import kt from"ajv";import Tl from"lodash/uniqBy";import{JSONEditor as Al,isTextContent as Sl,createAjvValidator as kl,Mode as Rl}from"vanilla-jsoneditor";import lt from"@material-ui/icons/Add";import $l from"@material-ui/icons/Remove";import Il from"@material-ui/icons/Edit";import Ol from"@material-ui/icons/Check";import Bl from"@material-ui/icons/KeyboardArrowDown";import Ml from"@material-ui/icons/KeyboardArrowUp";import Ll from"../images/no-permissions.svg";import Fl from"../images/no-roles.svg";import jl from"@material-ui/icons/MoreHoriz";import Hl from"@material-ui/icons/Undo";import Wl from"@material-ui/icons/CloudUpload";import zl from"@material-ui/icons/Save";import Gl from"@material-ui/icons/Settings";import Ul from"@material-ui/icons/VerticalAlignTop";import{A as Vl}from"./Authorized-636e7b48.esm.js";import"@backstage/errors";const Rt=He(null),_l=({children:t})=>{const n=I(Rn),l=I(G),r=I(re),[a,o]=k(null),i=R(async()=>{var s;if(!a){const m=await l.fetchAllPermissionMetadata((s=n.getOptionalStringArray("permission.permissionedPlugins"))!=null?s:[]),c=Jl(m.rules);On(c,d=>{d.length!==1&&r.post({message:`The plugin(s) ${d.slice(1).join(", ")} expose rules which are conflicting with rules exposed by the ${d[0]} plugin. These rules will not be available for use. Please contact RBAC support if you need assistance resolving this issue.`,severity:"error"})});const p=ql(m,c);return o(p),p}return a},[r,a,l,n]);return e.createElement(Rt.Provider,{value:L(()=>({getMetadata:i}),[i])},t)};function Oe(){const t=We(Rt),{value:n}=ue(async()=>t==null?void 0:t.getMetadata(),[t]);return n}function $t(){var t;const n=Oe();return(t=n==null?void 0:n.rules)!=null?t:null}function It(){var t;const n=Oe();return(t=n==null?void 0:n.permissions)!=null?t:null}function Ot(){const t=Oe();return t?[...new Set(t.permissions.filter(n=>Ue(n)).map(({resourceType:n})=>n))]:null}function Yl(){const t=Oe(),n=Ot();return!t||!n?null:n.reduce((l,r)=>{const a=t.rules.find(o=>o.resourceType===r);return a&&(l[r]={pluginId:a.pluginId}),l},{})}function Jl(t){return Bn(Mn(t,"resourceType"),n=>Ln(n.map(({pluginId:l})=>l)))}function ql(t,n){return{...t,rules:t.rules.filter(({resourceType:l,pluginId:r})=>{const a=n[l];return r===a[0]})}}const Kl=N(t=>({breadcrumbs:{marginBottom:t.spacing(4)}}));function Ql({pages:t}){const n=$n(In),l=Kl();return e.createElement(Fn,{className:l.breadcrumbs},e.createElement(de,{to:n()},"Home"),t.map(({title:r,path:a},o)=>a?e.createElement(de,{to:a,key:a,relative:"path"},r):e.createElement(b,{key:`${o}`},r)))}function Be({children:t,header:n,pages:l}){return e.createElement(jn,{themeId:"tool"},e.createElement(nl,{backend:"rbac",invalidLicenseMessage:"Your existing policy will continue to apply, but you will be unable to make any changes until you enter a valid license."}),e.createElement(Hn,{title:"Role Based Access Control"}),e.createElement(Wn,null,e.createElement(Gn,{maxWidth:"lg"},e.createElement(F,{container:!0,spacing:4},e.createElement(F,{item:!0,xs:12},l&&e.createElement(Ql,{pages:l}),n),t))))}const Bt=He({policies:void 0,setPolicies:()=>{},setPolicy:()=>{},getPolicy:()=>{},removePolicy:()=>{}}),at=()=>We(Bt);function Xl({children:t,initialState:n={policies:void 0,cache:{}}}){const[l,r]=k(n),a=R(m=>{r(c=>({...c,policies:m,cache:Mt(c.cache,m)}))},[]),o=R(m=>l.cache[m],[l.cache]),i=R(m=>r(c=>({...c,cache:{...c.cache,[m]:void 0},policies:void 0})),[]),s=R(m=>r(c=>({...c,policies:void 0,cache:Mt(c.cache,[m])})),[]);return e.createElement(Bt.Provider,{value:L(()=>({policies:l.policies,setPolicies:a,setPolicy:s,getPolicy:o,removePolicy:i}),[l.policies,a,s,o,i])},t)}function Mt(t,n){if(!n)return t;const l={...t};return n.forEach(r=>{l[r.id]=r}),l}const he=()=>{const t=I(G),{setPolicies:n,policies:l}=at(),[{loading:r,error:a},o]=ie(()=>t.getPolicies(),[t],l?{loading:!1,value:{items:l,totalItems:l.length}}:{loading:!0}),i=R(async()=>{const s=await o();n(s.items)},[o,n]);return{loading:r,error:a,fetchPolicies:i}};function Zl(){const t=I(G),n=_(),l=I(re);function r(a){var o,i;const s=(i=(o=a.target)==null?void 0:o.files)==null?void 0:i[0],m=new FileReader;s&&(m.readAsText(s,"utf-8"),m.onload=async c=>{var p,d;const u=(d=(p=c.target)==null?void 0:p.result)==null?void 0:d.toString();if(u){let C=null;try{C=al.load(u)}catch{l.post({message:"YAML file is invalid",severity:"error"});return}if(!$e.safeParse(C).success){l.post({message:"Imported policy is invalid",severity:"error"});return}if((await t.getPolicies()).items.some(E=>E.status==="draft")){l.post({message:"Unable to import new policy due to existing draft policy",severity:"error"});return}const g=C,y=await t.createDraft({name:g.name,roles:g.roles});n(`./versions/${y.id}`),l.post({message:"Policy imported successfully",severity:"success"})}})}return e.createElement(T,{variant:"outlined",color:"primary",component:"label"},"Import",e.createElement("input",{role:"input",type:"file",hidden:!0,onChange:r,accept:".yaml"}))}const ea=N(t=>({cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}}}));function ta(){const t=ea(),n=I(G),l=_(),[r,a]=ie(async()=>n.createDraft({roles:[],options:{resolutionStrategy:"any-allow"}}),[n]);return V(()=>{r.value&&l(`./versions/${r.value.id}`)},[l,r.value]),e.createElement(Y,null,e.createElement(pe,{className:t.cardContent},e.createElement(Ne,{missing:"content",title:"No policy configured",description:e.createElement(e.Fragment,null,e.createElement(f,{component:"span",display:"block",pb:2},"Until you've configured your policy, authorization will be denied for all permissions."),e.createElement(f,{component:"span",display:"block"},"Click the button below to create the first version of your policy.")),action:e.createElement(T,{variant:"contained",color:"primary",disabled:r.loading,onClick:a},"New version")})))}function na(t){var n,l;return((l=(n=t==null?void 0:t.body)==null?void 0:n.response)==null?void 0:l.statusCode)===404}const la=(t,n)=>{const l={resolutionStrategy:{operation:"UNCHANGED",before:t==null?void 0:t.resolutionStrategy,after:n==null?void 0:n.resolutionStrategy}};for(const r of Object.keys(l)){const a=r;l[a].before!==l[a].after&&(l[a].operation="CHANGED")}return l},rt=(t,n)=>{const l=Object.entries(t);for(const[,r]of l){const a=n(r);for(const[,o]of l){const i=n(o);i.operation!=="ADDED"&&i.operation!=="REMOVED"&&(a.operation==="ADDED"&&a.indexAfter<i.indexAfter?i.indexBefore+=1:a.operation==="REMOVED"&&a.indexBefore<i.indexBefore&&(i.indexBefore-=1))}}for(const[,r]of l){const a=n(r);a.operation==="UNCHANGED"&&a.indexAfter!==a.indexBefore&&(a.operation=a.indexAfter>a.indexBefore?"MOVED_DOWN":"MOVED_UP")}return t},ot=(t,n)=>{if(t==="*")return n==="*"?{"*":{operation:"UNCHANGED",after:"*",before:"*",indexAfter:0,indexBefore:0}}:{"*":{operation:"REMOVED",after:null,before:"*",indexAfter:-1,indexBefore:0},...Object.fromEntries(n.map((r,a)=>[r,{operation:"ADDED",after:r,before:null,indexAfter:a,indexBefore:-1}]))};if(n==="*")return{"*":{operation:"ADDED",after:"*",before:null,indexAfter:0,indexBefore:-1},...Object.fromEntries(t.map((r,a)=>[r,{operation:"REMOVED",after:null,before:r,indexAfter:-1,indexBefore:a}]))};const l=Object.fromEntries(n.map((r,a)=>[r,{operation:"ADDED",after:r,before:null,indexAfter:a,indexBefore:-1}]));for(let r=0;r<t.length;r++){const a=t[r];l[a]?(l[a].before=a,l[a].indexBefore=r,l[a].operation="UNCHANGED"):l[a]={operation:"REMOVED",after:null,before:a,indexAfter:-1,indexBefore:r}}return rt(l,r=>r)},it=(t,n)=>{const l=Nt(n,"id"),r=Object.fromEntries(n.map((a,o)=>[a.id,{operation:"ADDED",indexAfter:o,indexBefore:-1,after:a,before:null}]));for(let a=0;a<t.length;a++){const o=t[a];if(r[o.id]){const i=!dl(o,l[o.id]);r[o.id].before=o,r[o.id].indexBefore=a,r[o.id].operation=i?"CHANGED":"UNCHANGED"}else r[o.id]={operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:a}}return rt(r,a=>a)},aa=(t=[],n=[])=>{const l=Nt(n,"id"),r=Object.fromEntries(n.map((a,o)=>[a.id,{role:{operation:"ADDED",indexAfter:o,indexBefore:-1,after:a,before:null},members:ot([],a.members),permissions:it([],a.permissions)}]));for(let a=0;a<t.length;a++){const o=t[a];if(l[o.id]){const i=l[o.id],s=ot(o.members,i.members),m=it(o.permissions,i.permissions),c=Object.values(m).some(({operation:u})=>u!=="UNCHANGED"),p=Object.values(s).some(({operation:u})=>u!=="UNCHANGED"),d=o.name!==i.name||c||p;r[o.id].role.before=o,r[o.id].role.indexBefore=a,r[o.id].role.operation=d?"CHANGED":"UNCHANGED",r[o.id].members=s,r[o.id].permissions=m}else r[o.id]={role:{operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:a},members:ot(o.members,[]),permissions:it(o.permissions,[])}}return rt(r,({role:a})=>a)},ra=(t,n)=>{const l=aa((t==null?void 0:t.roles)||[],n.roles||[]),r=la(t==null?void 0:t.options,n.options),a=(t==null?void 0:t.name)!==n.name,o=Object.values(r).some(({operation:i})=>i!=="UNCHANGED");return{policy:{operation:a||o?"CHANGED":"UNCHANGED",before:t,after:n},roles:l,options:r}},Lt=t=>{const n=I(G),{value:l,loading:r,error:a}=ue(()=>n.getActivePolicy(),[n]);return L(()=>t&&!r&&!a?ra(l,t):null,[l,t,r,a])},oa=N(t=>({chip:{margin:0},icon:{color:t.palette.success.main}}));function Ft(t){const n=oa();return t.status==="inactive"?null:t.status==="draft"?e.createElement(Ae,{className:n.chip,label:"Draft",size:t.size}):e.createElement(Ae,{className:n.chip,classes:{icon:n.icon},label:"Active",icon:e.createElement(fl,null),size:t.size})}const ct=(t,n)=>{switch(n){case"ADDED":return t.palette.success.main;case"REMOVED":return t.palette.error.main;case"CHANGED":return t.palette.info.main;case"MOVED_UP":case"MOVED_DOWN":return t.palette.info.main;case"UNCHANGED":default:return t.palette.text.primary}},ia=t=>{switch(t){case"ADDED":return"New";case"REMOVED":return"Removed";case"CHANGED":return"Changed";case"MOVED_UP":return"Moved up";case"MOVED_DOWN":return"Moved down";case"UNCHANGED":default:return"No changes"}};function ca(t){var n;return et(t.decision)?"Conditional":(n={allow:"Allow",deny:"Deny"}[t.decision])!=null?n:"Unknown"}function st(t){var n;if(t.match==="*")return"All";if(t.match.name)return t.match.name;const l=[];return t.match.resourceType&&l.push(t.match.resourceType),(n=t.match.actions)!=null&&n.length&&l.push(t.match.actions.join(", ")),l.join(" | ")}const sa=N(t=>({root:({operation:n})=>({color:ct(t,n)})})),M=t=>e.createElement(b,{...t,variant:"body2"}),x=t=>{const n=sa(t);return e.createElement(f,{...t,className:n.root,component:"span",fontWeight:"fontWeightBold"})},jt=({policy:t})=>{var n,l,r,a;const o=Lt(t),i=(o==null?void 0:o.policy.operation)==="CHANGED"||Object.values((n=o==null?void 0:o.roles)!=null?n:{}).some(d=>d.role.operation!=="UNCHANGED")||((l=o==null?void 0:o.options)==null?void 0:l.resolutionStrategy.operation)==="CHANGED";if(!o||!i)return e.createElement(f,null,"No changes");const s=!!o.policy.before&&!!o.policy.after&&o.policy.before.name!==o.policy.after.name,m=o.options.resolutionStrategy.operation==="CHANGED",c=({before:d,after:u})=>d&&u&&d.name!==u.name,p=({operation:d})=>d!=="ADDED"&&d!=="REMOVED";return e.createElement(f,null,s&&e.createElement(M,null,"Policy name ",e.createElement(x,{operation:"CHANGED"},"changed")," from"," ",e.createElement(x,null,'"',(r=o.policy.before)==null?void 0:r.name,'"')," to"," ",e.createElement(x,null,'"',(a=o.policy.after)==null?void 0:a.name,'"')),m&&e.createElement(M,null,"Resolution Strategy ",e.createElement(x,{operation:"CHANGED"},"changed")," ","from ",e.createElement(x,null,'"',o.options.resolutionStrategy.before,'"')," to"," ",e.createElement(x,null,'"',o.options.resolutionStrategy.after,'"')),Object.entries(o.roles).map(([d,{role:u,permissions:C,members:g}])=>{var y,E,P,A,$,H;return e.createElement(Pe,{key:d},u.operation==="ADDED"&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(y=u.after)==null?void 0:y.name,'"')," has been"," ",e.createElement(x,{operation:"ADDED"},"added")),u.operation==="REMOVED"&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(E=u.before)==null?void 0:E.name,'"')," has been"," ",e.createElement(x,{operation:"REMOVED"},"removed")),c(u)&&e.createElement(M,null,"Role name changed from ",e.createElement(x,null,'"',(P=u.before)==null?void 0:P.name,'"')," ","to ",e.createElement(x,null,'"',(A=u.after)==null?void 0:A.name,'"')),u.indexAfter>u.indexBefore&&u.indexBefore!==-1&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',($=u.after)==null?void 0:$.name,'"')," has been"," ",e.createElement(x,{operation:"MOVED_DOWN"},"moved down")," in priority"),u.indexAfter<u.indexBefore&&u.indexAfter!==-1&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(H=u.after)==null?void 0:H.name,'"')," has been"," ",e.createElement(x,{operation:"MOVED_UP"},"moved up")," in priority"),p(u)&&e.createElement(e.Fragment,null,Object.entries(C).map(([B,v])=>{var w,h,S,O,te;const{before:J,after:se}=v,ne=J&&st(J),q=se&&st(se);return e.createElement(Pe,{key:B},v.operation==="ADDED"&&v.after&&e.createElement(M,null,"Permission decision"," ",e.createElement(x,null,'"',q,'"')," has been"," ",e.createElement(x,{operation:"ADDED"},"added")," to"," ",e.createElement(x,null,'"',(w=u.after)==null?void 0:w.name,'"')),v.operation==="REMOVED"&&v.before&&e.createElement(M,null,"Permission decision"," ",e.createElement(x,null,'"',ne,'"')," has been"," ",e.createElement(x,{operation:"REMOVED"},"removed")," ","from ",e.createElement(x,null,'"',(h=u.after)==null?void 0:h.name,'"')),v.operation==="CHANGED"&&e.createElement(M,null,ne!==q?e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(x,null,'"',ne,'"')," has been"," ",e.createElement(x,{operation:"CHANGED"},"updated")," ","to ",e.createElement(x,null,'"',q,'"')):e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(x,null,'"',ne,'"')," has been"," ",e.createElement(x,{operation:"CHANGED"},"updated"))," ","in ",e.createElement(x,null,'"',(S=u.after)==null?void 0:S.name,'"')),v.indexAfter>v.indexBefore&&v.indexBefore!==-1&&e.createElement(M,null,"Permission decision"," ",e.createElement(x,null,'"',q,'"')," has been"," ",e.createElement(x,{operation:"MOVED_DOWN"},"moved down")," ","in priority in"," ",e.createElement(x,null,'"',(O=u.after)==null?void 0:O.name,'"')),v.indexAfter<v.indexBefore&&v.indexAfter!==-1&&e.createElement(M,null,"Permission decision"," ",e.createElement(x,null,'"',q,'"')," has been"," ",e.createElement(x,{operation:"MOVED_UP"},"moved up")," ","in priority in"," ",e.createElement(x,null,'"',(te=u.after)==null?void 0:te.name,'"')))}),Object.entries(g).map(([B,v])=>{var w,h;return e.createElement(Pe,{key:B},v.operation==="ADDED"&&v.after&&e.createElement(M,null,"Member ",e.createElement(x,null,'"',v.after,'"')," has been"," ",e.createElement(x,{operation:"ADDED"},"added")," to"," ",e.createElement(x,null,'"',(w=u.after)==null?void 0:w.name,'"')),v.operation==="REMOVED"&&v.before&&e.createElement(M,null,"Member ",e.createElement(x,null,'"',v.before,'"')," has been"," ",e.createElement(x,{operation:"REMOVED"},"removed")," from"," ",e.createElement(x,null,'"',(h=u.after)==null?void 0:h.name,'"')))})))}))},ma=N(()=>({root:{display:"inline-flex"}})),Ht=({timestamp:t,description:n})=>{const l=ma(),r=Ie.fromISO(t).toLocaleString(Ie.DATETIME_FULL),a=ll(t),o=n?`${n}${a}`:a;return e.createElement("span",{className:l.root},e.createElement(fe,{title:r},e.createElement(b,{component:"span",display:"inline",variant:"inherit"},o)))};function Wt(t,n,l){var r,a;let o=n.created,i=t.createdBy;l!=null&&l.created&&(i=l.created+i);let s=t.createdAt;return t.status==="active"?(o=n.published,i=(r=t.lastPublishedBy)!=null?r:"",l!=null&&l.published&&(i=l.published+i),s=(a=t.lastPublishedAt)!=null?a:""):t.createdAt!==t.updatedAt&&(o=n.updated,i=t.updatedBy,l!=null&&l.updated&&(i=l.updated+i),s=t.updatedAt),{activityDateText:o,activityUser:i,timestamp:s}}const ua=N(t=>({card:n=>({backgroundImage:n.policy.status==="active"?"linear-gradient(256.15deg, #00782A 19.77%, #1DB954 100%)":"linear-gradient(256.15deg, #BDBDBD 19.77%, #EEEEEE 100%)",backgroundPosition:"top",backgroundSize:"100% 8px",backgroundRepeat:"no-repeat",paddingTop:"8px",height:"100%"}),diffSummaryContainer:{backgroundColor:t.palette.background.default,padding:t.spacing(2),borderWidth:"1px",borderStyle:"solid",borderColor:t.palette.divider,borderRadius:t.shape.borderRadius},header:{display:"flex",justifyContent:"space-between",alignItems:"center"},detailsHeader:{...t.typography.body1,paddingTop:t.spacing(2),color:t.palette.text.secondary},activityList:{color:t.palette.text.secondary},activityListItem:{padding:0},actions:{justifyContent:"flex-start"}}));function ve(t){const n=ua(t),{policy:l,to:r,withChangeSummary:a}=t,o=`${l.name} ${l.status==="draft"?"- Draft":""}`,i={created:"Created: ",published:"Published: ",updated:"Updated: "},s={created:"Created by ",published:"Published by ",updated:"Updated by "},{activityDateText:m,activityUser:c,timestamp:p}=Wt(l,i,s);return e.createElement(Y,{className:n.card},e.createElement(pe,null,e.createElement("div",{className:n.header},r?e.createElement(de,{to:`versions/${l.id}`},e.createElement(b,{variant:"h5",component:"h1"},o)):e.createElement(b,{variant:"h5",component:"h1"},o),l.status==="active"?e.createElement(Ft,{status:"active",size:"small"}):null),l.description?e.createElement(b,{variant:"body1",color:"textSecondary"},'"',l.description,'"'):null,e.createElement(b,{component:"h2",className:n.detailsHeader},"Details"),e.createElement(Un,{className:n.activityList},e.createElement(vt,{className:n.activityListItem},e.createElement(K,null,e.createElement(pl,null)),e.createElement(Q,{primary:e.createElement(Ht,{timestamp:p,description:m})})),e.createElement(vt,{className:n.activityListItem},e.createElement(K,null,e.createElement(Tt,null)),e.createElement(Q,{primary:c}))),a&&e.createElement(f,{paddingTop:2},e.createElement(b,{gutterBottom:!0,variant:"subtitle2"},"What's changed"),e.createElement(f,{className:n.diffSummaryContainer},e.createElement(jt,{policy:l})))),t.actions?e.createElement(Vn,{className:n.actions},t.actions):null)}const da=N(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"},label:{align:"center",display:"block",marginBottom:t.spacing(1),color:t.palette.text.secondary,fontSize:t.typography.caption.fontSize},policiesContainer:{display:"flex",gap:t.spacing(4),marginTop:t.spacing(4),marginBottom:t.spacing(4)},button:{marginTop:t.spacing(4)}})),pa=({localPolicy:t,onSelectLocalPolicy:n,onSelectServerPolicy:l,serverPolicy:r})=>{const a=da();return e.createElement(oe,{open:!0,maxWidth:"md"},e.createElement(X,null,e.createElement(f,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(f,{display:"flex",justifyContent:"center"},e.createElement(wt,{className:a.icon})),e.createElement(b,{align:"center",variant:"h6"},"There is a conflict with your drafts"),e.createElement(f,null,e.createElement(b,{align:"center"},"A newer version of the draft you are trying to edit has been recently saved."),e.createElement(b,{align:"center"},"Please review the changes and decide on a version to keep."))),e.createElement(f,{className:a.policiesContainer},e.createElement(f,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(b,{className:a.label,variant:"button"},"Your local draft"),e.createElement(ve,{policy:t,withChangeSummary:!0}),e.createElement(T,{className:a.button,color:"primary",onClick:n,variant:"outlined"},"Keep local draft")),e.createElement(f,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(b,{className:a.label,variant:"button"},"Recently saved draft"),e.createElement(ve,{policy:r,withChangeSummary:!0}),e.createElement(T,{className:a.button,color:"primary",onClick:l,variant:"outlined"},"Keep recently saved draft")))))},fa=({serverPolicy:t,localPolicy:n})=>!n||!t?{policy:t,policyConflict:!1}:t.status!=="draft"?{policy:t,policyConflict:!1}:n.id!==t.id?{policy:t,policyConflict:!1}:n.updatedAt===t.updatedAt?{policy:n,policyConflict:!1}:{policy:n,policyConflict:!0},Ea=()=>El("@spotify/backstage-plugin-rbac:draftPolicy");function zt(t){const n=new Blob([ya(t)],{type:"text/yaml"});yl(n,`${(t.name||"policy").toLocaleLowerCase().replace(/\W/g,"-")}.yaml`)}function ya(t){const{name:n,roles:l,options:r,description:a}=t;return`# this is an autogenerated file, do not edit
2
+ ${rl(gl({name:n,description:a,options:r,roles:l.map(({permissions:o,...i})=>({...At(i,["id"]),permissions:o.map(s=>At(s,["id"]))}))},o=>o!==null||o!==void 0))}`}const ga=N(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"}})),ha=({onConfirm:t,policy:n})=>{const l=ga(),r=()=>{zt(n)};return e.createElement(oe,{open:!0},e.createElement(X,null,e.createElement(f,{display:"flex",flexDirection:"column",gridGap:16},e.createElement(f,{display:"flex",flexDirection:"column",gridGap:4},e.createElement(f,{display:"flex",justifyContent:"center"},e.createElement(wt,{className:l.icon})),e.createElement(b,{align:"center",variant:"h6"},"Invalid local draft")),e.createElement(f,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(b,{align:"center"},"You have a local draft that is no longer compatible or has become corrupted."),e.createElement(b,{align:"center"},"Click export to download your draft. You can attempt to restore your draft by importing this file on the RBAC home page."),e.createElement(b,{align:"center"},"Clicking continue will discard your draft."," ",e.createElement(f,{component:"span",fontWeight:"fontWeightBold"},"This action cannot be undone."))),e.createElement(f,{display:"flex",justifyContent:"center",gridGap:8,marginY:3},e.createElement(T,{color:"primary",onClick:r,variant:"outlined"},"Export"),e.createElement(T,{color:"primary",onClick:t,variant:"contained"},"Discard and continue")))))};function mt(){const t=I(G),n=I(re),l=ie(async(a,o)=>{if(a)return await t.publishPolicy(a.id,{description:o}),t.getPolicy(a.id)},[]),[{error:r}]=l;return V(()=>{r&&n.post({message:r.message,severity:"error"})},[r,n]),l}const va=N(t=>({closeButton:{color:t.palette.text.secondary},diffSummaryContainer:{backgroundColor:t.palette.background.default,marginBottom:t.spacing(2)}}));function ut({open:t,onPublish:n,onClose:l,policy:r}){const[a,o]=k(!1),i=va(),s=ae(null),m=async()=>{var c,p;o(!0),await n((p=(c=s.current)==null?void 0:c.value)!=null?p:""),o(!1)};return e.createElement(oe,{open:t,onClose:l,fullWidth:!0},e.createElement(Se,null,e.createElement(f,{display:"flex",justifyContent:"space-between",alignItems:"center"},"Ready to publish?",e.createElement(T,{startIcon:e.createElement(tt,null),onClick:l,className:i.closeButton},"Close")),e.createElement(b,null,"Double check your changes, then click Publish to activate this version of your policy. This will immediately apply the permissions defined in this version across Backstage.")),e.createElement(X,{className:i.diffSummaryContainer,dividers:!0},e.createElement(jt,{policy:r})),e.createElement(X,null,e.createElement(Ee,{variant:"outlined",fullWidth:!0,label:"Summary (optional)",placeholder:"Briefly describe this version (or changes from a previous version)",inputRef:s})),e.createElement(Ve,null,e.createElement(T,{color:"primary",onClick:m,disabled:a},a?e.createElement(bt,{size:20}):"Publish")))}const ba=N(t=>({paper:{padding:t.spacing(2,2,0,2)}})),dt=({isOpen:t,onClose:n,policy:l})=>{const r=ba();return e.createElement(oe,{classes:{...r},open:t,onClose:n},e.createElement(Se,{disableTypography:!0},e.createElement(f,{display:"flex",flexDirection:"row"},e.createElement(f,null,e.createElement(b,{variant:"h4",component:"h2"},"Success!"),e.createElement(b,null,l.name," has been published and is now your active policy.")),e.createElement(f,null,e.createElement(j,{onClick:n,title:"Close dialog"},e.createElement(tt,null))))),e.createElement(X,null,e.createElement(ve,{policy:l})),e.createElement(Ve,null,e.createElement(f,{display:"flex",flexDirection:"row",flexGrow:1,justifyContent:"flex-start"},e.createElement(T,{component:Sn,color:"primary",onClick:n,role:"link",to:"/rbac"},"View all versions"))))},Ca={canPublish:!1,diff:null,hasChanges:!1,isValid:!1,policy:void 0,createNewRole:()=>"",discardLocalDraft:()=>{},exportPolicy:()=>{},publish:()=>{},saveLocalDraftToServer:()=>Promise.reject(),refetchPolicy:()=>Promise.reject(),updateLocalDraft:()=>{}},Gt=He(Ca),ee=()=>We(Gt);function Me({children:t,policyId:n}){const l=_(),r=I(re),a=I(G),{getPolicy:o,setPolicy:i}=at(),s=Ge(),{NotFoundErrorPage:m}=s.getComponents(),[c,p]=k(!1),[d,u]=k(!1),[{loading:C,value:g},y]=mt(),E=o(n),[P,A,$]=Ea(),H=!P||$e.safeParse(P).success,B=H?P:void 0,{policy:v,policyConflict:w}=fa({serverPolicy:E,localPolicy:B}),h=Lt(v),S=$e.safeParse(v).success,O=S&&!B&&!C,[{loading:te,error:J},se]=ie(()=>a.getPolicy(n),[a,n],E?{loading:!1,value:E}:{loading:!0}),ne=()=>{p(!0)},q=R(async W=>{await y(v,W),p(!1)},[v,y,p]),vn=async()=>{u(!1)},bn=()=>{A(W=>W&&E&&{...W,updatedAt:E.updatedAt})},le=R(async()=>{const W=await se();i(W)},[se,i]),Cn=R(async()=>{if(!v)throw new Error("No policy to save");try{await a.updateDraft(v.id,{name:v.name,roles:v.roles,options:v.options}),r.post({message:"Policy saved",severity:"success"}),$(),le==null||le()}catch(W){r.post({message:(W==null?void 0:W.message)||"An error occurred while updating the policy",severity:"error"})}},[r,a,v,le,$]),xn=R(()=>{if(!v)throw new Error("No policy to create a new role");const W=new Set(v.roles.map(wn=>wn.id));let me;do me=ce().split("-")[0];while(W.has(me));const Nn={name:`Role ${me}`,permissions:[],members:"*",id:me};return A({...v,roles:[...v.roles,Nn]}),me},[v,A]),Pn=()=>{$(),l("/rbac")},Dn=()=>{v&&zt(v)};return V(()=>{E||le()},[le,E]),V(()=>{g&&u(!0)},[g]),H?v?e.createElement(Gt.Provider,{value:{canPublish:O,diff:h,hasChanges:!!B,isValid:S,policy:v,createNewRole:xn,discardLocalDraft:$,exportPolicy:Dn,publish:ne,saveLocalDraftToServer:Cn,refetchPolicy:le,updateLocalDraft:A}},w&&B&&E&&e.createElement(pa,{localPolicy:B,onSelectLocalPolicy:bn,onSelectServerPolicy:$,serverPolicy:E}),e.createElement(ut,{open:c,onClose:()=>p(!1),onPublish:q,policy:v}),g&&e.createElement(dt,{isOpen:d,onClose:vn,policy:g}),t):te?e.createElement(we,null):J?na(J)?e.createElement(m,null):e.createElement(gt,{error:J!=null?J:new Error("Unknown")}):null:e.createElement(ha,{onConfirm:Pn,policy:P})}function xa(t){throw new Error("Invalid state")}function Ut(){const t=I(G),n=I(re),{fetchPolicies:l}=he();return ie(async r=>{if(!r)return;const{roles:a,name:o,options:i}=r;return t.createDraft({roles:a,options:i,name:o}).then(l).catch(s=>(n.post({message:s.message,severity:"error"}),Promise.reject(s)))},[])}const Pa=[{title:"Name",field:"name",render:t=>e.createElement(de,{to:`versions/${t.id}`},t.name)},{title:"Status",field:"status",render:t=>{switch(t.status){case"active":return"Active";case"draft":return"Draft";case"inactive":return"Inactive";default:return xa(t.status)}}},{title:"Publish date",field:"lastPublishedAt",render:t=>t.lastPublishedAt?Ie.fromISO(t.lastPublishedAt).toLocaleString(Ie.DATETIME_MED_WITH_SECONDS):"",type:"datetime",defaultSort:"desc"},{title:"Published by",field:"lastPublishedBy"}];function Da(t){const n=t.data.length>3,{fetchPolicies:l}=he(),[{loading:r},a]=Ut(),[{loading:o,value:i},s]=mt(),[m,c]=k(void 0),[p,d]=k(!1),u=()=>{c(void 0),l()},C=(m==null?void 0:m.id)===(i==null?void 0:i.id)?i:void 0,g=[y=>{const{tableData:E,...P}=y;return{icon:hl,tooltip:"Publish",onClick:()=>{c(P),d(!0)},disabled:o}},y=>{const{tableData:E,...P}=y;return{icon:vl,tooltip:"Duplicate",disabled:r||!t.canDuplicate,onClick:()=>a(P)}}];return e.createElement(e.Fragment,null,e.createElement(zn,{title:"Previous Versions",columns:Pa,data:t.data,options:{paging:n,pageSize:3,pageSizeOptions:[3,5,10,20],actionsColumnIndex:-1,loadingType:"linear"},actions:g}),m&&e.createElement(ut,{open:p,onPublish:y=>{s(m,y),d(!1)},onClose:()=>{c(void 0),d(!1)},policy:m}),C&&e.createElement(dt,{isOpen:!0,policy:C,onClose:u}))}const Na=t=>{const[n,l]=k(!1),{fetchPolicies:r}=he(),[{loading:a,value:o},i]=mt(),{policy:s,hasChanges:m}=ee(),c=$e.safeParse(s).success,p=!m&&c,d=async C=>{await i(s,C),l(!1)},u=()=>{r()};return e.createElement(e.Fragment,null,e.createElement(T,{...t,onClick:()=>l(!0),disabled:!p||a},"Publish"),e.createElement(ut,{open:n,onClose:()=>l(!1),onPublish:d,policy:s}),o&&e.createElement(dt,{isOpen:!0,onClose:u,policy:o}))};function wa(t){const n=I(G),l=I(re),{fetchPolicies:r}=he();return ie(async()=>{if(t)return n.deleteDraft(t.id).then(r).catch(a=>(l.post({message:a.message,severity:"error"}),Promise.reject(a)))},[t])}function Ta({policies:t}){const n=t.find(c=>c.status==="draft"),l=t.find(c=>c.status==="active"),[r,a]=Ut(),[o,i]=wa(n),s=_(),m=Aa(t);return e.createElement(F,{container:!0,spacing:4},l?e.createElement(F,{item:!0,xs:12,md:6},e.createElement(ve,{policy:l,to:`./versions/${l.id}`,actions:e.createElement(T,{color:"primary",disabled:r.loading||!!n,onClick:()=>a(l)},"Duplicate")})):null,n?e.createElement(F,{item:!0,xs:12,md:6},e.createElement(ve,{policy:n,to:`./versions/${n.id}`,actions:e.createElement(e.Fragment,null,e.createElement(T,{onClick:()=>s(`versions/${n.id}`),color:"primary"},"Edit"),e.createElement(T,{color:"primary",disabled:o.loading,onClick:i},"Delete Draft"),e.createElement(Me,{policyId:n.id},e.createElement(Na,{color:"primary"})))})):null,e.createElement(F,{item:!0,xs:12},e.createElement(Da,{data:m,canDuplicate:!n})))}function Aa(t){return t.filter(({status:n})=>n==="inactive")}function Sa(){const{policies:t}=at(),{loading:n,error:l,fetchPolicies:r}=he();ht(()=>{t||r()});let a;return n?a=e.createElement(F,{item:!0,xs:12},e.createElement(we,null)):l?a=e.createElement(gt,{error:l}):!t||t.length===0?a=e.createElement(ta,null):a=e.createElement(Ta,{policies:t}),e.createElement(Be,{pages:void 0,header:e.createElement(Te,{title:"RBAC Policies"},e.createElement(Zl,null))},a)}const ka=N(t=>({titleWrapper:{display:"flex",alignItems:"center",gap:t.spacing(2)}}));function Vt({children:t}){const n=ka();return e.createElement(b,{noWrap:!0,variant:"h4",component:"h2",color:"textSecondary",className:n.titleWrapper},t)}const Ra=N({autocomplete:{display:"flex",flex:1}});function $a({members:t,options:n,namespaceOptions:l,loading:r=!1,disabled:a=!1,isMultiNamespaces:o=!1,onTextChange:i,onToggleMember:s,onChange:m}){const[c,p]=k(!1),d=Ra(),[u,C]=Tn(E=>E+1,0),g=(E,P)=>{P&&(s(P),C())};V(()=>{c&&i("")},[c,i]);const y=o?l.concat((n==null?void 0:n.members)||[]):(n==null?void 0:n.members)||[];return e.createElement(f,{width:250},e.createElement(nt,{key:`${u}`,open:c,onOpen:()=>{p(!0)},onClose:()=>{p(!1)},onChange:g,getOptionLabel:be,groupBy:Ia,renderOption:E=>e.createElement(e.Fragment,null,e.createElement(_e,{id:`checkbox-${E.entityRef}`,checked:t.includes(E.entityRef),color:"primary"}),e.createElement("label",{htmlFor:`checkbox-${E.entityRef}`},o?be(E,!1):be(E))),options:y,filterOptions:E=>E,openOnFocus:!0,disabled:a,loading:r,className:d.autocomplete,renderInput:E=>e.createElement(Ee,{...E,label:o?"Select members":"Select specific users/groups",variant:"standard",onChange:m,InputProps:{...E.InputProps,endAdornment:e.createElement(e.Fragment,null,r?e.createElement(bt,{color:"inherit",size:20}):null,E.InputProps.endAdornment)}})}))}function be(t,n=!0){var l;const r=Z(t.entityRef);return r.name==="*"?r.namespace:Cl({...r,name:(l=t.name)!=null?l:r.name},{defaultKind:r.kind,defaultNamespace:n?bl:!1})}const _t={user:"USERS",group:"GROUPS",namespace:"NAMESPACES"};function Ia(t){const{name:n,kind:l}=Z(t.entityRef),r=n==="*"?"namespace":l;if(!_t[r])throw new Error(`Group '${r}' is not supported for members in a policy`);return _t[r]}const Oa=N(t=>({root:({operation:n})=>({borderRadius:100,borderColor:ct(t,n),borderSize:1,borderStyle:"solid",color:ct(t,n),lineHeight:1,padding:t.spacing(.5,1),whiteSpace:"nowrap"})})),Ba={small:"span",medium:"div",large:"div"},Ma={small:"caption",medium:"body1",large:"subtitle1"},Ce=({operation:t,size:n="small"})=>{const l=Oa({operation:t}),r=ia(t);return!t||t==="UNCHANGED"?null:e.createElement(b,{className:l.root,variant:Ma[n],component:Ba[n]},r)},La=N(t=>({actionCol:{width:48},typeIconCol:{paddingRight:"0.4rem"},nameCol:{paddingLeft:0},typeIcon:{color:t.palette.grey[500]}}));function Fa({diff:t,loading:n,isMultiNamespaces:l,members:r,error:a,onToggleMember:o,readonly:i=!1}){const s=La();if(n)return e.createElement(U,null,e.createElement(D,{scope:"row",colSpan:4},e.createElement(we,null)));if(a&&a.message!=null,r==="*")return e.createElement(U,null,e.createElement(D,null,"All"),e.createElement(D,{height:80},"any"),e.createElement(D,{colSpan:i?2:3},e.createElement(Ce,{operation:t==null?void 0:t.members["*"].operation})));if(r.length===0)return e.createElement(U,null,e.createElement(D,{scope:"row",colSpan:4},"Select users or groups using the drop-down menu above."));const m=r.sort((c,p)=>{let d=0;l&&p.name==="*"&&c.name!=="*"?d=1:l&&c.name==="*"&&p.name!=="*"&&(d=-1);const u=c.type.localeCompare(p.type),C=Z(c.entityRef).namespace.localeCompare(Z(p.entityRef).namespace),g=Z(c.entityRef).name.localeCompare(Z(p.entityRef).name);return d||u||C||g});return e.createElement(e.Fragment,null,m.map(c=>{var p;const{name:d,type:u,entityRef:C}=c;return e.createElement(U,{key:C},e.createElement(D,{className:s.typeIconCol},u==="group"&&e.createElement(Nl,{className:s.typeIcon})||l&&d==="*"&&e.createElement(wl,{className:s.typeIcon})||e.createElement(Tt,{className:s.typeIcon})),e.createElement(D,{scope:"row",className:s.nameCol},(p=l?be(c,!1):be(c))!=null?p:"Unknown"),e.createElement(D,{scope:"row"},d==="*"&&l?"namespace":u),e.createElement(D,null,d&&e.createElement(Ce,{operation:t==null?void 0:t.members[C].operation})),!i&&e.createElement(D,{scope:"row",className:s.actionCol},e.createElement(j,{"aria-label":"delete",onClick:()=>o(c),size:"small"},e.createElement(ge,null))))}))}const ja=N(()=>({header:{display:"flex",flexDirection:"row",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",gap:"1rem"},actionCol:{width:48},typeIconCol:{paddingRight:"0.4rem"},nameCol:{paddingLeft:0}}));function Ha({diff:t,policyId:n,role:l,onToggleMember:r,readonly:a=!1,debounceTime:o=1e3}){const i=I(G),s=I(xl),m=ja(),c=l.members==="*",[p,d]=k(""),{current:u}=ae({}),C=h=>{u[h.entityRef]=h,r(h.entityRef)},g=h=>{var S;if(u[h])return u[h];const O=Z(h);return{entityRef:h,type:O.kind.toLowerCase(),name:(S=O.name)!=null?S:h}},{value:y,loading:E}=ue(async()=>await i.searchMembers({query:p}),[i,p]),{loading:P,value:A}=ue(async()=>{const h=await s.getEntityFacets({facets:["metadata.namespace"]}).then(S=>S.facets["metadata.namespace"].map(O=>O.value));return Wa(h)},[s]),$=A?(A==null?void 0:A.length)>1:!1,H=A?A.filter(h=>h.entityRef.toLowerCase().includes(p)):[],B=L(()=>_n(h=>{d(h.target.value.toLowerCase())},o),[d,o]),{loading:v,error:w}=ue(async()=>{l.members==="*"||l.members.length===0||(await i.getPolicy(n)).roles.find(h=>h.id===l.id)===void 0||l.members.forEach(h=>{const S=g(h);u[S.entityRef]=S})},[n,c]);return e.createElement(e.Fragment,null,e.createElement("div",{className:m.header},e.createElement("h2",null,"Members"),e.createElement($a,{onToggleMember:C,members:l.members,disabled:a,options:y,namespaceOptions:H,isMultiNamespaces:$,loading:E||P,onTextChange:d,onChange:B})),e.createElement(Ye,null,e.createElement(Je,null,e.createElement(U,null,e.createElement(D,{className:m.typeIconCol}),e.createElement(D,{className:m.nameCol},"Name"),e.createElement(D,null,"Type"),e.createElement(D,null),!a&&e.createElement(D,{className:m.actionCol}))),e.createElement(qe,null,e.createElement(Fa,{diff:t,loading:v||P,isMultiNamespaces:$,error:w,members:Array.isArray(l.members)?l.members.map(g):l.members,onToggleMember:C,readonly:a}))))}function Wa(t){return t.map(n=>({name:"*",type:"user",entityRef:`user:${n}/*`})).sort((n,l)=>n.entityRef.toLowerCase().localeCompare(l.entityRef.toLowerCase()))}function Yt(t){return`${t.palette.primary.main}50`}const za=N(t=>({indicator:{right:"unset"},tab:{maxWidth:"none","&.Mui-selected":{backgroundColor:Yt(t),color:t.palette.primary.main}}}));function Ga({options:t,selected:n,onChange:l,readonly:r=!1}){const a=za();return e.createElement(Yn,{orientation:"vertical",value:t.map(({id:o})=>o).indexOf(n),onChange:(o,i)=>l(t[i].id),indicatorColor:"primary",TabIndicatorProps:{className:a.indicator}},t.map(o=>e.createElement(Jn,{key:o.id,label:o.displayText.toUpperCase(),className:a.tab,disabled:r})))}const Ua=["condition","anyOf","allOf","not"],Jt={condition:"Condition",anyOf:"Any of",allOf:"All of",not:"Not"};function pt(t){return t===null?!1:t.hasOwnProperty("id")&&t.hasOwnProperty("ruleName")&&t.hasOwnProperty("parameters")}function xe(t){return t.hasOwnProperty("levelType")}function Va(t){return t==="anyOf"||t==="allOf"||t==="not"}function _a(t){return t?{id:t.id,match:Ya(t),decisionType:Ja(t),criteria:et(t.decision)?Le(t.decision.conditions):null}:{id:ce(),match:{method:"specificPermission"},decisionType:"allow",criteria:null}}function Ya(t){var n;return t.match==="*"?{method:"all"}:t.match.name?{method:"specificPermission",name:t.match.name}:t.match.resourceType||(n=t.match.actions)!=null&&n.length?{method:"filter",resourceType:t.match.resourceType,actions:t.match.actions}:{method:"specificPermission"}}function Ja(t){return typeof t.decision=="string"?t.decision:"conditional"}function Le(t){const n=ce();return ol(t)?{id:n,levelType:"allOf",children:t.allOf.map(l=>Le(l))}:il(t)?{id:n,levelType:"anyOf",children:t.anyOf.map(l=>Le(l))}:cl(t)?{id:n,levelType:"not",children:[Le(t.not)]}:{id:n,ruleName:t.rule,parameters:t.params}}function qt(t,n){if(!t)return!1;if(xe(t))return t.children.length>0&&t.children.every(r=>qt(r,n));if(!t.ruleName)return!1;const l=n==null?void 0:n.find(({name:r})=>r===t.ruleName);return l?l.paramsSchema?new kt({allErrors:!0}).compile(l.paramsSchema)(t.parameters):!0:!1}function qa(t,n,l){return{id:t,match:Kt(n,l),decision:l}}function Kt({method:t,...n},l){return t==="all"?"*":l&&et(l)?{resourceType:l.resourceType,...n}:n}function ft(t){return pt(t)?{rule:t.ruleName,params:t.parameters}:t.levelType==="not"?{not:ft(t.children[0])}:{[t.levelType]:t.children.map(n=>ft(n))}}const Ka=N(t=>({toggleButton:{"&.Mui-selected":{backgroundColor:Yt(t),color:t.palette.primary.main},"&.Mui-selected:hover":{backgroundColor:"#97BBE8"},color:t.palette.primary.main,border:`1px solid ${t.palette.primary.main}`}}));function Et({className:t,...n}){const l=Ka();return e.createElement(Pl,{className:`${l.toggleButton} ${t}`,...n})}const Qa=N({fullWidth:{width:"100%","& > *":{flexGrow:1}}});function Xa({className:t,fullWidth:n,...l}){const r=Qa();return e.createElement(Dl,{className:`${n?r.fullWidth:""} ${t}`,...l})}function Za(t,n){const l=(t!=null?t:[]).filter(o=>sl(o,Kt(n))),r=Tl(l,o=>Ue(o)?o.resourceType:void 0),a=r.length===1&&Ue(r[0])?r[0].resourceType:void 0;return{permissions:l,commonResourceType:a}}const er=N(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Qt="Permission name";function tr({name:t="",readonly:n,onNameChange:l}){const r=er(),a=It();return e.createElement(Ke,{className:r.fullWidth,variant:"outlined",disabled:n},e.createElement(ke,{id:"match-by-name-dropdown"},Qt),e.createElement(Qe,{labelId:"match-by-name-dropdown",label:Qt,value:a?t:"",onChange:o=>l==null?void 0:l(o.target.value)},a==null?void 0:a.map(o=>e.createElement(z,{key:o.name,value:o.name},o.name))))}const nr=N(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Xt="Resource type";function lr({resourceType:t="",readonly:n,onResourceTypeChange:l}){const r=nr(),a=Ot();return e.createElement(Ke,{className:r.fullWidth,variant:"outlined",disabled:n},e.createElement(ke,{id:"match-by-resource-dropdown"},Xt),e.createElement(Qe,{labelId:"match-by-resource-dropdown",label:Xt,value:a?t:"",onChange:o=>l==null?void 0:l(o.target.value),displayEmpty:!0},a==null?void 0:a.map(o=>e.createElement(z,{key:o,value:o},o))))}const ar="Action";function rr({actions:t,readonly:n,onActionsChange:l}){return e.createElement(nt,{multiple:!0,id:"match-by-attribute-dropdown",options:["create","read","update","delete"],getOptionLabel:r=>r,value:t!=null?t:[],onChange:(r,a)=>l==null?void 0:l(a),filterSelectedOptions:!0,renderInput:r=>e.createElement(Ee,{...r,variant:"outlined",label:ar,placeholder:"Choose attributes",margin:"normal"}),disabled:n})}const or=N(t=>({descriptiveText:{fontWeight:500,marginBottom:t.spacing(1)}})),Fe=({children:t})=>{const n=or();return e.createElement(b,{variant:"body2",className:n.descriptiveText},t)},Zt="#FF737F",ir="#E22134";function en({condition:t}){return e.createElement(Fe,null,e.createElement(f,{component:"span",color:Zt},t.ruleName,"("),e.createElement(f,{component:"span",color:ir},JSON.stringify(t.parameters)),e.createElement(f,{component:"span",color:Zt},")"))}const tn=({children:t})=>e.createElement(f,{pl:3},t);function nn({level:t}){return e.createElement(e.Fragment,null,e.createElement(Fe,null,Jt[t.levelType]),e.createElement(tn,null,t.children.map((n,l)=>xe(n)?e.createElement(nn,{key:l,level:n}):e.createElement(en,{key:l,condition:n}))))}const cr="#4CAF50";function sr({permissionCriteria:t}){return e.createElement("div",null,e.createElement(Fe,null,"If the below conditions are met"),e.createElement(tn,null,pt(t)&&e.createElement(en,{condition:t}),xe(t)&&e.createElement(nn,{level:t})),e.createElement(Fe,null,"Then the action is"," ",e.createElement(f,{component:"span",color:cr},"allowed")))}const mr=N(()=>({addButton:{paddingLeft:40,paddingRight:40}}));function ln({onSelect:t}){const n=mr(),l=ae(null),[r,a]=k(!1),o=()=>{a(i=>!i)};return e.createElement("div",null,e.createElement(T,{className:n.addButton,variant:"outlined",color:"primary",onClick:o,ref:l},"Add"),e.createElement(Ct,{anchorEl:l.current,open:r,onClose:o,BackdropProps:{}},Ua.map(i=>e.createElement(z,{key:i,onClick:()=>{t==null||t(i),a(!1)}},Jt[i]))))}const ur=N(t=>({editor:{"--jse-main-border":`1px solid ${t.palette.divider}`,"--jse-panel-border":`1px solid ${t.palette.divider}`,"--jse-message-error-background":t.palette.error.main,"--jse-message-warning-background":t.palette.warning.main,"--jse-background-color":t.palette.background.default,"--jse-panel-background":t.palette.background.default,"--jse-delimiter-color":t.palette.type==="light"?"rgba(0, 0, 0, 0.38)":"rgba(255, 255, 255, 0.38)","--jse-error-color":t.palette.text.primary,"--jse-key-color":t.palette.text.primary,"--jse-value-color":t.palette.text.primary,"--jse-text-color":t.palette.text.primary,"--jse-panel-color-readonly":t.palette.text.hint,"--jse-value-color-string":t.palette.status.ok,"--jse-value-color-null":t.palette.status.warning,"--jse-value-color-number":t.palette.status.error,"--jse-value-color-boolean":t.palette.status.running,"--jse-font-family":"inherit"}})),dr=t=>"parseError"in t,pr=t=>{var n;return t?dr(t)?!!t.parseError:((n=t==null?void 0:t.validationErrors)==null?void 0:n.length)>0:!1};function fr({onChange:t,schema:n,value:l}){const r=ae(null),a=ae(),o=ur();return V(()=>(r.current&&!a.current&&(a.current=new Al({target:r.current,props:{onChange:(i,s,{contentErrors:m})=>{!pr(m)&&Sl(i)&&t(JSON.parse(i.text))},validator:kl({schema:n}),content:{json:{}},mainMenuBar:!1,mode:Rl.text}})),()=>{var i;(i=a.current)==null||i.destroy(),a.current=void 0}),[t,n]),ht(()=>{var i;(i=a.current)==null||i.updateProps({content:{json:l}})}),e.createElement("div",{ref:r,className:o.editor,style:{height:300}})}const Er=[];function yr(t){const{onChange:n,schema:l,name:r}=t,{description:a,items:o}=l,[i,s]=e.useState(!1),m=Array.isArray(t.value)?t.value:Er,c=m.includes(ye),p=(E,P)=>{if(!Array.isArray(P)){const A=[...m];A[E]=P||"",n(A)}},d=R(()=>{n([...m,""])},[n,m]),u=E=>{n(m.filter((P,A)=>A!==E))},C=()=>{n(c?[]:[ye])},g=()=>{c&&s(!0)},y=()=>{s(!1)};return V(()=>{m.length?c&&m.length>1&&n([ye]):d()},[d,n,m,c]),!o||!("type"in o)?null:e.createElement(e.Fragment,null,(m!=null?m:[]).map((E,P,{length:A})=>e.createElement(rn,{allowEmptyStrings:!0,key:P,onChange:$=>p(P,$),name:P===0?r:"",schema:{description:P===A-1?a:"",type:o.type},value:E,controls:e.createElement(j,{size:"small",onClick:()=>u(P)},e.createElement($l,null))})),!!(m!=null&&m.length)&&e.createElement(f,{alignItems:"center",display:"flex",flexDirection:"row",justifyContent:"space-between"},e.createElement(f,null,e.createElement(xt,{control:e.createElement(_e,{checked:c,onChange:C,name:"checkedB",color:"primary"}),label:"Use the claims from the logged in users token"})),e.createElement(f,null,e.createElement(fe,{onClose:y,onOpen:g,open:i,title:"To add additional entries you must uncheck using the claims from the logged in user."},e.createElement("span",null,e.createElement(j,{disabled:c,size:"small",onClick:d},e.createElement(lt,null)))))))}function gr(t){const{onChange:n,schema:l,name:r,value:a}=t,{description:o}=l;return e.createElement(f,{mb:1},e.createElement(xt,{control:e.createElement(_e,{checked:a===!0,onChange:i=>{n(i.target.checked)},name:r,color:"primary"}),label:r}),o&&e.createElement(b,{display:"block",variant:"caption",color:"textSecondary"},o))}function hr({allowEmptyStrings:t,controls:n,name:l,onChange:r,schema:a,value:o}){const i=s=>{r(br({value:s.currentTarget.value,type:a.type}))};return e.createElement(f,{mb:1},e.createElement(f,{display:"flex",gridGap:6},e.createElement(Ee,{fullWidth:!0,id:l,label:l,placeholder:"Enter",variant:"outlined",size:"small",value:vr(o,t),onChange:yt(o,t)?void 0:i,disabled:yt(o,t)}),n&&e.createElement(f,{alignSelf:"center"},n)),a.description&&e.createElement(b,{variant:"caption",color:"textSecondary"},a.description,yt(o)&&!t&&e.createElement(e.Fragment,null," (switch to JSON editor to edit)")))}function yt(t,n=!1){return!n&&t===""||t===null||t===ye}function vr(t,n=!1){return!n&&t===""?"[empty string]":t===null?"[null]":t===ye?"[BackstageUserClaims]":t||""}function br({value:t,type:n}){switch(n){case"string":return t===""?void 0:t;case"number":case"integer":return Number.isNaN(Number(t))?void 0:Number(t);case"null":return t==="null"?null:void 0;default:return}}function an(t){return!!t&&"type"in t&&(t.type==="array"||t.type==="boolean"||t.type==="null"||t.type==="number"||t.type==="integer"||t.type==="string")}function Cr(t){return"type"in t&&t.type==="array"}function xr(t){return"type"in t&&t.type==="boolean"}function rn({schema:t,...n}){return an(t)?Cr(t)?e.createElement(yr,{...n,schema:t}):xr(t)?e.createElement(gr,{...n,schema:t}):e.createElement(hr,{...n,schema:t}):null}const Pr=new kt({allErrors:!0});function Dr({onChange:t,schema:n,value:l}){var r;const a=L(()=>Pr.compile(n),[n]),o=L(()=>a(l),[a,l]),i=Object.entries(n.properties),s=m=>c=>{t({...l,[m]:c})};return e.createElement(e.Fragment,null,i.map(([m,c])=>{var p;return e.createElement(rn,{isRequired:((p=n.required)==null?void 0:p.includes(m))||!1,key:m,name:m,onChange:s(m),schema:c,value:l==null?void 0:l[m]})}),e.createElement(Pt,{error:!o},(r=a.errors)==null?void 0:r[0].message))}const Nr=t=>!!t&&"properties"in t;function wr({onChange:t,rule:n,value:l}){const[r,a]=k(!1),{paramsSchema:o}=n!=null?n:{},i=()=>a(p=>!p);if(!Nr(o))return null;const s=!Tr(o),m=s||r,c=e.createElement(T,{size:"small",onClick:i,disabled:s},m?"Close editor":"Edit as JSON");return e.createElement(f,{marginTop:2},e.createElement("form",null,m?e.createElement(fr,{onChange:t,schema:o,value:l}):e.createElement(e.Fragment,null,e.createElement(f,{marginBottom:2},e.createElement(ke,null,"Parameters")),e.createElement(Dr,{onChange:t,schema:o,value:l}))),e.createElement(f,{display:"flex",flexDirection:"column",alignItems:"flex-end",marginTop:1},s?e.createElement(fe,{title:"Only JSON editing is supported for this parameter",arrow:!0},e.createElement("span",null,c)):c))}function Tr(t){return Object.values(t.properties).every(an)}const Ar=N(t=>({conditionCard:{minWidth:t.spacing(63)},conditionCardBar:{height:t.spacing(1),backgroundImage:"linear-gradient(90deg, #007DFF 0%, #0057B2 100%)"},autocomplete:{flex:1}}));function on({ruleName:t,parameters:n,resourceType:l,onChange:r,onDelete:a}){var o;const i=Ar(),s=$t(),m=(o=s==null?void 0:s.filter(u=>u.resourceType===l))!=null?o:[],c=m.find(u=>u.name===t),p=u=>{r(u,{})},d=R(u=>{r(t,u)},[r,t]);return e.createElement(f,{display:"flex",alignItems:"center"},e.createElement(Y,{className:i.conditionCard},e.createElement("div",{className:i.conditionCardBar}),e.createElement(pe,null,e.createElement(f,null,e.createElement(f,null,e.createElement(nt,{className:i.autocomplete,"data-testid":"rule-select",getOptionLabel:u=>u.name,getOptionSelected:(u,C)=>u.name===C.name,options:m,onChange:(u,C)=>p(C?C.name:null),renderInput:u=>e.createElement(e.Fragment,null,e.createElement(f,{marginBottom:2},e.createElement(ke,null,"Rule")),e.createElement(Ee,{...u,placeholder:"Select",variant:"outlined",size:"small",name:"rule"})),renderOption:u=>e.createElement(f,null,e.createElement(b,{variant:"body2"},u.name),e.createElement(b,{noWrap:!0,variant:"caption"},u.description)),value:c||null,PopperComponent:u=>e.createElement(qn,{...u,style:{width:"auto"},placement:"bottom-start"})})),e.createElement(f,{flex:"1"},e.createElement(f,{display:"flex",flexDirection:"column"},e.createElement(wr,{rule:c,onChange:d,value:n})))))),e.createElement(f,{ml:1},e.createElement(j,{"aria-label":"delete",onClick:a,size:"small"},e.createElement(ge,null))))}function je(){return{id:ce(),ruleName:null,parameters:{}}}const Sr=N(t=>({conditionTypeFormControl:{minWidth:80,marginLeft:t.spacing(1)}}));function kr({level:t,onSelect:n}){const l=Sr(),r=t.children.length>1;return e.createElement(f,{display:"flex",alignItems:"center"},e.createElement(Ke,{className:l.conditionTypeFormControl},e.createElement(Qe,{value:t.levelType,onChange:a=>n==null?void 0:n(a.target.value)},e.createElement(z,{key:"anyOf",value:"anyOf"},"Any of"),e.createElement(z,{key:"allOf",value:"allOf"},"All of"),e.createElement(z,{key:"not",value:"not",disabled:r},"Not"))),e.createElement(f,{ml:1},e.createElement(j,{"aria-label":"delete",onClick:()=>n==null?void 0:n(null),size:"small"},e.createElement(ge,null))))}const Rr=N(t=>({treeVerticalSpacer:{width:t.spacing(2),borderLeft:`1px solid ${t.palette.status.aborted}`},treeHorizontalSpacer:{height:t.spacing(3),borderLeft:`1px solid ${t.palette.status.aborted}`},treeVerticalBranchHalf:{position:"absolute",height:"50%",borderLeft:`1px solid ${t.palette.status.aborted}`,alignSelf:"flex-start"},treeVerticalBranchFull:{borderLeft:`1px solid ${t.palette.status.aborted}`,alignSelf:"stretch"},treeHorizontalBranch:{width:t.spacing(2),borderTop:`1px solid ${t.palette.status.aborted}`}}));function cn({level:t,resourceType:n,onChange:l,parentConditionType:r,isRoot:a=!1}){const o=Rr(),i=R((g,y)=>{const E=[...t.children];return E.splice(g,1,y),E},[t]),s=R(g=>{l({...t,children:g})},[l,t]),m=R(g=>{g===null?l(null):g==="not"&&t.children.length>1?l({...t,levelType:g,children:t.children.slice(0,1)}):l({...t,levelType:g})},[l,t]),c=R((g,y)=>{s(g===null?sn(t.children,y):i(y,g))},[t,s,i]),p=g=>{const y=ce();g==="condition"?s([...t.children,je()]):g==="not"?s([...t.children,{id:y,levelType:g,children:[]}]):Va(g)&&s([...t.children,{id:y,levelType:g,children:[je()]}])},d=g=>{s(sn(t.children,g))},u=L(()=>t.children.map((g,y)=>(E,P)=>{s(i(y,{...g,ruleName:E,parameters:P}))}),[t.children,s,i]),C=L(()=>t.children.map((g,y)=>E=>c(E,y)),[t.children,c]);return e.createElement("div",null,!a&&e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(f,{display:"flex",alignItems:"center",position:"relative"},!a&&e.createElement(e.Fragment,null,e.createElement("div",{className:r==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch})),e.createElement(kr,{level:t,onSelect:m})),e.createElement(f,{display:"flex"},a||r==="not"?e.createElement(f,{pl:2}):e.createElement("div",{className:o.treeVerticalSpacer}),!a&&e.createElement(f,{pl:2}),e.createElement("div",null,t.children.map((g,y)=>xe(g)?e.createElement(f,{key:g.id},e.createElement(cn,{level:g,resourceType:n,parentConditionType:t.levelType,onChange:C[y]})):e.createElement(Pe,{key:g.id},e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(f,{display:"flex",alignItems:"center",position:"relative"},e.createElement("div",{className:t.levelType==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch}),e.createElement(on,{ruleName:g.ruleName,parameters:g.parameters,resourceType:n,onChange:u[y],onDelete:()=>d(y)})))),!(t.levelType==="not"&&t.children.length>=1)&&e.createElement(e.Fragment,null,e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(f,{display:"flex",alignItems:"center",position:"relative"},e.createElement("div",{className:o.treeVerticalBranchHalf}),e.createElement("div",{className:o.treeHorizontalBranch}),e.createElement(ln,{onSelect:p}))))))}function sn(t,n){const l=[...t];return l.splice(n,1),l}const $r=N(t=>({paper:{backgroundColor:t.palette.background.default,padding:t.spacing(3),marginBottom:t.spacing(3),minHeight:t.spacing(48)}}));function Ir({permissionCriteria:t,resourceType:n,onUpdate:l,readonly:r=!1}){const a=$r(),o=R(p=>{l(d=>({...d,...p}))},[l]),i=R(p=>{const d=ce();o(p==="condition"?je():p==="not"?{id:d,levelType:p,children:[]}:{id:d,levelType:p,children:[je()]})},[o]),s=R((p,d)=>{l(u=>({...u,ruleName:p,parameters:d}))},[l]),m=R(()=>{l(null)},[l]);let c;return r?c=e.createElement(sr,{permissionCriteria:t}):t===null?c=e.createElement(ln,{onSelect:i}):pt(t)?c=e.createElement(on,{ruleName:t.ruleName,parameters:t.parameters,resourceType:n,onChange:s,onDelete:m}):xe(t)&&(c=e.createElement(cn,{level:t,resourceType:n,onChange:l,isRoot:!0})),e.createElement(Kn,{variant:"outlined",className:a.paper},c)}const Or=N(t=>({dialogTitle:{display:"flex",alignItems:"center",justifyContent:"space-between"},fullWidth:{width:"100%","& > *":{flexGrow:1}},infoIcon:{position:"absolute",right:t.spacing(3)},content:{padding:t.spacing(7)},saveButton:{paddingLeft:t.spacing(5),paddingRight:t.spacing(5)},contentContainerConditional:{display:"flex",gap:t.spacing(5),maxWidth:1480}})),Br={specificPermission:"Choose a specific permission",filter:"Filter by permission properties",all:"Match all permissions"},mn="Choose the name of a resource permission or filter by resource type to set a conditional decision.";function Mr({rolePermission:t,readonly:n=!1,onClose:l,onSave:r}){const a=Or(),o=It(),i=$t(),s=Yl(),m=_a(t),[c,p]=k(m.match),[d,u]=k(m.decisionType),[C,g]=k(m.criteria),y=L(()=>Za(o,c),[o,c]),E=d==="conditional",P=E?"xl":"sm";V(()=>{E&&o&&!y.commonResourceType&&u("allow")},[E,o,y.commonResourceType,u]);const A=w=>{w!==null&&u(w)},$=L(()=>c.method==="specificPermission"&&!c.name||c.method==="filter"&&!c.resourceType&&!c.actions,[c]),H=L(()=>y.permissions.length===0?!1:!$,[y,$]),B=L(()=>d!=="conditional"?!0:!(!y.commonResourceType||!(s!=null&&s[y.commonResourceType].pluginId)||!qt(C,i)),[d,y,s,C,i]),v=()=>{r==null||r(qa(m.id,c,d==="conditional"?{resourceType:y.commonResourceType,pluginId:s[y.commonResourceType].pluginId,conditions:ft(C)}:d))};return e.createElement(oe,{open:!0,maxWidth:P,onClose:l,fullWidth:!0},e.createElement(Se,{disableTypography:!0,className:a.dialogTitle},e.createElement(b,{variant:"h4",component:"h2"},"New Permission Decision"),e.createElement(T,{startIcon:e.createElement(tt,null),onClick:l},"Close")),e.createElement(X,{dividers:!0,className:a.content},e.createElement(f,{className:E?a.contentContainerConditional:void 0},e.createElement(f,{mb:5,flex:1},e.createElement(Ga,{options:Object.entries(Br).map(([w,h])=>({id:w,displayText:h})),selected:c.method,onChange:w=>p({method:w}),readonly:n})),e.createElement(f,{mb:5,height:189,flex:1},c.method==="specificPermission"&&e.createElement(tr,{name:c.name,readonly:n,onNameChange:w=>p({...c,name:w})}),c.method==="filter"&&e.createElement(e.Fragment,null,e.createElement(lr,{resourceType:c.resourceType,readonly:n,onResourceTypeChange:w=>p({...c,resourceType:w})}),e.createElement(rr,{actions:c.actions,readonly:n,onActionsChange:w=>p({...c,actions:w.length?w:void 0})}),$?null:e.createElement(e.Fragment,null,e.createElement(f,{marginY:2},e.createElement(Xe,{variant:"middle"})),e.createElement(Pt,null,`Matched ${y.permissions.length} ${y.permissions.length===1?"permission":"permissions"}`)))),e.createElement(f,{mb:5,flex:1},e.createElement(f,{display:"flex",alignItems:"center"},e.createElement(Xa,{value:d,exclusive:!0,fullWidth:!0,"aria-label":"Decision result",onChange:(w,h)=>A(h)},e.createElement(Et,{value:"allow","aria-label":"Decision allowed",disabled:n},"Allow"),e.createElement(Et,{value:"deny","aria-label":"Decision denied",disabled:n},"Deny"),e.createElement(Et,{value:"conditional","aria-label":"Decision conditionally allowed",disabled:!y.commonResourceType||n},"Conditional")),!E&&!n&&e.createElement(fe,{title:mn},e.createElement(St,{className:a.infoIcon,color:"primary","aria-label":mn}))))),d==="conditional"&&!!y.commonResourceType&&e.createElement(Ir,{permissionCriteria:C,resourceType:y.commonResourceType,onUpdate:g,readonly:n}),!n&&e.createElement(f,{display:"flex",justifyContent:"flex-end"},e.createElement(T,{variant:"contained",color:"primary",className:a.saveButton,onClick:v,disabled:!H||!B},"Save"))))}const Lr=N(t=>({container:{display:"flex",position:"relative",alignItems:"center",gap:t.spacing(1),flexShrink:1,maxWidth:"100%",minWidth:0},input:({invalid:n})=>({boxSizing:"content-box",display:"block",maxWidth:"100%",padding:0,borderWidth:2,borderStyle:"solid",borderColor:n?t.palette.error.main:"transparent",borderRadius:t.shape.borderRadius,backgroundColor:"transparent",color:t.palette.textContrast,fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit",fontWeight:"inherit",textOverflow:"ellipsis"}),hiddenSpan:{position:"absolute",top:0,left:0,borderWidth:1,whiteSpace:"pre",opacity:0,pointerEvents:"none"}}));function un({invalid:t,name:n,value:l,onTextChange:r}){const a=Lr({invalid:t}),[o,i]=k(!1),[s,m]=k(null),c=ae(null),[p,d]=k(l);V(()=>{d(l)},[l]),An(()=>{c.current&&s&&c.current.style.setProperty("width",`max(${s.getBoundingClientRect().width}px, 3ch)`)},[s,p]);const u=()=>{i(!1),d(l)},C=()=>{i(!1),r==null||r(p)},g=()=>{var E;o?C():(i(!0),(E=c.current)==null||E.focus())},y=E=>{var P;E.key==="Enter"&&((P=c.current)==null||P.blur()),E.key==="Escape"&&u()};return e.createElement(e.Fragment,null,e.createElement("div",{className:a.container},e.createElement("input",{"aria-label":n,className:a.input,name:n,ref:c,onChange:E=>d(E.target.value),onFocus:g,onBlur:C,onKeyDown:y,value:p}),e.createElement("span",{"aria-hidden":"true",className:a.hiddenSpan,ref:m},p),e.createElement(j,{onClick:g,size:"small"},o?e.createElement(Ol,{"aria-label":"Save title"}):e.createElement(Il,{"aria-label":"Edit title"}))))}const dn=t=>{if(t.success)return{};const n={};for(const l of t.error.issues)n[l.path.join(".")]=!0;return n},pn=({children:t,onConfirm:n,message:l,title:r})=>{const[a,o]=k(!1),i=()=>o(!1),s=()=>o(!0),m=()=>{n(),i()};return e.createElement(e.Fragment,null,t({onClick:s}),e.createElement(oe,{open:a,onClose:i},e.createElement(Se,null,e.createElement(f,{display:"flex",justifyContent:"space-between",alignItems:"center"},r)),e.createElement(X,null,e.createElement(Qn,null,l)),e.createElement(Ve,null,e.createElement(T,{"aria-label":"Cancel action",color:"primary",onClick:i},"Cancel"),e.createElement(T,{"aria-label":"Confirm action",color:"secondary",onClick:m,variant:"contained"},"Confirm"))))},fn=({helpText:t})=>e.createElement(f,{display:"flex",alignItems:"center"},e.createElement(f,{component:"span",mr:1},e.createElement(b,{variant:"body2",noWrap:!0},"Reorder")),e.createElement(fe,{title:t},e.createElement(St,{color:"primary","aria-label":t}))),En=(t,n,l)=>{const r=n+l;if(r<0||r>=t.length)return t;const a=[...t];return[a[r],a[n]]=[a[n],a[r]],a},yn=({array:t,index:n,onReorder:l})=>{const r=n===0,a=n===t.length-1;return e.createElement(f,{display:"flex"},e.createElement(j,{disabled:r,onClick:()=>l(En(t,n,-1)),"aria-label":"Move up",size:"small"},e.createElement(Ml,null)),e.createElement(j,{disabled:a,onClick:()=>l(En(t,n,1)),"aria-label":"Move down",size:"small"},e.createElement(Bl,null)))},Fr=N(()=>({emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function gn({src:t,alt:n}){const l=Fr();return e.createElement("img",{src:t,className:`${l.emptyStateImage} `,alt:n})}const jr="Use the arrows to change the order in which permission decisions are evaluated.";function Hr({diff:t,permissions:n,onReorderPermissions:l,onNewPermissionClick:r,onOpenPermission:a,onRemovePermissionClick:o,anyAllow:i,readonly:s=!1}){return e.createElement(e.Fragment,null,e.createElement(f,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(b,{variant:"h5"},"Permission Decisions"),!s&&n.length!==0&&e.createElement(T,{color:"primary",variant:"outlined",startIcon:e.createElement(lt,null),onClick:r},"New")),e.createElement(Ye,null,e.createElement(Je,null,e.createElement(U,null,!s&&!i&&e.createElement(D,{style:{width:0}},e.createElement(fn,{helpText:jr})),e.createElement(D,null,"Match by"),e.createElement(D,null,"Decision"),e.createElement(D,null),!s&&e.createElement(D,null))),e.createElement(qe,null,n.length===0&&e.createElement(U,null,e.createElement(D,{colSpan:5},e.createElement(Ne,{title:"No permission decisions set",description:"Click the button below to create your first permission.",missing:{customImage:e.createElement(gn,{src:Ll,alt:"No permission placeholder"})},action:e.createElement(T,{variant:"contained",color:"primary",onClick:r},"New permission decision")}))),n.map((m,c)=>e.createElement(U,{key:c},!s&&!i&&e.createElement(D,null,e.createElement(yn,{array:n,index:c,onReorder:l})),e.createElement(D,null,e.createElement(Xn,{onClick:()=>a(c)},e.createElement(b,{variant:"body2",color:"primary"},st(m)))),e.createElement(D,null,ca(m)),e.createElement(D,null,e.createElement(Ce,{operation:t==null?void 0:t.permissions[m.id].operation})),!s&&e.createElement(D,{align:"right"},e.createElement(pn,{message:"Are you sure you want to remove this permission decision?",onConfirm:()=>o(c),title:"Remove?"},p=>e.createElement(j,{...p,"aria-label":"Remove permission decision",size:"small"},e.createElement(ge,null)))))))))}function Wr(){const{roleId:t,versionId:n}=ze();return Re(t),Re(n),e.createElement(Me,{policyId:n},e.createElement(zr,{roleId:t}))}function zr({roleId:t}){const{diff:n,updateLocalDraft:l,policy:r}=ee(),a=r.roles.find(h=>h.id===t),o=n==null?void 0:n.roles[t],[i,s]=k(null),[m,c]=k(!1),p=Ge(),{NotFoundErrorPage:d}=p.getComponents(),u=_(),C=N(h=>({cardContainer:{margin:h.spacing(0)}}))();if(!a)return e.createElement(d,null);const g=a.name,y=h=>{const S=r.roles.findIndex(te=>te.id===h.id),O=[...r.roles];O.splice(S,1,h),l({...r,roles:O})},E=h=>{y({...a,name:h})},P=h=>{if(i===null)y({...a,permissions:[h,...a.permissions]});else{const S=[...a.permissions];S.splice(i,1,h),y({...a,permissions:S})}c(!1)},A=h=>{if(h==="*")y({...a,members:a.members==="*"?[]:"*"});else if(a.members==="*")y({...a,members:[h]});else{const S=a.members.includes(h)?a.members.filter(O=>O!==h):[...a.members,h];y({...a,members:S.length===0?"*":S})}},$=h=>{y({...a,permissions:a.permissions.filter((S,O)=>h!==O)})},H=h=>{y({...a,permissions:h})},B=dn(ml.safeParse(a)).name,v=r.status!=="draft",w=r.options.resolutionStrategy==="any-allow";return e.createElement(e.Fragment,null,e.createElement(Be,{pages:[{title:r.name,path:`../../../${r.id}`},{title:g}],header:e.createElement(Te,{titleComponent:e.createElement(Vt,null,r.name," \xA0\u01C0",v?e.createElement(e.Fragment,null,"\xA0",g):e.createElement(un,{invalid:B,value:g,onTextChange:E}),e.createElement(Ce,{operation:o==null?void 0:o.role.operation,size:"large"})),description:r.description},e.createElement(T,{variant:"outlined",color:"primary",onClick:()=>u("../..",{relative:"path"})},"Back to policy"))},e.createElement(F,{container:!0,className:C.cardContainer,spacing:4,direction:"row"},e.createElement(F,{item:!0,xs:6},e.createElement(Y,null,e.createElement(Ha,{diff:o||null,role:a,policyId:r.id,onToggleMember:A,readonly:v}))),e.createElement(F,{item:!0,xs:6},e.createElement(Y,null,e.createElement(Hr,{diff:o||null,permissions:a.permissions,onNewPermissionClick:()=>{s(null),c(!0)},onOpenPermission:h=>{s(h),c(!0)},onReorderPermissions:H,onRemovePermissionClick:$,anyAllow:w,readonly:v}))))),m&&e.createElement(Mr,{rolePermission:i!==null?a.permissions[i]:void 0,onClose:()=>c(!1),onSave:P,readonly:v}))}const Gr="Use the arrows to change the order in which roles are evaluated.";function Ur({}){const{diff:t,policy:n,createNewRole:l,updateLocalDraft:r}=ee(),a=_(),o=Vr(n),i=n.status!=="draft",s=n.options.resolutionStrategy==="any-allow",m=d=>{r({...n,roles:d})},c=d=>{r({...n,roles:n.roles.filter(({id:u})=>u!==d)})},p=()=>{a(`./roles/${l()}`)};return e.createElement(Y,null,e.createElement(f,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(b,{variant:"h3"},"Roles"),!i&&e.createElement(T,{color:"primary",variant:"outlined",startIcon:e.createElement(lt,null),onClick:()=>p()},"New role")),e.createElement(Ye,null,e.createElement(Je,null,e.createElement(U,null,!i&&!s&&e.createElement(D,{style:{width:0}},e.createElement(fn,{helpText:Gr})),e.createElement(D,null,"Name"),e.createElement(D,null,"Users"),e.createElement(D,null,"Groups"),!i&&e.createElement(D,{style:{width:0}}))),e.createElement(qe,null,o.map((d,u)=>e.createElement(U,{key:u},!i&&!s&&e.createElement(D,null,e.createElement(yn,{array:n.roles,index:u,onReorder:m})),e.createElement(D,null,e.createElement(f,{alignItems:"center",display:"flex",gridGap:8},e.createElement(de,{to:`roles/${d.id}`},d.name),e.createElement(Ce,{operation:t==null?void 0:t.roles[d.id].role.operation}))),e.createElement(D,null,d.userCount),e.createElement(D,null,d.groupCount),!i&&e.createElement(D,{align:"right"},e.createElement(pn,{message:"Are you sure you want to remove this role?",title:"Remove role?",onConfirm:()=>c(d.id)},C=>e.createElement(j,{...C,"aria-label":"Remove role",size:"small"},e.createElement(ge,null)))))))))}function Vr(t){return t.roles.map(n=>({id:n.id,name:n.name,userCount:Array.isArray(n.members)?n.members.filter(l=>l.startsWith("user:")).length:n.members,groupCount:Array.isArray(n.members)?n.members.filter(l=>l.startsWith("group:")).length:n.members}))}const _r=N(t=>({cardHeader:{padding:t.spacing(3,3),borderBottom:`1px solid ${t.palette.border}`},cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}},emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function Yr({readonly:t}){const n=_r(),l=_(),{createNewRole:r}=ee(),a=()=>{const o=r();l(`./roles/${o}`)};return e.createElement(Y,null,e.createElement(Dt,{title:"Roles",className:n.cardHeader}),e.createElement(pe,{className:n.cardContent},t?e.createElement(Ne,{title:"No roles configured",missing:"content"}):e.createElement(Ne,{title:"No roles yet",description:"Click the button below to create your first role.",missing:{customImage:e.createElement(gn,{src:Fl,alt:"No roles placeholder"})},action:e.createElement(T,{variant:"contained",color:"primary",onClick:()=>a()},"New role")})))}const Jr=N(t=>({new:{borderRadius:100,backgroundColor:t.palette.success.main,color:t.palette.common.white,padding:t.spacing(.5,1)}}));function qr(){const[t,n]=k(null),{canPublish:l,discardLocalDraft:r,exportPolicy:a,hasChanges:o,isValid:i,policy:s,publish:m,saveLocalDraftToServer:c}=ee(),p=_(),d=Jr();return e.createElement(e.Fragment,null,e.createElement(j,{onClick:u=>{n(u.currentTarget)}},e.createElement(jl,null)),e.createElement(Ct,{getContentAnchorEl:null,anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!t,onClose:()=>{n(null)},PaperProps:{style:{width:240}}},e.createElement(Ze,null,s.status==="draft"&&e.createElement(z,{disabled:!i,onClick:()=>c()},e.createElement(K,null,e.createElement(zl,{fontSize:"small"})),e.createElement(Q,null,"Save")),e.createElement(z,{disabled:!l,onClick:()=>m()},e.createElement(K,null,e.createElement(Wl,{fontSize:"small"})),e.createElement(Q,null,"Publish")),s.status==="draft"&&e.createElement(z,{disabled:!o,onClick:()=>r()},e.createElement(K,null,e.createElement(Hl,{color:o?"secondary":"inherit",fontSize:"small"})),e.createElement(Q,null,e.createElement(b,{color:o?"secondary":"inherit"},"Discard changes")))),e.createElement(Xe,null),e.createElement(Ze,null,e.createElement(z,{onClick:()=>a()},e.createElement(K,null,e.createElement(Ul,{fontSize:"small"})),e.createElement(Q,null,"Export"))),e.createElement(Xe,null),e.createElement(Ze,null,e.createElement(z,{disabled:!i,onClick:()=>p("./options")},e.createElement(K,null,e.createElement(Gl,{fontSize:"small"})),e.createElement(Q,null,"Options"),e.createElement(Zn,null,e.createElement(b,{className:d.new,variant:"caption"},"New"))))))}function Kr(){const{versionId:t}=ze();return Re(t),e.createElement(Me,{policyId:t},e.createElement(Qr,null))}function Qr(){const{policy:t,updateLocalDraft:n}=ee(),l=o=>{n({...t,name:o})},r=dn(ul.safeParse(t)).name,a=t.status!=="draft";return e.createElement(Be,{pages:[{title:t.name}],header:e.createElement(Te,{title:t.name,titleComponent:e.createElement(e.Fragment,null,e.createElement(Vt,null,a?t.name:e.createElement(un,{invalid:r,name:"Policy name",value:t.name,onTextChange:l}),e.createElement(Ft,{status:t.status})),Xr(t))},e.createElement(qr,null))},e.createElement(F,{item:!0,xs:12},t.roles.length>0?e.createElement(Ur,null):e.createElement(Yr,{readonly:a})))}function Xr(t){const n={created:"Created by ",published:"Last published by ",updated:"Last updated by "},{activityDateText:l,activityUser:r,timestamp:a}=Wt(t,n);return e.createElement(b,{variant:"body2"},e.createElement(b,{component:"span",display:"inline",variant:"body2"},`${l} ${r} `),e.createElement(Ht,{timestamp:a}))}const Zr=N(t=>({card:n=>({marginTop:t.spacing(3),height:"100%","&:hover":n.readonly?{pointerEvents:"none"}:{}}),cardHeader:{paddingBottom:t.spacing(2),alignItems:"flex-start"},defaultChip:{marginLeft:t.spacing(1),marginBottom:0},title:{display:"flex",alignItems:"center",paddingTop:t.spacing(.5),paddingBottom:t.spacing(1)}}));function hn(t){const n=Zr(t),{title:l,description:r,active:a,changeResolutionStrategy:o,defaultOption:i,readonly:s}=t,m=()=>{s||o()};return e.createElement(Y,{className:`${n.card}`,onClick:m},e.createElement(el,{disabled:s},e.createElement(pe,null,e.createElement(Dt,{className:n.cardHeader,avatar:e.createElement(tl,{checked:a,color:"primary",disabled:s}),title:e.createElement("div",{className:n.title},e.createElement(b,{variant:"h6",component:"h2"},l),i?e.createElement(Ae,{label:"Default",size:"small",className:n.defaultChip}):null),subheader:r}))))}const eo=N(t=>({title:{display:"flex",alignItems:"center",paddingBottom:t.spacing(2)},maxWidthWrapper:{maxWidth:"800px"},readOnlyChip:{marginLeft:t.spacing(1)},paragraph:{paddingBottom:t.spacing(1)}}));function to(){const{versionId:t}=ze();return Re(t),e.createElement(Me,{policyId:t},e.createElement(no,null))}function no(){const t=eo(),{policy:n,updateLocalDraft:l}=ee(),r=_(),a=n.status!=="draft",o=i=>{l({...n,options:{...n.options,resolutionStrategy:i}})};return e.createElement(Be,{pages:[{title:n.name,path:".."},{title:"Options"}],header:e.createElement(Te,{title:"Options"},e.createElement(T,{variant:"outlined",color:"primary",onClick:()=>r("..",{relative:"path"})},"Back to policy"))},e.createElement(F,{item:!0,xs:12,className:t.maxWidthWrapper},e.createElement("div",null,e.createElement("div",{className:t.title},e.createElement(b,{variant:"h5",component:"h1"},"Decision resolution strategy"),a?e.createElement(Ae,{label:"Read only",className:t.readOnlyChip}):null),e.createElement(b,{variant:"body2",component:"p",className:t.paragraph},"Multiple decisions from multiple roles could be applicable to a single user when authorizing a permission request. Please select the decision resolution strategy that makes sense for your policy."),e.createElement(b,{variant:"body2",component:"p",className:t.paragraph},"Please note this strategy will be applied to the whole policy and greatly affects the outcome of permission decisions."),e.createElement(hn,{title:"Any-allow",changeResolutionStrategy:()=>o("any-allow"),readonly:a,defaultOption:!0,description:e.createElement(e.Fragment,null,e.createElement(b,{variant:"body2",color:"textSecondary",component:"p",className:t.paragraph},"The first allow decision from all of the roles and decisions is the final result. A single explicit allow or an allow as a result of a conditional decision would result in a final allow decision, otherwise the decision is deny."),e.createElement(b,{variant:"body2",color:"textSecondary",component:"p",className:t.paragraph},"With this option, the order of roles and decisions does not matter.")),active:n.options.resolutionStrategy==="any-allow"}),e.createElement(hn,{title:"First match",changeResolutionStrategy:()=>o("first-match"),readonly:a,description:e.createElement(e.Fragment,null,e.createElement(b,{variant:"body2",color:"textSecondary",component:"p",className:t.paragraph},"The first matching decision from the first matching role that is applicable to the user is the final result, regardless if that decision is an allow, deny or conditional."),e.createElement(b,{variant:"body2",color:"textSecondary",component:"p",className:t.paragraph},"With this option, the order in which you define roles and decisions matters.")),active:n.options.resolutionStrategy==="first-match"}))))}function lo(){const t=Ge(),{NotFoundErrorPage:n}=t.getComponents();return e.createElement(Vl,{loading:e.createElement(we,null),unauthorized:e.createElement(n,null)},e.createElement(Xl,null,e.createElement(_l,null,e.createElement(kn,null,e.createElement(De,{element:e.createElement(Sa,null),path:"/"}),e.createElement(De,{element:e.createElement(Kr,null),path:"/versions/:versionId"}),e.createElement(De,{element:e.createElement(to,null),path:"/versions/:versionId/options"}),e.createElement(De,{element:e.createElement(Wr,null),path:"/versions/:versionId/roles/:roleId"})))))}export{lo as RBACRoot};
3
+ //# sourceMappingURL=Root-11543b00.esm.js.map
@@ -1,2 +1,2 @@
1
- import{createApiRef as b,createRouteRef as v,createPlugin as g,createApiFactory as R,fetchApiRef as B,discoveryApiRef as C,createRoutableExtension as $,createComponentExtension as U}from"@backstage/core-plugin-api";import{ResponseError as P}from"@backstage/errors";var S=(s,t,e)=>{if(!t.has(s))throw TypeError("Cannot "+e)},f=(s,t,e)=>{if(t.has(s))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(s):t.set(s,e)},r=(s,t,e)=>(S(s,t,"access private method"),e),n,d,a,o;const y=b({id:"plugin.rbac"});class T{constructor(t){f(this,n),f(this,a),this.fetchApi=t.fetchApi,this.discoveryApi=t.discoveryApi}async getPolicies(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/policies`);return r(this,a,o).call(this,e)}async getPolicy(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`);return r(this,a,o).call(this,i)}async getActivePolicy(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/active`);return r(this,a,o).call(this,e)}async searchMembers(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/members?query=${encodeURIComponent(t.query)}`);return r(this,a,o).call(this,i)}async authorize(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/authorize`);return r(this,a,o).call(this,e)}async createDraft(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r(this,a,o).call(this,i)}async updateDraft(t,e){const{fetch:i}=this.fetchApi,c=await i(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`,{method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}});return r(this,a,o).call(this,c)}async deleteDraft(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`,{method:"DELETE"});return r(this,a,o).call(this,i)}async publishPolicy(t,e){const{fetch:i}=this.fetchApi,c=await i(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}/publish`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:e.description})});return r(this,a,o).call(this,c)}async fetchAllPermissionMetadata(t){const e=await Promise.all(t.map(i=>r(this,n,d).call(this,i)));return{permissions:e.flatMap(({permissions:i})=>i),rules:e.flatMap(({rules:i})=>i)}}}n=new WeakSet,d=async function(s){var t,e,i,c;const m=await this.discoveryApi.getBaseUrl(s),l=await(await this.fetchApi.fetch(`${m}/.well-known/backstage/permissions/metadata`)).json(),u=(e=(t=l.permissions)==null?void 0:t.filter(Boolean))!=null?e:[],A=(c=(i=l.rules)==null?void 0:i.filter(Boolean))!=null?c:[];return{permissions:u,rules:A.map(w=>({...w,pluginId:s}))}},a=new WeakSet,o=async function(s){var t,e;if(s.ok)return s.status===204?void 0:s.json();const i=await P.fromResponse(s);throw i.message=(e=(t=i.body.error.message)!=null?t:i.message)!=null?e:"Unknown error",i};const h=v({id:"rbac"}),p=g({id:"rbac",routes:{root:h},apis:[R({api:y,deps:{fetchApi:B,discoveryApi:C},factory(s){return new T(s)}})]}),E=p.provide($({name:"RBACRoot",component:()=>import("./Root-2f3e058e.esm.js").then(s=>s.RBACRoot),mountPoint:h})),k=p.provide(U({name:"RBACSidebarItem",component:{lazy:()=>import("./RBACSidebarItem-cdefd88c.esm.js").then(s=>s.RBACSidebarItem)}}));export{E as R,h as a,p as b,k as c,y as r};
2
- //# sourceMappingURL=index-e1e7669d.esm.js.map
1
+ import{createApiRef as b,createRouteRef as v,createPlugin as g,createApiFactory as R,fetchApiRef as B,discoveryApiRef as C,createRoutableExtension as $,createComponentExtension as U}from"@backstage/core-plugin-api";import{ResponseError as P}from"@backstage/errors";var S=(s,t,e)=>{if(!t.has(s))throw TypeError("Cannot "+e)},f=(s,t,e)=>{if(t.has(s))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(s):t.set(s,e)},r=(s,t,e)=>(S(s,t,"access private method"),e),h,d,a,o;const y=b({id:"plugin.rbac"});class T{constructor(t){f(this,h),f(this,a),this.fetchApi=t.fetchApi,this.discoveryApi=t.discoveryApi}async getPolicies(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/policies`);return r(this,a,o).call(this,e)}async getPolicy(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`);return r(this,a,o).call(this,i)}async getActivePolicy(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/active`);return r(this,a,o).call(this,e)}async searchMembers(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/members?query=${encodeURIComponent(t.query)}`);return r(this,a,o).call(this,i)}async authorize(){const{fetch:t}=this.fetchApi,e=await t(`${await this.discoveryApi.getBaseUrl("rbac")}/authorize`);return r(this,a,o).call(this,e)}async createDraft(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r(this,a,o).call(this,i)}async updateDraft(t,e){const{fetch:i}=this.fetchApi,c=await i(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`,{method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}});return r(this,a,o).call(this,c)}async deleteDraft(t){const{fetch:e}=this.fetchApi,i=await e(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}`,{method:"DELETE"});return r(this,a,o).call(this,i)}async publishPolicy(t,e){const{fetch:i}=this.fetchApi,c=await i(`${await this.discoveryApi.getBaseUrl("rbac")}/policies/${t}/publish`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:e.description})});return r(this,a,o).call(this,c)}async fetchAllPermissionMetadata(t){const e=await Promise.all(t.map(i=>r(this,h,d).call(this,i)));return{permissions:e.flatMap(({permissions:i})=>i),rules:e.flatMap(({rules:i})=>i)}}}h=new WeakSet,d=async function(s){var t,e,i,c;const u=await this.discoveryApi.getBaseUrl(s);let n;try{n=await(await this.fetchApi.fetch(`${u}/.well-known/backstage/permissions/metadata`)).json()}catch{return{permissions:[],rules:[]}}const m=(e=(t=n.permissions)==null?void 0:t.filter(Boolean))!=null?e:[],A=(c=(i=n.rules)==null?void 0:i.filter(Boolean))!=null?c:[];return{permissions:m,rules:A.map(w=>({...w,pluginId:s}))}},a=new WeakSet,o=async function(s){var t,e;if(s.ok)return s.status===204?void 0:s.json();const i=await P.fromResponse(s);throw i.message=(e=(t=i.body.error.message)!=null?t:i.message)!=null?e:"Unknown error",i};const l=v({id:"rbac"}),p=g({id:"rbac",routes:{root:l},apis:[R({api:y,deps:{fetchApi:B,discoveryApi:C},factory(s){return new T(s)}})]}),E=p.provide($({name:"RBACRoot",component:()=>import("./Root-11543b00.esm.js").then(s=>s.RBACRoot),mountPoint:l})),k=p.provide(U({name:"RBACSidebarItem",component:{lazy:()=>import("./RBACSidebarItem-7f1b6ef3.esm.js").then(s=>s.RBACSidebarItem)}}));export{E as R,l as a,p as b,k as c,y as r};
2
+ //# sourceMappingURL=index-b4653372.esm.js.map
package/dist/index.d.ts CHANGED
@@ -6,11 +6,11 @@ import { SidebarItem } from '@backstage/core-components';
6
6
  /**
7
7
  * @public
8
8
  */
9
- declare type PropsFor<T> = T extends React.ComponentType<infer P> ? P : never;
9
+ type PropsFor<T> = T extends React.ComponentType<infer P> ? P : never;
10
10
  /**
11
11
  * @public
12
12
  */
13
- declare type RBACSidebarItemProps = Partial<PropsFor<typeof SidebarItem>>;
13
+ type RBACSidebarItemProps = Partial<PropsFor<typeof SidebarItem>>;
14
14
 
15
15
  /**
16
16
  * @public
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import{R as i,c as m,b as R}from"./esm/index/index-e1e7669d.esm.js";import"@backstage/core-plugin-api";import"@backstage/errors";export{i as RBACRoot,m as RBACSidebarItem,R as rbacPlugin};
1
+ import{R as i,c as m,b as R}from"./esm/index-b4653372.esm.js";import"@backstage/core-plugin-api";import"@backstage/errors";export{i as RBACRoot,m as RBACSidebarItem,R as rbacPlugin};
2
2
  //# sourceMappingURL=index.esm.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spotify/backstage-plugin-rbac",
3
3
  "description": "Control access to actions and data in Backstage with ease.",
4
- "version": "0.5.1",
4
+ "version": "0.5.3",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "homepage": "https://backstage.spotify.com/",
7
7
  "main": "dist/index.esm.js",
@@ -23,21 +23,21 @@
23
23
  "postpack": "backstage-cli package postpack"
24
24
  },
25
25
  "dependencies": {
26
- "@backstage/catalog-model": "^1.2.1",
27
- "@backstage/core-components": "^0.12.5",
28
- "@backstage/core-plugin-api": "^1.5.0",
26
+ "@backstage/catalog-model": "^1.3.0",
27
+ "@backstage/core-components": "^0.13.1",
28
+ "@backstage/core-plugin-api": "^1.5.1",
29
29
  "@backstage/errors": "^1.1.5",
30
- "@backstage/plugin-catalog-react": "^1.4.0",
31
- "@backstage/plugin-permission-common": "^0.7.4",
32
- "@backstage/plugin-permission-node": "^0.7.6",
33
- "@backstage/plugin-permission-react": "^0.4.11",
34
- "@backstage/theme": "^0.2.18",
30
+ "@backstage/plugin-catalog-react": "^1.6.0",
31
+ "@backstage/plugin-permission-common": "^0.7.5",
32
+ "@backstage/plugin-permission-node": "^0.7.8",
33
+ "@backstage/plugin-permission-react": "^0.4.12",
34
+ "@backstage/theme": "^0.3.0",
35
35
  "@backstage/types": "^1.0.2",
36
36
  "@material-ui/core": "^4.12.2",
37
37
  "@material-ui/icons": "^4.9.1",
38
38
  "@material-ui/lab": "4.0.0-alpha.61",
39
- "@spotify/backstage-plugin-core": "^0.5.0",
40
- "@spotify/backstage-plugin-rbac-common": "^0.5.0",
39
+ "@spotify/backstage-plugin-core": "^0.5.2",
40
+ "@spotify/backstage-plugin-rbac-common": "^0.5.2",
41
41
  "ajv": "^8.11.2",
42
42
  "file-saver": "^2.0.5",
43
43
  "js-yaml": "^4.1.0",
@@ -46,20 +46,22 @@
46
46
  "luxon": "^3.1.1",
47
47
  "react-use": "^17.2.4",
48
48
  "uuid": "^9.0.0",
49
- "vanilla-jsoneditor": "^0.16.0",
49
+ "vanilla-jsoneditor": "^0.17.0",
50
50
  "zod": "^3.20.0",
51
51
  "zod-to-json-schema": "^3.20.2"
52
52
  },
53
53
  "peerDependencies": {
54
- "@backstage/plugin-permission-node": "^0.7.6",
54
+ "@backstage/plugin-permission-node": "^0.7.8",
55
55
  "react": "^16.13.1 || ^17.0.0",
56
56
  "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@backstage/cli": "^0.22.4",
60
- "@backstage/core-app-api": "^1.6.0",
61
- "@backstage/dev-utils": "^1.0.13",
62
- "@backstage/test-utils": "^1.2.6",
59
+ "@backstage/cli": "^0.22.7",
60
+ "@backstage/core-app-api": "^1.8.0",
61
+ "@backstage/dev-utils": "^1.0.15",
62
+ "@backstage/test-utils": "^1.3.1",
63
+ "@internal/e2e-test-utils": "^0.0.0",
64
+ "@playwright/test": "^1.32.3",
63
65
  "@testing-library/jest-dom": "^5.10.1",
64
66
  "@testing-library/react": "^12.1.5",
65
67
  "@testing-library/react-hooks": "^8.0.1",
@@ -1,2 +0,0 @@
1
- import{useApi as i}from"@backstage/core-plugin-api";import e from"react";import u from"react-use/lib/useAsync";import{r as m}from"./index-e1e7669d.esm.js";function p({children:n,loading:l=null,unauthorized:o=null}){var r;const a=i(m),t=u(()=>a.authorize(),[]);return t.loading?e.createElement(e.Fragment,null,l):(r=t.value)!=null&&r.authorized?e.createElement(e.Fragment,null,n):e.createElement(e.Fragment,null,o)}export{p as A};
2
- //# sourceMappingURL=Authorized-93283dff.esm.js.map
@@ -1,3 +0,0 @@
1
- import e,{createContext as ke,useState as O,useCallback as B,useMemo as L,useContext as Re,useEffect as V,Fragment as ye,useRef as Q,useReducer as pn,useLayoutEffect as fn}from"react";import{Link as En,useNavigate as _,useParams as lt,Routes as yn,Route as Se}from"react-router-dom";import{useApi as $,configApiRef as gn,alertApiRef as X,useApp as Ie,useRouteRef as hn}from"@backstage/core-plugin-api";import le from"react-use/lib/useAsync";import{isResourcePermission as at}from"@backstage/plugin-permission-common";import{r as W,a as vn}from"./index-e1e7669d.esm.js";import{forEach as bn,mapValues as Cn,groupBy as xn,uniq as Dn}from"lodash";import{Link as ae,Progress as ge,ErrorPanel as ot,Table as Pn,Breadcrumbs as Nn,Page as Tn,Header as wn,Content as An,ContentHeader as Oe,EmptyState as he}from"@backstage/core-components";import Z from"react-use/lib/useAsyncFn";import it from"react-use/lib/useMount";import{makeStyles as w,Chip as ct,Box as p,Typography as D,Tooltip as oe,Card as Y,CardContent as ve,List as kn,ListItem as st,ListItemIcon as mt,ListItemText as ut,CardActions as Rn,Dialog as ee,DialogTitle as be,IconButton as j,DialogContent as J,DialogActions as Be,Button as T,TextField as ie,CircularProgress as dt,Container as Sn,Grid as H,Checkbox as $e,debounce as In,Table as Me,TableHead as Fe,TableRow as z,TableCell as x,TableBody as Le,FormControlLabel as pt,FormHelperText as ft,InputLabel as Ce,Paper as On,Menu as Bn,MenuItem as te,Popper as $n,FormControl as je,Select as He,Tabs as Mn,Tab as Fn,Divider as Ln,DialogContentText as jn,ButtonBase as Hn,CardHeader as Wn}from"@material-ui/core";import zn from"@material-ui/icons/Publish";import Un from"@material-ui/icons/FilterNone";import{DateTime as xe}from"luxon";import We from"@material-ui/icons/Close";import Vn from"@material-ui/icons/CalendarToday";import Et from"@material-ui/icons/Person";import Gn from"@material-ui/icons/FiberManualRecord";import yt from"lodash/keyBy";import _n from"lodash/isEqual";import{isConditionalDecision as ze,PolicyConfigParser as De,BackstageUserPlaceholder as ce,isAllOfPermissionCriteria as Yn,isAnyOfPermissionCriteria as Jn,isNotPermissionCriteria as Kn,isMatchingPermission as qn,RoleParser as Qn,UpdateDraftRequestParser as Xn}from"@spotify/backstage-plugin-rbac-common";import{useAutoUpdatingRelativeTime as Zn,SpotifyLicenseBanner as er,invariant as Ue}from"@spotify/backstage-plugin-core";import{v4 as ne}from"uuid";import gt from"@material-ui/icons/ReportProblemOutlined";import tr from"react-use/lib/useLocalStorage";import{saveAs as nr}from"file-saver";import rr,{dump as lr}from"js-yaml";import ht from"lodash/omit";import ar from"lodash/pickBy";import Ve from"@material-ui/icons/Add";import se from"@material-ui/icons/Delete";import{parseEntityRef as K,DEFAULT_NAMESPACE as or}from"@backstage/catalog-model";import{humanizeEntityRef as ir,catalogApiRef as cr}from"@backstage/plugin-catalog-react";import{Autocomplete as Ge,ToggleButton as sr,ToggleButtonGroup as mr}from"@material-ui/lab";import ur from"@material-ui/icons/Group";import dr from"@material-ui/icons/GroupWork";import pr from"lodash/uniqBy";import vt from"@material-ui/icons/Info";import{JSONEditor as fr,isTextContent as Er,createAjvValidator as yr,Mode as gr}from"vanilla-jsoneditor";import bt from"ajv";import hr from"@material-ui/icons/Remove";import vr from"@material-ui/icons/Edit";import br from"@material-ui/icons/Check";import Cr from"@material-ui/icons/KeyboardArrowDown";import xr from"@material-ui/icons/KeyboardArrowUp";import Dr from"../../images/no-permissions.svg";import Pr from"../../images/no-roles.svg";import{A as Nr}from"./Authorized-93283dff.esm.js";import"@backstage/errors";const Ct=ke(null),Tr=({children:t})=>{const n=$(gn),r=$(W),a=$(X),[l,o]=O(null),i=B(async()=>{var m;if(!l){const u=await r.fetchAllPermissionMetadata((m=n.getOptionalStringArray("permission.permissionedPlugins"))!=null?m:[]),c=Ar(u.rules);bn(c,f=>{f.length!==1&&a.post({message:`The plugin(s) ${f.slice(1).join(", ")} expose rules which are conflicting with rules exposed by the ${f[0]} plugin. These rules will not be available for use. Please contact RBAC support if you need assistance resolving this issue.`,severity:"error"})});const s=kr(u,c);return o(s),s}return l},[a,l,r,n]);return e.createElement(Ct.Provider,{value:L(()=>({getMetadata:i}),[i])},t)};function Pe(){const t=Re(Ct),{value:n}=le(async()=>t==null?void 0:t.getMetadata(),[t]);return n}function xt(){var t;const n=Pe();return(t=n==null?void 0:n.rules)!=null?t:null}function Dt(){var t;const n=Pe();return(t=n==null?void 0:n.permissions)!=null?t:null}function Pt(){const t=Pe();return t?[...new Set(t.permissions.filter(n=>at(n)).map(({resourceType:n})=>n))]:null}function wr(){const t=Pe(),n=Pt();return!t||!n?null:n.reduce((r,a)=>{const l=t.rules.find(o=>o.resourceType===a);return l&&(r[a]={pluginId:l.pluginId}),r},{})}function Ar(t){return Cn(xn(t,"resourceType"),n=>Dn(n.map(({pluginId:r})=>r)))}function kr(t,n){return{...t,rules:t.rules.filter(({resourceType:r,pluginId:a})=>{const l=n[r];return a===l[0]})}}function Rr(t){throw new Error("Invalid state")}const Nt=ke({policies:void 0,setPolicies:()=>{},setPolicy:()=>{},getPolicy:()=>{},removePolicy:()=>{}}),_e=()=>Re(Nt);function Sr({children:t,initialState:n={policies:void 0,cache:{}}}){const[r,a]=O(n),l=B(u=>{a(c=>({...c,policies:u,cache:Tt(c.cache,u)}))},[]),o=B(u=>r.cache[u],[r.cache]),i=B(u=>a(c=>({...c,cache:{...c.cache,[u]:void 0},policies:void 0})),[]),m=B(u=>a(c=>({...c,policies:void 0,cache:Tt(c.cache,[u])})),[]);return e.createElement(Nt.Provider,{value:L(()=>({policies:r.policies,setPolicies:l,setPolicy:m,getPolicy:o,removePolicy:i}),[r.policies,l,m,o,i])},t)}function Tt(t,n){if(!n)return t;const r={...t};return n.forEach(a=>{r[a.id]=a}),r}const me=()=>{const t=$(W),{setPolicies:n,policies:r}=_e(),[{loading:a,error:l},o]=Z(()=>t.getPolicies(),[t],r?{loading:!1,value:{items:r,totalItems:r.length}}:{loading:!0}),i=B(async()=>{const m=await o();n(m.items)},[o,n]);return{loading:a,error:l,fetchPolicies:i}};function wt(){const t=$(W),n=$(X),{fetchPolicies:r}=me();return Z(async a=>{if(!a)return;const{roles:l,name:o,options:i}=a;return t.createDraft({roles:l,options:i,name:o}).then(r).catch(m=>(n.post({message:m.message,severity:"error"}),Promise.reject(m)))},[])}function At(){const t=$(W),n=$(X),r=Z(async(l,o)=>{if(l)return await t.publishPolicy(l.id,{description:o}),t.getPolicy(l.id)},[]),[{error:a}]=r;return V(()=>{a&&n.post({message:a.message,severity:"error"})},[a,n]),r}const Ir=w(t=>({chip:{margin:0},icon:{color:t.palette.success.main}}));function kt(t){const n=Ir();return t.status==="inactive"?null:t.status==="draft"?e.createElement(ct,{className:n.chip,label:"Draft",size:t.size}):e.createElement(ct,{className:n.chip,classes:{icon:n.icon},label:"Active",icon:e.createElement(Gn,null),size:t.size})}const Ye=(t,n)=>{const r=Object.entries(t);for(const[,a]of r){const l=n(a);for(const[,o]of r){const i=n(o);i.operation!=="ADDED"&&i.operation!=="REMOVED"&&(l.operation==="ADDED"&&l.indexAfter<i.indexAfter?i.indexBefore+=1:l.operation==="REMOVED"&&l.indexBefore<i.indexBefore&&(i.indexBefore-=1))}}for(const[,a]of r){const l=n(a);l.operation==="UNCHANGED"&&l.indexAfter!==l.indexBefore&&(l.operation=l.indexAfter>l.indexBefore?"MOVED_DOWN":"MOVED_UP")}return t},Je=(t,n)=>{const r=yt(n,"id"),a=Object.fromEntries(n.map((l,o)=>[l.id,{operation:"ADDED",indexAfter:o,indexBefore:-1,after:l,before:null}]));for(let l=0;l<t.length;l++){const o=t[l];if(a[o.id]){const i=!_n(o,r[o.id]);a[o.id].before=o,a[o.id].indexBefore=l,a[o.id].operation=i?"CHANGED":"UNCHANGED"}else a[o.id]={operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:l}}return Ye(a,l=>l)},Ke=(t,n)=>{if(t==="*")return n==="*"?{"*":{operation:"UNCHANGED",after:"*",before:"*",indexAfter:0,indexBefore:0}}:{"*":{operation:"REMOVED",after:null,before:"*",indexAfter:-1,indexBefore:0},...Object.fromEntries(n.map((a,l)=>[a,{operation:"ADDED",after:a,before:null,indexAfter:l,indexBefore:-1}]))};if(n==="*")return{"*":{operation:"ADDED",after:"*",before:null,indexAfter:0,indexBefore:-1},...Object.fromEntries(t.map((a,l)=>[a,{operation:"REMOVED",after:null,before:a,indexAfter:-1,indexBefore:l}]))};const r=Object.fromEntries(n.map((a,l)=>[a,{operation:"ADDED",after:a,before:null,indexAfter:l,indexBefore:-1}]));for(let a=0;a<t.length;a++){const l=t[a];r[l]?(r[l].before=l,r[l].indexBefore=a,r[l].operation="UNCHANGED"):r[l]={operation:"REMOVED",after:null,before:l,indexAfter:-1,indexBefore:a}}return Ye(r,a=>a)},Or=(t=[],n=[])=>{const r=yt(n,"id"),a=Object.fromEntries(n.map((l,o)=>[l.id,{role:{operation:"ADDED",indexAfter:o,indexBefore:-1,after:l,before:null},members:Ke([],l.members),permissions:Je([],l.permissions)}]));for(let l=0;l<t.length;l++){const o=t[l];if(r[o.id]){const i=r[o.id],m=Ke(o.members,i.members),u=Je(o.permissions,i.permissions),c=Object.values(u).some(({operation:E})=>E!=="UNCHANGED"),s=Object.values(m).some(({operation:E})=>E!=="UNCHANGED"),f=o.name!==i.name||c||s;a[o.id].role.before=o,a[o.id].role.indexBefore=l,a[o.id].role.operation=f?"CHANGED":"UNCHANGED",a[o.id].members=m,a[o.id].permissions=u}else a[o.id]={role:{operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:l},members:Ke(o.members,[]),permissions:Je(o.permissions,[])}}return Ye(a,({role:l})=>l)},Br=(t,n)=>{const r={resolutionStrategy:{operation:"UNCHANGED",before:t==null?void 0:t.resolutionStrategy,after:n==null?void 0:n.resolutionStrategy}};for(const a of Object.keys(r)){const l=a;r[l].before!==r[l].after&&(r[l].operation="CHANGED")}return r},$r=(t,n)=>{const r=Or((t==null?void 0:t.roles)||[],(n==null?void 0:n.roles)||[]),a=Br(t==null?void 0:t.options,n==null?void 0:n.options),l=(t==null?void 0:t.name)!==(n==null?void 0:n.name),o=Object.values(a).some(({operation:i})=>i!=="UNCHANGED");return{policy:{operation:l||o?"CHANGED":"UNCHANGED",before:t,after:n},roles:r,options:a}},Rt=t=>{const n=$(W),{value:r}=le(()=>n.getActivePolicy(),[n]);return L(()=>t?$r(r,t):null,[r,t])},qe=(t,n)=>{switch(n){case"ADDED":return t.palette.success.main;case"REMOVED":return t.palette.error.main;case"CHANGED":return t.palette.info.main;case"MOVED_UP":case"MOVED_DOWN":return t.palette.info.main;case"UNCHANGED":default:return t.palette.text.primary}},Mr=t=>{switch(t){case"ADDED":return"New";case"REMOVED":return"Removed";case"CHANGED":return"Changed";case"MOVED_UP":return"Moved up";case"MOVED_DOWN":return"Moved down";case"UNCHANGED":default:return"No changes"}};function Fr(t){var n;return ze(t.decision)?"Conditional":(n={allow:"Allow",deny:"Deny"}[t.decision])!=null?n:"Unknown"}function Qe(t){var n;if(t.match==="*")return"All";if(t.match.name)return t.match.name;const r=[];return t.match.resourceType&&r.push(t.match.resourceType),(n=t.match.actions)!=null&&n.length&&r.push(t.match.actions.join(", ")),r.join(" | ")}const Lr=w(t=>({root:({operation:n})=>({color:qe(t,n)})})),F=t=>e.createElement(D,{...t,variant:"body2"}),C=t=>{const n=Lr(t);return e.createElement(p,{...t,className:n.root,component:"span",fontWeight:"fontWeightBold"})},St=({policy:t})=>{var n,r,a;const l=Rt(t),o=(l==null?void 0:l.policy.operation)==="CHANGED"||Object.values((n=l==null?void 0:l.roles)!=null?n:{}).some(c=>c.role.operation!=="UNCHANGED");if(!l||!o)return e.createElement(p,null,"No changes");const i=!!l.policy.before&&!!l.policy.after&&l.policy.before.name!==l.policy.after.name,m=({before:c,after:s})=>c&&s&&c.name!==s.name,u=({operation:c})=>c!=="ADDED"&&c!=="REMOVED";return e.createElement(p,null,i&&e.createElement(F,null,"Policy name ",e.createElement(C,{operation:"CHANGED"},"changed")," from"," ",e.createElement(C,null,'"',(r=l.policy.before)==null?void 0:r.name,'"')," to"," ",e.createElement(C,null,'"',(a=l.policy.after)==null?void 0:a.name,'"')),Object.entries(l.roles).map(([c,{role:s,permissions:f,members:E}])=>{var v,y,d,g,P,A;return e.createElement(ye,{key:c},s.operation==="ADDED"&&e.createElement(F,null,"Role ",e.createElement(C,null,'"',(v=s.after)==null?void 0:v.name,'"')," has been"," ",e.createElement(C,{operation:"ADDED"},"added")),s.operation==="REMOVED"&&e.createElement(F,null,"Role ",e.createElement(C,null,'"',(y=s.before)==null?void 0:y.name,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")),m(s)&&e.createElement(F,null,"Role name changed from ",e.createElement(C,null,'"',(d=s.before)==null?void 0:d.name,'"')," ","to ",e.createElement(C,null,'"',(g=s.after)==null?void 0:g.name,'"')),s.indexAfter>s.indexBefore&&s.indexBefore!==-1&&e.createElement(F,null,"Role ",e.createElement(C,null,'"',(P=s.after)==null?void 0:P.name,'"')," has been"," ",e.createElement(C,{operation:"MOVED_DOWN"},"moved down")," in priority"),s.indexAfter<s.indexBefore&&s.indexAfter!==-1&&e.createElement(F,null,"Role ",e.createElement(C,null,'"',(A=s.after)==null?void 0:A.name,'"')," has been"," ",e.createElement(C,{operation:"MOVED_UP"},"moved up")," in priority"),u(s)&&e.createElement(e.Fragment,null,Object.entries(f).map(([R,N])=>{var M,k,h,b,S;const{before:I,after:U}=N,q=I&&Qe(I),G=U&&Qe(U);return e.createElement(ye,{key:R},N.operation==="ADDED"&&N.after&&e.createElement(F,null,"Permission decision"," ",e.createElement(C,null,'"',G,'"')," has been"," ",e.createElement(C,{operation:"ADDED"},"added")," to"," ",e.createElement(C,null,'"',(M=s.after)==null?void 0:M.name,'"')),N.operation==="REMOVED"&&N.before&&e.createElement(F,null,"Permission decision"," ",e.createElement(C,null,'"',q,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")," ","from ",e.createElement(C,null,'"',(k=s.after)==null?void 0:k.name,'"')),N.operation==="CHANGED"&&e.createElement(F,null,q!==G?e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(C,null,'"',q,'"')," has been"," ",e.createElement(C,{operation:"CHANGED"},"updated")," ","to ",e.createElement(C,null,'"',G,'"')):e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(C,null,'"',q,'"')," has been"," ",e.createElement(C,{operation:"CHANGED"},"updated"))," ","in ",e.createElement(C,null,'"',(h=s.after)==null?void 0:h.name,'"')),N.indexAfter>N.indexBefore&&N.indexBefore!==-1&&e.createElement(F,null,"Permission decision"," ",e.createElement(C,null,'"',G,'"')," has been"," ",e.createElement(C,{operation:"MOVED_DOWN"},"moved down")," ","in priority in"," ",e.createElement(C,null,'"',(b=s.after)==null?void 0:b.name,'"')),N.indexAfter<N.indexBefore&&N.indexAfter!==-1&&e.createElement(F,null,"Permission decision"," ",e.createElement(C,null,'"',G,'"')," has been"," ",e.createElement(C,{operation:"MOVED_UP"},"moved up")," ","in priority in"," ",e.createElement(C,null,'"',(S=s.after)==null?void 0:S.name,'"')))}),Object.entries(E).map(([R,N])=>{var M,k;return e.createElement(ye,{key:R},N.operation==="ADDED"&&N.after&&e.createElement(F,null,"Member ",e.createElement(C,null,'"',N.after,'"')," has been"," ",e.createElement(C,{operation:"ADDED"},"added")," to"," ",e.createElement(C,null,'"',(M=s.after)==null?void 0:M.name,'"')),N.operation==="REMOVED"&&N.before&&e.createElement(F,null,"Member ",e.createElement(C,null,'"',N.before,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")," from"," ",e.createElement(C,null,'"',(k=s.after)==null?void 0:k.name,'"')))})))}))},jr=w(()=>({root:{display:"inline-flex"}})),It=({timestamp:t,description:n})=>{const r=jr(),a=xe.fromISO(t).toLocaleString(xe.DATETIME_FULL),l=Zn(t),o=n?`${n}${l}`:l;return e.createElement("span",{className:r.root},e.createElement(oe,{title:a},e.createElement(D,{component:"span",display:"inline",variant:"inherit"},o)))};function Ot(t,n,r){var a,l;let o=n.created,i=t.createdBy;r!=null&&r.created&&(i=r.created+i);let m=t.createdAt;return t.status==="active"?(o=n.published,i=(a=t.lastPublishedBy)!=null?a:"",r!=null&&r.published&&(i=r.published+i),m=(l=t.lastPublishedAt)!=null?l:""):t.createdAt!==t.updatedAt&&(o=n.updated,i=t.updatedBy,r!=null&&r.updated&&(i=r.updated+i),m=t.updatedAt),{activityDateText:o,activityUser:i,timestamp:m}}const Hr=w(t=>({card:n=>({backgroundImage:n.policy.status==="active"?"linear-gradient(256.15deg, #00782A 19.77%, #1DB954 100%)":"linear-gradient(256.15deg, #BDBDBD 19.77%, #EEEEEE 100%)",backgroundPosition:"top",backgroundSize:"100% 8px",backgroundRepeat:"no-repeat",paddingTop:"8px",height:"100%"}),diffSummaryContainer:{backgroundColor:t.palette.background.default,padding:t.spacing(2),borderWidth:"1px",borderStyle:"solid",borderColor:t.palette.divider,borderRadius:t.shape.borderRadius},header:{display:"flex",justifyContent:"space-between",alignItems:"center"},detailsHeader:{...t.typography.body1,paddingTop:t.spacing(2),color:t.palette.text.secondary},activityList:{color:t.palette.text.secondary},activityListItem:{padding:0},actions:{justifyContent:"flex-start"}}));function ue(t){const n=Hr(t),{policy:r,to:a,withChangeSummary:l}=t,o=`${r.name} ${r.status==="draft"?"- Draft":""}`,i={created:"Created: ",published:"Published: ",updated:"Updated: "},m={created:"Created by ",published:"Published by ",updated:"Updated by "},{activityDateText:u,activityUser:c,timestamp:s}=Ot(r,i,m);return e.createElement(Y,{className:n.card},e.createElement(ve,null,e.createElement("div",{className:n.header},a?e.createElement(ae,{to:`versions/${r.id}`},e.createElement(D,{variant:"h5",component:"h1"},o)):e.createElement(D,{variant:"h5",component:"h1"},o),r.status==="active"?e.createElement(kt,{status:"active",size:"small"}):null),r.description?e.createElement(D,{variant:"body1",color:"textSecondary"},'"',r.description,'"'):null,e.createElement(D,{component:"h2",className:n.detailsHeader},"Details"),e.createElement(kn,{className:n.activityList},e.createElement(st,{className:n.activityListItem},e.createElement(mt,null,e.createElement(Vn,null)),e.createElement(ut,{primary:e.createElement(It,{timestamp:s,description:u})})),e.createElement(st,{className:n.activityListItem},e.createElement(mt,null,e.createElement(Et,null)),e.createElement(ut,{primary:c}))),l&&e.createElement(p,{paddingTop:2},e.createElement(D,{gutterBottom:!0,variant:"subtitle2"},"What's changed"),e.createElement(p,{className:n.diffSummaryContainer},e.createElement(St,{policy:r})))),t.actions?e.createElement(Rn,{className:n.actions},t.actions):null)}const Wr=w(t=>({paper:{padding:t.spacing(2,2,0,2)}})),Bt=({isOpen:t,onClose:n,policy:r})=>{const a=Wr();return e.createElement(ee,{classes:{...a},open:t,onClose:n},e.createElement(be,{disableTypography:!0},e.createElement(p,{display:"flex",flexDirection:"row"},e.createElement(p,null,e.createElement(D,{variant:"h4",component:"h2"},"Success!"),e.createElement(D,null,r.name," has been published and is now your active policy.")),e.createElement(p,null,e.createElement(j,{onClick:n,title:"Close dialog"},e.createElement(We,null))))),e.createElement(J,null,e.createElement(ue,{policy:r})),e.createElement(Be,null,e.createElement(p,{display:"flex",flexDirection:"row",flexGrow:1,justifyContent:"flex-start"},e.createElement(T,{component:En,color:"primary",onClick:n,role:"link",to:"/rbac"},"View all versions"))))};function zr(t){var n,r;return((r=(n=t==null?void 0:t.body)==null?void 0:n.response)==null?void 0:r.statusCode)===404}const Ur=w(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"},label:{align:"center",display:"block",marginBottom:t.spacing(1),color:t.palette.text.secondary,fontSize:t.typography.caption.fontSize},policiesContainer:{display:"flex",gap:t.spacing(4),marginTop:t.spacing(4),marginBottom:t.spacing(4)},button:{marginTop:t.spacing(4)}})),Vr=({localPolicy:t,onSelectLocalPolicy:n,onSelectServerPolicy:r,serverPolicy:a})=>{const l=Ur();return e.createElement(ee,{open:!0,maxWidth:"md"},e.createElement(J,null,e.createElement(p,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(p,{display:"flex",justifyContent:"center"},e.createElement(gt,{className:l.icon})),e.createElement(D,{align:"center",variant:"h6"},"There is a conflict with your drafts"),e.createElement(p,null,e.createElement(D,{align:"center"},"A newer version of the draft you are trying to edit has been recently saved."),e.createElement(D,{align:"center"},"Please review the changes and decide on a version to keep."))),e.createElement(p,{className:l.policiesContainer},e.createElement(p,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(D,{className:l.label,variant:"button"},"Your local draft"),e.createElement(ue,{policy:t,withChangeSummary:!0}),e.createElement(T,{className:l.button,color:"primary",onClick:n,variant:"outlined"},"Keep local draft")),e.createElement(p,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(D,{className:l.label,variant:"button"},"Recently saved draft"),e.createElement(ue,{policy:a,withChangeSummary:!0}),e.createElement(T,{className:l.button,color:"primary",onClick:r,variant:"outlined"},"Keep recently saved draft")))))},Gr=({serverPolicy:t,localPolicy:n})=>!n||!t?{policy:t,policyConflict:!1}:t.status!=="draft"?{policy:t,policyConflict:!1}:n.id!==t.id?{policy:t,policyConflict:!1}:n.updatedAt===t.updatedAt?{policy:n,policyConflict:!1}:{policy:n,policyConflict:!0},_r=()=>tr("@spotify/backstage-plugin-rbac:draftPolicy");function $t(t){const n=new Blob([Yr(t)],{type:"text/yaml"});nr(n,`${(t.name||"policy").toLocaleLowerCase().replace(/\W/g,"-")}.yaml`)}function Yr(t){const{name:n,roles:r,options:a,description:l}=t;return`# this is an autogenerated file, do not edit
2
- ${lr(ar({name:n,description:l,options:a,roles:r.map(({permissions:o,...i})=>({...ht(i,["id"]),permissions:o.map(m=>ht(m,["id"]))}))},o=>o!==null||o!==void 0))}`}const Jr=w(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"}})),Kr=({onConfirm:t,policy:n})=>{const r=Jr(),a=()=>{$t(n)};return e.createElement(ee,{open:!0},e.createElement(J,null,e.createElement(p,{display:"flex",flexDirection:"column",gridGap:16},e.createElement(p,{display:"flex",flexDirection:"column",gridGap:4},e.createElement(p,{display:"flex",justifyContent:"center"},e.createElement(gt,{className:r.icon})),e.createElement(D,{align:"center",variant:"h6"},"Invalid local draft")),e.createElement(p,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(D,{align:"center"},"You have a local draft that is no longer compatible or has become corrupted."),e.createElement(D,{align:"center"},"Click export to download your draft. You can attempt to restore your draft by importing this file on the RBAC home page."),e.createElement(D,{align:"center"},"Clicking continue will discard your draft."," ",e.createElement(p,{component:"span",fontWeight:"fontWeightBold"},"This action cannot be undone."))),e.createElement(p,{display:"flex",justifyContent:"center",gridGap:8,marginY:3},e.createElement(T,{color:"primary",onClick:a,variant:"outlined"},"Export"),e.createElement(T,{color:"primary",onClick:t,variant:"contained"},"Discard and continue")))))},Mt=ke({diff:null,hasChanges:!1,policy:void 0,createNewRole:()=>"",discardLocalDraft:()=>{},saveLocalDraftToServer:()=>Promise.reject(),refetchPolicy:()=>Promise.reject(),updateLocalDraft:()=>{}}),re=()=>Re(Mt);function Ne({children:t,policyId:n}){const r=_(),a=$(X),l=$(W),{getPolicy:o,setPolicy:i}=_e(),m=Ie(),{NotFoundErrorPage:u}=m.getComponents(),c=o(n),[s,f,E]=_r(),v=!s||De.safeParse(s).success,y=v?s:void 0,{policy:d,policyConflict:g}=Gr({serverPolicy:c,localPolicy:y}),P=Rt(d),[{loading:A,error:R},N]=Z(()=>l.getPolicy(n),[l,n],c?{loading:!1,value:c}:{loading:!0}),M=()=>{f(I=>I&&c&&{...I,updatedAt:c.updatedAt})},k=B(async()=>{const I=await N();i(I)},[N,i]),h=B(async()=>{if(!d)throw new Error("No policy to save");try{await l.updateDraft(d.id,{name:d.name,roles:d.roles}),a.post({message:"Policy saved",severity:"success"}),E(),k==null||k()}catch(I){a.post({message:(I==null?void 0:I.message)||"An error occurred while updating the policy",severity:"error"})}},[a,l,d,k,E]),b=B(()=>{if(!d)throw new Error("No policy to create a new role");const I=new Set(d.roles.map(G=>G.id));let U;do U=ne().split("-")[0];while(I.has(U));const q={name:`Role ${U}`,permissions:[],members:"*",id:U};return f({...d,roles:[...d.roles,q]}),U},[d,f]),S=()=>{E(),r("/rbac")};return V(()=>{c||k()},[k,c]),v?d?e.createElement(Mt.Provider,{value:{diff:P,hasChanges:!!y,policy:d,createNewRole:b,discardLocalDraft:E,saveLocalDraftToServer:h,refetchPolicy:k,updateLocalDraft:f}},g&&y&&c&&e.createElement(Vr,{localPolicy:y,onSelectLocalPolicy:M,onSelectServerPolicy:E,serverPolicy:c}),t):A?e.createElement(ge,null):R?zr(R)?e.createElement(u,null):e.createElement(ot,{error:R!=null?R:new Error("Unknown")}):null:e.createElement(Kr,{onConfirm:S,policy:s})}const qr=w(t=>({closeButton:{color:t.palette.text.secondary},diffSummaryContainer:{backgroundColor:t.palette.background.default,marginBottom:t.spacing(2)}}));function Ft({open:t,onPublish:n,onClose:r}){const[a,l]=O(!1),{policy:o}=re(),i=qr(),m=Q(null),u=async()=>{var c,s;l(!0),await n((s=(c=m.current)==null?void 0:c.value)!=null?s:""),l(!1)};return e.createElement(ee,{open:t,onClose:r,fullWidth:!0},e.createElement(be,null,e.createElement(p,{display:"flex",justifyContent:"space-between",alignItems:"center"},"Ready to publish?",e.createElement(T,{startIcon:e.createElement(We,null),onClick:r,className:i.closeButton},"Close")),e.createElement(D,null,"Double check your changes, then click Publish to activate this version of your policy. This will immediately apply the permissions defined in this version across Backstage.")),e.createElement(J,{className:i.diffSummaryContainer,dividers:!0},e.createElement(St,{policy:o})),e.createElement(J,null,e.createElement(ie,{variant:"outlined",fullWidth:!0,label:"Summary (optional)",placeholder:"Briefly describe this version (or changes from a previous version)",inputRef:m})),e.createElement(Be,null,e.createElement(T,{color:"primary",onClick:u,disabled:a},a?e.createElement(dt,{size:20}):"Publish")))}const Qr=[{title:"Name",field:"name",render:t=>e.createElement(ae,{to:`versions/${t.id}`},t.name)},{title:"Status",field:"status",render:t=>{switch(t.status){case"active":return"Active";case"draft":return"Draft";case"inactive":return"Inactive";default:return Rr(t.status)}}},{title:"Publish date",field:"lastPublishedAt",render:t=>t.lastPublishedAt?xe.fromISO(t.lastPublishedAt).toLocaleString(xe.DATETIME_MED_WITH_SECONDS):"",type:"datetime",defaultSort:"desc"},{title:"Published by",field:"lastPublishedBy"}];function Xr(t){const n=t.data.length>3,{fetchPolicies:r}=me(),[{loading:a},l]=wt(),[{loading:o,value:i},m]=At(),[u,c]=O(void 0),[s,f]=O(!1),E=()=>{c(void 0),r()},v=(u==null?void 0:u.id)===(i==null?void 0:i.id)?i:void 0,y=[d=>{const{tableData:g,...P}=d;return{icon:zn,tooltip:"Publish",onClick:()=>{c(P),f(!0)},disabled:o}},d=>{const{tableData:g,...P}=d;return{icon:Un,tooltip:"Duplicate",disabled:a||!t.canDuplicate,onClick:()=>l(P)}}];return e.createElement(e.Fragment,null,e.createElement(Pn,{title:"Previous Versions",columns:Qr,data:t.data,options:{paging:n,pageSize:3,pageSizeOptions:[3,5,10,20],actionsColumnIndex:-1,loadingType:"linear"},actions:y}),u&&e.createElement(Ne,{policyId:u.id},e.createElement(Ft,{open:s,onPublish:d=>{m(u,d),f(!1)},onClose:()=>{c(void 0),f(!1)}})),v&&e.createElement(Bt,{isOpen:!0,policy:v,onClose:E}))}const Zr=w(t=>({breadcrumbs:{marginBottom:t.spacing(4)}}));function el({pages:t}){const n=hn(vn),r=Zr();return e.createElement(Nn,{className:r.breadcrumbs},e.createElement(ae,{to:n()},"Home"),t.map(({title:a,path:l},o)=>l?e.createElement(ae,{to:l,key:l,relative:"path"},a):e.createElement(D,{key:`${o}`},a)))}function Xe({children:t,header:n,pages:r}){return e.createElement(Tn,{themeId:"tool"},e.createElement(er,{backend:"rbac",invalidLicenseMessage:"Your existing policy will continue to apply, but you will be unable to make any changes until you enter a valid license."}),e.createElement(wn,{title:"Role Based Access Control"}),e.createElement(An,null,e.createElement(Sn,{maxWidth:"lg"},e.createElement(H,{container:!0,spacing:4},e.createElement(H,{item:!0,xs:12},r&&e.createElement(el,{pages:r}),n),t))))}const Lt=t=>{const[n,r]=O(!1),{fetchPolicies:a}=me(),[{loading:l,value:o},i]=At(),{policy:m,hasChanges:u}=re(),c=De.safeParse(m).success,s=!u&&c,f=async v=>{await i(m,v),r(!1)},E=()=>{a()};return e.createElement(e.Fragment,null,e.createElement(T,{...t,onClick:()=>r(!0),disabled:!s||l},"Publish"),e.createElement(Ft,{open:n,onClose:()=>r(!1),onPublish:f}),o&&e.createElement(Bt,{isOpen:!0,onClose:E,policy:o}))};function tl(t){const n=$(W),r=$(X),{fetchPolicies:a}=me();return Z(async()=>{if(t)return n.deleteDraft(t.id).then(a).catch(l=>(r.post({message:l.message,severity:"error"}),Promise.reject(l)))},[t])}function nl(){const t=$(W),n=_(),r=$(X);function a(l){var o,i;const m=(i=(o=l.target)==null?void 0:o.files)==null?void 0:i[0],u=new FileReader;m&&(u.readAsText(m,"utf-8"),u.onload=async c=>{var s,f;const E=(f=(s=c.target)==null?void 0:s.result)==null?void 0:f.toString();if(E){let v=null;try{v=rr.load(E)}catch{r.post({message:"YAML file is invalid",severity:"error"});return}if(!De.safeParse(v).success){r.post({message:"Imported policy is invalid",severity:"error"});return}if((await t.getPolicies()).items.some(g=>g.status==="draft")){r.post({message:"Unable to import new policy due to existing draft policy",severity:"error"});return}const y=v,d=await t.createDraft({name:y.name,roles:y.roles});n(`./versions/${d.id}`),r.post({message:"Policy imported successfully",severity:"success"})}})}return e.createElement(T,{variant:"outlined",color:"primary",component:"label"},"Import",e.createElement("input",{role:"input",type:"file",hidden:!0,onChange:a,accept:".yaml"}))}function rl(){const{policies:t}=_e(),{loading:n,error:r,fetchPolicies:a}=me();it(()=>{t||a()});let l;return n?l=e.createElement(H,{item:!0,xs:12},e.createElement(ge,null)):r?l=e.createElement(ot,{error:r}):!t||t.length===0?l=e.createElement(al,null):l=e.createElement(ol,{policies:t}),e.createElement(Xe,{pages:void 0,header:e.createElement(Oe,{title:"RBAC Policies"},e.createElement(nl,null))},l)}const ll=w(t=>({cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}}}));function al(){const t=ll(),n=$(W),r=_(),[a,l]=Z(async()=>n.createDraft({roles:[]}),[n]);return V(()=>{a.value&&r(`./versions/${a.value.id}`)},[r,a.value]),e.createElement(Y,null,e.createElement(ve,{className:t.cardContent},e.createElement(he,{missing:"content",title:"No policy configured",description:e.createElement(e.Fragment,null,e.createElement(p,{component:"span",display:"block",pb:2},"Until you've configured your policy, authorization will be denied for all permissions."),e.createElement(p,{component:"span",display:"block"},"Click the button below to create the first version of your policy.")),action:e.createElement(T,{variant:"contained",color:"primary",disabled:a.loading,onClick:l},"New version")})))}function ol({policies:t}){const n=t.find(c=>c.status==="draft"),r=t.find(c=>c.status==="active"),[a,l]=wt(),[o,i]=tl(n),m=_(),u=il(t);return e.createElement(H,{container:!0,spacing:4},r?e.createElement(H,{item:!0,xs:12,md:6},e.createElement(ue,{policy:r,to:`./versions/${r.id}`,actions:e.createElement(T,{color:"primary",disabled:a.loading||!!n,onClick:()=>l(r)},"Duplicate")})):null,n?e.createElement(H,{item:!0,xs:12,md:6},e.createElement(ue,{policy:n,to:`./versions/${n.id}`,actions:e.createElement(e.Fragment,null,e.createElement(T,{onClick:()=>m(`versions/${n.id}`),color:"primary"},"Edit"),e.createElement(T,{color:"primary",disabled:o.loading,onClick:i},"Delete Draft"),e.createElement(Ne,{policyId:n.id},e.createElement(Lt,{color:"primary"})))})):null,e.createElement(H,{item:!0,xs:12},e.createElement(Xr,{data:u,canDuplicate:!n})))}function il(t){return t.filter(({status:n})=>n==="inactive")}const cl=w(t=>({titleWrapper:{display:"flex",alignItems:"center",gap:t.spacing(2)}}));function jt({children:t}){const n=cl();return e.createElement(D,{noWrap:!0,variant:"h4",component:"h2",color:"textSecondary",className:n.titleWrapper},t)}const sl=w({autocomplete:{display:"flex",flex:1}});function ml({members:t,options:n,namespaceOptions:r,loading:a=!1,disabled:l=!1,isMultiNamespaces:o=!1,onTextChange:i,onToggleMember:m,onChange:u}){const[c,s]=O(!1),f=sl(),[E,v]=pn(g=>g+1,0),y=(g,P)=>{P&&(m(P),v())};V(()=>{c&&i("")},[c,i]);const d=o?r.concat((n==null?void 0:n.members)||[]):(n==null?void 0:n.members)||[];return e.createElement(p,{width:250},e.createElement(Ge,{key:`${E}`,open:c,onOpen:()=>{s(!0)},onClose:()=>{s(!1)},onChange:y,getOptionLabel:de,groupBy:ul,renderOption:g=>e.createElement(e.Fragment,null,e.createElement($e,{id:`checkbox-${g.entityRef}`,checked:t.includes(g.entityRef),color:"primary"}),e.createElement("label",{htmlFor:`checkbox-${g.entityRef}`},o?de(g,!1):de(g))),options:d,filterOptions:g=>g,openOnFocus:!0,disabled:l,loading:a,className:f.autocomplete,renderInput:g=>e.createElement(ie,{...g,label:o?"Select members":"Select specific users/groups",variant:"standard",onChange:u,InputProps:{...g.InputProps,endAdornment:e.createElement(e.Fragment,null,a?e.createElement(dt,{color:"inherit",size:20}):null,g.InputProps.endAdornment)}})}))}function de(t,n=!0){var r;const a=K(t.entityRef);return a.name==="*"?a.namespace:ir({...a,name:(r=t.name)!=null?r:a.name},{defaultKind:a.kind,defaultNamespace:n?or:!1})}const Ht={user:"USERS",group:"GROUPS",namespace:"NAMESPACES"};function ul(t){const{name:n,kind:r}=K(t.entityRef),a=n==="*"?"namespace":r;if(!Ht[a])throw new Error(`Group '${a}' is not supported for members in a policy`);return Ht[a]}const dl=w(t=>({root:({operation:n})=>({borderRadius:100,borderColor:qe(t,n),borderSize:1,borderStyle:"solid",color:qe(t,n),lineHeight:1,padding:t.spacing(.5,1),whiteSpace:"nowrap"})})),pe=({operation:t,size:n="small"})=>{const r=dl({operation:t}),a=Mr(t),l=n==="small"&&"caption"||n==="medium"&&"body1"||n==="large"&&"subtitle1"||"inherit";return!t||t==="UNCHANGED"?null:e.createElement(D,{className:r.root,variant:l},a)},Wt=w(t=>({header:{display:"flex",flexDirection:"row",justifyContent:"space-between",paddingLeft:"1rem",paddingRight:"1rem",gap:"1rem"},actionCol:{width:48},typeIconCol:{paddingRight:"0.4rem"},nameCol:{paddingLeft:0},typeIcon:{color:t.palette.grey[500]}}));function pl({diff:t,policyId:n,role:r,onToggleMember:a,readonly:l=!1,debounceTime:o=1e3}){const i=$(W),m=$(cr),u=Wt(),c=r.members==="*",[s,f]=O(""),{current:E}=Q({}),v=b=>{E[b.entityRef]=b,a(b.entityRef)},y=b=>{var S;if(E[b])return E[b];const I=K(b);return{entityRef:b,type:I.kind.toLowerCase(),name:(S=I.name)!=null?S:b}},{value:d,loading:g}=le(async()=>await i.searchMembers({query:s}),[i,s]),{loading:P,value:A}=le(async()=>{const b=await m.getEntityFacets({facets:["metadata.namespace"]}).then(S=>S.facets["metadata.namespace"].map(I=>I.value));return El(b)},[m]),R=A?(A==null?void 0:A.length)>1:!1,N=A?A.filter(b=>b.entityRef.toLowerCase().includes(s)):[],M=L(()=>In(b=>{f(b.target.value.toLowerCase())},o),[f,o]),{loading:k,error:h}=le(async()=>{r.members==="*"||r.members.length===0||(await i.getPolicy(n)).roles.find(b=>b.id===r.id)===void 0||r.members.forEach(b=>{const S=y(b);E[S.entityRef]=S})},[n,c]);return e.createElement(e.Fragment,null,e.createElement("div",{className:u.header},e.createElement("h2",null,"Members"),e.createElement(ml,{onToggleMember:v,members:r.members,disabled:l,options:d,namespaceOptions:N,isMultiNamespaces:R,loading:g||P,onTextChange:f,onChange:M})),e.createElement(Me,null,e.createElement(Fe,null,e.createElement(z,null,e.createElement(x,{className:u.typeIconCol}),e.createElement(x,{className:u.nameCol},"Name"),e.createElement(x,null,"Type"),e.createElement(x,null),!l&&e.createElement(x,{className:u.actionCol}))),e.createElement(Le,null,e.createElement(fl,{diff:t,loading:k||P,isMultiNamespaces:R,error:h,members:Array.isArray(r.members)?r.members.map(y):r.members,onToggleMember:v,readonly:l}))))}function fl({diff:t,loading:n,isMultiNamespaces:r,members:a,error:l,onToggleMember:o,readonly:i=!1}){const m=Wt();if(n)return e.createElement(z,null,e.createElement(x,{scope:"row",colSpan:4},e.createElement(ge,null)));if(l&&l.message!=null,a==="*")return e.createElement(z,null,e.createElement(x,null,"All"),e.createElement(x,{height:80},"any"),e.createElement(x,{colSpan:i?2:3},e.createElement(pe,{operation:t==null?void 0:t.members["*"].operation})));if(a.length===0)return e.createElement(z,null,e.createElement(x,{scope:"row",colSpan:4},"Select users or groups using the drop-down menu above."));const u=a.sort((c,s)=>{let f=0;r&&s.name==="*"&&c.name!=="*"?f=1:r&&c.name==="*"&&s.name!=="*"&&(f=-1);const E=c.type.localeCompare(s.type),v=K(c.entityRef).namespace.localeCompare(K(s.entityRef).namespace),y=K(c.entityRef).name.localeCompare(K(s.entityRef).name);return f||E||v||y});return e.createElement(e.Fragment,null,u.map(c=>{var s;const{name:f,type:E,entityRef:v}=c;return e.createElement(z,{key:v},e.createElement(x,{className:m.typeIconCol},E==="group"&&e.createElement(ur,{className:m.typeIcon})||r&&f==="*"&&e.createElement(dr,{className:m.typeIcon})||e.createElement(Et,{className:m.typeIcon})),e.createElement(x,{scope:"row",className:m.nameCol},(s=r?de(c,!1):de(c))!=null?s:"Unknown"),e.createElement(x,{scope:"row"},f==="*"&&r?"namespace":E),e.createElement(x,null,f&&e.createElement(pe,{operation:t==null?void 0:t.members[v].operation})),!i&&e.createElement(x,{scope:"row",className:m.actionCol},e.createElement(j,{"aria-label":"delete",onClick:()=>o(c),size:"small"},e.createElement(se,null))))}))}function El(t){return t.map(n=>({name:"*",type:"user",entityRef:`user:${n}/*`})).sort((n,r)=>n.entityRef.toLowerCase().localeCompare(r.entityRef.toLowerCase()))}const yl=["condition","anyOf","allOf","not"],zt={condition:"Condition",anyOf:"Any of",allOf:"All of",not:"Not"};function Ze(t){return t===null?!1:t.hasOwnProperty("id")&&t.hasOwnProperty("ruleName")&&t.hasOwnProperty("parameters")}function fe(t){return t.hasOwnProperty("levelType")}function gl(t){return t==="anyOf"||t==="allOf"||t==="not"}const hl=w(t=>({descriptiveText:{fontWeight:500,marginBottom:t.spacing(1)}})),Te=({children:t})=>{const n=hl();return e.createElement(D,{variant:"body2",className:n.descriptiveText},t)},Ut=({children:t})=>e.createElement(p,{pl:3},t),vl="#4CAF50";function bl({permissionCriteria:t}){return e.createElement("div",null,e.createElement(Te,null,"If the below conditions are met"),e.createElement(Ut,null,Ze(t)&&e.createElement(_t,{condition:t}),fe(t)&&e.createElement(Vt,{level:t})),e.createElement(Te,null,"Then the action is"," ",e.createElement(p,{component:"span",color:vl},"allowed")))}function Vt({level:t}){return e.createElement(e.Fragment,null,e.createElement(Te,null,zt[t.levelType]),e.createElement(Ut,null,t.children.map((n,r)=>fe(n)?e.createElement(Vt,{key:r,level:n}):e.createElement(_t,{key:r,condition:n}))))}const Gt="#FF737F",Cl="#E22134";function _t({condition:t}){return e.createElement(Te,null,e.createElement(p,{component:"span",color:Gt},t.ruleName,"("),e.createElement(p,{component:"span",color:Cl},JSON.stringify(t.parameters)),e.createElement(p,{component:"span",color:Gt},")"))}const xl=w(t=>({editor:{"--jse-main-border":`1px solid ${t.palette.divider}`,"--jse-panel-border":`1px solid ${t.palette.divider}`,"--jse-message-error-background":t.palette.error.main,"--jse-message-warning-background":t.palette.warning.main,"--jse-background-color":t.palette.background.default,"--jse-panel-background":t.palette.background.default,"--jse-delimiter-color":t.palette.type==="light"?"rgba(0, 0, 0, 0.38)":"rgba(255, 255, 255, 0.38)","--jse-error-color":t.palette.text.primary,"--jse-key-color":t.palette.text.primary,"--jse-value-color":t.palette.text.primary,"--jse-text-color":t.palette.text.primary,"--jse-panel-color-readonly":t.palette.text.hint,"--jse-value-color-string":t.palette.status.ok,"--jse-value-color-null":t.palette.status.warning,"--jse-value-color-number":t.palette.status.error,"--jse-value-color-boolean":t.palette.status.running,"--jse-font-family":"inherit"}})),Dl=t=>"parseError"in t,Pl=t=>{var n;return t?Dl(t)?!!t.parseError:((n=t==null?void 0:t.validationErrors)==null?void 0:n.length)>0:!1};function Nl({onChange:t,schema:n,value:r}){const a=Q(null),l=Q(),o=xl();return V(()=>(a.current&&!l.current&&(l.current=new fr({target:a.current,props:{onChange:(i,m,{contentErrors:u})=>{!Pl(u)&&Er(i)&&t(JSON.parse(i.text))},validator:yr({schema:n}),content:{json:{}},mainMenuBar:!1,mode:gr.text}})),()=>{var i;(i=l.current)==null||i.destroy(),l.current=void 0}),[t,n]),it(()=>{var i;(i=l.current)==null||i.updateProps({content:{json:r}})}),e.createElement("div",{ref:a,className:o.editor,style:{height:300}})}const Tl=[];function wl(t){const{onChange:n,schema:r,name:a}=t,{description:l,items:o}=r,[i,m]=e.useState(!1),u=Array.isArray(t.value)?t.value:Tl,c=u.includes(ce),s=(g,P)=>{if(!Array.isArray(P)){const A=[...u];A[g]=P||"",n(A)}},f=B(()=>{n([...u,""])},[n,u]),E=g=>{n(u.filter((P,A)=>A!==g))},v=()=>{n(c?[]:[ce])},y=()=>{c&&m(!0)},d=()=>{m(!1)};return V(()=>{u.length?c&&u.length>1&&n([ce]):f()},[f,n,u,c]),!o||!("type"in o)?null:e.createElement(e.Fragment,null,(u!=null?u:[]).map((g,P,{length:A})=>e.createElement(Jt,{allowEmptyStrings:!0,key:P,onChange:R=>s(P,R),name:P===0?a:"",schema:{description:P===A-1?l:"",type:o.type},value:g,controls:e.createElement(j,{size:"small",onClick:()=>E(P)},e.createElement(hr,null))})),!!(u!=null&&u.length)&&e.createElement(p,{alignItems:"center",display:"flex",flexDirection:"row",justifyContent:"space-between"},e.createElement(p,null,e.createElement(pt,{control:e.createElement($e,{checked:c,onChange:v,name:"checkedB",color:"primary"}),label:"Use the claims from the logged in users token"})),e.createElement(p,null,e.createElement(oe,{onClose:d,onOpen:y,open:i,title:"To add additional entries you must uncheck using the claims from the logged in user."},e.createElement("span",null,e.createElement(j,{disabled:c,size:"small",onClick:f},e.createElement(Ve,null)))))))}function Al(t){const{onChange:n,schema:r,name:a,value:l}=t,{description:o}=r;return e.createElement(p,{mb:1},e.createElement(pt,{control:e.createElement($e,{checked:l===!0,onChange:i=>{n(i.target.checked)},name:a,color:"primary"}),label:a}),o&&e.createElement(D,{display:"block",variant:"caption",color:"textSecondary"},o))}function kl({allowEmptyStrings:t,controls:n,name:r,onChange:a,schema:l,value:o}){const i=m=>{a(Sl({value:m.currentTarget.value,type:l.type}))};return e.createElement(p,{mb:1},e.createElement(p,{display:"flex",gridGap:6},e.createElement(ie,{fullWidth:!0,id:r,label:r,placeholder:"Enter",variant:"outlined",size:"small",value:Rl(o,t),onChange:et(o,t)?void 0:i,disabled:et(o,t)}),n&&e.createElement(p,{alignSelf:"center"},n)),l.description&&e.createElement(D,{variant:"caption",color:"textSecondary"},l.description,et(o)&&!t&&e.createElement(e.Fragment,null," (switch to JSON editor to edit)")))}function et(t,n=!1){return!n&&t===""||t===null||t===ce}function Rl(t,n=!1){return!n&&t===""?"[empty string]":t===null?"[null]":t===ce?"[BackstageUserClaims]":t||""}function Sl({value:t,type:n}){switch(n){case"string":return t===""?void 0:t;case"number":case"integer":return Number.isNaN(Number(t))?void 0:Number(t);case"null":return t==="null"?null:void 0;default:return}}function Yt(t){return!!t&&"type"in t&&(t.type==="array"||t.type==="boolean"||t.type==="null"||t.type==="number"||t.type==="integer"||t.type==="string")}function Il(t){return"type"in t&&t.type==="array"}function Ol(t){return"type"in t&&t.type==="boolean"}function Jt({schema:t,...n}){return Yt(t)?Il(t)?e.createElement(wl,{...n,schema:t}):Ol(t)?e.createElement(Al,{...n,schema:t}):e.createElement(kl,{...n,schema:t}):null}const Bl=new bt({allErrors:!0});function $l({onChange:t,schema:n,value:r}){var a;const l=L(()=>Bl.compile(n),[n]),o=L(()=>l(r),[l,r]),i=Object.entries(n.properties),m=u=>c=>{t({...r,[u]:c})};return e.createElement(e.Fragment,null,i.map(([u,c])=>{var s;return e.createElement(Jt,{isRequired:((s=n.required)==null?void 0:s.includes(u))||!1,key:u,name:u,onChange:m(u),schema:c,value:r==null?void 0:r[u]})}),e.createElement(ft,{error:!o},(a=l.errors)==null?void 0:a[0].message))}const Ml=t=>!!t&&"properties"in t;function Fl({onChange:t,rule:n,value:r}){const[a,l]=O(!1),{paramsSchema:o}=n!=null?n:{},i=()=>l(s=>!s);if(!Ml(o))return null;const m=!Ll(o),u=m||a,c=e.createElement(T,{size:"small",onClick:i,disabled:m},u?"Close editor":"Edit as JSON");return e.createElement(p,{marginTop:2},e.createElement("form",null,u?e.createElement(Nl,{onChange:t,schema:o,value:r}):e.createElement(e.Fragment,null,e.createElement(p,{marginBottom:2},e.createElement(Ce,null,"Parameters")),e.createElement($l,{onChange:t,schema:o,value:r}))),e.createElement(p,{display:"flex",flexDirection:"column",alignItems:"flex-end",marginTop:1},m?e.createElement(oe,{title:"Only JSON editing is supported for this parameter",arrow:!0},e.createElement("span",null,c)):c))}function Ll(t){return Object.values(t.properties).every(Yt)}const Ee=w(t=>({paper:{backgroundColor:t.palette.background.default,padding:t.spacing(3),marginBottom:t.spacing(3),minHeight:t.spacing(48)},conditionCard:{minWidth:t.spacing(63)},conditionCardBar:{height:t.spacing(1),backgroundImage:"linear-gradient(90deg, #007DFF 0%, #0057B2 100%)"},conditionTypeFormControl:{minWidth:80,marginLeft:t.spacing(1)},autocomplete:{flex:1},conditionContent:{gap:t.spacing(2)},treeVerticalSpacer:{width:t.spacing(2),borderLeft:`1px solid ${t.palette.status.aborted}`},treeHorizontalSpacer:{height:t.spacing(3),borderLeft:`1px solid ${t.palette.status.aborted}`},treeVerticalBranchHalf:{position:"absolute",height:"50%",borderLeft:`1px solid ${t.palette.status.aborted}`,alignSelf:"flex-start"},treeVerticalBranchFull:{borderLeft:`1px solid ${t.palette.status.aborted}`,alignSelf:"stretch"},treeHorizontalBranch:{width:t.spacing(2),borderTop:`1px solid ${t.palette.status.aborted}`},addButton:{paddingLeft:40,paddingRight:40}}));function jl({permissionCriteria:t,resourceType:n,onUpdate:r,readonly:a=!1}){const l=Ee(),o=B(s=>{r(f=>({...f,...s}))},[r]),i=B(s=>{const f=ne();o(s==="condition"?we():s==="not"?{id:f,levelType:s,children:[]}:{id:f,levelType:s,children:[we()]})},[o]),m=B((s,f)=>{r(E=>({...E,ruleName:s,parameters:f}))},[r]),u=B(()=>{r(null)},[r]);let c;return a?c=e.createElement(bl,{permissionCriteria:t}):t===null?c=e.createElement(Kt,{onSelect:i}):Ze(t)?c=e.createElement(qt,{ruleName:t.ruleName,parameters:t.parameters,resourceType:n,onChange:m,onDelete:u}):fe(t)&&(c=e.createElement(Qt,{level:t,resourceType:n,onChange:r,isRoot:!0})),e.createElement(On,{variant:"outlined",className:l.paper},c)}function we(){return{id:ne(),ruleName:null,parameters:{}}}function Kt({onSelect:t}){const n=Ee(),r=Q(null),[a,l]=O(!1),o=()=>{l(i=>!i)};return e.createElement("div",null,e.createElement(T,{className:n.addButton,variant:"outlined",color:"primary",onClick:o,ref:r},"Add"),e.createElement(Bn,{anchorEl:r.current,open:a,onClose:o,BackdropProps:{}},yl.map(i=>e.createElement(te,{key:i,onClick:()=>{t==null||t(i),l(!1)}},zt[i]))))}function qt({ruleName:t,parameters:n,resourceType:r,onChange:a,onDelete:l}){var o;const i=Ee(),m=xt(),u=(o=m==null?void 0:m.filter(E=>E.resourceType===r))!=null?o:[],c=u.find(E=>E.name===t),s=E=>{a(E,{})},f=B(E=>{a(t,E)},[a,t]);return e.createElement(p,{display:"flex",alignItems:"center"},e.createElement(Y,{className:i.conditionCard},e.createElement("div",{className:i.conditionCardBar}),e.createElement(ve,null,e.createElement(p,null,e.createElement(p,null,e.createElement(Ge,{className:i.autocomplete,"data-testid":"rule-select",getOptionLabel:E=>E.name,getOptionSelected:(E,v)=>E.name===v.name,options:u,onChange:(E,v)=>s(v?v.name:null),renderInput:E=>e.createElement(e.Fragment,null,e.createElement(p,{marginBottom:2},e.createElement(Ce,null,"Rule")),e.createElement(ie,{...E,placeholder:"Select",variant:"outlined",size:"small",name:"rule"})),renderOption:E=>e.createElement(p,null,e.createElement(D,{variant:"body2"},E.name),e.createElement(D,{noWrap:!0,variant:"caption"},E.description)),value:c||null,PopperComponent:E=>e.createElement($n,{...E,style:{width:"auto"},placement:"bottom-start"})})),e.createElement(p,{flex:"1"},e.createElement(p,{display:"flex",flexDirection:"column"},e.createElement(Fl,{rule:c,onChange:f,value:n})))))),e.createElement(p,{ml:1},e.createElement(j,{"aria-label":"delete",onClick:l,size:"small"},e.createElement(se,null))))}function Qt({level:t,resourceType:n,onChange:r,parentConditionType:a,isRoot:l=!1}){const o=Ee(),i=B((y,d)=>{const g=[...t.children];return g.splice(y,1,d),g},[t]),m=B(y=>{r({...t,children:y})},[r,t]),u=B(y=>{y===null?r(null):y==="not"&&t.children.length>1?r({...t,levelType:y,children:t.children.slice(0,1)}):r({...t,levelType:y})},[r,t]),c=B((y,d)=>{m(y===null?Xt(t.children,d):i(d,y))},[t,m,i]),s=y=>{const d=ne();y==="condition"?m([...t.children,we()]):y==="not"?m([...t.children,{id:d,levelType:y,children:[]}]):gl(y)&&m([...t.children,{id:d,levelType:y,children:[we()]}])},f=y=>{m(Xt(t.children,y))},E=L(()=>t.children.map((y,d)=>(g,P)=>{m(i(d,{...y,ruleName:g,parameters:P}))}),[t.children,m,i]),v=L(()=>t.children.map((y,d)=>g=>c(g,d)),[t.children,c]);return e.createElement("div",null,!l&&e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(p,{display:"flex",alignItems:"center",position:"relative"},!l&&e.createElement(e.Fragment,null,e.createElement("div",{className:a==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch})),e.createElement(Hl,{level:t,onSelect:u})),e.createElement(p,{display:"flex"},l||a==="not"?e.createElement(p,{pl:2}):e.createElement("div",{className:o.treeVerticalSpacer}),!l&&e.createElement(p,{pl:2}),e.createElement("div",null,t.children.map((y,d)=>fe(y)?e.createElement(p,{key:y.id},e.createElement(Qt,{level:y,resourceType:n,parentConditionType:t.levelType,onChange:v[d]})):e.createElement(ye,{key:y.id},e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(p,{display:"flex",alignItems:"center",position:"relative"},e.createElement("div",{className:t.levelType==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch}),e.createElement(qt,{ruleName:y.ruleName,parameters:y.parameters,resourceType:n,onChange:E[d],onDelete:()=>f(d)})))),!(t.levelType==="not"&&t.children.length>=1)&&e.createElement(e.Fragment,null,e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(p,{display:"flex",alignItems:"center",position:"relative"},e.createElement("div",{className:o.treeVerticalBranchHalf}),e.createElement("div",{className:o.treeHorizontalBranch}),e.createElement(Kt,{onSelect:s}))))))}function Xt(t,n){const r=[...t];return r.splice(n,1),r}function Hl({level:t,onSelect:n}){const r=Ee(),a=t.children.length>1;return e.createElement(p,{display:"flex",alignItems:"center"},e.createElement(je,{className:r.conditionTypeFormControl},e.createElement(He,{value:t.levelType,onChange:l=>n==null?void 0:n(l.target.value)},e.createElement(te,{key:"anyOf",value:"anyOf"},"Any of"),e.createElement(te,{key:"allOf",value:"allOf"},"All of"),e.createElement(te,{key:"not",value:"not",disabled:a},"Not"))),e.createElement(p,{ml:1},e.createElement(j,{"aria-label":"delete",onClick:()=>n==null?void 0:n(null),size:"small"},e.createElement(se,null))))}function Zt(t){return`${t.palette.primary.main}50`}const Wl=w(t=>({indicator:{right:"unset"},tab:{maxWidth:"none","&.Mui-selected":{backgroundColor:Zt(t),color:t.palette.primary.main}}}));function zl({options:t,selected:n,onChange:r,readonly:a=!1}){const l=Wl();return e.createElement(Mn,{orientation:"vertical",value:t.map(({id:o})=>o).indexOf(n),onChange:(o,i)=>r(t[i].id),indicatorColor:"primary",TabIndicatorProps:{className:l.indicator}},t.map(o=>e.createElement(Fn,{key:o.id,label:o.displayText.toUpperCase(),className:l.tab,disabled:a})))}function Ul(t){return t?{id:t.id,match:Vl(t),decisionType:Gl(t),criteria:ze(t.decision)?Ae(t.decision.conditions):null}:{id:ne(),match:{method:"specificPermission"},decisionType:"allow",criteria:null}}function Vl(t){var n;return t.match==="*"?{method:"all"}:t.match.name?{method:"specificPermission",name:t.match.name}:t.match.resourceType||(n=t.match.actions)!=null&&n.length?{method:"filter",resourceType:t.match.resourceType,actions:t.match.actions}:{method:"specificPermission"}}function Gl(t){return typeof t.decision=="string"?t.decision:"conditional"}function Ae(t){const n=ne();return Yn(t)?{id:n,levelType:"allOf",children:t.allOf.map(r=>Ae(r))}:Jn(t)?{id:n,levelType:"anyOf",children:t.anyOf.map(r=>Ae(r))}:Kn(t)?{id:n,levelType:"not",children:[Ae(t.not)]}:{id:n,ruleName:t.rule,parameters:t.params}}function en(t,n){if(!t)return!1;if(fe(t))return t.children.length>0&&t.children.every(a=>en(a,n));if(!t.ruleName)return!1;const r=n==null?void 0:n.find(({name:a})=>a===t.ruleName);return r?r.paramsSchema?new bt({allErrors:!0}).compile(r.paramsSchema)(t.parameters):!0:!1}function _l(t,n,r){return{id:t,match:tn(n,r),decision:r}}function tn({method:t,...n},r){return t==="all"?"*":r&&ze(r)?{resourceType:r.resourceType,...n}:n}function tt(t){return Ze(t)?{rule:t.ruleName,params:t.parameters}:t.levelType==="not"?{not:tt(t.children[0])}:{[t.levelType]:t.children.map(n=>tt(n))}}const Yl=w(t=>({toggleButton:{"&.Mui-selected":{backgroundColor:Zt(t),color:t.palette.primary.main},"&.Mui-selected:hover":{backgroundColor:"#97BBE8"},color:t.palette.primary.main,border:`1px solid ${t.palette.primary.main}`}}));function nt({className:t,...n}){const r=Yl();return e.createElement(sr,{className:`${r.toggleButton} ${t}`,...n})}const Jl=w({fullWidth:{width:"100%","& > *":{flexGrow:1}}});function Kl({className:t,fullWidth:n,...r}){const a=Jl();return e.createElement(mr,{className:`${n?a.fullWidth:""} ${t}`,...r})}const rt=w(t=>({dialogTitle:{display:"flex",alignItems:"center",justifyContent:"space-between"},fullWidth:{width:"100%","& > *":{flexGrow:1}},infoIcon:{position:"absolute",right:t.spacing(3)},content:{padding:t.spacing(7)},saveButton:{paddingLeft:t.spacing(5),paddingRight:t.spacing(5)},contentContainerConditional:{display:"flex",gap:t.spacing(5),maxWidth:1480}})),ql={specificPermission:"Choose a specific permission",filter:"Filter by permission properties",all:"Match all permissions"},nn="Choose the name of a resource permission or filter by resource type to set a conditional decision.";function Ql({rolePermission:t,readonly:n=!1,onClose:r,onSave:a}){const l=rt(),o=Dt(),i=xt(),m=wr(),u=Ul(t),[c,s]=O(u.match),[f,E]=O(u.decisionType),[v,y]=O(u.criteria),d=L(()=>Xl(o,c),[o,c]),g=f==="conditional",P=g?"xl":"sm";V(()=>{g&&o&&!d.commonResourceType&&E("allow")},[g,o,d.commonResourceType,E]);const A=h=>{h!==null&&E(h)},R=L(()=>c.method==="specificPermission"&&!c.name||c.method==="filter"&&!c.resourceType&&!c.actions,[c]),N=L(()=>d.permissions.length===0?!1:!R,[d,R]),M=L(()=>f!=="conditional"?!0:!(!d.commonResourceType||!(m!=null&&m[d.commonResourceType].pluginId)||!en(v,i)),[f,d,m,v,i]),k=()=>{a==null||a(_l(u.id,c,f==="conditional"?{resourceType:d.commonResourceType,pluginId:m[d.commonResourceType].pluginId,conditions:tt(v)}:f))};return e.createElement(ee,{open:!0,maxWidth:P,onClose:r,fullWidth:!0},e.createElement(be,{disableTypography:!0,className:l.dialogTitle},e.createElement(D,{variant:"h4",component:"h2"},"New Permission Decision"),e.createElement(T,{startIcon:e.createElement(We,null),onClick:r},"Close")),e.createElement(J,{dividers:!0,className:l.content},e.createElement(p,{className:g?l.contentContainerConditional:void 0},e.createElement(p,{mb:5,flex:1},e.createElement(zl,{options:Object.entries(ql).map(([h,b])=>({id:h,displayText:b})),selected:c.method,onChange:h=>s({method:h}),readonly:n})),e.createElement(p,{mb:5,height:189,flex:1},c.method==="specificPermission"&&e.createElement(Zl,{name:c.name,readonly:n,onNameChange:h=>s({...c,name:h})}),c.method==="filter"&&e.createElement(e.Fragment,null,e.createElement(ea,{resourceType:c.resourceType,readonly:n,onResourceTypeChange:h=>s({...c,resourceType:h})}),e.createElement(na,{actions:c.actions,readonly:n,onActionsChange:h=>s({...c,actions:h.length?h:void 0})}),R?null:e.createElement(e.Fragment,null,e.createElement(p,{marginY:2},e.createElement(Ln,{variant:"middle"})),e.createElement(ft,null,`Matched ${d.permissions.length} ${d.permissions.length===1?"permission":"permissions"}`)))),e.createElement(p,{mb:5,flex:1},e.createElement(p,{display:"flex",alignItems:"center"},e.createElement(Kl,{value:f,exclusive:!0,fullWidth:!0,"aria-label":"Decision result",onChange:(h,b)=>A(b)},e.createElement(nt,{value:"allow","aria-label":"Decision allowed",disabled:n},"Allow"),e.createElement(nt,{value:"deny","aria-label":"Decision denied",disabled:n},"Deny"),e.createElement(nt,{value:"conditional","aria-label":"Decision conditionally allowed",disabled:!d.commonResourceType||n},"Conditional")),!g&&!n&&e.createElement(oe,{title:nn},e.createElement(vt,{className:l.infoIcon,color:"primary","aria-label":nn}))))),f==="conditional"&&!!d.commonResourceType&&e.createElement(jl,{permissionCriteria:v,resourceType:d.commonResourceType,onUpdate:y,readonly:n}),!n&&e.createElement(p,{display:"flex",justifyContent:"flex-end"},e.createElement(T,{variant:"contained",color:"primary",className:l.saveButton,onClick:k,disabled:!N||!M},"Save"))))}function Xl(t,n){const r=(t!=null?t:[]).filter(o=>qn(o,tn(n))),a=pr(r,"resourceType"),l=a.length===1&&at(a[0])?a[0].resourceType:void 0;return{permissions:r,commonResourceType:l}}const rn="Permission name";function Zl({name:t="",readonly:n,onNameChange:r}){const a=rt(),l=Dt();return e.createElement(je,{className:a.fullWidth,variant:"outlined",disabled:n},e.createElement(Ce,{id:"match-by-name-dropdown"},rn),e.createElement(He,{labelId:"match-by-name-dropdown",label:rn,value:l?t:"",onChange:o=>r==null?void 0:r(o.target.value)},l==null?void 0:l.map(o=>e.createElement(te,{key:o.name,value:o.name},o.name))))}const ln="Resource type";function ea({resourceType:t="",readonly:n,onResourceTypeChange:r}){const a=rt(),l=Pt();return e.createElement(je,{className:a.fullWidth,variant:"outlined",disabled:n},e.createElement(Ce,{id:"match-by-resource-dropdown"},ln),e.createElement(He,{labelId:"match-by-resource-dropdown",label:ln,value:l?t:"",onChange:o=>r==null?void 0:r(o.target.value),displayEmpty:!0},l==null?void 0:l.map(o=>e.createElement(te,{key:o,value:o},o))))}const ta="Action";function na({actions:t,readonly:n,onActionsChange:r}){return e.createElement(Ge,{multiple:!0,id:"match-by-attribute-dropdown",options:["create","read","update","delete"],getOptionLabel:a=>a,value:t!=null?t:[],onChange:(a,l)=>r==null?void 0:r(l),filterSelectedOptions:!0,renderInput:a=>e.createElement(ie,{...a,variant:"outlined",label:ta,placeholder:"Choose attributes",margin:"normal"}),disabled:n})}const ra=w(t=>({container:{display:"flex",position:"relative",alignItems:"center",gap:t.spacing(1),flexShrink:1,maxWidth:"100%",minWidth:0},input:({invalid:n})=>({boxSizing:"content-box",display:"block",maxWidth:"100%",padding:0,borderWidth:2,borderStyle:"solid",borderColor:n?t.palette.error.main:"transparent",borderRadius:t.shape.borderRadius,backgroundColor:"transparent",color:t.palette.textContrast,fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit",fontWeight:"inherit",textOverflow:"ellipsis"}),hiddenSpan:{position:"absolute",top:0,left:0,borderWidth:1,whiteSpace:"pre",opacity:0,pointerEvents:"none"}}));function an({invalid:t,name:n,value:r,onTextChange:a}){const l=ra({invalid:t}),[o,i]=O(!1),[m,u]=O(null),c=Q(null),[s,f]=O(r);V(()=>{f(r)},[r]),fn(()=>{c.current&&m&&c.current.style.setProperty("width",`max(${m.getBoundingClientRect().width}px, 3ch)`)},[m,s]);const E=()=>{i(!1),f(r)},v=()=>{i(!1),a==null||a(s)},y=()=>{var g;o?v():(i(!0),(g=c.current)==null||g.focus())},d=g=>{var P;g.key==="Enter"&&((P=c.current)==null||P.blur()),g.key==="Escape"&&E()};return e.createElement(e.Fragment,null,e.createElement("div",{className:l.container},e.createElement("input",{"aria-label":n,className:l.input,name:n,ref:c,onChange:g=>f(g.target.value),onFocus:y,onBlur:v,onKeyDown:d,value:s}),e.createElement("span",{"aria-hidden":"true",className:l.hiddenSpan,ref:u},s),e.createElement(j,{onClick:y,size:"small"},o?e.createElement(br,{"aria-label":"Save title"}):e.createElement(vr,{"aria-label":"Edit title"}))))}const on=({children:t,onConfirm:n,message:r,title:a})=>{const[l,o]=O(!1),i=()=>o(!1),m=()=>o(!0),u=()=>{n(),i()};return e.createElement(e.Fragment,null,t({onClick:m}),e.createElement(ee,{open:l,onClose:i},e.createElement(be,null,e.createElement(p,{display:"flex",justifyContent:"space-between",alignItems:"center"},a)),e.createElement(J,null,e.createElement(jn,null,r)),e.createElement(Be,null,e.createElement(T,{"aria-label":"Cancel action",color:"primary",onClick:i},"Cancel"),e.createElement(T,{"aria-label":"Confirm action",color:"secondary",onClick:u,variant:"contained"},"Confirm"))))},cn=({helpText:t})=>e.createElement(p,{display:"flex",alignItems:"center"},e.createElement(p,{component:"span",mr:1},e.createElement(D,{variant:"body2",noWrap:!0},"Reorder")),e.createElement(oe,{title:t},e.createElement(vt,{color:"primary","aria-label":t}))),sn=(t,n,r)=>{const a=n+r;if(a<0||a>=t.length)return t;const l=[...t];return[l[a],l[n]]=[l[n],l[a]],l},mn=({array:t,index:n,onReorder:r})=>{const a=n===0,l=n===t.length-1;return e.createElement(p,{display:"flex"},e.createElement(j,{disabled:a,onClick:()=>r(sn(t,n,-1)),"aria-label":"Move up",size:"small"},e.createElement(xr,null)),e.createElement(j,{disabled:l,onClick:()=>r(sn(t,n,1)),"aria-label":"Move down",size:"small"},e.createElement(Cr,null)))},un=t=>{if(t.success)return{};const n={};for(const r of t.error.issues)n[r.path.join(".")]=!0;return n},la=w(()=>({emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function dn({src:t,alt:n}){const r=la();return e.createElement("img",{src:t,className:`${r.emptyStateImage} `,alt:n})}const aa="Use the arrows to change the order in which permission decisions are evaluated.";function oa(){const{roleId:t,versionId:n}=lt();return Ue(t),Ue(n),e.createElement(Ne,{policyId:n},e.createElement(ia,{roleId:t}))}function ia({roleId:t}){const{diff:n,updateLocalDraft:r,policy:a}=re(),l=a.roles.find(h=>h.id===t),o=n==null?void 0:n.roles[t],[i,m]=O(null),[u,c]=O(!1),s=Ie(),{NotFoundErrorPage:f}=s.getComponents(),E=_(),v=w(h=>({cardContainer:{margin:h.spacing(0)}}))();if(!l)return e.createElement(f,null);const y=l.name,d=h=>{const b=a.roles.findIndex(I=>I.id===h.id),S=[...a.roles];S.splice(b,1,h),r({...a,roles:S})},g=h=>{d({...l,name:h})},P=h=>{if(i===null)d({...l,permissions:[h,...l.permissions]});else{const b=[...l.permissions];b.splice(i,1,h),d({...l,permissions:b})}c(!1)},A=h=>{if(h==="*")d({...l,members:l.members==="*"?[]:"*"});else if(l.members==="*")d({...l,members:[h]});else{const b=l.members.includes(h)?l.members.filter(S=>S!==h):[...l.members,h];d({...l,members:b.length===0?"*":b})}},R=h=>{d({...l,permissions:l.permissions.filter((b,S)=>h!==S)})},N=h=>{d({...l,permissions:h})},M=un(Qn.safeParse(l)).name,k=a.status!=="draft";return e.createElement(e.Fragment,null,e.createElement(Xe,{pages:[{title:a.name,path:`../../../${a.id}`},{title:y}],header:e.createElement(Oe,{titleComponent:e.createElement(jt,null,a.name," \xA0\u01C0",k?e.createElement(e.Fragment,null,"\xA0",y):e.createElement(an,{invalid:M,value:y,onTextChange:g}),e.createElement(pe,{operation:o==null?void 0:o.role.operation,size:"large"})),description:a.description},e.createElement(T,{variant:"outlined",color:"primary",onClick:()=>E("../..",{relative:"path"})},"Back to policy"))},e.createElement(H,{container:!0,className:v.cardContainer,spacing:4,direction:"row"},e.createElement(H,{item:!0,xs:6},e.createElement(Y,null,e.createElement(pl,{diff:o||null,role:l,policyId:a.id,onToggleMember:A,readonly:k}))),e.createElement(H,{item:!0,xs:6},e.createElement(Y,null,e.createElement(ca,{diff:o||null,permissions:l.permissions,onNewPermissionClick:()=>{m(null),c(!0)},onOpenPermission:h=>{m(h),c(!0)},onReorderPermissions:N,onRemovePermissionClick:R,readonly:k}))))),u&&e.createElement(Ql,{rolePermission:i!==null?l.permissions[i]:void 0,onClose:()=>c(!1),onSave:P,readonly:k}))}function ca({diff:t,permissions:n,onReorderPermissions:r,onNewPermissionClick:a,onOpenPermission:l,onRemovePermissionClick:o,readonly:i=!1}){return e.createElement(e.Fragment,null,e.createElement(p,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(D,{variant:"h5"},"Permission Decisions"),!i&&n.length!==0&&e.createElement(T,{color:"primary",variant:"outlined",startIcon:e.createElement(Ve,null),onClick:a},"New")),e.createElement(Me,null,e.createElement(Fe,null,e.createElement(z,null,!i&&e.createElement(x,{style:{width:0}},e.createElement(cn,{helpText:aa})),e.createElement(x,null,"Match by"),e.createElement(x,null,"Decision"),e.createElement(x,null),!i&&e.createElement(x,null))),e.createElement(Le,null,n.length===0&&e.createElement(z,null,e.createElement(x,{colSpan:5},e.createElement(he,{title:"No permission decisions set",description:"Click the button below to create your first permission.",missing:{customImage:e.createElement(dn,{src:Dr,alt:"No permission placeholder"})},action:e.createElement(T,{variant:"contained",color:"primary",onClick:a},"New permission decision")}))),n.map((m,u)=>e.createElement(z,{key:u},!i&&e.createElement(x,null,e.createElement(mn,{array:n,index:u,onReorder:r})),e.createElement(x,null,e.createElement(Hn,{onClick:()=>l(u)},e.createElement(D,{variant:"body2",color:"primary"},Qe(m)))),e.createElement(x,null,Fr(m)),e.createElement(x,null,e.createElement(pe,{operation:t==null?void 0:t.permissions[m.id].operation})),!i&&e.createElement(x,{align:"right"},e.createElement(on,{message:"Are you sure you want to remove this permission decision?",onConfirm:()=>o(u),title:"Remove?"},c=>e.createElement(j,{...c,"aria-label":"Remove permission decision",size:"small"},e.createElement(se,null)))))))))}const sa="Use the arrows to change the order in which roles are evaluated.";function ma({}){const{diff:t,policy:n,createNewRole:r,updateLocalDraft:a}=re(),l=_(),o=ua(n),i=n.status!=="draft",m=s=>{a({...n,roles:s})},u=s=>{a({...n,roles:n.roles.filter(({id:f})=>f!==s)})},c=()=>{l(`./roles/${r()}`)};return e.createElement(Y,null,e.createElement(p,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(D,{variant:"h3"},"Roles"),!i&&e.createElement(T,{color:"primary",variant:"outlined",startIcon:e.createElement(Ve,null),onClick:()=>c()},"New role")),e.createElement(Me,null,e.createElement(Fe,null,e.createElement(z,null,!i&&e.createElement(x,{style:{width:0}},e.createElement(cn,{helpText:sa})),e.createElement(x,null,"Name"),e.createElement(x,null,"Users"),e.createElement(x,null,"Groups"),!i&&e.createElement(x,{style:{width:0}}))),e.createElement(Le,null,o.map((s,f)=>e.createElement(z,{key:f},!i&&e.createElement(x,null,e.createElement(mn,{array:n.roles,index:f,onReorder:m})),e.createElement(x,null,e.createElement(p,{alignItems:"center",display:"flex",gridGap:8},e.createElement(ae,{to:`roles/${s.id}`},s.name),e.createElement(pe,{operation:t==null?void 0:t.roles[s.id].role.operation}))),e.createElement(x,null,s.userCount),e.createElement(x,null,s.groupCount),!i&&e.createElement(x,{align:"right"},e.createElement(on,{message:"Are you sure you want to remove this role?",title:"Remove role?",onConfirm:()=>u(s.id)},E=>e.createElement(j,{...E,"aria-label":"Remove role",size:"small"},e.createElement(se,null)))))))))}function ua(t){return t.roles.map(n=>({id:n.id,name:n.name,userCount:Array.isArray(n.members)?n.members.filter(r=>r.startsWith("user:")).length:n.members,groupCount:Array.isArray(n.members)?n.members.filter(r=>r.startsWith("group:")).length:n.members}))}function da(){const{versionId:t}=lt();return Ue(t),e.createElement(Ne,{policyId:t},e.createElement(pa,null))}function pa(){const{policy:t,hasChanges:n,discardLocalDraft:r,saveLocalDraftToServer:a,updateLocalDraft:l}=re(),o=s=>{l({...t,name:s})},i=un(Xn.safeParse(t)).name,m=t.status!=="draft",u=De.safeParse(t).success,c=n&&u;return e.createElement(Xe,{pages:[{title:t.name}],header:e.createElement(Oe,{title:t.name,titleComponent:e.createElement(e.Fragment,null,e.createElement(jt,null,m?t.name:e.createElement(an,{invalid:i,name:"Policy name",value:t.name,onTextChange:o}),e.createElement(kt,{status:t.status})),ya(t))},e.createElement(p,{display:"flex",gridGap:8},e.createElement(T,{variant:"outlined",color:"primary",onClick:()=>$t(t)},"Export"),t.status==="draft"&&e.createElement(e.Fragment,null,n&&e.createElement(T,{variant:"outlined",color:"secondary",onClick:r},"Discard changes"),e.createElement(T,{variant:"outlined",color:"primary",onClick:a,disabled:!c},"Save draft")),t.status!=="active"&&e.createElement(Lt,{color:"primary",variant:"contained"})))},e.createElement(H,{item:!0,xs:12},t.roles.length>0?e.createElement(ma,null):e.createElement(Ea,{readonly:m})))}const fa=w(t=>({cardHeader:{padding:t.spacing(3,3),borderBottom:`1px solid ${t.palette.border}`},cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}},emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function Ea({readonly:t}){const n=fa(),r=_(),{createNewRole:a}=re(),l=()=>{const o=a();r(`./roles/${o}`)};return e.createElement(Y,null,e.createElement(Wn,{title:"Roles",className:n.cardHeader}),e.createElement(ve,{className:n.cardContent},t?e.createElement(he,{title:"No roles configured",missing:"content"}):e.createElement(he,{title:"No roles yet",description:"Click the button below to create your first role.",missing:{customImage:e.createElement(dn,{src:Pr,alt:"No roles placeholder"})},action:e.createElement(T,{variant:"contained",color:"primary",onClick:()=>l()},"New role")})))}function ya(t){const n={created:"Created by ",published:"Last published by ",updated:"Last updated by "},{activityDateText:r,activityUser:a,timestamp:l}=Ot(t,n);return e.createElement(D,{variant:"body2"},e.createElement(D,{component:"span",display:"inline",variant:"body2"},`${r} ${a} `),e.createElement(It,{timestamp:l}))}function ga(){const t=Ie(),{NotFoundErrorPage:n}=t.getComponents();return e.createElement(Nr,{loading:e.createElement(ge,null),unauthorized:e.createElement(n,null)},e.createElement(Sr,null,e.createElement(Tr,null,e.createElement(yn,null,e.createElement(Se,{element:e.createElement(rl,null),path:"/"}),e.createElement(Se,{element:e.createElement(da,null),path:"/versions/:versionId"}),e.createElement(Se,{element:e.createElement(oa,null),path:"/versions/:versionId/roles/:roleId"})))))}export{ga as RBACRoot};
3
- //# sourceMappingURL=Root-2f3e058e.esm.js.map