@spotify/backstage-plugin-rbac 0.5.2 → 0.5.4
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 +28 -0
- package/README.md +11 -0
- package/dist/esm/{Authorized-2927d77b.esm.js → Authorized-ef4876f3.esm.js} +2 -2
- package/dist/esm/{RBACSidebarItem-5a6fc4a0.esm.js → RBACSidebarItem-e6e67e1e.esm.js} +2 -2
- package/dist/esm/Root-6e97b92d.esm.js +3 -0
- package/dist/esm/{index-11b12986.esm.js → index-8cbef8b1.esm.js} +2 -2
- package/dist/index.esm.js +1 -1
- package/package.json +20 -20
- package/dist/esm/Root-bc165381.esm.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @spotify/backstage-plugin-rbac
|
|
2
2
|
|
|
3
|
+
## 0.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed a bug where all imported policies were set to the first-match decision resolution strategy.
|
|
8
|
+
- Upgraded to Backstage `v1.15.0`
|
|
9
|
+
- Updated dependency `@types/node` to `^18.0.0`.
|
|
10
|
+
- Added a 'Save and Publish' option to the policy page menu to combine both the save and publish actions together, and added a default primary action that sits next to the menu button to either save, republish or duplicate policies depending on their state
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @spotify/backstage-plugin-core@0.5.3
|
|
15
|
+
- @spotify/backstage-plugin-rbac-common@0.5.3
|
|
16
|
+
|
|
17
|
+
## 0.5.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Minor accessibility improvements.
|
|
22
|
+
- Upgraded to Backstage `v1.14.0`
|
|
23
|
+
- 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.
|
|
24
|
+
- Minor UI tweaks and improvements.
|
|
25
|
+
- Set the default Resolution Strategy to be 'any-allow' for new policy drafts that are created.
|
|
26
|
+
- Updated dependency `vanilla-jsoneditor` to `^0.17.0`.
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @spotify/backstage-plugin-rbac-common@0.5.2
|
|
29
|
+
- @spotify/backstage-plugin-core@0.5.2
|
|
30
|
+
|
|
3
31
|
## 0.5.2
|
|
4
32
|
|
|
5
33
|
### 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.
|
|
@@ -1,2 +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-
|
|
2
|
-
//# sourceMappingURL=Authorized-
|
|
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-8cbef8b1.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-ef4876f3.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-
|
|
2
|
-
//# sourceMappingURL=RBACSidebarItem-
|
|
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-ef4876f3.esm.js";import"@backstage/core-plugin-api";import"react-use/lib/useAsync";import"./index-8cbef8b1.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-e6e67e1e.esm.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import e,{createContext as We,useState as k,useCallback as R,useMemo as L,useContext as ze,useEffect as _,Fragment as Pe,useRef as ne,useReducer as Tn,useLayoutEffect as Sn}from"react";import{useNavigate as z,Link as kn,useParams as Ge,Routes as Rn,Route as De}from"react-router-dom";import{useApi as I,configApiRef as $n,alertApiRef as ae,useRouteRef as In,useApp as Ue}from"@backstage/core-plugin-api";import de from"react-use/lib/useAsync";import{isResourcePermission as Ve}from"@backstage/plugin-permission-common";import{r as G,a as On}from"./index-8cbef8b1.esm.js";import{forEach as Bn,mapValues as Mn,groupBy as Ln,uniq as Fn}from"lodash";import{Breadcrumbs as jn,Link as ue,Page as Hn,Header as Wn,Content as zn,EmptyState as Ne,Progress as we,ErrorPanel as ht,Table as Gn,ContentHeader as Ae}from"@backstage/core-components";import vt from"react-use/lib/useMount";import{makeStyles as D,Typography as C,Container as Un,Grid as F,Button as w,Card as Y,CardContent as pe,Box as f,Chip as Te,Tooltip as fe,List as Vn,ListItem as bt,ListItemIcon as le,ListItemText as re,CardActions as _n,Dialog as oe,DialogContent as K,DialogTitle as Se,TextField as Ee,DialogActions as _e,CircularProgress as Ct,IconButton as W,Checkbox as Ye,TableRow as U,TableCell as N,debounce as Yn,Table as Je,TableHead as qe,TableBody as Ke,Tabs as Jn,Tab as qn,FormControl as Qe,InputLabel as ke,Select as Xe,MenuItem as V,Menu as xt,FormControlLabel as Pt,FormHelperText as Dt,Popper as Kn,Paper as Qn,Divider as Ze,DialogContentText as Xn,ButtonBase as Zn,CardHeader as Nt,ButtonGroup as ea,MenuList as et,ListItemSecondaryAction as ta,CardActionArea as na,Radio as aa}from"@material-ui/core";import{SpotifyLicenseBanner as la,useAutoUpdatingRelativeTime as ra,invariant as Re}from"@spotify/backstage-plugin-core";import ie from"react-use/lib/useAsyncFn";import oa,{dump as ia}from"js-yaml";import{PolicyConfigParser as $e,isConditionalDecision as tt,isAllOfPermissionCriteria as ca,isAnyOfPermissionCriteria as sa,isNotPermissionCriteria as ma,isMatchingPermission as da,BackstageUserPlaceholder as ye,RoleParser as ua,UpdateDraftRequestParser as pa}from"@spotify/backstage-plugin-rbac-common";import{v4 as ce}from"uuid";import wt from"lodash/keyBy";import fa from"lodash/isEqual";import At from"@material-ui/icons/ReportProblemOutlined";import Ea from"@material-ui/icons/CalendarToday";import Tt from"@material-ui/icons/Person";import ya from"@material-ui/icons/FiberManualRecord";import{DateTime as Ie}from"luxon";import ga from"react-use/lib/useLocalStorage";import{saveAs as ha}from"file-saver";import St from"lodash/omit";import va from"lodash/pickBy";import nt from"@material-ui/icons/Close";import ba from"@material-ui/icons/Publish";import Ca from"@material-ui/icons/FilterNone";import{parseEntityRef as Q,DEFAULT_NAMESPACE as xa}from"@backstage/catalog-model";import{humanizeEntityRef as Pa,catalogApiRef as Da}from"@backstage/plugin-catalog-react";import{Autocomplete as at,ToggleButton as Na,ToggleButtonGroup as wa}from"@material-ui/lab";import ge from"@material-ui/icons/Delete";import Aa from"@material-ui/icons/Group";import Ta from"@material-ui/icons/GroupWork";import kt from"@material-ui/icons/Info";import Rt from"ajv";import Sa from"lodash/uniqBy";import{JSONEditor as ka,isTextContent as Ra,createAjvValidator as $a,Mode as Ia}from"vanilla-jsoneditor";import lt from"@material-ui/icons/Add";import Oa from"@material-ui/icons/Remove";import Ba from"@material-ui/icons/Edit";import Ma from"@material-ui/icons/Check";import La from"@material-ui/icons/KeyboardArrowDown";import Fa from"@material-ui/icons/KeyboardArrowUp";import ja from"../images/no-permissions.svg";import Ha from"../images/no-roles.svg";import Wa from"@material-ui/icons/MoreHoriz";import za from"@material-ui/icons/Undo";import Ga from"@material-ui/icons/Save";import Ua from"@material-ui/icons/Settings";import Va from"@material-ui/icons/VerticalAlignTop";import{A as _a}from"./Authorized-ef4876f3.esm.js";import"@backstage/errors";const $t=We(null),Ya=({children:t})=>{const n=I($n),a=I(G),r=I(ae),[l,o]=k(null),i=R(async()=>{var s;if(!l){const m=await a.fetchAllPermissionMetadata((s=n.getOptionalStringArray("permission.permissionedPlugins"))!=null?s:[]),c=qa(m.rules);Bn(c,u=>{u.length!==1&&r.post({message:`The plugin(s) ${u.slice(1).join(", ")} expose rules which are conflicting with rules exposed by the ${u[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=Ka(m,c);return o(p),p}return l},[r,l,a,n]);return e.createElement($t.Provider,{value:L(()=>({getMetadata:i}),[i])},t)};function Oe(){const t=ze($t),{value:n}=de(async()=>t==null?void 0:t.getMetadata(),[t]);return n}function It(){var t;const n=Oe();return(t=n==null?void 0:n.rules)!=null?t:null}function Ot(){var t;const n=Oe();return(t=n==null?void 0:n.permissions)!=null?t:null}function Bt(){const t=Oe();return t?[...new Set(t.permissions.filter(n=>Ve(n)).map(({resourceType:n})=>n))]:null}function Ja(){const t=Oe(),n=Bt();return!t||!n?null:n.reduce((a,r)=>{const l=t.rules.find(o=>o.resourceType===r);return l&&(a[r]={pluginId:l.pluginId}),a},{})}function qa(t){return Mn(Ln(t,"resourceType"),n=>Fn(n.map(({pluginId:a})=>a)))}function Ka(t,n){return{...t,rules:t.rules.filter(({resourceType:a,pluginId:r})=>{const l=n[a];return r===l[0]})}}const Qa=D(t=>({breadcrumbs:{marginBottom:t.spacing(4)}}));function Xa({pages:t}){const n=In(On),a=Qa();return e.createElement(jn,{className:a.breadcrumbs},e.createElement(ue,{to:n()},"Home"),t.map(({title:r,path:l},o)=>l?e.createElement(ue,{to:l,key:l,relative:"path"},r):e.createElement(C,{key:`${o}`},r)))}function Be({children:t,header:n,pages:a}){return e.createElement(Hn,{themeId:"tool"},e.createElement(la,{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(zn,null,e.createElement(Un,{maxWidth:"lg"},e.createElement(F,{container:!0,spacing:4},e.createElement(F,{item:!0,xs:12},a&&e.createElement(Xa,{pages:a}),n),t))))}const Mt=We({hasDraftPolicy:!1,policies:void 0,setPolicies:()=>{},setPolicy:()=>{},getPolicy:()=>{},removePolicy:()=>{}}),Me=()=>ze(Mt);function Za({children:t,initialState:n={policies:void 0,cache:{}}}){const[a,r]=k(n),l=R(m=>{r(c=>({...c,policies:m,cache:Lt(c.cache,m)}))},[]),o=R(m=>a.cache[m],[a.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:Lt(c.cache,[m])})),[]);return e.createElement(Mt.Provider,{value:L(()=>{var m;return{hasDraftPolicy:((m=a.policies)==null?void 0:m.some(({status:c})=>c==="draft"))||!1,policies:a.policies,setPolicies:l,setPolicy:s,getPolicy:o,removePolicy:i}},[a.policies,l,s,o,i])},t)}function Lt(t,n){if(!n)return t;const a={...t};return n.forEach(r=>{a[r.id]=r}),a}const he=()=>{const t=I(G),{setPolicies:n,policies:a}=Me(),[{loading:r,error:l},o]=ie(()=>t.getPolicies(),[t],a?{loading:!1,value:{items:a,totalItems:a.length}}:{loading:!0}),i=R(async()=>{const s=await o();n(s.items)},[o,n]);return{loading:r,error:l,fetchPolicies:i}};function el(){const t=I(G),n=z(),a=I(ae);function r(l){var o,i;const s=(i=(o=l.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,u;const d=(u=(p=c.target)==null?void 0:p.result)==null?void 0:u.toString();if(d){let b=null;try{b=oa.load(d)}catch{a.post({message:"YAML file is invalid",severity:"error"});return}if(!$e.safeParse(b).success){a.post({message:"Imported policy is invalid",severity:"error"});return}if((await t.getPolicies()).items.some(E=>E.status==="draft")){a.post({message:"Unable to import new policy due to existing draft policy",severity:"error"});return}const g=b,y=await t.createDraft({name:g.name,roles:g.roles,options:g.options});n(`./versions/${y.id}`),a.post({message:"Policy imported successfully",severity:"success"})}})}return e.createElement(w,{variant:"outlined",color:"primary",component:"label"},"Import",e.createElement("input",{role:"input",type:"file",hidden:!0,onChange:r,accept:".yaml"}))}const tl=D(t=>({cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}}}));function nl(){const t=tl(),n=I(G),a=z(),[r,l]=ie(async()=>n.createDraft({roles:[],options:{resolutionStrategy:"any-allow"}}),[n]);return _(()=>{r.value&&a(`./versions/${r.value.id}`)},[a,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(w,{variant:"contained",color:"primary",disabled:r.loading,onClick:l},"New version")})))}function al(t){var n,a;return((a=(n=t==null?void 0:t.body)==null?void 0:n.response)==null?void 0:a.statusCode)===404}const ll=(t,n)=>{const a={resolutionStrategy:{operation:"UNCHANGED",before:t==null?void 0:t.resolutionStrategy,after:n==null?void 0:n.resolutionStrategy}};for(const r of Object.keys(a)){const l=r;a[l].before!==a[l].after&&(a[l].operation="CHANGED")}return a},rt=(t,n)=>{const a=Object.entries(t);for(const[,r]of a){const l=n(r);for(const[,o]of a){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[,r]of a){const l=n(r);l.operation==="UNCHANGED"&&l.indexAfter!==l.indexBefore&&(l.operation=l.indexAfter>l.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,l)=>[r,{operation:"ADDED",after:r,before:null,indexAfter:l,indexBefore:-1}]))};if(n==="*")return{"*":{operation:"ADDED",after:"*",before:null,indexAfter:0,indexBefore:-1},...Object.fromEntries(t.map((r,l)=>[r,{operation:"REMOVED",after:null,before:r,indexAfter:-1,indexBefore:l}]))};const a=Object.fromEntries(n.map((r,l)=>[r,{operation:"ADDED",after:r,before:null,indexAfter:l,indexBefore:-1}]));for(let r=0;r<t.length;r++){const l=t[r];a[l]?(a[l].before=l,a[l].indexBefore=r,a[l].operation="UNCHANGED"):a[l]={operation:"REMOVED",after:null,before:l,indexAfter:-1,indexBefore:r}}return rt(a,r=>r)},it=(t,n)=>{const a=wt(n,"id"),r=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(r[o.id]){const i=!fa(o,a[o.id]);r[o.id].before=o,r[o.id].indexBefore=l,r[o.id].operation=i?"CHANGED":"UNCHANGED"}else r[o.id]={operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:l}}return rt(r,l=>l)},rl=(t=[],n=[])=>{const a=wt(n,"id"),r=Object.fromEntries(n.map((l,o)=>[l.id,{role:{operation:"ADDED",indexAfter:o,indexBefore:-1,after:l,before:null},members:ot([],l.members),permissions:it([],l.permissions)}]));for(let l=0;l<t.length;l++){const o=t[l];if(a[o.id]){const i=a[o.id],s=ot(o.members,i.members),m=it(o.permissions,i.permissions),c=Object.values(m).some(({operation:d})=>d!=="UNCHANGED"),p=Object.values(s).some(({operation:d})=>d!=="UNCHANGED"),u=o.name!==i.name||c||p;r[o.id].role.before=o,r[o.id].role.indexBefore=l,r[o.id].role.operation=u?"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:l},members:ot(o.members,[]),permissions:it(o.permissions,[])}}return rt(r,({role:l})=>l)},ol=(t,n)=>{const a=rl((t==null?void 0:t.roles)||[],n.roles||[]),r=ll(t==null?void 0:t.options,n.options),l=(t==null?void 0:t.name)!==n.name,o=Object.values(r).some(({operation:i})=>i!=="UNCHANGED");return{policy:{operation:l||o?"CHANGED":"UNCHANGED",before:t,after:n},roles:a,options:r}},Ft=t=>{const n=I(G),{value:a,loading:r,error:l}=de(()=>n.getActivePolicy(),[n]);return L(()=>t&&!r&&!l?ol(a,t):null,[a,t,r,l])},il=D(t=>({chip:{margin:0},icon:{color:t.palette.success.main}}));function jt(t){const n=il();return t.status==="inactive"?null:t.status==="draft"?e.createElement(Te,{className:n.chip,label:"Draft",size:t.size}):e.createElement(Te,{className:n.chip,classes:{icon:n.icon},label:"Active",icon:e.createElement(ya,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}},cl=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 sl(t){var n;return tt(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 a=[];return t.match.resourceType&&a.push(t.match.resourceType),(n=t.match.actions)!=null&&n.length&&a.push(t.match.actions.join(", ")),a.join(" | ")}const ml=D(t=>({root:({operation:n})=>({color:ct(t,n)})})),M=t=>e.createElement(C,{...t,variant:"body2"}),x=t=>{const n=ml(t);return e.createElement(f,{...t,className:n.root,component:"span",fontWeight:"fontWeightBold"})},Ht=({policy:t})=>{var n,a,r,l;const o=Ft(t),i=(o==null?void 0:o.policy.operation)==="CHANGED"||Object.values((n=o==null?void 0:o.roles)!=null?n:{}).some(u=>u.role.operation!=="UNCHANGED")||((a=o==null?void 0:o.options)==null?void 0:a.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:u,after:d})=>u&&d&&u.name!==d.name,p=({operation:u})=>u!=="ADDED"&&u!=="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,'"',(l=o.policy.after)==null?void 0:l.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(([u,{role:d,permissions:b,members:g}])=>{var y,E,P,T,$,j;return e.createElement(Pe,{key:u},d.operation==="ADDED"&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(y=d.after)==null?void 0:y.name,'"')," has been"," ",e.createElement(x,{operation:"ADDED"},"added")),d.operation==="REMOVED"&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(E=d.before)==null?void 0:E.name,'"')," has been"," ",e.createElement(x,{operation:"REMOVED"},"removed")),c(d)&&e.createElement(M,null,"Role name changed from ",e.createElement(x,null,'"',(P=d.before)==null?void 0:P.name,'"')," ","to ",e.createElement(x,null,'"',(T=d.after)==null?void 0:T.name,'"')),d.indexAfter>d.indexBefore&&d.indexBefore!==-1&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',($=d.after)==null?void 0:$.name,'"')," has been"," ",e.createElement(x,{operation:"MOVED_DOWN"},"moved down")," in priority"),d.indexAfter<d.indexBefore&&d.indexAfter!==-1&&e.createElement(M,null,"Role ",e.createElement(x,null,'"',(j=d.after)==null?void 0:j.name,'"')," has been"," ",e.createElement(x,{operation:"MOVED_UP"},"moved up")," in priority"),p(d)&&e.createElement(e.Fragment,null,Object.entries(b).map(([B,v])=>{var A,h,S,O,Z;const{before:J,after:se}=v,ee=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,'"',(A=d.after)==null?void 0:A.name,'"')),v.operation==="REMOVED"&&v.before&&e.createElement(M,null,"Permission decision"," ",e.createElement(x,null,'"',ee,'"')," has been"," ",e.createElement(x,{operation:"REMOVED"},"removed")," ","from ",e.createElement(x,null,'"',(h=d.after)==null?void 0:h.name,'"')),v.operation==="CHANGED"&&e.createElement(M,null,ee!==q?e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(x,null,'"',ee,'"')," 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,'"',ee,'"')," has been"," ",e.createElement(x,{operation:"CHANGED"},"updated"))," ","in ",e.createElement(x,null,'"',(S=d.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=d.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,'"',(Z=d.after)==null?void 0:Z.name,'"')))}),Object.entries(g).map(([B,v])=>{var A,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,'"',(A=d.after)==null?void 0:A.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=d.after)==null?void 0:h.name,'"')))})))}))},dl=D(()=>({root:{display:"inline-flex"}})),Wt=({timestamp:t,description:n})=>{const a=dl(),r=Ie.fromISO(t).toLocaleString(Ie.DATETIME_FULL),l=ra(t),o=n?`${n}${l}`:l;return e.createElement("span",{className:a.root},e.createElement(fe,{title:r},e.createElement(C,{component:"span",display:"inline",variant:"inherit"},o)))};function zt(t,n,a){var r,l;let o=n.created,i=t.createdBy;a!=null&&a.created&&(i=a.created+i);let s=t.createdAt;return t.status==="active"?(o=n.published,i=(r=t.lastPublishedBy)!=null?r:"",a!=null&&a.published&&(i=a.published+i),s=(l=t.lastPublishedAt)!=null?l:""):t.createdAt!==t.updatedAt&&(o=n.updated,i=t.updatedBy,a!=null&&a.updated&&(i=a.updated+i),s=t.updatedAt),{activityDateText:o,activityUser:i,timestamp:s}}const ul=D(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=ul(t),{policy:a,to:r,withChangeSummary:l}=t,o=`${a.name} ${a.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}=zt(a,i,s);return e.createElement(Y,{className:n.card},e.createElement(pe,null,e.createElement("div",{className:n.header},r?e.createElement(ue,{to:`versions/${a.id}`},e.createElement(C,{variant:"h5",component:"h1"},o)):e.createElement(C,{variant:"h5",component:"h1"},o),a.status==="active"?e.createElement(jt,{status:"active",size:"small"}):null),a.description?e.createElement(C,{variant:"body1",color:"textSecondary"},'"',a.description,'"'):null,e.createElement(C,{component:"h2",className:n.detailsHeader},"Details"),e.createElement(Vn,{className:n.activityList},e.createElement(bt,{className:n.activityListItem},e.createElement(le,null,e.createElement(Ea,null)),e.createElement(re,{primary:e.createElement(Wt,{timestamp:p,description:m})})),e.createElement(bt,{className:n.activityListItem},e.createElement(le,null,e.createElement(Tt,null)),e.createElement(re,{primary:c}))),l&&e.createElement(f,{paddingTop:2},e.createElement(C,{gutterBottom:!0,variant:"subtitle2"},"What's changed"),e.createElement(f,{className:n.diffSummaryContainer},e.createElement(Ht,{policy:a})))),t.actions?e.createElement(_n,{className:n.actions},t.actions):null)}const pl=D(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)}})),fl=({localPolicy:t,onSelectLocalPolicy:n,onSelectServerPolicy:a,serverPolicy:r})=>{const l=pl();return e.createElement(oe,{open:!0,maxWidth:"md"},e.createElement(K,null,e.createElement(f,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(f,{display:"flex",justifyContent:"center"},e.createElement(At,{className:l.icon})),e.createElement(C,{align:"center",variant:"h6"},"There is a conflict with your drafts"),e.createElement(f,null,e.createElement(C,{align:"center"},"A newer version of the draft you are trying to edit has been recently saved."),e.createElement(C,{align:"center"},"Please review the changes and decide on a version to keep."))),e.createElement(f,{className:l.policiesContainer},e.createElement(f,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(C,{className:l.label,variant:"button"},"Your local draft"),e.createElement(ve,{policy:t,withChangeSummary:!0}),e.createElement(w,{className:l.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(C,{className:l.label,variant:"button"},"Recently saved draft"),e.createElement(ve,{policy:r,withChangeSummary:!0}),e.createElement(w,{className:l.button,color:"primary",onClick:a,variant:"outlined"},"Keep recently saved draft")))))},El=({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},yl=()=>ga("@spotify/backstage-plugin-rbac:draftPolicy");function Gt(t){const n=new Blob([gl(t)],{type:"text/yaml"});ha(n,`${(t.name||"policy").toLocaleLowerCase().replace(/\W/g,"-")}.yaml`)}function gl(t){const{name:n,roles:a,options:r,description:l}=t;return`# this is an autogenerated file, do not edit
|
|
2
|
+
${ia(va({name:n,description:l,options:r,roles:a.map(({permissions:o,...i})=>({...St(i,["id"]),permissions:o.map(s=>St(s,["id"]))}))},o=>o!==null||o!==void 0))}`}const hl=D(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"}})),vl=({onConfirm:t,policy:n})=>{const a=hl(),r=()=>{Gt(n)};return e.createElement(oe,{open:!0},e.createElement(K,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(At,{className:a.icon})),e.createElement(C,{align:"center",variant:"h6"},"Invalid local draft")),e.createElement(f,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(C,{align:"center"},"You have a local draft that is no longer compatible or has become corrupted."),e.createElement(C,{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(C,{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(w,{color:"primary",onClick:r,variant:"outlined"},"Export"),e.createElement(w,{color:"primary",onClick:t,variant:"contained"},"Discard and continue")))))};function mt(){const t=I(G),n=I(ae),a=ie(async(l,o,i)=>{if(l)return await t.publishPolicy(l.id,{description:o,update:i}),t.getPolicy(l.id)},[]),[{error:r}]=a;return _(()=>{r&&n.post({message:r.message,severity:"error"})},[r,n]),a}const bl=D(t=>({closeButton:{color:t.palette.text.secondary},diffSummaryContainer:{backgroundColor:t.palette.background.default,marginBottom:t.spacing(2)}}));function dt({open:t,onPublish:n,onClose:a,policy:r}){const[l,o]=k(!1),i=bl(),s=ne(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:a,fullWidth:!0},e.createElement(Se,null,e.createElement(f,{display:"flex",justifyContent:"space-between",alignItems:"center"},"Ready to publish?",e.createElement(w,{startIcon:e.createElement(nt,null),onClick:a,className:i.closeButton},"Close")),e.createElement(C,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(K,{className:i.diffSummaryContainer,dividers:!0},e.createElement(Ht,{policy:r})),e.createElement(K,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(_e,null,e.createElement(w,{color:"primary",onClick:m,disabled:l},l?e.createElement(Ct,{size:20}):"Publish")))}const Cl=D(t=>({paper:{padding:t.spacing(2,2,0,2)}})),ut=({isOpen:t,onClose:n,policy:a})=>{const r=Cl();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(C,{variant:"h4",component:"h2"},"Success!"),e.createElement(C,null,a.name," has been published and is now your active policy.")),e.createElement(f,null,e.createElement(W,{onClick:n,title:"Close dialog"},e.createElement(nt,null))))),e.createElement(K,null,e.createElement(ve,{policy:a})),e.createElement(_e,null,e.createElement(f,{display:"flex",flexDirection:"row",flexGrow:1,justifyContent:"flex-start"},e.createElement(w,{component:kn,color:"primary",onClick:n,role:"link",to:"/rbac"},"View all versions"))))},xl={canPublish:!1,diff:null,hasChanges:!1,isValid:!1,policy:void 0,createNewRole:()=>"",discardLocalDraft:()=>{},exportPolicy:()=>{},publish:()=>{},saveLocalDraftToServer:()=>Promise.reject(),saveAndPublish:()=>Promise.reject(),refetchPolicy:()=>Promise.reject(),updateLocalDraft:()=>{}},Ut=We(xl),X=()=>ze(Ut);function Le({children:t,policyId:n}){const a=z(),r=I(ae),l=I(G),{getPolicy:o,setPolicy:i}=Me(),s=Ue(),{NotFoundErrorPage:m}=s.getComponents(),[c,p]=k({active:!1,update:!1}),[u,d]=k(!1),[{loading:b,value:g},y]=mt(),E=o(n),[P,T,$]=yl(),j=!P||$e.safeParse(P).success,B=j?P:void 0,{policy:v,policyConflict:A}=El({serverPolicy:E,localPolicy:B}),h=Ft(v),S=$e.safeParse(v).success,O=S&&!B&&!b,[{loading:Z,error:J},se]=ie(()=>l.getPolicy(n),[l,n],E?{loading:!1,value:E}:{loading:!0}),ee=()=>{p({active:!0,update:!1})},q=()=>{p({active:!0,update:!0})},vn=R(async H=>{await y(v,H,c.update?v:void 0),p({active:!1,update:!1})},[v,c,y,p]),bn=async()=>{d(!1)},Cn=()=>{T(H=>H&&E&&{...H,updatedAt:E.updatedAt})},te=R(async()=>{const H=await se();i(H)},[se,i]),xn=R(async()=>{if(!v)throw new Error("No policy to save");try{await l.updateDraft(v.id,{name:v.name,roles:v.roles,options:v.options}),r.post({message:"Policy saved",severity:"success"}),$(),te==null||te()}catch(H){r.post({message:(H==null?void 0:H.message)||"An error occurred while updating the policy",severity:"error"})}},[r,l,v,te,$]),Pn=R(()=>{if(!v)throw new Error("No policy to create a new role");const H=new Set(v.roles.map(An=>An.id));let me;do me=ce().split("-")[0];while(H.has(me));const wn={name:`Role ${me}`,permissions:[],members:"*",id:me};return T({...v,roles:[...v.roles,wn]}),me},[v,T]),Dn=()=>{$(),a("/rbac")},Nn=()=>{v&&Gt(v)};return _(()=>{E||te()},[te,E]),_(()=>{g&&d(!0)},[g]),j?v?e.createElement(Ut.Provider,{value:{canPublish:O,diff:h,hasChanges:!!B,isValid:S,policy:v,createNewRole:Pn,discardLocalDraft:$,exportPolicy:Nn,publish:ee,saveLocalDraftToServer:xn,refetchPolicy:te,updateLocalDraft:T,saveAndPublish:q}},A&&B&&E&&e.createElement(fl,{localPolicy:B,onSelectLocalPolicy:Cn,onSelectServerPolicy:$,serverPolicy:E}),e.createElement(dt,{open:c.active,onClose:()=>p({active:!1,update:!1}),onPublish:vn,policy:v}),g&&e.createElement(ut,{isOpen:u,onClose:bn,policy:g}),t):Z?e.createElement(we,null):J?al(J)?e.createElement(m,null):e.createElement(ht,{error:J!=null?J:new Error("Unknown")}):null:e.createElement(vl,{onConfirm:Dn,policy:P})}function Pl(t){throw new Error("Invalid state")}function pt(){const t=I(G),n=I(ae),a=z(),{fetchPolicies:r}=he();return ie(async l=>{if(!l)return;const{roles:o,name:i,options:s}=l;try{const m=await t.createDraft({roles:o,options:s,name:i});return await r(),a(`/rbac/versions/${m.id}`),m}catch(m){throw m instanceof Error&&n.post({message:m.message,severity:"error"}),m}},[a,t,n,r])}const Dl=[{title:"Name",field:"name",render:t=>e.createElement(ue,{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 Pl(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 Nl(t){const n=t.data.length>3,{fetchPolicies:a}=he(),[{loading:r},l]=pt(),[{loading:o,value:i},s]=mt(),[m,c]=k(void 0),[p,u]=k(!1),d=()=>{c(void 0),a()},b=(m==null?void 0:m.id)===(i==null?void 0:i.id)?i:void 0,g=[y=>{const{tableData:E,...P}=y;return{icon:ba,tooltip:"Republish",onClick:()=>{c(P),u(!0)},disabled:o}},y=>{const{tableData:E,...P}=y;return{icon:Ca,tooltip:"Duplicate",disabled:r||!t.canDuplicate,onClick:()=>l(P)}}];return e.createElement(e.Fragment,null,e.createElement(Gn,{title:"Previous Versions",columns:Dl,data:t.data,options:{paging:n,pageSize:3,pageSizeOptions:[3,5,10,20],actionsColumnIndex:-1,loadingType:"linear"},actions:g}),m&&e.createElement(dt,{open:p,onPublish:y=>{s(m,y),u(!1)},onClose:()=>{c(void 0),u(!1)},policy:m}),b&&e.createElement(ut,{isOpen:!0,policy:b,onClose:d}))}const wl=t=>{const[n,a]=k(!1),{fetchPolicies:r}=he(),[{loading:l,value:o},i]=mt(),{policy:s,hasChanges:m}=X(),c=$e.safeParse(s).success,p=!m&&c,u=async b=>{await i(s,b),a(!1)},d=()=>{r()};return e.createElement(e.Fragment,null,e.createElement(w,{...t,onClick:()=>a(!0),disabled:!p||l},"Publish"),e.createElement(dt,{open:n,onClose:()=>a(!1),onPublish:u,policy:s}),o&&e.createElement(ut,{isOpen:!0,onClose:d,policy:o}))};function Al(t){const n=I(G),a=I(ae),{fetchPolicies:r}=he();return ie(async()=>{if(t)return n.deleteDraft(t.id).then(r).catch(l=>(a.post({message:l.message,severity:"error"}),Promise.reject(l)))},[t])}function Tl({policies:t}){const n=t.find(c=>c.status==="draft"),a=t.find(c=>c.status==="active"),[r,l]=pt(),[o,i]=Al(n),s=z(),m=Sl(t);return e.createElement(F,{container:!0,spacing:4},a?e.createElement(F,{item:!0,xs:12,md:6},e.createElement(ve,{policy:a,to:`./versions/${a.id}`,actions:e.createElement(w,{color:"primary",disabled:r.loading||!!n,onClick:()=>l(a)},"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(w,{onClick:()=>s(`versions/${n.id}`),color:"primary"},"Edit"),e.createElement(w,{color:"primary",disabled:o.loading,onClick:i},"Delete Draft"),e.createElement(Le,{policyId:n.id},e.createElement(wl,{color:"primary"})))})):null,e.createElement(F,{item:!0,xs:12},e.createElement(Nl,{data:m,canDuplicate:!n})))}function Sl(t){return t.filter(({status:n})=>n==="inactive")}function kl(){const{policies:t}=Me(),{loading:n,error:a,fetchPolicies:r}=he();vt(()=>{t||r()});let l;return n?l=e.createElement(F,{item:!0,xs:12},e.createElement(we,null)):a?l=e.createElement(ht,{error:a}):!t||t.length===0?l=e.createElement(nl,null):l=e.createElement(Tl,{policies:t}),e.createElement(Be,{pages:void 0,header:e.createElement(Ae,{title:"RBAC Policies"},e.createElement(el,null))},l)}const Rl=D(t=>({titleWrapper:{display:"flex",alignItems:"center",gap:t.spacing(2)}}));function Vt({children:t}){const n=Rl();return e.createElement(C,{noWrap:!0,variant:"h4",component:"h2",color:"textSecondary",className:n.titleWrapper},t)}const $l=D({autocomplete:{display:"flex",flex:1}});function Il({members:t,options:n,namespaceOptions:a,loading:r=!1,disabled:l=!1,isMultiNamespaces:o=!1,onTextChange:i,onToggleMember:s,onChange:m}){const[c,p]=k(!1),u=$l(),[d,b]=Tn(E=>E+1,0),g=(E,P)=>{P&&(s(P),b())};_(()=>{c&&i("")},[c,i]);const y=o?a.concat((n==null?void 0:n.members)||[]):(n==null?void 0:n.members)||[];return e.createElement(f,{width:250},e.createElement(at,{key:`${d}`,open:c,onOpen:()=>{p(!0)},onClose:()=>{p(!1)},onChange:g,getOptionLabel:be,groupBy:Ol,renderOption:E=>e.createElement(e.Fragment,null,e.createElement(Ye,{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:l,loading:r,className:u.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(Ct,{color:"inherit",size:20}):null,E.InputProps.endAdornment)}})}))}function be(t,n=!0){var a;const r=Q(t.entityRef);return r.name==="*"?r.namespace:Pa({...r,name:(a=t.name)!=null?a:r.name},{defaultKind:r.kind,defaultNamespace:n?xa:!1})}const _t={user:"USERS",group:"GROUPS",namespace:"NAMESPACES"};function Ol(t){const{name:n,kind:a}=Q(t.entityRef),r=n==="*"?"namespace":a;if(!_t[r])throw new Error(`Group '${r}' is not supported for members in a policy`);return _t[r]}const Bl=D(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"})})),Ml={small:"span",medium:"div",large:"div"},Ll={small:"caption",medium:"body1",large:"subtitle1"},Ce=({operation:t,size:n="small"})=>{const a=Bl({operation:t}),r=cl(t);return!t||t==="UNCHANGED"?null:e.createElement(C,{className:a.root,variant:Ll[n],component:Ml[n]},r)},Fl=D(t=>({actionCol:{width:48},typeIconCol:{paddingRight:"0.4rem"},nameCol:{paddingLeft:0},typeIcon:{color:t.palette.grey[500]}}));function jl({diff:t,loading:n,isMultiNamespaces:a,members:r,error:l,onToggleMember:o,readonly:i=!1}){const s=Fl();if(n)return e.createElement(U,null,e.createElement(N,{scope:"row",colSpan:i?4:5},e.createElement(we,null)));if(l&&l.message!=null,r==="*")return e.createElement(U,null,e.createElement(N,{colSpan:2,height:80},"All"),e.createElement(N,{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(N,{scope:"row",colSpan:i?4:5},"Select users or groups using the drop-down menu above."));const m=r.sort((c,p)=>{let u=0;a&&p.name==="*"&&c.name!=="*"?u=1:a&&c.name==="*"&&p.name!=="*"&&(u=-1);const d=c.type.localeCompare(p.type),b=Q(c.entityRef).namespace.localeCompare(Q(p.entityRef).namespace),g=Q(c.entityRef).name.localeCompare(Q(p.entityRef).name);return u||d||b||g});return e.createElement(e.Fragment,null,m.map(c=>{var p;const{name:u,type:d,entityRef:b}=c;return e.createElement(U,{key:b},e.createElement(N,{className:s.typeIconCol},d==="group"&&e.createElement(Aa,{className:s.typeIcon})||a&&u==="*"&&e.createElement(Ta,{className:s.typeIcon})||e.createElement(Tt,{className:s.typeIcon})),e.createElement(N,{scope:"row",className:s.nameCol},(p=a?be(c,!1):be(c))!=null?p:"Unknown"),e.createElement(N,{scope:"row"},u==="*"&&a?"namespace":d),e.createElement(N,null,u&&e.createElement(Ce,{operation:t==null?void 0:t.members[b].operation})),!i&&e.createElement(N,{scope:"row",className:s.actionCol},e.createElement(W,{"aria-label":"delete",onClick:()=>o(c),size:"small"},e.createElement(ge,null))))}))}const Hl=D(()=>({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 Wl({diff:t,policyId:n,role:a,onToggleMember:r,readonly:l=!1,debounceTime:o=1e3}){const i=I(G),s=I(Da),m=Hl(),c=a.members==="*",[p,u]=k(""),{current:d}=ne({}),b=h=>{d[h.entityRef]=h,r(h.entityRef)},g=h=>{var S;if(d[h])return d[h];const O=Q(h);return{entityRef:h,type:O.kind.toLowerCase(),name:(S=O.name)!=null?S:h}},{value:y,loading:E}=de(async()=>await i.searchMembers({query:p}),[i,p]),{loading:P,value:T}=de(async()=>{const h=await s.getEntityFacets({facets:["metadata.namespace"]}).then(S=>S.facets["metadata.namespace"].map(O=>O.value));return zl(h)},[s]),$=T?(T==null?void 0:T.length)>1:!1,j=T?T.filter(h=>h.entityRef.toLowerCase().includes(p)):[],B=L(()=>Yn(h=>{u(h.target.value.toLowerCase())},o),[u,o]),{loading:v,error:A}=de(async()=>{a.members==="*"||a.members.length===0||(await i.getPolicy(n)).roles.find(h=>h.id===a.id)===void 0||a.members.forEach(h=>{const S=g(h);d[S.entityRef]=S})},[n,c]);return e.createElement(e.Fragment,null,e.createElement("div",{className:m.header},e.createElement("h2",null,"Members"),e.createElement(Il,{onToggleMember:b,members:a.members,disabled:l,options:y,namespaceOptions:j,isMultiNamespaces:$,loading:E||P,onTextChange:u,onChange:B})),e.createElement(Je,null,e.createElement(qe,null,e.createElement(U,null,e.createElement(N,{className:m.typeIconCol}),e.createElement(N,{className:m.nameCol},"Name"),e.createElement(N,null,"Type"),e.createElement(N,null),!l&&e.createElement(N,{className:m.actionCol}))),e.createElement(Ke,null,e.createElement(jl,{diff:t,loading:v||P,isMultiNamespaces:$,error:A,members:Array.isArray(a.members)?a.members.map(g):a.members,onToggleMember:b,readonly:l}))))}function zl(t){return t.map(n=>({name:"*",type:"user",entityRef:`user:${n}/*`})).sort((n,a)=>n.entityRef.toLowerCase().localeCompare(a.entityRef.toLowerCase()))}function Yt(t){return`${t.palette.primary.main}50`}const Gl=D(t=>({indicator:{right:"unset"},tab:{maxWidth:"none","&.Mui-selected":{backgroundColor:Yt(t),color:t.palette.primary.main}}}));function Ul({options:t,selected:n,onChange:a,readonly:r=!1}){const l=Gl();return e.createElement(Jn,{orientation:"vertical",value:t.map(({id:o})=>o).indexOf(n),onChange:(o,i)=>a(t[i].id),indicatorColor:"primary",TabIndicatorProps:{className:l.indicator}},t.map(o=>e.createElement(qn,{key:o.id,label:o.displayText.toUpperCase(),className:l.tab,disabled:r})))}const Vl=["condition","anyOf","allOf","not"],Jt={condition:"Condition",anyOf:"Any of",allOf:"All of",not:"Not"};function ft(t){return t===null?!1:t.hasOwnProperty("id")&&t.hasOwnProperty("ruleName")&&t.hasOwnProperty("parameters")}function xe(t){return t.hasOwnProperty("levelType")}function _l(t){return t==="anyOf"||t==="allOf"||t==="not"}function Yl(t){return t?{id:t.id,match:Jl(t),decisionType:ql(t),criteria:tt(t.decision)?Fe(t.decision.conditions):null}:{id:ce(),match:{method:"specificPermission"},decisionType:"allow",criteria:null}}function Jl(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 ql(t){return typeof t.decision=="string"?t.decision:"conditional"}function Fe(t){const n=ce();return ca(t)?{id:n,levelType:"allOf",children:t.allOf.map(a=>Fe(a))}:sa(t)?{id:n,levelType:"anyOf",children:t.anyOf.map(a=>Fe(a))}:ma(t)?{id:n,levelType:"not",children:[Fe(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 a=n==null?void 0:n.find(({name:r})=>r===t.ruleName);return a?a.paramsSchema?new Rt({allErrors:!0}).compile(a.paramsSchema)(t.parameters):!0:!1}function Kl(t,n,a){return{id:t,match:Kt(n,a),decision:a}}function Kt({method:t,...n},a){return t==="all"?"*":a&&tt(a)?{resourceType:a.resourceType,...n}:n}function Et(t){return ft(t)?{rule:t.ruleName,params:t.parameters}:t.levelType==="not"?{not:Et(t.children[0])}:{[t.levelType]:t.children.map(n=>Et(n))}}const Ql=D(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 yt({className:t,...n}){const a=Ql();return e.createElement(Na,{className:`${a.toggleButton} ${t}`,...n})}const Xl=D({fullWidth:{width:"100%","& > *":{flexGrow:1}}});function Zl({className:t,fullWidth:n,...a}){const r=Xl();return e.createElement(wa,{className:`${n?r.fullWidth:""} ${t}`,...a})}function er(t,n){const a=(t!=null?t:[]).filter(o=>da(o,Kt(n))),r=Sa(a,o=>Ve(o)?o.resourceType:void 0),l=r.length===1&&Ve(r[0])?r[0].resourceType:void 0;return{permissions:a,commonResourceType:l}}const tr=D(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Qt="Permission name";function nr({name:t="",readonly:n,onNameChange:a}){const r=tr(),l=Ot();return e.createElement(Qe,{className:r.fullWidth,variant:"outlined",disabled:n},e.createElement(ke,{id:"match-by-name-dropdown"},Qt),e.createElement(Xe,{labelId:"match-by-name-dropdown",label:Qt,value:l?t:"",onChange:o=>a==null?void 0:a(o.target.value)},l==null?void 0:l.map(o=>e.createElement(V,{key:o.name,value:o.name},o.name))))}const ar=D(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Xt="Resource type";function lr({resourceType:t="",readonly:n,onResourceTypeChange:a}){const r=ar(),l=Bt();return e.createElement(Qe,{className:r.fullWidth,variant:"outlined",disabled:n},e.createElement(ke,{id:"match-by-resource-dropdown"},Xt),e.createElement(Xe,{labelId:"match-by-resource-dropdown",label:Xt,value:l?t:"",onChange:o=>a==null?void 0:a(o.target.value),displayEmpty:!0},l==null?void 0:l.map(o=>e.createElement(V,{key:o,value:o},o))))}const rr="Action";function or({actions:t,readonly:n,onActionsChange:a}){return e.createElement(at,{multiple:!0,id:"match-by-attribute-dropdown",options:["create","read","update","delete"],getOptionLabel:r=>r,value:t!=null?t:[],onChange:(r,l)=>a==null?void 0:a(l),filterSelectedOptions:!0,renderInput:r=>e.createElement(Ee,{...r,variant:"outlined",label:rr,placeholder:"Choose attributes",margin:"normal"}),disabled:n})}const ir=D(t=>({descriptiveText:{fontWeight:500,marginBottom:t.spacing(1)}})),je=({children:t})=>{const n=ir();return e.createElement(C,{variant:"body2",className:n.descriptiveText},t)},Zt="#FF737F",cr="#E22134";function en({condition:t}){return e.createElement(je,null,e.createElement(f,{component:"span",color:Zt},t.ruleName,"("),e.createElement(f,{component:"span",color:cr},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(je,null,Jt[t.levelType]),e.createElement(tn,null,t.children.map((n,a)=>xe(n)?e.createElement(nn,{key:a,level:n}):e.createElement(en,{key:a,condition:n}))))}const sr="#4CAF50";function mr({permissionCriteria:t}){return e.createElement("div",null,e.createElement(je,null,"If the below conditions are met"),e.createElement(tn,null,ft(t)&&e.createElement(en,{condition:t}),xe(t)&&e.createElement(nn,{level:t})),e.createElement(je,null,"Then the action is"," ",e.createElement(f,{component:"span",color:sr},"allowed")))}const dr=D(()=>({addButton:{paddingLeft:40,paddingRight:40}}));function an({onSelect:t}){const n=dr(),a=ne(null),[r,l]=k(!1),o=()=>{l(i=>!i)};return e.createElement("div",null,e.createElement(w,{className:n.addButton,variant:"outlined",color:"primary",onClick:o,ref:a},"Add"),e.createElement(xt,{anchorEl:a.current,open:r,onClose:o,BackdropProps:{}},Vl.map(i=>e.createElement(V,{key:i,onClick:()=>{t==null||t(i),l(!1)}},Jt[i]))))}const ur=D(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"}})),pr=t=>"parseError"in t,fr=t=>{var n;return t?pr(t)?!!t.parseError:((n=t==null?void 0:t.validationErrors)==null?void 0:n.length)>0:!1};function Er({onChange:t,schema:n,value:a}){const r=ne(null),l=ne(),o=ur();return _(()=>(r.current&&!l.current&&(l.current=new ka({target:r.current,props:{onChange:(i,s,{contentErrors:m})=>{!fr(m)&&Ra(i)&&t(JSON.parse(i.text))},validator:$a({schema:n}),content:{json:{}},mainMenuBar:!1,mode:Ia.text}})),()=>{var i;(i=l.current)==null||i.destroy(),l.current=void 0}),[t,n]),vt(()=>{var i;(i=l.current)==null||i.updateProps({content:{json:a}})}),e.createElement("div",{ref:r,className:o.editor,style:{height:300}})}const yr=[];function gr(t){const{onChange:n,schema:a,name:r}=t,{description:l,items:o}=a,[i,s]=e.useState(!1),m=Array.isArray(t.value)?t.value:yr,c=m.includes(ye),p=(E,P)=>{if(!Array.isArray(P)){const T=[...m];T[E]=P||"",n(T)}},u=R(()=>{n([...m,""])},[n,m]),d=E=>{n(m.filter((P,T)=>T!==E))},b=()=>{n(c?[]:[ye])},g=()=>{c&&s(!0)},y=()=>{s(!1)};return _(()=>{m.length?c&&m.length>1&&n([ye]):u()},[u,n,m,c]),!o||!("type"in o)?null:e.createElement(e.Fragment,null,(m!=null?m:[]).map((E,P,{length:T})=>e.createElement(rn,{allowEmptyStrings:!0,key:P,onChange:$=>p(P,$),name:P===0?r:"",schema:{description:P===T-1?l:"",type:o.type},value:E,controls:e.createElement(W,{size:"small",onClick:()=>d(P)},e.createElement(Oa,null))})),!!(m!=null&&m.length)&&e.createElement(f,{alignItems:"center",display:"flex",flexDirection:"row",justifyContent:"space-between"},e.createElement(f,null,e.createElement(Pt,{control:e.createElement(Ye,{checked:c,onChange:b,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(W,{disabled:c,size:"small",onClick:u},e.createElement(lt,null)))))))}function hr(t){const{onChange:n,schema:a,name:r,value:l}=t,{description:o}=a;return e.createElement(f,{mb:1},e.createElement(Pt,{control:e.createElement(Ye,{checked:l===!0,onChange:i=>{n(i.target.checked)},name:r,color:"primary"}),label:r}),o&&e.createElement(C,{display:"block",variant:"caption",color:"textSecondary"},o))}function vr({allowEmptyStrings:t,controls:n,name:a,onChange:r,schema:l,value:o}){const i=s=>{r(Cr({value:s.currentTarget.value,type:l.type}))};return e.createElement(f,{mb:1},e.createElement(f,{display:"flex",gridGap:6},e.createElement(Ee,{fullWidth:!0,id:a,label:a,placeholder:"Enter",variant:"outlined",size:"small",value:br(o,t),onChange:gt(o,t)?void 0:i,disabled:gt(o,t)}),n&&e.createElement(f,{alignSelf:"center"},n)),l.description&&e.createElement(C,{variant:"caption",color:"textSecondary"},l.description,gt(o)&&!t&&e.createElement(e.Fragment,null," (switch to JSON editor to edit)")))}function gt(t,n=!1){return!n&&t===""||t===null||t===ye}function br(t,n=!1){return!n&&t===""?"[empty string]":t===null?"[null]":t===ye?"[BackstageUserClaims]":t||""}function Cr({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 ln(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 xr(t){return"type"in t&&t.type==="array"}function Pr(t){return"type"in t&&t.type==="boolean"}function rn({schema:t,...n}){return ln(t)?xr(t)?e.createElement(gr,{...n,schema:t}):Pr(t)?e.createElement(hr,{...n,schema:t}):e.createElement(vr,{...n,schema:t}):null}const Dr=new Rt({allErrors:!0});function Nr({onChange:t,schema:n,value:a}){var r;const l=L(()=>Dr.compile(n),[n]),o=L(()=>l(a),[l,a]),i=Object.entries(n.properties),s=m=>c=>{t({...a,[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:a==null?void 0:a[m]})}),e.createElement(Dt,{error:!o},(r=l.errors)==null?void 0:r[0].message))}const wr=t=>!!t&&"properties"in t;function Ar({onChange:t,rule:n,value:a}){const[r,l]=k(!1),{paramsSchema:o}=n!=null?n:{},i=()=>l(p=>!p);if(!wr(o))return null;const s=!Tr(o),m=s||r,c=e.createElement(w,{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(Er,{onChange:t,schema:o,value:a}):e.createElement(e.Fragment,null,e.createElement(f,{marginBottom:2},e.createElement(ke,null,"Parameters")),e.createElement(Nr,{onChange:t,schema:o,value:a}))),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(ln)}const Sr=D(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:a,onChange:r,onDelete:l}){var o;const i=Sr(),s=It(),m=(o=s==null?void 0:s.filter(d=>d.resourceType===a))!=null?o:[],c=m.find(d=>d.name===t),p=d=>{r(d,{})},u=R(d=>{r(t,d)},[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(at,{className:i.autocomplete,"data-testid":"rule-select",getOptionLabel:d=>d.name,getOptionSelected:(d,b)=>d.name===b.name,options:m,onChange:(d,b)=>p(b?b.name:null),renderInput:d=>e.createElement(e.Fragment,null,e.createElement(f,{marginBottom:2},e.createElement(ke,null,"Rule")),e.createElement(Ee,{...d,placeholder:"Select",variant:"outlined",size:"small",name:"rule"})),renderOption:d=>e.createElement(f,null,e.createElement(C,{variant:"body2"},d.name),e.createElement(C,{noWrap:!0,variant:"caption"},d.description)),value:c||null,PopperComponent:d=>e.createElement(Kn,{...d,style:{width:"auto"},placement:"bottom-start"})})),e.createElement(f,{flex:"1"},e.createElement(f,{display:"flex",flexDirection:"column"},e.createElement(Ar,{rule:c,onChange:u,value:n})))))),e.createElement(f,{ml:1},e.createElement(W,{"aria-label":"delete",onClick:l,size:"small"},e.createElement(ge,null))))}function He(){return{id:ce(),ruleName:null,parameters:{}}}const kr=D(t=>({conditionTypeFormControl:{minWidth:80,marginLeft:t.spacing(1)}}));function Rr({level:t,onSelect:n}){const a=kr(),r=t.children.length>1;return e.createElement(f,{display:"flex",alignItems:"center"},e.createElement(Qe,{className:a.conditionTypeFormControl},e.createElement(Xe,{value:t.levelType,onChange:l=>n==null?void 0:n(l.target.value)},e.createElement(V,{key:"anyOf",value:"anyOf"},"Any of"),e.createElement(V,{key:"allOf",value:"allOf"},"All of"),e.createElement(V,{key:"not",value:"not",disabled:r},"Not"))),e.createElement(f,{ml:1},e.createElement(W,{"aria-label":"delete",onClick:()=>n==null?void 0:n(null),size:"small"},e.createElement(ge,null))))}const $r=D(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:a,parentConditionType:r,isRoot:l=!1}){const o=$r(),i=R((g,y)=>{const E=[...t.children];return E.splice(g,1,y),E},[t]),s=R(g=>{a({...t,children:g})},[a,t]),m=R(g=>{g===null?a(null):g==="not"&&t.children.length>1?a({...t,levelType:g,children:t.children.slice(0,1)}):a({...t,levelType:g})},[a,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,He()]):g==="not"?s([...t.children,{id:y,levelType:g,children:[]}]):_l(g)&&s([...t.children,{id:y,levelType:g,children:[He()]}])},u=g=>{s(sn(t.children,g))},d=L(()=>t.children.map((g,y)=>(E,P)=>{s(i(y,{...g,ruleName:E,parameters:P}))}),[t.children,s,i]),b=L(()=>t.children.map((g,y)=>E=>c(E,y)),[t.children,c]);return e.createElement("div",null,!l&&e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(f,{display:"flex",alignItems:"center",position:"relative"},!l&&e.createElement(e.Fragment,null,e.createElement("div",{className:r==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch})),e.createElement(Rr,{level:t,onSelect:m})),e.createElement(f,{display:"flex"},l||r==="not"?e.createElement(f,{pl:2}):e.createElement("div",{className:o.treeVerticalSpacer}),!l&&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:b[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:d[y],onDelete:()=>u(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(an,{onSelect:p}))))))}function sn(t,n){const a=[...t];return a.splice(n,1),a}const Ir=D(t=>({paper:{backgroundColor:t.palette.background.default,padding:t.spacing(3),marginBottom:t.spacing(3),minHeight:t.spacing(48)}}));function Or({permissionCriteria:t,resourceType:n,onUpdate:a,readonly:r=!1}){const l=Ir(),o=R(p=>{a(u=>({...u,...p}))},[a]),i=R(p=>{const u=ce();o(p==="condition"?He():p==="not"?{id:u,levelType:p,children:[]}:{id:u,levelType:p,children:[He()]})},[o]),s=R((p,u)=>{a(d=>({...d,ruleName:p,parameters:u}))},[a]),m=R(()=>{a(null)},[a]);let c;return r?c=e.createElement(mr,{permissionCriteria:t}):t===null?c=e.createElement(an,{onSelect:i}):ft(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:a,isRoot:!0})),e.createElement(Qn,{variant:"outlined",className:l.paper},c)}const Br=D(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}})),Mr={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 Lr({rolePermission:t,readonly:n=!1,onClose:a,onSave:r}){const l=Br(),o=Ot(),i=It(),s=Ja(),m=Yl(t),[c,p]=k(m.match),[u,d]=k(m.decisionType),[b,g]=k(m.criteria),y=L(()=>er(o,c),[o,c]),E=u==="conditional",P=E?"xl":"sm";_(()=>{E&&o&&!y.commonResourceType&&d("allow")},[E,o,y.commonResourceType,d]);const T=A=>{A!==null&&d(A)},$=L(()=>c.method==="specificPermission"&&!c.name||c.method==="filter"&&!c.resourceType&&!c.actions,[c]),j=L(()=>y.permissions.length===0?!1:!$,[y,$]),B=L(()=>u!=="conditional"?!0:!(!y.commonResourceType||!(s!=null&&s[y.commonResourceType].pluginId)||!qt(b,i)),[u,y,s,b,i]),v=()=>{r==null||r(Kl(m.id,c,u==="conditional"?{resourceType:y.commonResourceType,pluginId:s[y.commonResourceType].pluginId,conditions:Et(b)}:u))};return e.createElement(oe,{open:!0,maxWidth:P,onClose:a,fullWidth:!0},e.createElement(Se,{disableTypography:!0,className:l.dialogTitle},e.createElement(C,{variant:"h4",component:"h2"},"New Permission Decision"),e.createElement(w,{startIcon:e.createElement(nt,null),onClick:a},"Close")),e.createElement(K,{dividers:!0,className:l.content},e.createElement(f,{className:E?l.contentContainerConditional:void 0},e.createElement(f,{mb:5,flex:1},e.createElement(Ul,{options:Object.entries(Mr).map(([A,h])=>({id:A,displayText:h})),selected:c.method,onChange:A=>p({method:A}),readonly:n})),e.createElement(f,{mb:5,height:189,flex:1},c.method==="specificPermission"&&e.createElement(nr,{name:c.name,readonly:n,onNameChange:A=>p({...c,name:A})}),c.method==="filter"&&e.createElement(e.Fragment,null,e.createElement(lr,{resourceType:c.resourceType,readonly:n,onResourceTypeChange:A=>p({...c,resourceType:A})}),e.createElement(or,{actions:c.actions,readonly:n,onActionsChange:A=>p({...c,actions:A.length?A:void 0})}),$?null:e.createElement(e.Fragment,null,e.createElement(f,{marginY:2},e.createElement(Ze,{variant:"middle"})),e.createElement(Dt,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(Zl,{value:u,exclusive:!0,fullWidth:!0,"aria-label":"Decision result",onChange:(A,h)=>T(h)},e.createElement(yt,{value:"allow","aria-label":"Decision allowed",disabled:n},"Allow"),e.createElement(yt,{value:"deny","aria-label":"Decision denied",disabled:n},"Deny"),e.createElement(yt,{value:"conditional","aria-label":"Decision conditionally allowed",disabled:!y.commonResourceType||n},"Conditional")),!E&&!n&&e.createElement(fe,{title:mn},e.createElement(kt,{className:l.infoIcon,color:"primary","aria-label":mn}))))),u==="conditional"&&!!y.commonResourceType&&e.createElement(Or,{permissionCriteria:b,resourceType:y.commonResourceType,onUpdate:g,readonly:n}),!n&&e.createElement(f,{display:"flex",justifyContent:"flex-end"},e.createElement(w,{variant:"contained",color:"primary",className:l.saveButton,onClick:v,disabled:!j||!B},"Save"))))}const Fr=D(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 dn({invalid:t,name:n,value:a,onTextChange:r}){const l=Fr({invalid:t}),[o,i]=k(!1),[s,m]=k(null),c=ne(null),[p,u]=k(a);_(()=>{u(a)},[a]),Sn(()=>{c.current&&s&&c.current.style.setProperty("width",`max(${s.getBoundingClientRect().width}px, 3ch)`)},[s,p]);const d=()=>{i(!1),u(a)},b=()=>{i(!1),r==null||r(p)},g=()=>{var E;o?b():(i(!0),(E=c.current)==null||E.focus())},y=E=>{var P;E.key==="Enter"&&((P=c.current)==null||P.blur()),E.key==="Escape"&&d()};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:E=>u(E.target.value),onFocus:g,onBlur:b,onKeyDown:y,value:p}),e.createElement("span",{"aria-hidden":"true",className:l.hiddenSpan,ref:m},p),e.createElement(W,{onClick:g,size:"small"},o?e.createElement(Ma,{"aria-label":"Save title"}):e.createElement(Ba,{"aria-label":"Edit title"}))))}const un=t=>{if(t.success)return{};const n={};for(const a of t.error.issues)n[a.path.join(".")]=!0;return n},pn=({children:t,onConfirm:n,message:a,title:r})=>{const[l,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:l,onClose:i},e.createElement(Se,null,e.createElement(f,{display:"flex",justifyContent:"space-between",alignItems:"center"},r)),e.createElement(K,null,e.createElement(Xn,null,a)),e.createElement(_e,null,e.createElement(w,{"aria-label":"Cancel action",color:"primary",onClick:i},"Cancel"),e.createElement(w,{"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(C,{variant:"body2",noWrap:!0},"Reorder")),e.createElement(fe,{title:t},e.createElement(kt,{color:"primary","aria-label":t}))),En=(t,n,a)=>{const r=n+a;if(r<0||r>=t.length)return t;const l=[...t];return[l[r],l[n]]=[l[n],l[r]],l},yn=({array:t,index:n,onReorder:a})=>{const r=n===0,l=n===t.length-1;return e.createElement(f,{display:"flex"},e.createElement(W,{disabled:r,onClick:()=>a(En(t,n,-1)),"aria-label":"Move up",size:"small"},e.createElement(Fa,null)),e.createElement(W,{disabled:l,onClick:()=>a(En(t,n,1)),"aria-label":"Move down",size:"small"},e.createElement(La,null)))},jr=D(()=>({emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function gn({src:t,alt:n}){const a=jr();return e.createElement("img",{src:t,className:`${a.emptyStateImage} `,alt:n})}const Hr="Use the arrows to change the order in which permission decisions are evaluated.";function Wr({diff:t,permissions:n,onReorderPermissions:a,onNewPermissionClick:r,onOpenPermission:l,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(C,{variant:"h5"},"Permission Decisions"),!s&&n.length!==0&&e.createElement(w,{color:"primary",variant:"outlined",startIcon:e.createElement(lt,null),onClick:r},"New")),e.createElement(Je,null,e.createElement(qe,null,e.createElement(U,null,!s&&!i&&e.createElement(N,{style:{width:0}},e.createElement(fn,{helpText:Hr})),e.createElement(N,null,"Match by"),e.createElement(N,null,"Decision"),e.createElement(N,null),!s&&e.createElement(N,null))),e.createElement(Ke,null,n.length===0&&e.createElement(U,null,e.createElement(N,{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:ja,alt:"No permission placeholder"})},action:e.createElement(w,{variant:"contained",color:"primary",onClick:r},"New permission decision")}))),n.map((m,c)=>e.createElement(U,{key:c},!s&&!i&&e.createElement(N,null,e.createElement(yn,{array:n,index:c,onReorder:a})),e.createElement(N,null,e.createElement(Zn,{onClick:()=>l(c)},e.createElement(C,{variant:"body2",color:"primary"},st(m)))),e.createElement(N,null,sl(m)),e.createElement(N,null,e.createElement(Ce,{operation:t==null?void 0:t.permissions[m.id].operation})),!s&&e.createElement(N,{align:"right"},e.createElement(pn,{message:"Are you sure you want to remove this permission decision?",onConfirm:()=>o(c),title:"Remove?"},p=>e.createElement(W,{...p,"aria-label":"Remove permission decision",size:"small"},e.createElement(ge,null)))))))))}function zr(){const{roleId:t,versionId:n}=Ge();return Re(t),Re(n),e.createElement(Le,{policyId:n},e.createElement(Gr,{roleId:t}))}function Gr({roleId:t}){const{diff:n,updateLocalDraft:a,policy:r}=X(),l=r.roles.find(h=>h.id===t),o=n==null?void 0:n.roles[t],[i,s]=k(null),[m,c]=k(!1),p=Ue(),{NotFoundErrorPage:u}=p.getComponents(),d=z(),b=D(h=>({cardContainer:{margin:h.spacing(0)}}))();if(!l)return e.createElement(u,null);const g=l.name,y=h=>{const S=r.roles.findIndex(Z=>Z.id===h.id),O=[...r.roles];O.splice(S,1,h),a({...r,roles:O})},E=h=>{y({...l,name:h})},P=h=>{if(i===null)y({...l,permissions:[h,...l.permissions]});else{const S=[...l.permissions];S.splice(i,1,h),y({...l,permissions:S})}c(!1)},T=h=>{if(h==="*")y({...l,members:l.members==="*"?[]:"*"});else if(l.members==="*")y({...l,members:[h]});else{const S=l.members.includes(h)?l.members.filter(O=>O!==h):[...l.members,h];y({...l,members:S.length===0?"*":S})}},$=h=>{y({...l,permissions:l.permissions.filter((S,O)=>h!==O)})},j=h=>{y({...l,permissions:h})},B=un(ua.safeParse(l)).name,v=r.status!=="draft",A=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(Ae,{titleComponent:e.createElement(Vt,null,r.name," \xA0\u01C0",v?e.createElement(e.Fragment,null,"\xA0",g):e.createElement(dn,{invalid:B,value:g,onTextChange:E}),e.createElement(Ce,{operation:o==null?void 0:o.role.operation,size:"large"})),description:r.description},e.createElement(w,{variant:"outlined",color:"primary",onClick:()=>d("../..",{relative:"path"})},"Back to policy"))},e.createElement(F,{container:!0,className:b.cardContainer,spacing:4,direction:"row"},e.createElement(F,{item:!0,xs:6},e.createElement(Y,null,e.createElement(Wl,{diff:o||null,role:l,policyId:r.id,onToggleMember:T,readonly:v}))),e.createElement(F,{item:!0,xs:6},e.createElement(Y,null,e.createElement(Wr,{diff:o||null,permissions:l.permissions,onNewPermissionClick:()=>{s(null),c(!0)},onOpenPermission:h=>{s(h),c(!0)},onReorderPermissions:j,onRemovePermissionClick:$,anyAllow:A,readonly:v}))))),m&&e.createElement(Lr,{rolePermission:i!==null?l.permissions[i]:void 0,onClose:()=>c(!1),onSave:P,readonly:v}))}const Ur="Use the arrows to change the order in which roles are evaluated.";function Vr({}){const{diff:t,policy:n,createNewRole:a,updateLocalDraft:r}=X(),l=z(),o=_r(n),i=n.status!=="draft",s=n.options.resolutionStrategy==="any-allow",m=u=>{r({...n,roles:u})},c=u=>{r({...n,roles:n.roles.filter(({id:d})=>d!==u)})},p=()=>{l(`./roles/${a()}`)};return e.createElement(Y,null,e.createElement(f,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(C,{variant:"h3"},"Roles"),!i&&e.createElement(w,{color:"primary",variant:"outlined",startIcon:e.createElement(lt,null),onClick:()=>p()},"New role")),e.createElement(Je,null,e.createElement(qe,null,e.createElement(U,null,!i&&!s&&e.createElement(N,{style:{width:0}},e.createElement(fn,{helpText:Ur})),e.createElement(N,null,"Name"),e.createElement(N,null,"Users"),e.createElement(N,null,"Groups"),!i&&e.createElement(N,{style:{width:0}}))),e.createElement(Ke,null,o.map((u,d)=>e.createElement(U,{key:d},!i&&!s&&e.createElement(N,null,e.createElement(yn,{array:n.roles,index:d,onReorder:m})),e.createElement(N,null,e.createElement(f,{alignItems:"center",display:"flex",gridGap:8},e.createElement(ue,{to:`roles/${u.id}`},u.name),e.createElement(Ce,{operation:t==null?void 0:t.roles[u.id].role.operation}))),e.createElement(N,null,u.userCount),e.createElement(N,null,u.groupCount),!i&&e.createElement(N,{align:"right"},e.createElement(pn,{message:"Are you sure you want to remove this role?",title:"Remove role?",onConfirm:()=>c(u.id)},b=>e.createElement(W,{...b,"aria-label":"Remove role",size:"small"},e.createElement(ge,null)))))))))}function _r(t){return t.roles.map(n=>({id:n.id,name:n.name,userCount:Array.isArray(n.members)?n.members.filter(a=>a.startsWith("user:")).length:n.members,groupCount:Array.isArray(n.members)?n.members.filter(a=>a.startsWith("group:")).length:n.members}))}const Yr=D(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 Jr({readonly:t}){const n=Yr(),a=z(),{createNewRole:r}=X(),l=()=>{const o=r();a(`./roles/${o}`)};return e.createElement(Y,null,e.createElement(Nt,{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:Ha,alt:"No roles placeholder"})},action:e.createElement(w,{variant:"contained",color:"primary",onClick:()=>l()},"New role")})))}const qr=D(t=>({new:{borderRadius:100,backgroundColor:t.palette.success.main,color:t.palette.common.white,padding:t.spacing(.5,1)}}));function Kr(){const[t,n]=k(null),{hasDraftPolicy:a}=Me(),{isValid:r,discardLocalDraft:l,exportPolicy:o,hasChanges:i,policy:s,saveLocalDraftToServer:m,saveAndPublish:c,publish:p}=X(),u=z(),d=qr(),[b,g]=pt(),y=P=>{n(P.currentTarget)},E=()=>{n(null)};return e.createElement(e.Fragment,null,e.createElement(ea,{variant:"contained",color:"primary"},s.status==="draft"&&e.createElement(w,{disabled:!r,onClick:()=>m()},"Save"),s.status==="inactive"&&e.createElement(w,{onClick:()=>p()},"Republish"),s.status==="active"&&e.createElement(w,{disabled:a||b.loading,onClick:()=>g(s)},"Duplicate"),e.createElement(w,{color:"primary",title:"options",size:"small",onClick:y},e.createElement(Wa,null))),e.createElement(xt,{getContentAnchorEl:null,anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!t,onClose:E,PaperProps:{style:{width:240}}},s.status==="draft"&&e.createElement(et,null,e.createElement(V,{disabled:!r,onClick:()=>c()},e.createElement(le,null,e.createElement(Ga,{fontSize:"small"})),e.createElement(re,null,"Save & Publish")),e.createElement(V,{disabled:!i,onClick:()=>l()},e.createElement(le,null,e.createElement(za,{color:i?"secondary":"inherit",fontSize:"small"})),e.createElement(re,null,e.createElement(C,{color:i?"secondary":"inherit"},"Discard changes"))),e.createElement(Ze,null)),e.createElement(et,null,e.createElement(V,{onClick:()=>o()},e.createElement(le,null,e.createElement(Va,{fontSize:"small"})),e.createElement(re,null,"Export"))),e.createElement(Ze,null),e.createElement(et,null,e.createElement(V,{disabled:!r,onClick:()=>u("./options")},e.createElement(le,null,e.createElement(Ua,{fontSize:"small"})),e.createElement(re,null,"Options"),e.createElement(ta,null,e.createElement(C,{className:d.new,variant:"caption"},"New"))))))}function Qr(){const{versionId:t}=Ge();return Re(t),e.createElement(Le,{policyId:t},e.createElement(Xr,null))}function Xr(){const{policy:t,updateLocalDraft:n}=X(),a=o=>{n({...t,name:o})},r=un(pa.safeParse(t)).name,l=t.status!=="draft";return e.createElement(Be,{pages:[{title:t.name}],header:e.createElement(Ae,{title:t.name,titleComponent:e.createElement(e.Fragment,null,e.createElement(Vt,null,l?t.name:e.createElement(dn,{invalid:r,name:"Policy name",value:t.name,onTextChange:a}),e.createElement(jt,{status:t.status})),Zr(t))},e.createElement(Kr,null))},e.createElement(F,{item:!0,xs:12},t.roles.length>0?e.createElement(Vr,null):e.createElement(Jr,{readonly:l})))}function Zr(t){const n={created:"Created by ",published:"Last published by ",updated:"Last updated by "},{activityDateText:a,activityUser:r,timestamp:l}=zt(t,n);return e.createElement(C,{variant:"body2"},e.createElement(C,{component:"span",display:"inline",variant:"body2"},`${a} ${r} `),e.createElement(Wt,{timestamp:l}))}const eo=D(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=eo(t),{title:a,description:r,active:l,changeResolutionStrategy:o,defaultOption:i,readonly:s}=t,m=()=>{s||o()};return e.createElement(Y,{className:`${n.card}`,onClick:m},e.createElement(na,{disabled:s},e.createElement(pe,null,e.createElement(Nt,{className:n.cardHeader,avatar:e.createElement(aa,{checked:l,color:"primary",disabled:s}),title:e.createElement("div",{className:n.title},e.createElement(C,{variant:"h6",component:"h2"},a),i?e.createElement(Te,{label:"Default",size:"small",className:n.defaultChip}):null),subheader:r}))))}const to=D(t=>({title:{display:"flex",alignItems:"center",paddingBottom:t.spacing(2)},maxWidthWrapper:{maxWidth:"800px"},readOnlyChip:{marginLeft:t.spacing(1)},paragraph:{paddingBottom:t.spacing(1)}}));function no(){const{versionId:t}=Ge();return Re(t),e.createElement(Le,{policyId:t},e.createElement(ao,null))}function ao(){const t=to(),{policy:n,updateLocalDraft:a}=X(),r=z(),l=n.status!=="draft",o=i=>{a({...n,options:{...n.options,resolutionStrategy:i}})};return e.createElement(Be,{pages:[{title:n.name,path:".."},{title:"Options"}],header:e.createElement(Ae,{title:"Options"},e.createElement(w,{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(C,{variant:"h5",component:"h1"},"Decision resolution strategy"),l?e.createElement(Te,{label:"Read only",className:t.readOnlyChip}):null),e.createElement(C,{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(C,{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:l,defaultOption:!0,description:e.createElement(e.Fragment,null,e.createElement(C,{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(C,{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:l,description:e.createElement(e.Fragment,null,e.createElement(C,{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(C,{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=Ue(),{NotFoundErrorPage:n}=t.getComponents();return e.createElement(_a,{loading:e.createElement(we,null),unauthorized:e.createElement(n,null)},e.createElement(Za,null,e.createElement(Ya,null,e.createElement(Rn,null,e.createElement(De,{element:e.createElement(kl,null),path:"/"}),e.createElement(De,{element:e.createElement(Qr,null),path:"/versions/:versionId"}),e.createElement(De,{element:e.createElement(no,null),path:"/versions/:versionId/options"}),e.createElement(De,{element:e.createElement(zr,null),path:"/versions/:versionId/roles/:roleId"})))))}export{lo as RBACRoot};
|
|
3
|
+
//# sourceMappingURL=Root-6e97b92d.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),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(
|
|
2
|
-
//# sourceMappingURL=index-
|
|
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(e)});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-6e97b92d.esm.js").then(s=>s.RBACRoot),mountPoint:l})),k=p.provide(U({name:"RBACSidebarItem",component:{lazy:()=>import("./RBACSidebarItem-e6e67e1e.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-8cbef8b1.esm.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{R as i,c as m,b as R}from"./esm/index-
|
|
1
|
+
import{R as i,c as m,b as R}from"./esm/index-8cbef8b1.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.
|
|
4
|
+
"version": "0.5.4",
|
|
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.
|
|
27
|
-
"@backstage/core-components": "^0.13.
|
|
28
|
-
"@backstage/core-plugin-api": "^1.5.
|
|
29
|
-
"@backstage/errors": "^1.
|
|
30
|
-
"@backstage/plugin-catalog-react": "^1.
|
|
31
|
-
"@backstage/plugin-permission-common": "^0.7.
|
|
32
|
-
"@backstage/plugin-permission-node": "^0.7.
|
|
33
|
-
"@backstage/plugin-permission-react": "^0.4.
|
|
34
|
-
"@backstage/theme": "^0.
|
|
35
|
-
"@backstage/types": "^1.0
|
|
26
|
+
"@backstage/catalog-model": "^1.4.0",
|
|
27
|
+
"@backstage/core-components": "^0.13.2",
|
|
28
|
+
"@backstage/core-plugin-api": "^1.5.2",
|
|
29
|
+
"@backstage/errors": "^1.2.0",
|
|
30
|
+
"@backstage/plugin-catalog-react": "^1.7.0",
|
|
31
|
+
"@backstage/plugin-permission-common": "^0.7.6",
|
|
32
|
+
"@backstage/plugin-permission-node": "^0.7.9",
|
|
33
|
+
"@backstage/plugin-permission-react": "^0.4.13",
|
|
34
|
+
"@backstage/theme": "^0.4.0",
|
|
35
|
+
"@backstage/types": "^1.1.0",
|
|
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.
|
|
40
|
-
"@spotify/backstage-plugin-rbac-common": "^0.5.
|
|
39
|
+
"@spotify/backstage-plugin-core": "^0.5.3",
|
|
40
|
+
"@spotify/backstage-plugin-rbac-common": "^0.5.3",
|
|
41
41
|
"ajv": "^8.11.2",
|
|
42
42
|
"file-saver": "^2.0.5",
|
|
43
43
|
"js-yaml": "^4.1.0",
|
|
@@ -46,20 +46,20 @@
|
|
|
46
46
|
"luxon": "^3.1.1",
|
|
47
47
|
"react-use": "^17.2.4",
|
|
48
48
|
"uuid": "^9.0.0",
|
|
49
|
-
"vanilla-jsoneditor": "^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.
|
|
54
|
+
"@backstage/plugin-permission-node": "^0.7.9",
|
|
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.
|
|
60
|
-
"@backstage/core-app-api": "^1.
|
|
61
|
-
"@backstage/dev-utils": "^1.0.
|
|
62
|
-
"@backstage/test-utils": "^1.
|
|
59
|
+
"@backstage/cli": "^0.22.8",
|
|
60
|
+
"@backstage/core-app-api": "^1.8.1",
|
|
61
|
+
"@backstage/dev-utils": "^1.0.16",
|
|
62
|
+
"@backstage/test-utils": "^1.4.0",
|
|
63
63
|
"@internal/e2e-test-utils": "^0.0.0",
|
|
64
64
|
"@playwright/test": "^1.32.3",
|
|
65
65
|
"@testing-library/jest-dom": "^5.10.1",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@testing-library/user-event": "^14.0.0",
|
|
69
69
|
"@types/file-saver": "^2.0.5",
|
|
70
70
|
"@types/jest": "^29.4.0",
|
|
71
|
-
"@types/node": "^
|
|
71
|
+
"@types/node": "^18.0.0",
|
|
72
72
|
"cross-fetch": "^3.1.5",
|
|
73
73
|
"msw": "^1.0.0"
|
|
74
74
|
},
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import e,{createContext as $e,useState as S,useCallback as I,useMemo as F,useContext as Ie,useEffect as _,Fragment as be,useRef as Z,useReducer as Nn,useLayoutEffect as wn}from"react";import{useNavigate as J,Link as Tn,useParams as ut,Routes as An,Route as Oe}from"react-router-dom";import{useApi as O,configApiRef as kn,alertApiRef as ee,useRouteRef as Sn,useApp as Be}from"@backstage/core-plugin-api";import ce from"react-use/lib/useAsync";import{isResourcePermission as Me}from"@backstage/plugin-permission-common";import{r as z,a as Rn}from"./index-11b12986.esm.js";import{forEach as $n,mapValues as In,groupBy as On,uniq as Bn}from"lodash";import{Breadcrumbs as Mn,Link as se,Page as Fn,Header as Ln,Content as jn,EmptyState as Ce,Progress as xe,ErrorPanel as dt,Table as Hn,ContentHeader as Fe}from"@backstage/core-components";import pt from"react-use/lib/useMount";import{makeStyles as w,Typography as D,Container as Wn,Grid as W,Button as k,Card as K,CardContent as Pe,Box as d,Chip as ft,Tooltip as me,List as zn,ListItem as Et,ListItemIcon as te,ListItemText as ne,CardActions as Vn,Dialog as le,DialogContent as q,DialogTitle as De,TextField as ue,DialogActions as Le,CircularProgress as yt,IconButton as L,Checkbox as je,TableRow as V,TableCell as P,debounce as Gn,Table as He,TableHead as We,TableBody as ze,Tabs as Un,Tab as _n,FormControl as Ve,InputLabel as Ne,Select as Ge,MenuItem as G,Menu as gt,FormControlLabel as ht,FormHelperText as vt,Popper as Yn,Paper as Jn,Divider as bt,DialogContentText as Kn,ButtonBase as qn,CardHeader as Qn,MenuList as Ct}from"@material-ui/core";import{SpotifyLicenseBanner as Xn,useAutoUpdatingRelativeTime as Zn,invariant as Ue}from"@spotify/backstage-plugin-core";import re from"react-use/lib/useAsyncFn";import el,{dump as tl}from"js-yaml";import{PolicyConfigParser as we,isConditionalDecision as _e,isAllOfPermissionCriteria as nl,isAnyOfPermissionCriteria as ll,isNotPermissionCriteria as rl,isMatchingPermission as al,BackstageUserPlaceholder as de,RoleParser as ol,UpdateDraftRequestParser as il}from"@spotify/backstage-plugin-rbac-common";import{v4 as ae}from"uuid";import xt from"lodash/keyBy";import cl from"lodash/isEqual";import Pt from"@material-ui/icons/ReportProblemOutlined";import sl from"@material-ui/icons/CalendarToday";import Dt from"@material-ui/icons/Person";import ml from"@material-ui/icons/FiberManualRecord";import{DateTime as Te}from"luxon";import ul from"react-use/lib/useLocalStorage";import{saveAs as dl}from"file-saver";import Nt from"lodash/omit";import pl from"lodash/pickBy";import Ye from"@material-ui/icons/Close";import fl from"@material-ui/icons/Publish";import El from"@material-ui/icons/FilterNone";import{parseEntityRef as Q,DEFAULT_NAMESPACE as yl}from"@backstage/catalog-model";import{humanizeEntityRef as gl,catalogApiRef as hl}from"@backstage/plugin-catalog-react";import{Autocomplete as Je,ToggleButton as vl,ToggleButtonGroup as bl}from"@material-ui/lab";import pe from"@material-ui/icons/Delete";import Cl from"@material-ui/icons/Group";import xl from"@material-ui/icons/GroupWork";import wt from"@material-ui/icons/Info";import Tt from"ajv";import Pl from"lodash/uniqBy";import{JSONEditor as Dl,isTextContent as Nl,createAjvValidator as wl,Mode as Tl}from"vanilla-jsoneditor";import Ke from"@material-ui/icons/Add";import Al from"@material-ui/icons/Remove";import kl from"@material-ui/icons/Edit";import Sl from"@material-ui/icons/Check";import Rl from"@material-ui/icons/KeyboardArrowDown";import $l from"@material-ui/icons/KeyboardArrowUp";import Il from"../images/no-permissions.svg";import Ol from"../images/no-roles.svg";import Bl from"@material-ui/icons/MoreHoriz";import Ml from"@material-ui/icons/Undo";import Fl from"@material-ui/icons/CloudUpload";import Ll from"@material-ui/icons/Save";import jl from"@material-ui/icons/VerticalAlignTop";import{A as Hl}from"./Authorized-2927d77b.esm.js";import"@backstage/errors";const At=$e(null),Wl=({children:t})=>{const n=O(kn),l=O(z),a=O(ee),[r,o]=S(null),i=I(async()=>{var m;if(!r){const u=await l.fetchAllPermissionMetadata((m=n.getOptionalStringArray("permission.permissionedPlugins"))!=null?m:[]),c=Vl(u.rules);$n(c,p=>{p.length!==1&&a.post({message:`The plugin(s) ${p.slice(1).join(", ")} expose rules which are conflicting with rules exposed by the ${p[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=Gl(u,c);return o(s),s}return r},[a,r,l,n]);return e.createElement(At.Provider,{value:F(()=>({getMetadata:i}),[i])},t)};function Ae(){const t=Ie(At),{value:n}=ce(async()=>t==null?void 0:t.getMetadata(),[t]);return n}function kt(){var t;const n=Ae();return(t=n==null?void 0:n.rules)!=null?t:null}function St(){var t;const n=Ae();return(t=n==null?void 0:n.permissions)!=null?t:null}function Rt(){const t=Ae();return t?[...new Set(t.permissions.filter(n=>Me(n)).map(({resourceType:n})=>n))]:null}function zl(){const t=Ae(),n=Rt();return!t||!n?null:n.reduce((l,a)=>{const r=t.rules.find(o=>o.resourceType===a);return r&&(l[a]={pluginId:r.pluginId}),l},{})}function Vl(t){return In(On(t,"resourceType"),n=>Bn(n.map(({pluginId:l})=>l)))}function Gl(t,n){return{...t,rules:t.rules.filter(({resourceType:l,pluginId:a})=>{const r=n[l];return a===r[0]})}}const Ul=w(t=>({breadcrumbs:{marginBottom:t.spacing(4)}}));function _l({pages:t}){const n=Sn(Rn),l=Ul();return e.createElement(Mn,{className:l.breadcrumbs},e.createElement(se,{to:n()},"Home"),t.map(({title:a,path:r},o)=>r?e.createElement(se,{to:r,key:r,relative:"path"},a):e.createElement(D,{key:`${o}`},a)))}function qe({children:t,header:n,pages:l}){return e.createElement(Fn,{themeId:"tool"},e.createElement(Xn,{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(Ln,{title:"Role Based Access Control"}),e.createElement(jn,null,e.createElement(Wn,{maxWidth:"lg"},e.createElement(W,{container:!0,spacing:4},e.createElement(W,{item:!0,xs:12},l&&e.createElement(_l,{pages:l}),n),t))))}const $t=$e({policies:void 0,setPolicies:()=>{},setPolicy:()=>{},getPolicy:()=>{},removePolicy:()=>{}}),Qe=()=>Ie($t);function Yl({children:t,initialState:n={policies:void 0,cache:{}}}){const[l,a]=S(n),r=I(u=>{a(c=>({...c,policies:u,cache:It(c.cache,u)}))},[]),o=I(u=>l.cache[u],[l.cache]),i=I(u=>a(c=>({...c,cache:{...c.cache,[u]:void 0},policies:void 0})),[]),m=I(u=>a(c=>({...c,policies:void 0,cache:It(c.cache,[u])})),[]);return e.createElement($t.Provider,{value:F(()=>({policies:l.policies,setPolicies:r,setPolicy:m,getPolicy:o,removePolicy:i}),[l.policies,r,m,o,i])},t)}function It(t,n){if(!n)return t;const l={...t};return n.forEach(a=>{l[a.id]=a}),l}const fe=()=>{const t=O(z),{setPolicies:n,policies:l}=Qe(),[{loading:a,error:r},o]=re(()=>t.getPolicies(),[t],l?{loading:!1,value:{items:l,totalItems:l.length}}:{loading:!0}),i=I(async()=>{const m=await o();n(m.items)},[o,n]);return{loading:a,error:r,fetchPolicies:i}};function Jl(){const t=O(z),n=J(),l=O(ee);function a(r){var o,i;const m=(i=(o=r.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,p;const f=(p=(s=c.target)==null?void 0:s.result)==null?void 0:p.toString();if(f){let v=null;try{v=el.load(f)}catch{l.post({message:"YAML file is invalid",severity:"error"});return}if(!we.safeParse(v).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=v,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(k,{variant:"outlined",color:"primary",component:"label"},"Import",e.createElement("input",{role:"input",type:"file",hidden:!0,onChange:a,accept:".yaml"}))}const Kl=w(t=>({cardContent:{padding:t.spacing(6,3),"& > *":{background:"transparent"}}}));function ql(){const t=Kl(),n=O(z),l=J(),[a,r]=re(async()=>n.createDraft({roles:[]}),[n]);return _(()=>{a.value&&l(`./versions/${a.value.id}`)},[l,a.value]),e.createElement(K,null,e.createElement(Pe,{className:t.cardContent},e.createElement(Ce,{missing:"content",title:"No policy configured",description:e.createElement(e.Fragment,null,e.createElement(d,{component:"span",display:"block",pb:2},"Until you've configured your policy, authorization will be denied for all permissions."),e.createElement(d,{component:"span",display:"block"},"Click the button below to create the first version of your policy.")),action:e.createElement(k,{variant:"contained",color:"primary",disabled:a.loading,onClick:r},"New version")})))}function Ql(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 Xl=(t,n)=>{const l={resolutionStrategy:{operation:"UNCHANGED",before:t==null?void 0:t.resolutionStrategy,after:n==null?void 0:n.resolutionStrategy}};for(const a of Object.keys(l)){const r=a;l[r].before!==l[r].after&&(l[r].operation="CHANGED")}return l},Xe=(t,n)=>{const l=Object.entries(t);for(const[,a]of l){const r=n(a);for(const[,o]of l){const i=n(o);i.operation!=="ADDED"&&i.operation!=="REMOVED"&&(r.operation==="ADDED"&&r.indexAfter<i.indexAfter?i.indexBefore+=1:r.operation==="REMOVED"&&r.indexBefore<i.indexBefore&&(i.indexBefore-=1))}}for(const[,a]of l){const r=n(a);r.operation==="UNCHANGED"&&r.indexAfter!==r.indexBefore&&(r.operation=r.indexAfter>r.indexBefore?"MOVED_DOWN":"MOVED_UP")}return t},Ze=(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,r)=>[a,{operation:"ADDED",after:a,before:null,indexAfter:r,indexBefore:-1}]))};if(n==="*")return{"*":{operation:"ADDED",after:"*",before:null,indexAfter:0,indexBefore:-1},...Object.fromEntries(t.map((a,r)=>[a,{operation:"REMOVED",after:null,before:a,indexAfter:-1,indexBefore:r}]))};const l=Object.fromEntries(n.map((a,r)=>[a,{operation:"ADDED",after:a,before:null,indexAfter:r,indexBefore:-1}]));for(let a=0;a<t.length;a++){const r=t[a];l[r]?(l[r].before=r,l[r].indexBefore=a,l[r].operation="UNCHANGED"):l[r]={operation:"REMOVED",after:null,before:r,indexAfter:-1,indexBefore:a}}return Xe(l,a=>a)},et=(t,n)=>{const l=xt(n,"id"),a=Object.fromEntries(n.map((r,o)=>[r.id,{operation:"ADDED",indexAfter:o,indexBefore:-1,after:r,before:null}]));for(let r=0;r<t.length;r++){const o=t[r];if(a[o.id]){const i=!cl(o,l[o.id]);a[o.id].before=o,a[o.id].indexBefore=r,a[o.id].operation=i?"CHANGED":"UNCHANGED"}else a[o.id]={operation:"REMOVED",after:null,before:o,indexAfter:-1,indexBefore:r}}return Xe(a,r=>r)},Zl=(t=[],n=[])=>{const l=xt(n,"id"),a=Object.fromEntries(n.map((r,o)=>[r.id,{role:{operation:"ADDED",indexAfter:o,indexBefore:-1,after:r,before:null},members:Ze([],r.members),permissions:et([],r.permissions)}]));for(let r=0;r<t.length;r++){const o=t[r];if(l[o.id]){const i=l[o.id],m=Ze(o.members,i.members),u=et(o.permissions,i.permissions),c=Object.values(u).some(({operation:f})=>f!=="UNCHANGED"),s=Object.values(m).some(({operation:f})=>f!=="UNCHANGED"),p=o.name!==i.name||c||s;a[o.id].role.before=o,a[o.id].role.indexBefore=r,a[o.id].role.operation=p?"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:r},members:Ze(o.members,[]),permissions:et(o.permissions,[])}}return Xe(a,({role:r})=>r)},er=(t,n)=>{const l=Zl((t==null?void 0:t.roles)||[],(n==null?void 0:n.roles)||[]),a=Xl(t==null?void 0:t.options,n==null?void 0:n.options),r=(t==null?void 0:t.name)!==(n==null?void 0:n.name),o=Object.values(a).some(({operation:i})=>i!=="UNCHANGED");return{policy:{operation:r||o?"CHANGED":"UNCHANGED",before:t,after:n},roles:l,options:a}},Ot=t=>{const n=O(z),{value:l}=ce(()=>n.getActivePolicy(),[n]);return F(()=>t?er(l,t):null,[l,t])},tr=w(t=>({chip:{margin:0},icon:{color:t.palette.success.main}}));function Bt(t){const n=tr();return t.status==="inactive"?null:t.status==="draft"?e.createElement(ft,{className:n.chip,label:"Draft",size:t.size}):e.createElement(ft,{className:n.chip,classes:{icon:n.icon},label:"Active",icon:e.createElement(ml,null),size:t.size})}const tt=(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}},nr=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 lr(t){var n;return _e(t.decision)?"Conditional":(n={allow:"Allow",deny:"Deny"}[t.decision])!=null?n:"Unknown"}function nt(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 rr=w(t=>({root:({operation:n})=>({color:tt(t,n)})})),M=t=>e.createElement(D,{...t,variant:"body2"}),C=t=>{const n=rr(t);return e.createElement(d,{...t,className:n.root,component:"span",fontWeight:"fontWeightBold"})},Mt=({policy:t})=>{var n,l,a;const r=Ot(t),o=(r==null?void 0:r.policy.operation)==="CHANGED"||Object.values((n=r==null?void 0:r.roles)!=null?n:{}).some(c=>c.role.operation!=="UNCHANGED");if(!r||!o)return e.createElement(d,null,"No changes");const i=!!r.policy.before&&!!r.policy.after&&r.policy.before.name!==r.policy.after.name,m=({before:c,after:s})=>c&&s&&c.name!==s.name,u=({operation:c})=>c!=="ADDED"&&c!=="REMOVED";return e.createElement(d,null,i&&e.createElement(M,null,"Policy name ",e.createElement(C,{operation:"CHANGED"},"changed")," from"," ",e.createElement(C,null,'"',(l=r.policy.before)==null?void 0:l.name,'"')," to"," ",e.createElement(C,null,'"',(a=r.policy.after)==null?void 0:a.name,'"')),Object.entries(r.roles).map(([c,{role:s,permissions:p,members:f}])=>{var v,g,y,E,x,A;return e.createElement(be,{key:c},s.operation==="ADDED"&&e.createElement(M,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(M,null,"Role ",e.createElement(C,null,'"',(g=s.before)==null?void 0:g.name,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")),m(s)&&e.createElement(M,null,"Role name changed from ",e.createElement(C,null,'"',(y=s.before)==null?void 0:y.name,'"')," ","to ",e.createElement(C,null,'"',(E=s.after)==null?void 0:E.name,'"')),s.indexAfter>s.indexBefore&&s.indexBefore!==-1&&e.createElement(M,null,"Role ",e.createElement(C,null,'"',(x=s.after)==null?void 0:x.name,'"')," has been"," ",e.createElement(C,{operation:"MOVED_DOWN"},"moved down")," in priority"),s.indexAfter<s.indexBefore&&s.indexAfter!==-1&&e.createElement(M,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(p).map(([R,T])=>{var B,N,h,b,$;const{before:j,after:ve}=T,U=j&&nt(j),Y=ve&&nt(ve);return e.createElement(be,{key:R},T.operation==="ADDED"&&T.after&&e.createElement(M,null,"Permission decision"," ",e.createElement(C,null,'"',Y,'"')," has been"," ",e.createElement(C,{operation:"ADDED"},"added")," to"," ",e.createElement(C,null,'"',(B=s.after)==null?void 0:B.name,'"')),T.operation==="REMOVED"&&T.before&&e.createElement(M,null,"Permission decision"," ",e.createElement(C,null,'"',U,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")," ","from ",e.createElement(C,null,'"',(N=s.after)==null?void 0:N.name,'"')),T.operation==="CHANGED"&&e.createElement(M,null,U!==Y?e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(C,null,'"',U,'"')," has been"," ",e.createElement(C,{operation:"CHANGED"},"updated")," ","to ",e.createElement(C,null,'"',Y,'"')):e.createElement(e.Fragment,null,"Permission decision"," ",e.createElement(C,null,'"',U,'"')," has been"," ",e.createElement(C,{operation:"CHANGED"},"updated"))," ","in ",e.createElement(C,null,'"',(h=s.after)==null?void 0:h.name,'"')),T.indexAfter>T.indexBefore&&T.indexBefore!==-1&&e.createElement(M,null,"Permission decision"," ",e.createElement(C,null,'"',Y,'"')," 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,'"')),T.indexAfter<T.indexBefore&&T.indexAfter!==-1&&e.createElement(M,null,"Permission decision"," ",e.createElement(C,null,'"',Y,'"')," has been"," ",e.createElement(C,{operation:"MOVED_UP"},"moved up")," ","in priority in"," ",e.createElement(C,null,'"',($=s.after)==null?void 0:$.name,'"')))}),Object.entries(f).map(([R,T])=>{var B,N;return e.createElement(be,{key:R},T.operation==="ADDED"&&T.after&&e.createElement(M,null,"Member ",e.createElement(C,null,'"',T.after,'"')," has been"," ",e.createElement(C,{operation:"ADDED"},"added")," to"," ",e.createElement(C,null,'"',(B=s.after)==null?void 0:B.name,'"')),T.operation==="REMOVED"&&T.before&&e.createElement(M,null,"Member ",e.createElement(C,null,'"',T.before,'"')," has been"," ",e.createElement(C,{operation:"REMOVED"},"removed")," from"," ",e.createElement(C,null,'"',(N=s.after)==null?void 0:N.name,'"')))})))}))},ar=w(()=>({root:{display:"inline-flex"}})),Ft=({timestamp:t,description:n})=>{const l=ar(),a=Te.fromISO(t).toLocaleString(Te.DATETIME_FULL),r=Zn(t),o=n?`${n}${r}`:r;return e.createElement("span",{className:l.root},e.createElement(me,{title:a},e.createElement(D,{component:"span",display:"inline",variant:"inherit"},o)))};function Lt(t,n,l){var a,r;let o=n.created,i=t.createdBy;l!=null&&l.created&&(i=l.created+i);let m=t.createdAt;return t.status==="active"?(o=n.published,i=(a=t.lastPublishedBy)!=null?a:"",l!=null&&l.published&&(i=l.published+i),m=(r=t.lastPublishedAt)!=null?r:""):t.createdAt!==t.updatedAt&&(o=n.updated,i=t.updatedBy,l!=null&&l.updated&&(i=l.updated+i),m=t.updatedAt),{activityDateText:o,activityUser:i,timestamp:m}}const or=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 Ee(t){const n=or(t),{policy:l,to:a,withChangeSummary:r}=t,o=`${l.name} ${l.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}=Lt(l,i,m);return e.createElement(K,{className:n.card},e.createElement(Pe,null,e.createElement("div",{className:n.header},a?e.createElement(se,{to:`versions/${l.id}`},e.createElement(D,{variant:"h5",component:"h1"},o)):e.createElement(D,{variant:"h5",component:"h1"},o),l.status==="active"?e.createElement(Bt,{status:"active",size:"small"}):null),l.description?e.createElement(D,{variant:"body1",color:"textSecondary"},'"',l.description,'"'):null,e.createElement(D,{component:"h2",className:n.detailsHeader},"Details"),e.createElement(zn,{className:n.activityList},e.createElement(Et,{className:n.activityListItem},e.createElement(te,null,e.createElement(sl,null)),e.createElement(ne,{primary:e.createElement(Ft,{timestamp:s,description:u})})),e.createElement(Et,{className:n.activityListItem},e.createElement(te,null,e.createElement(Dt,null)),e.createElement(ne,{primary:c}))),r&&e.createElement(d,{paddingTop:2},e.createElement(D,{gutterBottom:!0,variant:"subtitle2"},"What's changed"),e.createElement(d,{className:n.diffSummaryContainer},e.createElement(Mt,{policy:l})))),t.actions?e.createElement(Vn,{className:n.actions},t.actions):null)}const ir=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)}})),cr=({localPolicy:t,onSelectLocalPolicy:n,onSelectServerPolicy:l,serverPolicy:a})=>{const r=ir();return e.createElement(le,{open:!0,maxWidth:"md"},e.createElement(q,null,e.createElement(d,{display:"flex",flexDirection:"column",gridGap:8},e.createElement(d,{display:"flex",justifyContent:"center"},e.createElement(Pt,{className:r.icon})),e.createElement(D,{align:"center",variant:"h6"},"There is a conflict with your drafts"),e.createElement(d,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(d,{className:r.policiesContainer},e.createElement(d,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(D,{className:r.label,variant:"button"},"Your local draft"),e.createElement(Ee,{policy:t,withChangeSummary:!0}),e.createElement(k,{className:r.button,color:"primary",onClick:n,variant:"outlined"},"Keep local draft")),e.createElement(d,{alignItems:"center",display:"flex",flexDirection:"column",flex:"1 1 0%"},e.createElement(D,{className:r.label,variant:"button"},"Recently saved draft"),e.createElement(Ee,{policy:a,withChangeSummary:!0}),e.createElement(k,{className:r.button,color:"primary",onClick:l,variant:"outlined"},"Keep recently saved draft")))))},sr=({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},mr=()=>ul("@spotify/backstage-plugin-rbac:draftPolicy");function jt(t){const n=new Blob([ur(t)],{type:"text/yaml"});dl(n,`${(t.name||"policy").toLocaleLowerCase().replace(/\W/g,"-")}.yaml`)}function ur(t){const{name:n,roles:l,options:a,description:r}=t;return`# this is an autogenerated file, do not edit
|
|
2
|
-
${tl(pl({name:n,description:r,options:a,roles:l.map(({permissions:o,...i})=>({...Nt(i,["id"]),permissions:o.map(m=>Nt(m,["id"]))}))},o=>o!==null||o!==void 0))}`}const dr=w(t=>({icon:{color:t.palette.warning.main,width:"2rem",height:"2rem"}})),pr=({onConfirm:t,policy:n})=>{const l=dr(),a=()=>{jt(n)};return e.createElement(le,{open:!0},e.createElement(q,null,e.createElement(d,{display:"flex",flexDirection:"column",gridGap:16},e.createElement(d,{display:"flex",flexDirection:"column",gridGap:4},e.createElement(d,{display:"flex",justifyContent:"center"},e.createElement(Pt,{className:l.icon})),e.createElement(D,{align:"center",variant:"h6"},"Invalid local draft")),e.createElement(d,{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(d,{component:"span",fontWeight:"fontWeightBold"},"This action cannot be undone."))),e.createElement(d,{display:"flex",justifyContent:"center",gridGap:8,marginY:3},e.createElement(k,{color:"primary",onClick:a,variant:"outlined"},"Export"),e.createElement(k,{color:"primary",onClick:t,variant:"contained"},"Discard and continue")))))};function lt(){const t=O(z),n=O(ee),l=re(async(r,o)=>{if(r)return await t.publishPolicy(r.id,{description:o}),t.getPolicy(r.id)},[]),[{error:a}]=l;return _(()=>{a&&n.post({message:a.message,severity:"error"})},[a,n]),l}const fr=w(t=>({closeButton:{color:t.palette.text.secondary},diffSummaryContainer:{backgroundColor:t.palette.background.default,marginBottom:t.spacing(2)}}));function rt({open:t,onPublish:n,onClose:l,policy:a}){const[r,o]=S(!1),i=fr(),m=Z(null),u=async()=>{var c,s;o(!0),await n((s=(c=m.current)==null?void 0:c.value)!=null?s:""),o(!1)};return e.createElement(le,{open:t,onClose:l,fullWidth:!0},e.createElement(De,null,e.createElement(d,{display:"flex",justifyContent:"space-between",alignItems:"center"},"Ready to publish?",e.createElement(k,{startIcon:e.createElement(Ye,null),onClick:l,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(q,{className:i.diffSummaryContainer,dividers:!0},e.createElement(Mt,{policy:a})),e.createElement(q,null,e.createElement(ue,{variant:"outlined",fullWidth:!0,label:"Summary (optional)",placeholder:"Briefly describe this version (or changes from a previous version)",inputRef:m})),e.createElement(Le,null,e.createElement(k,{color:"primary",onClick:u,disabled:r},r?e.createElement(yt,{size:20}):"Publish")))}const Er=w(t=>({paper:{padding:t.spacing(2,2,0,2)}})),at=({isOpen:t,onClose:n,policy:l})=>{const a=Er();return e.createElement(le,{classes:{...a},open:t,onClose:n},e.createElement(De,{disableTypography:!0},e.createElement(d,{display:"flex",flexDirection:"row"},e.createElement(d,null,e.createElement(D,{variant:"h4",component:"h2"},"Success!"),e.createElement(D,null,l.name," has been published and is now your active policy.")),e.createElement(d,null,e.createElement(L,{onClick:n,title:"Close dialog"},e.createElement(Ye,null))))),e.createElement(q,null,e.createElement(Ee,{policy:l})),e.createElement(Le,null,e.createElement(d,{display:"flex",flexDirection:"row",flexGrow:1,justifyContent:"flex-start"},e.createElement(k,{component:Tn,color:"primary",onClick:n,role:"link",to:"/rbac"},"View all versions"))))},yr={canPublish:!1,diff:null,hasChanges:!1,isValid:!1,policy:void 0,createNewRole:()=>"",discardLocalDraft:()=>{},exportPolicy:()=>{},publish:()=>{},saveLocalDraftToServer:()=>Promise.reject(),refetchPolicy:()=>Promise.reject(),updateLocalDraft:()=>{}},Ht=$e(yr),oe=()=>Ie(Ht);function ot({children:t,policyId:n}){const l=J(),a=O(ee),r=O(z),{getPolicy:o,setPolicy:i}=Qe(),m=Be(),{NotFoundErrorPage:u}=m.getComponents(),[c,s]=S(!1),[p,f]=S(!1),[{loading:v,value:g},y]=lt(),E=o(n),[x,A,R]=mr(),T=!x||we.safeParse(x).success,B=T?x:void 0,{policy:N,policyConflict:h}=sr({serverPolicy:E,localPolicy:B}),b=Ot(N),$=we.safeParse(N).success,j=$&&!B&&!v,[{loading:ve,error:U},Y]=re(()=>r.getPolicy(n),[r,n],E?{loading:!1,value:E}:{loading:!0}),En=()=>{s(!0)},yn=I(async H=>{await y(N,H),s(!1)},[N,y,s]),gn=async()=>{f(!1)},hn=()=>{A(H=>H&&E&&{...H,updatedAt:E.updatedAt})},X=I(async()=>{const H=await Y();i(H)},[Y,i]),vn=I(async()=>{if(!N)throw new Error("No policy to save");try{await r.updateDraft(N.id,{name:N.name,roles:N.roles}),a.post({message:"Policy saved",severity:"success"}),R(),X==null||X()}catch(H){a.post({message:(H==null?void 0:H.message)||"An error occurred while updating the policy",severity:"error"})}},[a,r,N,X,R]),bn=I(()=>{if(!N)throw new Error("No policy to create a new role");const H=new Set(N.roles.map(Dn=>Dn.id));let ie;do ie=ae().split("-")[0];while(H.has(ie));const Pn={name:`Role ${ie}`,permissions:[],members:"*",id:ie};return A({...N,roles:[...N.roles,Pn]}),ie},[N,A]),Cn=()=>{R(),l("/rbac")},xn=()=>{N&&jt(N)};return _(()=>{E||X()},[X,E]),_(()=>{g&&f(!0)},[g]),T?N?e.createElement(Ht.Provider,{value:{canPublish:j,diff:b,hasChanges:!!B,isValid:$,policy:N,createNewRole:bn,discardLocalDraft:R,exportPolicy:xn,publish:En,saveLocalDraftToServer:vn,refetchPolicy:X,updateLocalDraft:A}},h&&B&&E&&e.createElement(cr,{localPolicy:B,onSelectLocalPolicy:hn,onSelectServerPolicy:R,serverPolicy:E}),e.createElement(rt,{open:c,onClose:()=>s(!1),onPublish:yn,policy:N}),g&&e.createElement(at,{isOpen:p,onClose:gn,policy:g}),t):ve?e.createElement(xe,null):U?Ql(U)?e.createElement(u,null):e.createElement(dt,{error:U!=null?U:new Error("Unknown")}):null:e.createElement(pr,{onConfirm:Cn,policy:x})}function gr(t){throw new Error("Invalid state")}function Wt(){const t=O(z),n=O(ee),{fetchPolicies:l}=fe();return re(async a=>{if(!a)return;const{roles:r,name:o,options:i}=a;return t.createDraft({roles:r,options:i,name:o}).then(l).catch(m=>(n.post({message:m.message,severity:"error"}),Promise.reject(m)))},[])}const hr=[{title:"Name",field:"name",render:t=>e.createElement(se,{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 gr(t.status)}}},{title:"Publish date",field:"lastPublishedAt",render:t=>t.lastPublishedAt?Te.fromISO(t.lastPublishedAt).toLocaleString(Te.DATETIME_MED_WITH_SECONDS):"",type:"datetime",defaultSort:"desc"},{title:"Published by",field:"lastPublishedBy"}];function vr(t){const n=t.data.length>3,{fetchPolicies:l}=fe(),[{loading:a},r]=Wt(),[{loading:o,value:i},m]=lt(),[u,c]=S(void 0),[s,p]=S(!1),f=()=>{c(void 0),l()},v=(u==null?void 0:u.id)===(i==null?void 0:i.id)?i:void 0,g=[y=>{const{tableData:E,...x}=y;return{icon:fl,tooltip:"Publish",onClick:()=>{c(x),p(!0)},disabled:o}},y=>{const{tableData:E,...x}=y;return{icon:El,tooltip:"Duplicate",disabled:a||!t.canDuplicate,onClick:()=>r(x)}}];return e.createElement(e.Fragment,null,e.createElement(Hn,{title:"Previous Versions",columns:hr,data:t.data,options:{paging:n,pageSize:3,pageSizeOptions:[3,5,10,20],actionsColumnIndex:-1,loadingType:"linear"},actions:g}),u&&e.createElement(rt,{open:s,onPublish:y=>{m(u,y),p(!1)},onClose:()=>{c(void 0),p(!1)},policy:u}),v&&e.createElement(at,{isOpen:!0,policy:v,onClose:f}))}const br=t=>{const[n,l]=S(!1),{fetchPolicies:a}=fe(),[{loading:r,value:o},i]=lt(),{policy:m,hasChanges:u}=oe(),c=we.safeParse(m).success,s=!u&&c,p=async v=>{await i(m,v),l(!1)},f=()=>{a()};return e.createElement(e.Fragment,null,e.createElement(k,{...t,onClick:()=>l(!0),disabled:!s||r},"Publish"),e.createElement(rt,{open:n,onClose:()=>l(!1),onPublish:p,policy:m}),o&&e.createElement(at,{isOpen:!0,onClose:f,policy:o}))};function Cr(t){const n=O(z),l=O(ee),{fetchPolicies:a}=fe();return re(async()=>{if(t)return n.deleteDraft(t.id).then(a).catch(r=>(l.post({message:r.message,severity:"error"}),Promise.reject(r)))},[t])}function xr({policies:t}){const n=t.find(c=>c.status==="draft"),l=t.find(c=>c.status==="active"),[a,r]=Wt(),[o,i]=Cr(n),m=J(),u=Pr(t);return e.createElement(W,{container:!0,spacing:4},l?e.createElement(W,{item:!0,xs:12,md:6},e.createElement(Ee,{policy:l,to:`./versions/${l.id}`,actions:e.createElement(k,{color:"primary",disabled:a.loading||!!n,onClick:()=>r(l)},"Duplicate")})):null,n?e.createElement(W,{item:!0,xs:12,md:6},e.createElement(Ee,{policy:n,to:`./versions/${n.id}`,actions:e.createElement(e.Fragment,null,e.createElement(k,{onClick:()=>m(`versions/${n.id}`),color:"primary"},"Edit"),e.createElement(k,{color:"primary",disabled:o.loading,onClick:i},"Delete Draft"),e.createElement(ot,{policyId:n.id},e.createElement(br,{color:"primary"})))})):null,e.createElement(W,{item:!0,xs:12},e.createElement(vr,{data:u,canDuplicate:!n})))}function Pr(t){return t.filter(({status:n})=>n==="inactive")}function Dr(){const{policies:t}=Qe(),{loading:n,error:l,fetchPolicies:a}=fe();pt(()=>{t||a()});let r;return n?r=e.createElement(W,{item:!0,xs:12},e.createElement(xe,null)):l?r=e.createElement(dt,{error:l}):!t||t.length===0?r=e.createElement(ql,null):r=e.createElement(xr,{policies:t}),e.createElement(qe,{pages:void 0,header:e.createElement(Fe,{title:"RBAC Policies"},e.createElement(Jl,null))},r)}const Nr=w(t=>({titleWrapper:{display:"flex",alignItems:"center",gap:t.spacing(2)}}));function zt({children:t}){const n=Nr();return e.createElement(D,{noWrap:!0,variant:"h4",component:"h2",color:"textSecondary",className:n.titleWrapper},t)}const wr=w({autocomplete:{display:"flex",flex:1}});function Tr({members:t,options:n,namespaceOptions:l,loading:a=!1,disabled:r=!1,isMultiNamespaces:o=!1,onTextChange:i,onToggleMember:m,onChange:u}){const[c,s]=S(!1),p=wr(),[f,v]=Nn(E=>E+1,0),g=(E,x)=>{x&&(m(x),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(d,{width:250},e.createElement(Je,{key:`${f}`,open:c,onOpen:()=>{s(!0)},onClose:()=>{s(!1)},onChange:g,getOptionLabel:ye,groupBy:Ar,renderOption:E=>e.createElement(e.Fragment,null,e.createElement(je,{id:`checkbox-${E.entityRef}`,checked:t.includes(E.entityRef),color:"primary"}),e.createElement("label",{htmlFor:`checkbox-${E.entityRef}`},o?ye(E,!1):ye(E))),options:y,filterOptions:E=>E,openOnFocus:!0,disabled:r,loading:a,className:p.autocomplete,renderInput:E=>e.createElement(ue,{...E,label:o?"Select members":"Select specific users/groups",variant:"standard",onChange:u,InputProps:{...E.InputProps,endAdornment:e.createElement(e.Fragment,null,a?e.createElement(yt,{color:"inherit",size:20}):null,E.InputProps.endAdornment)}})}))}function ye(t,n=!0){var l;const a=Q(t.entityRef);return a.name==="*"?a.namespace:gl({...a,name:(l=t.name)!=null?l:a.name},{defaultKind:a.kind,defaultNamespace:n?yl:!1})}const Vt={user:"USERS",group:"GROUPS",namespace:"NAMESPACES"};function Ar(t){const{name:n,kind:l}=Q(t.entityRef),a=n==="*"?"namespace":l;if(!Vt[a])throw new Error(`Group '${a}' is not supported for members in a policy`);return Vt[a]}const kr=w(t=>({root:({operation:n})=>({borderRadius:100,borderColor:tt(t,n),borderSize:1,borderStyle:"solid",color:tt(t,n),lineHeight:1,padding:t.spacing(.5,1),whiteSpace:"nowrap"})})),ge=({operation:t,size:n="small"})=>{const l=kr({operation:t}),a=nr(t),r=n==="small"&&"caption"||n==="medium"&&"body1"||n==="large"&&"subtitle1"||"inherit";return!t||t==="UNCHANGED"?null:e.createElement(D,{className:l.root,variant:r},a)},Sr=w(t=>({actionCol:{width:48},typeIconCol:{paddingRight:"0.4rem"},nameCol:{paddingLeft:0},typeIcon:{color:t.palette.grey[500]}}));function Rr({diff:t,loading:n,isMultiNamespaces:l,members:a,error:r,onToggleMember:o,readonly:i=!1}){const m=Sr();if(n)return e.createElement(V,null,e.createElement(P,{scope:"row",colSpan:4},e.createElement(xe,null)));if(r&&r.message!=null,a==="*")return e.createElement(V,null,e.createElement(P,null,"All"),e.createElement(P,{height:80},"any"),e.createElement(P,{colSpan:i?2:3},e.createElement(ge,{operation:t==null?void 0:t.members["*"].operation})));if(a.length===0)return e.createElement(V,null,e.createElement(P,{scope:"row",colSpan:4},"Select users or groups using the drop-down menu above."));const u=a.sort((c,s)=>{let p=0;l&&s.name==="*"&&c.name!=="*"?p=1:l&&c.name==="*"&&s.name!=="*"&&(p=-1);const f=c.type.localeCompare(s.type),v=Q(c.entityRef).namespace.localeCompare(Q(s.entityRef).namespace),g=Q(c.entityRef).name.localeCompare(Q(s.entityRef).name);return p||f||v||g});return e.createElement(e.Fragment,null,u.map(c=>{var s;const{name:p,type:f,entityRef:v}=c;return e.createElement(V,{key:v},e.createElement(P,{className:m.typeIconCol},f==="group"&&e.createElement(Cl,{className:m.typeIcon})||l&&p==="*"&&e.createElement(xl,{className:m.typeIcon})||e.createElement(Dt,{className:m.typeIcon})),e.createElement(P,{scope:"row",className:m.nameCol},(s=l?ye(c,!1):ye(c))!=null?s:"Unknown"),e.createElement(P,{scope:"row"},p==="*"&&l?"namespace":f),e.createElement(P,null,p&&e.createElement(ge,{operation:t==null?void 0:t.members[v].operation})),!i&&e.createElement(P,{scope:"row",className:m.actionCol},e.createElement(L,{"aria-label":"delete",onClick:()=>o(c),size:"small"},e.createElement(pe,null))))}))}const $r=w(()=>({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 Ir({diff:t,policyId:n,role:l,onToggleMember:a,readonly:r=!1,debounceTime:o=1e3}){const i=O(z),m=O(hl),u=$r(),c=l.members==="*",[s,p]=S(""),{current:f}=Z({}),v=b=>{f[b.entityRef]=b,a(b.entityRef)},g=b=>{var $;if(f[b])return f[b];const j=Q(b);return{entityRef:b,type:j.kind.toLowerCase(),name:($=j.name)!=null?$:b}},{value:y,loading:E}=ce(async()=>await i.searchMembers({query:s}),[i,s]),{loading:x,value:A}=ce(async()=>{const b=await m.getEntityFacets({facets:["metadata.namespace"]}).then($=>$.facets["metadata.namespace"].map(j=>j.value));return Or(b)},[m]),R=A?(A==null?void 0:A.length)>1:!1,T=A?A.filter(b=>b.entityRef.toLowerCase().includes(s)):[],B=F(()=>Gn(b=>{p(b.target.value.toLowerCase())},o),[p,o]),{loading:N,error:h}=ce(async()=>{l.members==="*"||l.members.length===0||(await i.getPolicy(n)).roles.find(b=>b.id===l.id)===void 0||l.members.forEach(b=>{const $=g(b);f[$.entityRef]=$})},[n,c]);return e.createElement(e.Fragment,null,e.createElement("div",{className:u.header},e.createElement("h2",null,"Members"),e.createElement(Tr,{onToggleMember:v,members:l.members,disabled:r,options:y,namespaceOptions:T,isMultiNamespaces:R,loading:E||x,onTextChange:p,onChange:B})),e.createElement(He,null,e.createElement(We,null,e.createElement(V,null,e.createElement(P,{className:u.typeIconCol}),e.createElement(P,{className:u.nameCol},"Name"),e.createElement(P,null,"Type"),e.createElement(P,null),!r&&e.createElement(P,{className:u.actionCol}))),e.createElement(ze,null,e.createElement(Rr,{diff:t,loading:N||x,isMultiNamespaces:R,error:h,members:Array.isArray(l.members)?l.members.map(g):l.members,onToggleMember:v,readonly:r}))))}function Or(t){return t.map(n=>({name:"*",type:"user",entityRef:`user:${n}/*`})).sort((n,l)=>n.entityRef.toLowerCase().localeCompare(l.entityRef.toLowerCase()))}function Gt(t){return`${t.palette.primary.main}50`}const Br=w(t=>({indicator:{right:"unset"},tab:{maxWidth:"none","&.Mui-selected":{backgroundColor:Gt(t),color:t.palette.primary.main}}}));function Mr({options:t,selected:n,onChange:l,readonly:a=!1}){const r=Br();return e.createElement(Un,{orientation:"vertical",value:t.map(({id:o})=>o).indexOf(n),onChange:(o,i)=>l(t[i].id),indicatorColor:"primary",TabIndicatorProps:{className:r.indicator}},t.map(o=>e.createElement(_n,{key:o.id,label:o.displayText.toUpperCase(),className:r.tab,disabled:a})))}const Fr=["condition","anyOf","allOf","not"],Ut={condition:"Condition",anyOf:"Any of",allOf:"All of",not:"Not"};function it(t){return t===null?!1:t.hasOwnProperty("id")&&t.hasOwnProperty("ruleName")&&t.hasOwnProperty("parameters")}function he(t){return t.hasOwnProperty("levelType")}function Lr(t){return t==="anyOf"||t==="allOf"||t==="not"}function jr(t){return t?{id:t.id,match:Hr(t),decisionType:Wr(t),criteria:_e(t.decision)?ke(t.decision.conditions):null}:{id:ae(),match:{method:"specificPermission"},decisionType:"allow",criteria:null}}function Hr(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 Wr(t){return typeof t.decision=="string"?t.decision:"conditional"}function ke(t){const n=ae();return nl(t)?{id:n,levelType:"allOf",children:t.allOf.map(l=>ke(l))}:ll(t)?{id:n,levelType:"anyOf",children:t.anyOf.map(l=>ke(l))}:rl(t)?{id:n,levelType:"not",children:[ke(t.not)]}:{id:n,ruleName:t.rule,parameters:t.params}}function _t(t,n){if(!t)return!1;if(he(t))return t.children.length>0&&t.children.every(a=>_t(a,n));if(!t.ruleName)return!1;const l=n==null?void 0:n.find(({name:a})=>a===t.ruleName);return l?l.paramsSchema?new Tt({allErrors:!0}).compile(l.paramsSchema)(t.parameters):!0:!1}function zr(t,n,l){return{id:t,match:Yt(n,l),decision:l}}function Yt({method:t,...n},l){return t==="all"?"*":l&&_e(l)?{resourceType:l.resourceType,...n}:n}function ct(t){return it(t)?{rule:t.ruleName,params:t.parameters}:t.levelType==="not"?{not:ct(t.children[0])}:{[t.levelType]:t.children.map(n=>ct(n))}}const Vr=w(t=>({toggleButton:{"&.Mui-selected":{backgroundColor:Gt(t),color:t.palette.primary.main},"&.Mui-selected:hover":{backgroundColor:"#97BBE8"},color:t.palette.primary.main,border:`1px solid ${t.palette.primary.main}`}}));function st({className:t,...n}){const l=Vr();return e.createElement(vl,{className:`${l.toggleButton} ${t}`,...n})}const Gr=w({fullWidth:{width:"100%","& > *":{flexGrow:1}}});function Ur({className:t,fullWidth:n,...l}){const a=Gr();return e.createElement(bl,{className:`${n?a.fullWidth:""} ${t}`,...l})}function _r(t,n){const l=(t!=null?t:[]).filter(o=>al(o,Yt(n))),a=Pl(l,o=>Me(o)?o.resourceType:void 0),r=a.length===1&&Me(a[0])?a[0].resourceType:void 0;return{permissions:l,commonResourceType:r}}const Yr=w(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Jt="Permission name";function Jr({name:t="",readonly:n,onNameChange:l}){const a=Yr(),r=St();return e.createElement(Ve,{className:a.fullWidth,variant:"outlined",disabled:n},e.createElement(Ne,{id:"match-by-name-dropdown"},Jt),e.createElement(Ge,{labelId:"match-by-name-dropdown",label:Jt,value:r?t:"",onChange:o=>l==null?void 0:l(o.target.value)},r==null?void 0:r.map(o=>e.createElement(G,{key:o.name,value:o.name},o.name))))}const Kr=w(()=>({fullWidth:{width:"100%","& > *":{flexGrow:1}}})),Kt="Resource type";function qr({resourceType:t="",readonly:n,onResourceTypeChange:l}){const a=Kr(),r=Rt();return e.createElement(Ve,{className:a.fullWidth,variant:"outlined",disabled:n},e.createElement(Ne,{id:"match-by-resource-dropdown"},Kt),e.createElement(Ge,{labelId:"match-by-resource-dropdown",label:Kt,value:r?t:"",onChange:o=>l==null?void 0:l(o.target.value),displayEmpty:!0},r==null?void 0:r.map(o=>e.createElement(G,{key:o,value:o},o))))}const Qr="Action";function Xr({actions:t,readonly:n,onActionsChange:l}){return e.createElement(Je,{multiple:!0,id:"match-by-attribute-dropdown",options:["create","read","update","delete"],getOptionLabel:a=>a,value:t!=null?t:[],onChange:(a,r)=>l==null?void 0:l(r),filterSelectedOptions:!0,renderInput:a=>e.createElement(ue,{...a,variant:"outlined",label:Qr,placeholder:"Choose attributes",margin:"normal"}),disabled:n})}const Zr=w(t=>({descriptiveText:{fontWeight:500,marginBottom:t.spacing(1)}})),Se=({children:t})=>{const n=Zr();return e.createElement(D,{variant:"body2",className:n.descriptiveText},t)},qt="#FF737F",ea="#E22134";function Qt({condition:t}){return e.createElement(Se,null,e.createElement(d,{component:"span",color:qt},t.ruleName,"("),e.createElement(d,{component:"span",color:ea},JSON.stringify(t.parameters)),e.createElement(d,{component:"span",color:qt},")"))}const Xt=({children:t})=>e.createElement(d,{pl:3},t);function Zt({level:t}){return e.createElement(e.Fragment,null,e.createElement(Se,null,Ut[t.levelType]),e.createElement(Xt,null,t.children.map((n,l)=>he(n)?e.createElement(Zt,{key:l,level:n}):e.createElement(Qt,{key:l,condition:n}))))}const ta="#4CAF50";function na({permissionCriteria:t}){return e.createElement("div",null,e.createElement(Se,null,"If the below conditions are met"),e.createElement(Xt,null,it(t)&&e.createElement(Qt,{condition:t}),he(t)&&e.createElement(Zt,{level:t})),e.createElement(Se,null,"Then the action is"," ",e.createElement(d,{component:"span",color:ta},"allowed")))}const la=w(()=>({addButton:{paddingLeft:40,paddingRight:40}}));function en({onSelect:t}){const n=la(),l=Z(null),[a,r]=S(!1),o=()=>{r(i=>!i)};return e.createElement("div",null,e.createElement(k,{className:n.addButton,variant:"outlined",color:"primary",onClick:o,ref:l},"Add"),e.createElement(gt,{anchorEl:l.current,open:a,onClose:o,BackdropProps:{}},Fr.map(i=>e.createElement(G,{key:i,onClick:()=>{t==null||t(i),r(!1)}},Ut[i]))))}const ra=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"}})),aa=t=>"parseError"in t,oa=t=>{var n;return t?aa(t)?!!t.parseError:((n=t==null?void 0:t.validationErrors)==null?void 0:n.length)>0:!1};function ia({onChange:t,schema:n,value:l}){const a=Z(null),r=Z(),o=ra();return _(()=>(a.current&&!r.current&&(r.current=new Dl({target:a.current,props:{onChange:(i,m,{contentErrors:u})=>{!oa(u)&&Nl(i)&&t(JSON.parse(i.text))},validator:wl({schema:n}),content:{json:{}},mainMenuBar:!1,mode:Tl.text}})),()=>{var i;(i=r.current)==null||i.destroy(),r.current=void 0}),[t,n]),pt(()=>{var i;(i=r.current)==null||i.updateProps({content:{json:l}})}),e.createElement("div",{ref:a,className:o.editor,style:{height:300}})}const ca=[];function sa(t){const{onChange:n,schema:l,name:a}=t,{description:r,items:o}=l,[i,m]=e.useState(!1),u=Array.isArray(t.value)?t.value:ca,c=u.includes(de),s=(E,x)=>{if(!Array.isArray(x)){const A=[...u];A[E]=x||"",n(A)}},p=I(()=>{n([...u,""])},[n,u]),f=E=>{n(u.filter((x,A)=>A!==E))},v=()=>{n(c?[]:[de])},g=()=>{c&&m(!0)},y=()=>{m(!1)};return _(()=>{u.length?c&&u.length>1&&n([de]):p()},[p,n,u,c]),!o||!("type"in o)?null:e.createElement(e.Fragment,null,(u!=null?u:[]).map((E,x,{length:A})=>e.createElement(nn,{allowEmptyStrings:!0,key:x,onChange:R=>s(x,R),name:x===0?a:"",schema:{description:x===A-1?r:"",type:o.type},value:E,controls:e.createElement(L,{size:"small",onClick:()=>f(x)},e.createElement(Al,null))})),!!(u!=null&&u.length)&&e.createElement(d,{alignItems:"center",display:"flex",flexDirection:"row",justifyContent:"space-between"},e.createElement(d,null,e.createElement(ht,{control:e.createElement(je,{checked:c,onChange:v,name:"checkedB",color:"primary"}),label:"Use the claims from the logged in users token"})),e.createElement(d,null,e.createElement(me,{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(L,{disabled:c,size:"small",onClick:p},e.createElement(Ke,null)))))))}function ma(t){const{onChange:n,schema:l,name:a,value:r}=t,{description:o}=l;return e.createElement(d,{mb:1},e.createElement(ht,{control:e.createElement(je,{checked:r===!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 ua({allowEmptyStrings:t,controls:n,name:l,onChange:a,schema:r,value:o}){const i=m=>{a(pa({value:m.currentTarget.value,type:r.type}))};return e.createElement(d,{mb:1},e.createElement(d,{display:"flex",gridGap:6},e.createElement(ue,{fullWidth:!0,id:l,label:l,placeholder:"Enter",variant:"outlined",size:"small",value:da(o,t),onChange:mt(o,t)?void 0:i,disabled:mt(o,t)}),n&&e.createElement(d,{alignSelf:"center"},n)),r.description&&e.createElement(D,{variant:"caption",color:"textSecondary"},r.description,mt(o)&&!t&&e.createElement(e.Fragment,null," (switch to JSON editor to edit)")))}function mt(t,n=!1){return!n&&t===""||t===null||t===de}function da(t,n=!1){return!n&&t===""?"[empty string]":t===null?"[null]":t===de?"[BackstageUserClaims]":t||""}function pa({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 tn(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 fa(t){return"type"in t&&t.type==="array"}function Ea(t){return"type"in t&&t.type==="boolean"}function nn({schema:t,...n}){return tn(t)?fa(t)?e.createElement(sa,{...n,schema:t}):Ea(t)?e.createElement(ma,{...n,schema:t}):e.createElement(ua,{...n,schema:t}):null}const ya=new Tt({allErrors:!0});function ga({onChange:t,schema:n,value:l}){var a;const r=F(()=>ya.compile(n),[n]),o=F(()=>r(l),[r,l]),i=Object.entries(n.properties),m=u=>c=>{t({...l,[u]:c})};return e.createElement(e.Fragment,null,i.map(([u,c])=>{var s;return e.createElement(nn,{isRequired:((s=n.required)==null?void 0:s.includes(u))||!1,key:u,name:u,onChange:m(u),schema:c,value:l==null?void 0:l[u]})}),e.createElement(vt,{error:!o},(a=r.errors)==null?void 0:a[0].message))}const ha=t=>!!t&&"properties"in t;function va({onChange:t,rule:n,value:l}){const[a,r]=S(!1),{paramsSchema:o}=n!=null?n:{},i=()=>r(s=>!s);if(!ha(o))return null;const m=!ba(o),u=m||a,c=e.createElement(k,{size:"small",onClick:i,disabled:m},u?"Close editor":"Edit as JSON");return e.createElement(d,{marginTop:2},e.createElement("form",null,u?e.createElement(ia,{onChange:t,schema:o,value:l}):e.createElement(e.Fragment,null,e.createElement(d,{marginBottom:2},e.createElement(Ne,null,"Parameters")),e.createElement(ga,{onChange:t,schema:o,value:l}))),e.createElement(d,{display:"flex",flexDirection:"column",alignItems:"flex-end",marginTop:1},m?e.createElement(me,{title:"Only JSON editing is supported for this parameter",arrow:!0},e.createElement("span",null,c)):c))}function ba(t){return Object.values(t.properties).every(tn)}const Ca=w(t=>({conditionCard:{minWidth:t.spacing(63)},conditionCardBar:{height:t.spacing(1),backgroundImage:"linear-gradient(90deg, #007DFF 0%, #0057B2 100%)"},autocomplete:{flex:1}}));function ln({ruleName:t,parameters:n,resourceType:l,onChange:a,onDelete:r}){var o;const i=Ca(),m=kt(),u=(o=m==null?void 0:m.filter(f=>f.resourceType===l))!=null?o:[],c=u.find(f=>f.name===t),s=f=>{a(f,{})},p=I(f=>{a(t,f)},[a,t]);return e.createElement(d,{display:"flex",alignItems:"center"},e.createElement(K,{className:i.conditionCard},e.createElement("div",{className:i.conditionCardBar}),e.createElement(Pe,null,e.createElement(d,null,e.createElement(d,null,e.createElement(Je,{className:i.autocomplete,"data-testid":"rule-select",getOptionLabel:f=>f.name,getOptionSelected:(f,v)=>f.name===v.name,options:u,onChange:(f,v)=>s(v?v.name:null),renderInput:f=>e.createElement(e.Fragment,null,e.createElement(d,{marginBottom:2},e.createElement(Ne,null,"Rule")),e.createElement(ue,{...f,placeholder:"Select",variant:"outlined",size:"small",name:"rule"})),renderOption:f=>e.createElement(d,null,e.createElement(D,{variant:"body2"},f.name),e.createElement(D,{noWrap:!0,variant:"caption"},f.description)),value:c||null,PopperComponent:f=>e.createElement(Yn,{...f,style:{width:"auto"},placement:"bottom-start"})})),e.createElement(d,{flex:"1"},e.createElement(d,{display:"flex",flexDirection:"column"},e.createElement(va,{rule:c,onChange:p,value:n})))))),e.createElement(d,{ml:1},e.createElement(L,{"aria-label":"delete",onClick:r,size:"small"},e.createElement(pe,null))))}function Re(){return{id:ae(),ruleName:null,parameters:{}}}const xa=w(t=>({conditionTypeFormControl:{minWidth:80,marginLeft:t.spacing(1)}}));function Pa({level:t,onSelect:n}){const l=xa(),a=t.children.length>1;return e.createElement(d,{display:"flex",alignItems:"center"},e.createElement(Ve,{className:l.conditionTypeFormControl},e.createElement(Ge,{value:t.levelType,onChange:r=>n==null?void 0:n(r.target.value)},e.createElement(G,{key:"anyOf",value:"anyOf"},"Any of"),e.createElement(G,{key:"allOf",value:"allOf"},"All of"),e.createElement(G,{key:"not",value:"not",disabled:a},"Not"))),e.createElement(d,{ml:1},e.createElement(L,{"aria-label":"delete",onClick:()=>n==null?void 0:n(null),size:"small"},e.createElement(pe,null))))}const Da=w(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 rn({level:t,resourceType:n,onChange:l,parentConditionType:a,isRoot:r=!1}){const o=Da(),i=I((g,y)=>{const E=[...t.children];return E.splice(g,1,y),E},[t]),m=I(g=>{l({...t,children:g})},[l,t]),u=I(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=I((g,y)=>{m(g===null?an(t.children,y):i(y,g))},[t,m,i]),s=g=>{const y=ae();g==="condition"?m([...t.children,Re()]):g==="not"?m([...t.children,{id:y,levelType:g,children:[]}]):Lr(g)&&m([...t.children,{id:y,levelType:g,children:[Re()]}])},p=g=>{m(an(t.children,g))},f=F(()=>t.children.map((g,y)=>(E,x)=>{m(i(y,{...g,ruleName:E,parameters:x}))}),[t.children,m,i]),v=F(()=>t.children.map((g,y)=>E=>c(E,y)),[t.children,c]);return e.createElement("div",null,!r&&e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(d,{display:"flex",alignItems:"center",position:"relative"},!r&&e.createElement(e.Fragment,null,e.createElement("div",{className:a==="not"?o.treeVerticalBranchHalf:o.treeVerticalBranchFull}),e.createElement("div",{className:o.treeHorizontalBranch})),e.createElement(Pa,{level:t,onSelect:u})),e.createElement(d,{display:"flex"},r||a==="not"?e.createElement(d,{pl:2}):e.createElement("div",{className:o.treeVerticalSpacer}),!r&&e.createElement(d,{pl:2}),e.createElement("div",null,t.children.map((g,y)=>he(g)?e.createElement(d,{key:g.id},e.createElement(rn,{level:g,resourceType:n,parentConditionType:t.levelType,onChange:v[y]})):e.createElement(be,{key:g.id},e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(d,{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(ln,{ruleName:g.ruleName,parameters:g.parameters,resourceType:n,onChange:f[y],onDelete:()=>p(y)})))),!(t.levelType==="not"&&t.children.length>=1)&&e.createElement(e.Fragment,null,e.createElement("div",{className:o.treeHorizontalSpacer}),e.createElement(d,{display:"flex",alignItems:"center",position:"relative"},e.createElement("div",{className:o.treeVerticalBranchHalf}),e.createElement("div",{className:o.treeHorizontalBranch}),e.createElement(en,{onSelect:s}))))))}function an(t,n){const l=[...t];return l.splice(n,1),l}const Na=w(t=>({paper:{backgroundColor:t.palette.background.default,padding:t.spacing(3),marginBottom:t.spacing(3),minHeight:t.spacing(48)}}));function wa({permissionCriteria:t,resourceType:n,onUpdate:l,readonly:a=!1}){const r=Na(),o=I(s=>{l(p=>({...p,...s}))},[l]),i=I(s=>{const p=ae();o(s==="condition"?Re():s==="not"?{id:p,levelType:s,children:[]}:{id:p,levelType:s,children:[Re()]})},[o]),m=I((s,p)=>{l(f=>({...f,ruleName:s,parameters:p}))},[l]),u=I(()=>{l(null)},[l]);let c;return a?c=e.createElement(na,{permissionCriteria:t}):t===null?c=e.createElement(en,{onSelect:i}):it(t)?c=e.createElement(ln,{ruleName:t.ruleName,parameters:t.parameters,resourceType:n,onChange:m,onDelete:u}):he(t)&&(c=e.createElement(rn,{level:t,resourceType:n,onChange:l,isRoot:!0})),e.createElement(Jn,{variant:"outlined",className:r.paper},c)}const Ta=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}})),Aa={specificPermission:"Choose a specific permission",filter:"Filter by permission properties",all:"Match all permissions"},on="Choose the name of a resource permission or filter by resource type to set a conditional decision.";function ka({rolePermission:t,readonly:n=!1,onClose:l,onSave:a}){const r=Ta(),o=St(),i=kt(),m=zl(),u=jr(t),[c,s]=S(u.match),[p,f]=S(u.decisionType),[v,g]=S(u.criteria),y=F(()=>_r(o,c),[o,c]),E=p==="conditional",x=E?"xl":"sm";_(()=>{E&&o&&!y.commonResourceType&&f("allow")},[E,o,y.commonResourceType,f]);const A=h=>{h!==null&&f(h)},R=F(()=>c.method==="specificPermission"&&!c.name||c.method==="filter"&&!c.resourceType&&!c.actions,[c]),T=F(()=>y.permissions.length===0?!1:!R,[y,R]),B=F(()=>p!=="conditional"?!0:!(!y.commonResourceType||!(m!=null&&m[y.commonResourceType].pluginId)||!_t(v,i)),[p,y,m,v,i]),N=()=>{a==null||a(zr(u.id,c,p==="conditional"?{resourceType:y.commonResourceType,pluginId:m[y.commonResourceType].pluginId,conditions:ct(v)}:p))};return e.createElement(le,{open:!0,maxWidth:x,onClose:l,fullWidth:!0},e.createElement(De,{disableTypography:!0,className:r.dialogTitle},e.createElement(D,{variant:"h4",component:"h2"},"New Permission Decision"),e.createElement(k,{startIcon:e.createElement(Ye,null),onClick:l},"Close")),e.createElement(q,{dividers:!0,className:r.content},e.createElement(d,{className:E?r.contentContainerConditional:void 0},e.createElement(d,{mb:5,flex:1},e.createElement(Mr,{options:Object.entries(Aa).map(([h,b])=>({id:h,displayText:b})),selected:c.method,onChange:h=>s({method:h}),readonly:n})),e.createElement(d,{mb:5,height:189,flex:1},c.method==="specificPermission"&&e.createElement(Jr,{name:c.name,readonly:n,onNameChange:h=>s({...c,name:h})}),c.method==="filter"&&e.createElement(e.Fragment,null,e.createElement(qr,{resourceType:c.resourceType,readonly:n,onResourceTypeChange:h=>s({...c,resourceType:h})}),e.createElement(Xr,{actions:c.actions,readonly:n,onActionsChange:h=>s({...c,actions:h.length?h:void 0})}),R?null:e.createElement(e.Fragment,null,e.createElement(d,{marginY:2},e.createElement(bt,{variant:"middle"})),e.createElement(vt,null,`Matched ${y.permissions.length} ${y.permissions.length===1?"permission":"permissions"}`)))),e.createElement(d,{mb:5,flex:1},e.createElement(d,{display:"flex",alignItems:"center"},e.createElement(Ur,{value:p,exclusive:!0,fullWidth:!0,"aria-label":"Decision result",onChange:(h,b)=>A(b)},e.createElement(st,{value:"allow","aria-label":"Decision allowed",disabled:n},"Allow"),e.createElement(st,{value:"deny","aria-label":"Decision denied",disabled:n},"Deny"),e.createElement(st,{value:"conditional","aria-label":"Decision conditionally allowed",disabled:!y.commonResourceType||n},"Conditional")),!E&&!n&&e.createElement(me,{title:on},e.createElement(wt,{className:r.infoIcon,color:"primary","aria-label":on}))))),p==="conditional"&&!!y.commonResourceType&&e.createElement(wa,{permissionCriteria:v,resourceType:y.commonResourceType,onUpdate:g,readonly:n}),!n&&e.createElement(d,{display:"flex",justifyContent:"flex-end"},e.createElement(k,{variant:"contained",color:"primary",className:r.saveButton,onClick:N,disabled:!T||!B},"Save"))))}const Sa=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 cn({invalid:t,name:n,value:l,onTextChange:a}){const r=Sa({invalid:t}),[o,i]=S(!1),[m,u]=S(null),c=Z(null),[s,p]=S(l);_(()=>{p(l)},[l]),wn(()=>{c.current&&m&&c.current.style.setProperty("width",`max(${m.getBoundingClientRect().width}px, 3ch)`)},[m,s]);const f=()=>{i(!1),p(l)},v=()=>{i(!1),a==null||a(s)},g=()=>{var E;o?v():(i(!0),(E=c.current)==null||E.focus())},y=E=>{var x;E.key==="Enter"&&((x=c.current)==null||x.blur()),E.key==="Escape"&&f()};return e.createElement(e.Fragment,null,e.createElement("div",{className:r.container},e.createElement("input",{"aria-label":n,className:r.input,name:n,ref:c,onChange:E=>p(E.target.value),onFocus:g,onBlur:v,onKeyDown:y,value:s}),e.createElement("span",{"aria-hidden":"true",className:r.hiddenSpan,ref:u},s),e.createElement(L,{onClick:g,size:"small"},o?e.createElement(Sl,{"aria-label":"Save title"}):e.createElement(kl,{"aria-label":"Edit title"}))))}const sn=t=>{if(t.success)return{};const n={};for(const l of t.error.issues)n[l.path.join(".")]=!0;return n},mn=({children:t,onConfirm:n,message:l,title:a})=>{const[r,o]=S(!1),i=()=>o(!1),m=()=>o(!0),u=()=>{n(),i()};return e.createElement(e.Fragment,null,t({onClick:m}),e.createElement(le,{open:r,onClose:i},e.createElement(De,null,e.createElement(d,{display:"flex",justifyContent:"space-between",alignItems:"center"},a)),e.createElement(q,null,e.createElement(Kn,null,l)),e.createElement(Le,null,e.createElement(k,{"aria-label":"Cancel action",color:"primary",onClick:i},"Cancel"),e.createElement(k,{"aria-label":"Confirm action",color:"secondary",onClick:u,variant:"contained"},"Confirm"))))},un=({helpText:t})=>e.createElement(d,{display:"flex",alignItems:"center"},e.createElement(d,{component:"span",mr:1},e.createElement(D,{variant:"body2",noWrap:!0},"Reorder")),e.createElement(me,{title:t},e.createElement(wt,{color:"primary","aria-label":t}))),dn=(t,n,l)=>{const a=n+l;if(a<0||a>=t.length)return t;const r=[...t];return[r[a],r[n]]=[r[n],r[a]],r},pn=({array:t,index:n,onReorder:l})=>{const a=n===0,r=n===t.length-1;return e.createElement(d,{display:"flex"},e.createElement(L,{disabled:a,onClick:()=>l(dn(t,n,-1)),"aria-label":"Move up",size:"small"},e.createElement($l,null)),e.createElement(L,{disabled:r,onClick:()=>l(dn(t,n,1)),"aria-label":"Move down",size:"small"},e.createElement(Rl,null)))},Ra=w(()=>({emptyStateImage:{width:"95%",zIndex:2,position:"relative",left:"50%",top:"50%",transform:"translate(-50%, 15%)"}}));function fn({src:t,alt:n}){const l=Ra();return e.createElement("img",{src:t,className:`${l.emptyStateImage} `,alt:n})}const $a="Use the arrows to change the order in which permission decisions are evaluated.";function Ia({diff:t,permissions:n,onReorderPermissions:l,onNewPermissionClick:a,onOpenPermission:r,onRemovePermissionClick:o,readonly:i=!1}){return e.createElement(e.Fragment,null,e.createElement(d,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(D,{variant:"h5"},"Permission Decisions"),!i&&n.length!==0&&e.createElement(k,{color:"primary",variant:"outlined",startIcon:e.createElement(Ke,null),onClick:a},"New")),e.createElement(He,null,e.createElement(We,null,e.createElement(V,null,!i&&e.createElement(P,{style:{width:0}},e.createElement(un,{helpText:$a})),e.createElement(P,null,"Match by"),e.createElement(P,null,"Decision"),e.createElement(P,null),!i&&e.createElement(P,null))),e.createElement(ze,null,n.length===0&&e.createElement(V,null,e.createElement(P,{colSpan:5},e.createElement(Ce,{title:"No permission decisions set",description:"Click the button below to create your first permission.",missing:{customImage:e.createElement(fn,{src:Il,alt:"No permission placeholder"})},action:e.createElement(k,{variant:"contained",color:"primary",onClick:a},"New permission decision")}))),n.map((m,u)=>e.createElement(V,{key:u},!i&&e.createElement(P,null,e.createElement(pn,{array:n,index:u,onReorder:l})),e.createElement(P,null,e.createElement(qn,{onClick:()=>r(u)},e.createElement(D,{variant:"body2",color:"primary"},nt(m)))),e.createElement(P,null,lr(m)),e.createElement(P,null,e.createElement(ge,{operation:t==null?void 0:t.permissions[m.id].operation})),!i&&e.createElement(P,{align:"right"},e.createElement(mn,{message:"Are you sure you want to remove this permission decision?",onConfirm:()=>o(u),title:"Remove?"},c=>e.createElement(L,{...c,"aria-label":"Remove permission decision",size:"small"},e.createElement(pe,null)))))))))}function Oa(){const{roleId:t,versionId:n}=ut();return Ue(t),Ue(n),e.createElement(ot,{policyId:n},e.createElement(Ba,{roleId:t}))}function Ba({roleId:t}){const{diff:n,updateLocalDraft:l,policy:a}=oe(),r=a.roles.find(h=>h.id===t),o=n==null?void 0:n.roles[t],[i,m]=S(null),[u,c]=S(!1),s=Be(),{NotFoundErrorPage:p}=s.getComponents(),f=J(),v=w(h=>({cardContainer:{margin:h.spacing(0)}}))();if(!r)return e.createElement(p,null);const g=r.name,y=h=>{const b=a.roles.findIndex(j=>j.id===h.id),$=[...a.roles];$.splice(b,1,h),l({...a,roles:$})},E=h=>{y({...r,name:h})},x=h=>{if(i===null)y({...r,permissions:[h,...r.permissions]});else{const b=[...r.permissions];b.splice(i,1,h),y({...r,permissions:b})}c(!1)},A=h=>{if(h==="*")y({...r,members:r.members==="*"?[]:"*"});else if(r.members==="*")y({...r,members:[h]});else{const b=r.members.includes(h)?r.members.filter($=>$!==h):[...r.members,h];y({...r,members:b.length===0?"*":b})}},R=h=>{y({...r,permissions:r.permissions.filter((b,$)=>h!==$)})},T=h=>{y({...r,permissions:h})},B=sn(ol.safeParse(r)).name,N=a.status!=="draft";return e.createElement(e.Fragment,null,e.createElement(qe,{pages:[{title:a.name,path:`../../../${a.id}`},{title:g}],header:e.createElement(Fe,{titleComponent:e.createElement(zt,null,a.name," \xA0\u01C0",N?e.createElement(e.Fragment,null,"\xA0",g):e.createElement(cn,{invalid:B,value:g,onTextChange:E}),e.createElement(ge,{operation:o==null?void 0:o.role.operation,size:"large"})),description:a.description},e.createElement(k,{variant:"outlined",color:"primary",onClick:()=>f("../..",{relative:"path"})},"Back to policy"))},e.createElement(W,{container:!0,className:v.cardContainer,spacing:4,direction:"row"},e.createElement(W,{item:!0,xs:6},e.createElement(K,null,e.createElement(Ir,{diff:o||null,role:r,policyId:a.id,onToggleMember:A,readonly:N}))),e.createElement(W,{item:!0,xs:6},e.createElement(K,null,e.createElement(Ia,{diff:o||null,permissions:r.permissions,onNewPermissionClick:()=>{m(null),c(!0)},onOpenPermission:h=>{m(h),c(!0)},onReorderPermissions:T,onRemovePermissionClick:R,readonly:N}))))),u&&e.createElement(ka,{rolePermission:i!==null?r.permissions[i]:void 0,onClose:()=>c(!1),onSave:x,readonly:N}))}const Ma="Use the arrows to change the order in which roles are evaluated.";function Fa({}){const{diff:t,policy:n,createNewRole:l,updateLocalDraft:a}=oe(),r=J(),o=La(n),i=n.status!=="draft",m=s=>{a({...n,roles:s})},u=s=>{a({...n,roles:n.roles.filter(({id:p})=>p!==s)})},c=()=>{r(`./roles/${l()}`)};return e.createElement(K,null,e.createElement(d,{display:"flex",justifyContent:"space-between",padding:2},e.createElement(D,{variant:"h3"},"Roles"),!i&&e.createElement(k,{color:"primary",variant:"outlined",startIcon:e.createElement(Ke,null),onClick:()=>c()},"New role")),e.createElement(He,null,e.createElement(We,null,e.createElement(V,null,!i&&e.createElement(P,{style:{width:0}},e.createElement(un,{helpText:Ma})),e.createElement(P,null,"Name"),e.createElement(P,null,"Users"),e.createElement(P,null,"Groups"),!i&&e.createElement(P,{style:{width:0}}))),e.createElement(ze,null,o.map((s,p)=>e.createElement(V,{key:p},!i&&e.createElement(P,null,e.createElement(pn,{array:n.roles,index:p,onReorder:m})),e.createElement(P,null,e.createElement(d,{alignItems:"center",display:"flex",gridGap:8},e.createElement(se,{to:`roles/${s.id}`},s.name),e.createElement(ge,{operation:t==null?void 0:t.roles[s.id].role.operation}))),e.createElement(P,null,s.userCount),e.createElement(P,null,s.groupCount),!i&&e.createElement(P,{align:"right"},e.createElement(mn,{message:"Are you sure you want to remove this role?",title:"Remove role?",onConfirm:()=>u(s.id)},f=>e.createElement(L,{...f,"aria-label":"Remove role",size:"small"},e.createElement(pe,null)))))))))}function La(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 ja=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 Ha({readonly:t}){const n=ja(),l=J(),{createNewRole:a}=oe(),r=()=>{const o=a();l(`./roles/${o}`)};return e.createElement(K,null,e.createElement(Qn,{title:"Roles",className:n.cardHeader}),e.createElement(Pe,{className:n.cardContent},t?e.createElement(Ce,{title:"No roles configured",missing:"content"}):e.createElement(Ce,{title:"No roles yet",description:"Click the button below to create your first role.",missing:{customImage:e.createElement(fn,{src:Ol,alt:"No roles placeholder"})},action:e.createElement(k,{variant:"contained",color:"primary",onClick:()=>r()},"New role")})))}function Wa(){const[t,n]=S(null),{canPublish:l,discardLocalDraft:a,exportPolicy:r,hasChanges:o,isValid:i,policy:m,publish:u,saveLocalDraftToServer:c}=oe();return e.createElement(e.Fragment,null,e.createElement(L,{onClick:s=>{n(s.currentTarget)}},e.createElement(Bl,null)),e.createElement(gt,{getContentAnchorEl:null,anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!t,onClose:()=>{n(null)},PaperProps:{style:{width:240}}},e.createElement(Ct,null,m.status==="draft"&&e.createElement(G,{disabled:!i,onClick:()=>c()},e.createElement(te,null,e.createElement(Ll,{fontSize:"small"})),e.createElement(ne,null,"Save")),e.createElement(G,{disabled:!l,onClick:()=>u()},e.createElement(te,null,e.createElement(Fl,{fontSize:"small"})),e.createElement(ne,null,"Publish")),m.status==="draft"&&e.createElement(G,{disabled:!o,onClick:()=>a()},e.createElement(te,null,e.createElement(Ml,{color:o?"secondary":"inherit",fontSize:"small"})),e.createElement(ne,null,e.createElement(D,{color:o?"secondary":"inherit"},"Discard changes")))),e.createElement(bt,null),e.createElement(Ct,null,e.createElement(G,{onClick:()=>r()},e.createElement(te,null,e.createElement(jl,{fontSize:"small"})),e.createElement(ne,null,"Export")))))}function za(){const{versionId:t}=ut();return Ue(t),e.createElement(ot,{policyId:t},e.createElement(Va,null))}function Va(){const{policy:t,updateLocalDraft:n}=oe(),l=o=>{n({...t,name:o})},a=sn(il.safeParse(t)).name,r=t.status!=="draft";return e.createElement(qe,{pages:[{title:t.name}],header:e.createElement(Fe,{title:t.name,titleComponent:e.createElement(e.Fragment,null,e.createElement(zt,null,r?t.name:e.createElement(cn,{invalid:a,name:"Policy name",value:t.name,onTextChange:l}),e.createElement(Bt,{status:t.status})),Ga(t))},e.createElement(Wa,null))},e.createElement(W,{item:!0,xs:12},t.roles.length>0?e.createElement(Fa,null):e.createElement(Ha,{readonly:r})))}function Ga(t){const n={created:"Created by ",published:"Last published by ",updated:"Last updated by "},{activityDateText:l,activityUser:a,timestamp:r}=Lt(t,n);return e.createElement(D,{variant:"body2"},e.createElement(D,{component:"span",display:"inline",variant:"body2"},`${l} ${a} `),e.createElement(Ft,{timestamp:r}))}function Ua(){const t=Be(),{NotFoundErrorPage:n}=t.getComponents();return e.createElement(Hl,{loading:e.createElement(xe,null),unauthorized:e.createElement(n,null)},e.createElement(Yl,null,e.createElement(Wl,null,e.createElement(An,null,e.createElement(Oe,{element:e.createElement(Dr,null),path:"/"}),e.createElement(Oe,{element:e.createElement(za,null),path:"/versions/:versionId"}),e.createElement(Oe,{element:e.createElement(Oa,null),path:"/versions/:versionId/roles/:roleId"})))))}export{Ua as RBACRoot};
|
|
3
|
-
//# sourceMappingURL=Root-bc165381.esm.js.map
|