Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v16] Enhance the clipboard sharing tooltip #44237

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions web/packages/teleport/src/DesktopSession/DesktopSession.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,41 @@ export const AnotherSessionActive = () => (
<DesktopSession {...props} showAnotherSessionActiveDialog={true} />
);

export const ClipboardSharingDisabledRbac = () => (
<DesktopSession
{...props}
fetchAttempt={{ status: 'success' }}
tdpConnection={{ status: 'success' }}
wsConnection={{ status: 'open' }}
clipboardSharingState={{ browserSupported: true, allowedByAcl: false }}
/>
);

export const ClipboardSharingDisabledIncompatibleBrowser = () => (
<DesktopSession
{...props}
fetchAttempt={{ status: 'success' }}
tdpConnection={{ status: 'success' }}
wsConnection={{ status: 'open' }}
clipboardSharingState={{ browserSupported: false, allowedByAcl: true }}
/>
);

export const ClipboardSharingDisabledBrowserPermissions = () => (
<DesktopSession
{...props}
fetchAttempt={{ status: 'success' }}
tdpConnection={{ status: 'success' }}
wsConnection={{ status: 'open' }}
clipboardSharingState={{
browserSupported: true,
allowedByAcl: true,
readState: 'granted',
writeState: 'denied',
}}
/>
);

export const Warnings = () => {
const client = fakeClient();
client.connect = async () => {
Expand Down
4 changes: 3 additions & 1 deletion web/packages/teleport/src/DesktopSession/DesktopSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import TdpClientCanvas from 'teleport/components/TdpClientCanvas';
import AuthnDialog from 'teleport/components/AuthnDialog';

import useDesktopSession, {
clipboardSharingMessage,
directorySharingPossible,
isSharingClipboard,
isSharingDirectory,
Expand All @@ -57,7 +58,6 @@ export function DesktopSession(props: State) {
tdpClient,
username,
hostname,
setClipboardSharingState,
directorySharingState,
setDirectorySharingState,
clientOnPngFrame,
Expand All @@ -80,6 +80,7 @@ export function DesktopSession(props: State) {
windowOnResize,
clientScreenSpecToRequest,
clipboardSharingState,
setClipboardSharingState,
onShareDirectory,
onCtrlAltDel,
warnings,
Expand Down Expand Up @@ -133,6 +134,7 @@ export function DesktopSession(props: State) {
canShareDirectory={directorySharingPossible(directorySharingState)}
isSharingDirectory={isSharingDirectory(directorySharingState)}
isSharingClipboard={isSharingClipboard(clipboardSharingState)}
clipboardSharingMessage={clipboardSharingMessage(clipboardSharingState)}
onShareDirectory={onShareDirectory}
onCtrlAltDel={onCtrlAltDel}
warnings={warnings}
Expand Down
8 changes: 3 additions & 5 deletions web/packages/teleport/src/DesktopSession/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function TopBar(props: Props) {
const {
userHost,
isSharingClipboard,
clipboardSharingMessage,
onDisconnect,
canShareDirectory,
isSharingDirectory,
Expand Down Expand Up @@ -73,11 +74,7 @@ export default function TopBar(props: Props) {
<FolderShared style={primaryOnTrue(isSharingDirectory)} pr={3} />
</HoverTooltip>
<HoverTooltip
tipContent={
isSharingClipboard
? 'Clipboard Sharing Enabled'
: 'Clipboard Sharing Disabled'
}
tipContent={clipboardSharingMessage}
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
transformOrigin={{ vertical: 'top', horizontal: 'center' }}
>
Expand Down Expand Up @@ -117,6 +114,7 @@ export const TopBarHeight = 40;
type Props = {
userHost: string;
isSharingClipboard: boolean;
clipboardSharingMessage: string;
canShareDirectory: boolean;
isSharingDirectory: boolean;
onDisconnect: VoidFunction;
Expand Down
20 changes: 20 additions & 0 deletions web/packages/teleport/src/DesktopSession/useDesktopSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,26 @@ export function isSharingClipboard(
);
}

/**
* Provides a user-friendly message indicating whether clipboard sharing is enabled,
* and the reason it is disabled.
*/
export function clipboardSharingMessage(state: ClipboardSharingState): string {
if (!state.allowedByAcl) {
return 'Clipboard Sharing disabled by Teleport RBAC.';
}
if (!state.browserSupported) {
return 'Clipboard Sharing is not supported in this browser.';
}
if (state.readState === 'denied' || state.writeState === 'denied') {
return 'Clipboard Sharing disabled due to browser permissions.';
}

return isSharingClipboard(state)
? 'Clipboard Sharing enabled.'
: 'Clipboard Sharing disabled.';
}

/**
* Determines whether directory sharing is/should-be possible based on whether it's allowed by the acl
* and whether it's supported by the browser.
Expand Down
Loading