@@ -68,8 +68,71 @@ function mockFeature(appName: string, typeName?: string) {
6868 } ) ;
6969}
7070
71+ function mockFeatureWithSubFeature ( appName : string , typeName : string ) {
72+ return new Feature ( {
73+ id : appName ,
74+ name : appName ,
75+ app : [ ] ,
76+ privileges : {
77+ all : {
78+ savedObject : {
79+ all : [ ] ,
80+ read : [ ] ,
81+ } ,
82+ ui : [ ] ,
83+ } ,
84+ read : {
85+ savedObject : {
86+ all : [ ] ,
87+ read : [ ] ,
88+ } ,
89+ ui : [ ] ,
90+ } ,
91+ } ,
92+ subFeatures : [
93+ {
94+ name : appName ,
95+ privilegeGroups : [
96+ {
97+ groupType : 'independent' ,
98+ privileges : [
99+ {
100+ id : 'doSomethingAlertRelated' ,
101+ name : 'sub feature alert' ,
102+ includeIn : 'all' ,
103+ alerting : {
104+ all : [ typeName ] ,
105+ } ,
106+ savedObject : {
107+ all : [ ] ,
108+ read : [ ] ,
109+ } ,
110+ ui : [ 'doSomethingAlertRelated' ] ,
111+ } ,
112+ {
113+ id : 'doSomethingAlertRelated' ,
114+ name : 'sub feature alert' ,
115+ includeIn : 'read' ,
116+ alerting : {
117+ read : [ typeName ] ,
118+ } ,
119+ savedObject : {
120+ all : [ ] ,
121+ read : [ ] ,
122+ } ,
123+ ui : [ 'doSomethingAlertRelated' ] ,
124+ } ,
125+ ] ,
126+ } ,
127+ ] ,
128+ } ,
129+ ] ,
130+ } ) ;
131+ }
132+
71133const myAppFeature = mockFeature ( 'myApp' , 'myType' ) ;
72134const myOtherAppFeature = mockFeature ( 'myOtherApp' , 'myType' ) ;
135+ const myAppWithSubFeature = mockFeatureWithSubFeature ( 'myAppWithSubFeature' , 'myType' ) ;
73136const myFeatureWithoutAlerting = mockFeature ( 'myOtherApp' ) ;
74137
75138beforeEach ( ( ) => {
@@ -91,7 +154,12 @@ beforeEach(() => {
91154 async executor ( ) { } ,
92155 producer : 'myApp' ,
93156 } ) ) ;
94- features . getFeatures . mockReturnValue ( [ myAppFeature , myOtherAppFeature , myFeatureWithoutAlerting ] ) ;
157+ features . getFeatures . mockReturnValue ( [
158+ myAppFeature ,
159+ myOtherAppFeature ,
160+ myAppWithSubFeature ,
161+ myFeatureWithoutAlerting ,
162+ ] ) ;
95163} ) ;
96164
97165describe ( 'ensureAuthorized' , ( ) => {
@@ -460,7 +528,7 @@ describe('getFindAuthorizationFilter', () => {
460528 alertTypeRegistry . list . mockReturnValue ( setOfAlertTypes ) ;
461529
462530 expect ( ( await alertAuthorization . getFindAuthorizationFilter ( ) ) . filter ) . toMatchInlineSnapshot (
463- `"((alert.attributes.alertTypeId:myAppAlertType and alert.attributes.consumer:(alerts or myApp or myOtherApp)) or (alert.attributes.alertTypeId:alertingAlertType and alert.attributes.consumer:(alerts or myApp or myOtherApp)))"`
531+ `"((alert.attributes.alertTypeId:myAppAlertType and alert.attributes.consumer:(alerts or myApp or myOtherApp or myAppWithSubFeature )) or (alert.attributes.alertTypeId:alertingAlertType and alert.attributes.consumer:(alerts or myApp or myOtherApp or myAppWithSubFeature )))"`
464532 ) ;
465533
466534 expect ( auditLogger . alertsAuthorizationSuccess ) . not . toHaveBeenCalled ( ) ;
@@ -639,6 +707,7 @@ describe('filterByAlertTypeAuthorization', () => {
639707 "alerts",
640708 "myApp",
641709 "myOtherApp",
710+ "myAppWithSubFeature",
642711 ],
643712 "defaultActionGroupId": "default",
644713 "id": "myAppAlertType",
@@ -652,6 +721,7 @@ describe('filterByAlertTypeAuthorization', () => {
652721 "alerts",
653722 "myApp",
654723 "myOtherApp",
724+ "myAppWithSubFeature",
655725 ],
656726 "defaultActionGroupId": "default",
657727 "id": "alertingAlertType",
0 commit comments