Add Warning for FB Employee
Summary: Add warning dialog when FB employee uses OSS Flipper Reviewed By: passy, danielbuechele Differential Revision: D16783408 fbshipit-source-id: 3e7e533c5b96d4204fc38570a4e65c23ac0aaa25
This commit is contained in:
committed by
Facebook Github Bot
parent
fc01f5536e
commit
b9e0aae1e4
55
src/chrome/WarningEmployee.tsx
Normal file
55
src/chrome/WarningEmployee.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2019-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {styled, FlexColumn, Text, Button, colors} from 'flipper';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
const Container = styled(FlexColumn)({
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: colors.light02,
|
||||
});
|
||||
|
||||
const Box = styled(FlexColumn)({
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
background: colors.white,
|
||||
borderRadius: 10,
|
||||
boxShadow: '0 1px 3px rgba(0,0,0,0.25)',
|
||||
paddingBottom: 16,
|
||||
});
|
||||
|
||||
const Warning = styled(Text)({
|
||||
fontSize: 24,
|
||||
fontWeight: 300,
|
||||
textAlign: 'center',
|
||||
margin: 16,
|
||||
});
|
||||
|
||||
const AckButton = styled(Button)({
|
||||
type: 'warning',
|
||||
});
|
||||
|
||||
export default function WarningEmployee(props: {
|
||||
onClick: (event: React.MouseEvent) => any;
|
||||
}) {
|
||||
return (
|
||||
<Container>
|
||||
<Box>
|
||||
<Warning>
|
||||
You are using the open-source version of Flipper. You will get access
|
||||
to more plugins. To use the internal version, please install it from
|
||||
Managed Software Center
|
||||
</Warning>
|
||||
<AckButton onClick={props.onClick}>Okay</AckButton>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -10,4 +10,5 @@ export default {
|
||||
bugReportButtonVisible: false,
|
||||
showLogin: false,
|
||||
showFlipperRating: false,
|
||||
warnFBEmployees: true,
|
||||
};
|
||||
|
||||
41
src/init.js
41
src/init.js
@@ -7,6 +7,7 @@
|
||||
|
||||
import {Provider} from 'react-redux';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {useState, useEffect} from 'react';
|
||||
import {ContextMenuProvider} from 'flipper';
|
||||
import GK from './fb-stubs/GK.tsx';
|
||||
import {init as initLogger} from './fb-stubs/Logger.tsx';
|
||||
@@ -22,7 +23,10 @@ import config from './utils/processConfig.tsx';
|
||||
import {stateSanitizer} from './utils/reduxDevToolsConfig.tsx';
|
||||
import {initLauncherHooks} from './utils/launcher.tsx';
|
||||
import initCrashReporter from './utils/electronCrashReporter.tsx';
|
||||
import fbConfig from './fb-stubs/config.tsx';
|
||||
import {isFBEmployee} from './utils/fbEmployee.js';
|
||||
import path from 'path';
|
||||
import WarningEmployee from './chrome/WarningEmployee.tsx';
|
||||
|
||||
const store = createStore(
|
||||
reducers,
|
||||
@@ -35,15 +39,34 @@ const bugReporter = new BugReporter(logger, store);
|
||||
|
||||
GK.init();
|
||||
|
||||
const AppFrame = () => (
|
||||
<TooltipProvider>
|
||||
<ContextMenuProvider>
|
||||
<Provider store={store}>
|
||||
<App logger={logger} bugReporter={bugReporter} />
|
||||
</Provider>
|
||||
</ContextMenuProvider>
|
||||
</TooltipProvider>
|
||||
);
|
||||
const AppFrame = () => {
|
||||
const [warnEmployee, setWarnEmployee] = useState(false);
|
||||
useEffect(() => {
|
||||
if (fbConfig.warnFBEmployees) {
|
||||
isFBEmployee().then(isEmployee => {
|
||||
setWarnEmployee(isEmployee);
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<ContextMenuProvider>
|
||||
<Provider store={store}>
|
||||
{warnEmployee ? (
|
||||
<WarningEmployee
|
||||
onClick={e => {
|
||||
setWarnEmployee(false);
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<App logger={logger} bugReporter={bugReporter} />
|
||||
)}
|
||||
</Provider>
|
||||
</ContextMenuProvider>
|
||||
</TooltipProvider>
|
||||
);
|
||||
};
|
||||
|
||||
function init() {
|
||||
// $FlowFixMe: this element exists!
|
||||
|
||||
25
src/utils/fbEmployee.js
Normal file
25
src/utils/fbEmployee.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2019-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
import util from 'util';
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
|
||||
const cmd = 'klist --json';
|
||||
const endWith = '@THEFACEBOOK.COM';
|
||||
|
||||
export function isFBEmployee(): Promise<boolean> {
|
||||
return exec(cmd).then(
|
||||
(stdobj: {stderr: string, stdout: string}) => {
|
||||
const principal = String(JSON.parse(stdobj.stdout).principal);
|
||||
|
||||
return principal.endsWith(endWith);
|
||||
},
|
||||
err => {
|
||||
return false;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user