fixing conflicts (#41896)

This commit is contained in:
James Gowdy 2019-07-24 18:17:05 +01:00 committed by GitHub
parent bcb81d3ec8
commit 91a1224a25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 22 deletions

View file

@ -68,3 +68,10 @@ export function getDefaultPrivileges(): Privileges {
canStartStopDataFrameJob: false,
};
}
export interface PrivilegesResponse {
capabilities: Privileges;
upgradeInProgress: boolean;
isPlatinumOrTrialLicense: boolean;
mlFeatureEnabledInSpace: boolean;
}

View file

@ -16,11 +16,14 @@ let privileges: Privileges = getDefaultPrivileges();
export function checkGetJobsPrivilege(kbnUrl: any): Promise<Privileges> {
return new Promise((resolve, reject) => {
getPrivileges().then(priv => {
privileges = priv;
// the minimum privilege for using ML with a platinum or trial license is being able to get the jobs list.
// all other functionality is controlled by the return privileges object
if (privileges.canGetJobs) {
getPrivileges().then(({ capabilities, isPlatinumOrTrialLicense }) => {
privileges = capabilities;
// the minimum privilege for using ML with a platinum or trial license is being able to get the transforms list.
// all other functionality is controlled by the return privileges object.
// if the license is basic (isPlatinumOrTrialLicense === false) then do not redirect,
// allow the promise to resolve as the separate license check will redirect then user to
// a basic feature
if (privileges.canGetJobs || isPlatinumOrTrialLicense === false) {
return resolve(privileges);
} else {
kbnUrl.redirect('/access-denied');
@ -32,9 +35,12 @@ export function checkGetJobsPrivilege(kbnUrl: any): Promise<Privileges> {
export function checkCreateJobsPrivilege(kbnUrl: any): Promise<Privileges> {
return new Promise((resolve, reject) => {
getPrivileges().then(priv => {
privileges = priv;
if (privileges.canCreateJob) {
getPrivileges().then(({ capabilities, isPlatinumOrTrialLicense }) => {
privileges = capabilities;
// if the license is basic (isPlatinumOrTrialLicense === false) then do not redirect,
// allow the promise to resolve as the separate license check will redirect then user to
// a basic feature
if (privileges.canCreateJob || isPlatinumOrTrialLicense === false) {
return resolve(privileges);
} else {
// if the user has no permission to create a job,
@ -48,8 +54,8 @@ export function checkCreateJobsPrivilege(kbnUrl: any): Promise<Privileges> {
export function checkFindFileStructurePrivilege(kbnUrl: any): Promise<Privileges> {
return new Promise((resolve, reject) => {
getPrivileges().then(priv => {
privileges = priv;
getPrivileges().then(({ capabilities }) => {
privileges = capabilities;
// the minimum privilege for using ML with a basic license is being able to use the datavisualizer.
// all other functionality is controlled by the return privileges object
if (privileges.canFindFileStructure) {
@ -64,8 +70,8 @@ export function checkFindFileStructurePrivilege(kbnUrl: any): Promise<Privileges
export function checkGetDataFrameJobsPrivilege(kbnUrl: any): Promise<Privileges> {
return new Promise((resolve, reject) => {
getPrivileges().then(priv => {
privileges = priv;
getPrivileges().then(({ capabilities }) => {
privileges = capabilities;
// the minimum privilege for using ML with a basic license is being able to use the data frames.
// all other functionality is controlled by the return privileges object
if (privileges.canGetDataFrameJobs) {
@ -80,8 +86,8 @@ export function checkGetDataFrameJobsPrivilege(kbnUrl: any): Promise<Privileges>
export function checkCreateDataFrameJobsPrivilege(kbnUrl: any): Promise<Privileges> {
return new Promise((resolve, reject) => {
getPrivileges().then(priv => {
privileges = priv;
getPrivileges().then(({ capabilities }) => {
privileges = capabilities;
if (
privileges.canCreateDataFrameJob &&
privileges.canPreviewDataFrameJob &&

View file

@ -7,19 +7,19 @@
import { ml } from '../services/ml_api_service';
import { setUpgradeInProgress } from '../services/upgrade_service';
import { Privileges, getDefaultPrivileges } from '../../common/types/privileges';
import { PrivilegesResponse } from '../../common/types/privileges';
export function getPrivileges(): Promise<Privileges> {
export function getPrivileges(): Promise<PrivilegesResponse> {
return new Promise((resolve, reject) => {
ml.checkMlPrivileges()
.then(({ capabilities, upgradeInProgress }) => {
if (upgradeInProgress === true) {
.then((resp: PrivilegesResponse) => {
if (resp.upgradeInProgress === true) {
setUpgradeInProgress(true);
}
resolve(capabilities);
resolve(resp);
})
.catch(() => {
reject(getDefaultPrivileges());
reject();
});
});
}

View file

@ -5,7 +5,7 @@
*/
import { Annotation } from '../../../common/types/annotations';
import { Privileges } from '../../../common/types/privileges';
import { PrivilegesResponse } from '../../../common/types/privileges';
// TODO This is not a complete representation of all methods of `ml.*`.
// It just satisfies needs for other parts of the code area which use
@ -37,7 +37,7 @@ declare interface Ml {
};
hasPrivileges(obj: object): Promise<any>;
checkMlPrivileges(): Promise<{ capabilities: Privileges; upgradeInProgress: boolean }>;
checkMlPrivileges(): Promise<PrivilegesResponse>;
esSearch: any;
getIndices(): Promise<EsIndex[]>;