@@ -78,7 +78,6 @@ interface Props {
7878 docLinks : DocumentationLinksService ;
7979 http : HttpStart ;
8080 license : SecurityLicense ;
81- spacesEnabled : boolean ;
8281 uiCapabilities : Capabilities ;
8382 notifications : NotificationsStart ;
8483 fatalErrors : FatalErrorsSetup ;
@@ -221,14 +220,21 @@ function useRole(
221220 return [ role , setRole ] as [ Role | null , typeof setRole ] ;
222221}
223222
224- function useSpaces ( http : HttpStart , fatalErrors : FatalErrorsSetup , spacesEnabled : boolean ) {
225- const [ spaces , setSpaces ] = useState < Space [ ] | null > ( null ) ;
223+ function useSpaces ( http : HttpStart , fatalErrors : FatalErrorsSetup ) {
224+ const [ spaces , setSpaces ] = useState < { enabled : boolean ; list : Space [ ] } | null > ( null ) ;
226225 useEffect ( ( ) => {
227- ( spacesEnabled ? http . get ( '/api/spaces/space' ) : Promise . resolve ( [ ] ) ) . then (
228- fetchedSpaces => setSpaces ( fetchedSpaces ) ,
229- err => fatalErrors . add ( err )
226+ http . get ( '/api/spaces/space' ) . then (
227+ fetchedSpaces => setSpaces ( { enabled : true , list : fetchedSpaces } ) ,
228+ ( err : IHttpFetchError ) => {
229+ // Spaces plugin can be disabled and hence this endpoint can be unavailable.
230+ if ( err . response ?. status === 404 ) {
231+ setSpaces ( { enabled : false , list : [ ] } ) ;
232+ } else {
233+ fatalErrors . add ( err ) ;
234+ }
235+ }
230236 ) ;
231- } , [ http , fatalErrors , spacesEnabled ] ) ;
237+ } , [ http , fatalErrors ] ) ;
232238
233239 return spaces ;
234240}
@@ -278,7 +284,6 @@ export const EditRolePage: FunctionComponent<Props> = ({
278284 roleName,
279285 action,
280286 fatalErrors,
281- spacesEnabled,
282287 license,
283288 docLinks,
284289 uiCapabilities,
@@ -292,7 +297,7 @@ export const EditRolePage: FunctionComponent<Props> = ({
292297 const runAsUsers = useRunAsUsers ( userAPIClient , fatalErrors ) ;
293298 const indexPatternsTitles = useIndexPatternsTitles ( indexPatterns , fatalErrors , notifications ) ;
294299 const privileges = usePrivileges ( privilegesAPIClient , fatalErrors ) ;
295- const spaces = useSpaces ( http , fatalErrors , spacesEnabled ) ;
300+ const spaces = useSpaces ( http , fatalErrors ) ;
296301 const features = useFeatures ( getFeatures , fatalErrors ) ;
297302 const [ role , setRole ] = useRole (
298303 rolesAPIClient ,
@@ -432,8 +437,8 @@ export const EditRolePage: FunctionComponent<Props> = ({
432437 < EuiSpacer />
433438 < KibanaPrivilegesRegion
434439 kibanaPrivileges = { new KibanaPrivileges ( kibanaPrivileges , features ) }
435- spaces = { spaces }
436- spacesEnabled = { spacesEnabled }
440+ spaces = { spaces . list }
441+ spacesEnabled = { spaces . enabled }
437442 uiCapabilities = { uiCapabilities }
438443 canCustomizeSubFeaturePrivileges = { license . getFeatures ( ) . allowSubFeaturePrivileges }
439444 editable = { ! isRoleReadOnly }
@@ -517,7 +522,7 @@ export const EditRolePage: FunctionComponent<Props> = ({
517522 setFormError ( null ) ;
518523
519524 try {
520- await rolesAPIClient . saveRole ( { role, spacesEnabled } ) ;
525+ await rolesAPIClient . saveRole ( { role, spacesEnabled : spaces . enabled } ) ;
521526 } catch ( error ) {
522527 notifications . toasts . addDanger ( get ( error , 'data.message' ) ) ;
523528 return ;
@@ -552,7 +557,7 @@ export const EditRolePage: FunctionComponent<Props> = ({
552557 backToRoleList ( ) ;
553558 } ;
554559
555- const description = spacesEnabled ? (
560+ const description = spaces . enabled ? (
556561 < FormattedMessage
557562 id = "xpack.security.management.editRole.setPrivilegesToKibanaSpacesDescription"
558563 defaultMessage = "Set privileges on your Elasticsearch data and control access to your Kibana spaces."
0 commit comments