Skip to content

Commit

Permalink
Remove Connect My Computer feature flag (#32835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious authored Oct 2, 2023
1 parent 10453b9 commit 3ea1e26
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 52 deletions.
4 changes: 0 additions & 4 deletions web/packages/teleterm/src/services/config/appConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ export const createAppConfigSchema = (platform: Platform) => {
'keymap.openSearchBar': shortcutSchema
.default(defaultKeymap['openSearchBar'])
.describe(getShortcutDesc('open the search bar')),
'feature.connectMyComputer': z
.boolean()
.default(false)
.describe('Enables sharing the computer.'),
'headless.skipConfirm': z
.boolean()
.default(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ function ShowState(props: {
new MockAppContext({ appVersion: cluster.proxyVersion });

appContext.mainProcessClient.getAgentState = () => props.agentProcessState;
appContext.configService.set('feature.connectMyComputer', true);
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { makeRootCluster } from 'teleterm/services/tshd/testHelpers';
import { MockAppContext } from 'teleterm/ui/fixtures/mocks';
import { MockAppContextProvider } from 'teleterm/ui/fixtures/MockAppContextProvider';

import { createMockConfigService } from 'teleterm/services/config/fixtures/mocks';

import { AgentProcessState } from 'teleterm/mainProcess/types';

import { NavigationMenu } from './NavigationMenu';
Expand Down Expand Up @@ -163,9 +161,6 @@ function ShowState({
proxyVersion: '17.0.0',
});
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.configService = createMockConfigService({
'feature.connectMyComputer': true,
});
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces[cluster.uri] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
makeRootCluster,
makeServer,
} from 'teleterm/services/tshd/testHelpers';
import { createMockConfigService } from 'teleterm/services/config/fixtures/mocks';

import {
AgentCompatibilityError,
Expand All @@ -42,7 +41,7 @@ import {
import type { IAppContext } from 'teleterm/ui/types';
import type { Cluster } from 'teleterm/services/tshd/types';

function getMocksWithConnectMyComputerEnabled() {
function getMocks() {
const rootCluster = makeRootCluster({
loggedInUser: makeLoggedInUser({
acl: {
Expand Down Expand Up @@ -73,9 +72,6 @@ function getMocksWithConnectMyComputerEnabled() {
accessRequests: undefined,
};
});
appContext.configService = createMockConfigService({
'feature.connectMyComputer': true,
});

return { appContext, rootCluster };
}
Expand All @@ -98,7 +94,7 @@ function renderUseConnectMyComputerContextHook(
}

test('startAgent re-throws errors that are thrown while spawning the process', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();
const eventEmitter = new EventEmitter();
const errorStatus: AgentProcessState = {
status: 'error',
Expand Down Expand Up @@ -150,7 +146,7 @@ test('startAgent re-throws errors that are thrown while spawning the process', a
});

test('starting the agent flips the workspace autoStart flag to true', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();

jest
.spyOn(appContext.connectMyComputerService, 'waitForNodeToJoin')
Expand All @@ -172,7 +168,7 @@ test('starting the agent flips the workspace autoStart flag to true', async () =
});

test('killing the agent flips the workspace autoStart flag to false', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();

const { result } = renderUseConnectMyComputerContextHook(
appContext,
Expand All @@ -187,7 +183,7 @@ test('killing the agent flips the workspace autoStart flag to false', async () =
});

test('failed autostart flips the workspace autoStart flag to false', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();

let currentAgentProcessState: AgentProcessState = {
status: 'not-started',
Expand Down Expand Up @@ -224,7 +220,7 @@ test('failed autostart flips the workspace autoStart flag to false', async () =>
});

test('starts the agent automatically if the workspace autoStart flag is true', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();

const eventEmitter = new EventEmitter();
let currentAgentProcessState: AgentProcessState = {
Expand Down Expand Up @@ -278,54 +274,35 @@ test('starts the agent automatically if the workspace autoStart flag is true', a
describe('canUse', () => {
const cases = [
{
name: 'should be true when the user has permissions and the feature flag is enabled',
name: 'should be true when the user has permissions',
hasPermissions: true,
isFeatureFlagEnabled: true,
isAgentConfigured: false,
expected: true,
},
{
name: 'should be true when the user does not have permissions, but the agent has been configured and the feature flag is enabled',
name: 'should be true when the user does not have permissions, but the agent has been configured',
hasPermissions: false,
isFeatureFlagEnabled: true,
isAgentConfigured: true,
expected: true,
},
{
name: 'should be false when the user does not have permissions, the agent has not been configured and the feature flag is enabled',
name: 'should be false when the user does not have permissions and the agent has not been configured',
hasPermissions: false,
isAgentConfigured: false,
isFeatureFlagEnabled: true,
expected: false,
},
{
name: 'should be false when the user has permissions and the agent is configured but the feature flag is disabled',
hasPermissions: true,
isAgentConfigured: true,
isFeatureFlagEnabled: false,
expected: false,
},
];

test.each(cases)(
'$name',
async ({
hasPermissions,
isAgentConfigured,
isFeatureFlagEnabled,
expected,
}) => {
const { appContext, rootCluster } =
getMocksWithConnectMyComputerEnabled();
async ({ hasPermissions, isAgentConfigured, expected }) => {
const { appContext, rootCluster } = getMocks();
// update Connect My Computer permissions
appContext.clustersService.setState(draftState => {
draftState.clusters.get(
rootCluster.uri
).loggedInUser.acl.tokens.create = hasPermissions;
});
appContext.configService = createMockConfigService({
'feature.connectMyComputer': isFeatureFlagEnabled,
});
const isAgentConfigFileCreated = Promise.resolve(isAgentConfigured);
jest
.spyOn(appContext.connectMyComputerService, 'isAgentConfigFileCreated')
Expand Down Expand Up @@ -353,7 +330,7 @@ describe('canUse', () => {
});

test('removing the agent shows a notification', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();

const { result } = renderUseConnectMyComputerContextHook(
appContext,
Expand All @@ -372,7 +349,7 @@ test('removing the agent shows a notification', async () => {
});

test('when the user does not have permissions to remove node a custom notification is shown', async () => {
const { appContext, rootCluster } = getMocksWithConnectMyComputerEnabled();
const { appContext, rootCluster } = getMocks();
jest
.spyOn(appContext.connectMyComputerService, 'removeConnectMyComputerNode')
.mockRejectedValue(new Error('access denied'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export const ConnectMyComputerContextProvider: FC<{
mainProcessClient,
connectMyComputerService,
clustersService,
configService,
workspacesService,
usageService,
} = ctx;
Expand All @@ -125,19 +124,18 @@ export const ConnectMyComputerContextProvider: FC<{
isAgentConfiguredAttempt.data;

const rootCluster = clustersService.findCluster(rootClusterUri);

const canUse = useMemo(() => {
const isFeatureFlagEnabled = configService.get(
'feature.connectMyComputer'
).value;
const hasPermissions = hasConnectMyComputerPermissions(
rootCluster,
mainProcessClient.getRuntimeSettings()
);

// We check `isAgentConfigured`, because the user should always have access to the agent after configuring it.
// https://github.com/gravitational/teleport/blob/master/rfd/0133-connect-my-computer.md#access-to-ui-and-autostart
return isFeatureFlagEnabled && (hasPermissions || isAgentConfigured);
}, [configService, isAgentConfigured, mainProcessClient, rootCluster]);
return hasPermissions || isAgentConfigured;
}, [isAgentConfigured, mainProcessClient, rootCluster]);

const agentCompatibility = useMemo(
() =>
checkAgentCompatibility(
Expand Down

0 comments on commit 3ea1e26

Please sign in to comment.