forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure user profile for granular app privs (elastic#23750)
merging to feature branch for further development
- Loading branch information
Showing
23 changed files
with
399 additions
and
5 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/core_plugins/kibana/public/discover/discover_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { uiModules } from 'ui/modules'; | ||
|
||
uiModules.get('kibana') | ||
.provider('discoverConfig', () => { | ||
return { | ||
$get() { | ||
return { | ||
getHideWriteControls() { | ||
return false; | ||
} | ||
}; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { uiModules } from '../../modules'; | ||
|
||
export function initConfig() { | ||
uiModules.get('kibana') | ||
.provider('chromeConfig', () => { | ||
return { | ||
$get() { | ||
return { | ||
shouldHideNavLink() { | ||
return false; | ||
} | ||
}; | ||
} | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { Capabilities, UserProfile } from './user_profile'; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/xpack_main/common/user_profile/capabilities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface Capabilities { | ||
[capability: string]: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
export { Capabilities } from './capabilities'; | ||
export { UserProfile } from './user_profile'; |
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/xpack_main/common/user_profile/user_profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Capabilities } from './capabilities'; | ||
|
||
export class UserProfile { | ||
private capabilities: Capabilities; | ||
constructor(profileData: Capabilities = {}) { | ||
this.capabilities = { | ||
...profileData, | ||
}; | ||
} | ||
|
||
public hasCapability(capability: string, defaultValue: boolean = true): boolean { | ||
return capability in this.capabilities ? this.capabilities[capability] : defaultValue; | ||
} | ||
|
||
public canAccessFeature(feature: string, defaultValue: boolean = true): boolean { | ||
return this.hasCapability(`ui:${feature}/read`, defaultValue); | ||
} | ||
|
||
public canReadSavedObject(savedObjectType: string, defaultValue: boolean = true): boolean { | ||
return this.hasCapability(`saved_objects/${savedObjectType}/get`, defaultValue); | ||
} | ||
|
||
public canWriteSavedObject(savedObjectType: string, defaultValue: boolean = true): boolean { | ||
return this.hasCapability(`saved_objects/${savedObjectType}/create`, defaultValue); | ||
} | ||
|
||
public toJSON() { | ||
return { | ||
...this.capabilities, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import chrome from 'ui/chrome'; | ||
// @ts-ignore | ||
import { uiModules } from 'ui/modules'; | ||
import { UserProfile } from '../../common'; | ||
|
||
uiModules.get('userProfile').provider('userProfile', function userProfileProvider() { | ||
// @ts-ignore | ||
this.$get = () => { | ||
return new UserProfile(chrome.getInjected('userProfileData')); | ||
}; | ||
}); |
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/xpack_main/public/hacks/user_profile_config_decorators.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { uiModules } from 'ui/modules'; | ||
|
||
uiModules.get('kibana') | ||
.config(($provide, $injector) => { | ||
if ($injector.has('dashboardConfig')) { | ||
$provide.decorator('dashboardConfig', function ($delegate, userProfile) { | ||
return { | ||
getHideWriteControls() { | ||
if (!userProfile.canWriteSavedObject('dashboard')) { | ||
return true; | ||
} | ||
|
||
return $delegate.getHideWriteControls(); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
if ($injector.has('discoverConfig')) { | ||
$provide.decorator('discoverConfig', function ($delegate, userProfile) { | ||
return { | ||
getHideWriteControls() { | ||
if (!userProfile.canWriteSavedObject('search')) { | ||
return true; | ||
} | ||
|
||
return $delegate.getHideWriteControls(); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
if ($injector.has('chromeConfig')) { | ||
$provide.decorator('chromeConfig', function ($delegate, userProfile) { | ||
return { | ||
shouldHideNavLink(navLink) { | ||
if (!userProfile.canAccessFeature(navLink.id)) { | ||
return true; | ||
} | ||
|
||
return $delegate.shouldHideNavLink(navLink); | ||
} | ||
}; | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.