Skip to content
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
133 changes: 133 additions & 0 deletions frontend/src/components/DeviceAppSetting.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { describe, it, expect, vi } from 'vitest'

vi.mock('../services/post', () => ({ post: vi.fn() }))
vi.mock('../services/graphQL', () => ({ graphQLBasicRequest: vi.fn(), graphQLGetErrors: vi.fn() }))
vi.mock('../hooks/useDeviceSettings', () => ({ useDeviceSettings: () => ({ setting: vi.fn() }) }))
vi.mock('./ListItemSetting', () => ({
ListItemSetting: ({ label, subLabel, toggle, disabled, onClick }: any) => (
<button data-row data-on={String(toggle)} disabled={disabled} onClick={onClick}>
{label}
{subLabel ? ` — ${subLabel}` : ''}
</button>
),
}))
vi.mock('./SelectSetting', () => ({
SelectSetting: ({ value, values, disabled, helperText, onChange }: any) => (
<div data-select data-value={value} data-disabled={String(!!disabled)}>
{values.map((v: any) => (
<button key={v.key} data-choice={v.key} disabled={disabled} onClick={() => onChange(v.key)} />
))}
{helperText}
</div>
),
}))
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (_key: string, text: string, values?: any) => text.replace(/{{(\w+)}}/g, (_, k) => values?.[k] ?? ''),
}),
}))

import { DeviceAppSetting } from './DeviceAppSetting'
import type { DeviceAppSetting as Setting } from '../services/graphQLDeviceApps'
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true

// The console's "Allow AI commands" (forcible: its administrator may hold it on as well as off).
const aiCommands = (control: string, more: Partial<Setting> = {}): Setting => ({
name: 'ai_commands',
type: 'bool',
label: 'Allow AI commands',
help: 'Commands an AI runs on this device through MCP, as the people you allow',
default: true,
value: true,
at: null,
by: null,
onDevice: false,
control: control as any,
locked: null,
choices: null,
deprecated: null,
...more,
})

async function render(setting: Setting, onChange = vi.fn()) {
const container = document.createElement('div')
await act(async () =>
createRoot(container).render(
<DeviceAppSetting setting={setting} label={setting.label} help={setting.help} onChange={onChange} />
)
)
return container
}
const row = (page: HTMLElement) => page.querySelector('[data-row]') as HTMLButtonElement

describe('an app setting its device’s administrator holds', () => {
it('ai_commands held off: off, greyed, "Set by this device’s administrator" — no change offered', async () => {
const onChange = vi.fn()
const page = await render(aiCommands('off', { value: false }), onChange)
expect(row(page).dataset.on).toBe('false')
expect(row(page).disabled).toBe(true)
expect(row(page).textContent).toBe('Allow AI commands — Set by this device’s administrator')
await act(async () => row(page).click())
expect(onChange).not.toHaveBeenCalled()
})

it('ai_commands held on: on, greyed, said the same', async () => {
const page = await render(aiCommands('on', { value: true }))
expect(row(page).dataset.on).toBe('true')
expect(row(page).disabled).toBe(true)
expect(row(page).textContent).toBe('Allow AI commands — Set by this device’s administrator')
})

it('held by its administrator and its product: both said', async () => {
const page = await render(
aiCommands('off', { value: false, locked: { product: 'Kiosks', level: 'enforced' } as any })
)
expect(row(page).textContent).toBe(
'Allow AI commands — Set by this device’s administrator · Managed by product Kiosks (enforced)'
)
})

it('not held: switched here, its help said; local is set on the device only; its product’s lock alone as before', async () => {
for (const control of ['cloud+local', 'cloud']) {
const onChange = vi.fn()
const page = await render(aiCommands(control), onChange)
expect(row(page).disabled).toBe(false)
expect(row(page).textContent).toBe(
'Allow AI commands — Commands an AI runs on this device through MCP, as the people you allow'
)
await act(async () => row(page).click())
expect(onChange).toHaveBeenCalledWith(false)
}
const local = await render(aiCommands('local'))
expect(row(local).disabled).toBe(true)
expect(row(local).textContent).toBe('Allow AI commands — Set only on the device')
const product = await render(aiCommands('cloud+local', { locked: { product: 'Kiosks', level: 'synced' } as any }))
expect(row(product).disabled).toBe(true)
expect(row(product).textContent).toBe('Allow AI commands — Set by its product Kiosks')
})

it('a choice it fixes: that choice, greyed, said the same', async () => {
const mode: Setting = {
...aiCommands('nightly'),
name: 'mode',
type: 'choice',
label: 'Back up',
help: null,
value: 'nightly',
default: 'hourly',
choices: [
{ value: 'hourly', label: 'Every hour' },
{ value: 'nightly', label: 'Every night' },
],
}
const page = await render(mode)
const select = page.querySelector('[data-select]') as HTMLElement
expect(select.dataset.value).toBe('nightly')
expect(select.dataset.disabled).toBe('true')
expect(select.textContent).toBe('Set by this device’s administrator')
const free = await render({ ...mode, control: 'cloud+local' as any })
expect((free.querySelector('[data-select]') as HTMLElement).dataset.disabled).toBe('false')
})
})
23 changes: 21 additions & 2 deletions frontend/src/components/DeviceAppSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button, ListItem, TextField } from '@mui/material'
import type { TFunction } from 'i18next'
import { AppStringRules, DeviceAppSetting as Setting } from '../services/graphQLDeviceApps'
import { settingLocked } from '../services/graphQLDeviceSettings'
import { productLockNote } from '../helpers/productPolicyHelper'
import { DeviceSettingChoice, DeviceSettingRow, deprecatedLine, settingNote } from './DeviceSettingRow'
import { spacing } from '../styling'

Expand Down Expand Up @@ -43,9 +44,25 @@ export const DeviceAppSetting: React.FC<Props> = props => {
)
}

// Whether the device's administrator holds the setting (graphql's DeviceAppSetting.control, the device's
// `<app>.<name>_control`): off, on (where its release says forcible, as the console's ai_commands) or a choice it fixes.
// The device applies the held value, and graphql refuses a change to it.
export const adminHolds = (setting: Setting) =>
!!setting.control && !['cloud+local', 'cloud', 'local'].includes(setting.control)

/* Why an app's setting is as it is, where that is not the portal's doing: held by the device's administrator — and by
its product too, where its product locks it — else what a device setting's row says (set only on the device, its
product's lock, a change made on the device). None for one set here. */
export function appSettingNote(t: TFunction, setting: Setting): string | undefined {
if (!adminHolds(setting)) return settingNote(t, setting)
const held = t('deviceApps.settingAdminHeld', 'Set by this device’s administrator')
return setting.locked ? `${held} · ${productLockNote(t, setting.locked)}` : held
}

const AppSettingControl: React.FC<Props> = ({ setting, label, help, disabled, onChange }) => {
const { t } = useTranslation()
const deprecated = deprecatedLine(t, setting.deprecated)
const note = appSettingNote(t, setting)

switch (setting.type) {
case 'bool':
Expand All @@ -55,7 +72,8 @@ const AppSettingControl: React.FC<Props> = ({ setting, label, help, disabled, on
hideIcon
disableGutters
label={label}
subLabel={help}
subLabel={note || help}
quiet
deprecated={setting.deprecated}
disabled={disabled}
onChange={onChange}
Expand All @@ -71,6 +89,7 @@ const AppSettingControl: React.FC<Props> = ({ setting, label, help, disabled, on
label={label}
value={fixed ? setting.control : String(setting.value ?? '')}
choices={choices}
why={note}
note={deprecated || help || undefined}
disabled={disabled}
onChange={onChange}
Expand Down Expand Up @@ -148,7 +167,7 @@ const AppSettingField: React.FC<Props> = ({ setting, label, help, disabled, onCh
onChange(list ? listItems(text) : text)
}

const note = [deprecatedLine(t, setting.deprecated), settingNote(t, setting) || help].filter(Boolean).join(' · ')
const note = [deprecatedLine(t, setting.deprecated), appSettingNote(t, setting) || help].filter(Boolean).join(' · ')
const max = setting.type === 'string' ? setting.declaration?.string?.max : undefined

return (
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/DeviceApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export const DeviceApps: React.FC<{ device: IDevice }> = ({ device }) => {

/* Open, for any app reached as a service (serviceId) while it runs: its service's connection, started and launched as
its application type launches (graphql makes the type from the manifest's protocol: http and https open in the
browser, vnc and rdp in a viewer), as any service's Connect page does; said by its protocol (Open page, Open
screen). One whose service
browser, vnc and rdp in a viewer, udp nothing: a port for the person's own UDP client), as any service's Connect
page does; said by its protocol (Open page, Open screen, Connect). One whose service
opens as a terminal (helpers/sshHelper opensTerminal) has Open terminal instead (components/AppTerminal). */
export const AppOpen: React.FC<{ device: IDevice; app: DeviceApp }> = ({ device, app }) => {
const { t } = useTranslation()
Expand All @@ -230,7 +230,8 @@ export const AppOpen: React.FC<{ device: IDevice; app: DeviceApp }> = ({ device,
onClick={() =>
history.push({
pathname: `/devices/${device.id}/${app.serviceId}/connect`,
state: { autoConnect: true, autoLaunch: true },
// A udp service's connection is all it has: its port is for the person's own UDP client.
state: app.protocol === 'udp' ? { autoConnect: true } : { autoConnect: true, autoLaunch: true },
})
}
>
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/DeviceSettingRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ export const DeviceSettingChoice: React.FC<{
value: string // the value standing, as the setting's control fixes it
choices: ISelect[]
note?: React.ReactNode // the setting's state, below who set it
why?: string // who set it, or why it is fixed, in the caller's words (an app's setting); else a device setting's
disabled?: boolean
onChange: (value: string) => void
}> = ({ setting, icon, hideIcon, label, value, choices, note, disabled, onChange }) => {
}> = ({ setting, icon, hideIcon, label, value, choices, note, why: said, disabled, onChange }) => {
const { t } = useTranslation()
const fixed = choices.find(choice => choice.key === setting.control)
const why = fixed
? t('deviceSetting.controlFixedTo', "Set to {{value}} by the device's administrator", { value: fixed.name })
: settingNote(t, setting)
const why =
said ??
(fixed
? t('deviceSetting.controlFixedTo', "Set to {{value}} by the device's administrator", { value: fixed.name })
: settingNote(t, setting))
return (
<SelectSetting
icon={icon}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/helpers/appsHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('an app’s icon and service, from what the API says — never its id',
expect(appIcon('https')).toBe('globe')
expect(appIcon('http')).toBe('globe')
expect(appIcon('tcp')).toBe('cube')
expect(appIcon('udp')).toBe('cube')
expect(appIcon(null)).toBe('cube')
})

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/helpers/appsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export const appIcon = (protocol?: string | null) =>
? 'desktop'
: 'cube'

// Open, in the words of how its service opens (its protocol): a page, a screen, else its service's connection.
// Open, in the words of how its service opens (its protocol): a page, a screen, a UDP service's connection (nothing to
// launch: the person's own UDP client uses its port), else its service's connection.
export function openWord(t: TFunction, protocol?: string | null): string {
switch (protocol) {
case 'udp':
return t('deviceApps.connect', 'Connect')
case 'http':
case 'https':
return t('deviceApps.openPage', 'Open page')
Expand Down
1 change: 1 addition & 0 deletions frontend/src/helpers/sshHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('sshHelper', () => {
).toBe(true)
expect(opensTerminal({ protocol: 'ssh', capabilities: ['ssh-exec'] })).toBe(false)
expect(opensTerminal({ protocol: 'https', capabilities: ['person-certificates'] })).toBe(false)
expect(opensTerminal({ protocol: 'udp', capabilities: ['person-certificates'] })).toBe(false)
expect(opensTerminal({ protocol: null, capabilities: [] })).toBe(false)
expect(opensTerminal(undefined)).toBe(false)
})
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/de/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
"searchDevices": "",
"service": "",
"serviceLine": "",
"serviceLineUdp": "",
"servicePort": "",
"serviceStopped": "",
"sessionAs": "als {{login}}",
Expand Down Expand Up @@ -1174,6 +1175,7 @@
"beta": "",
"between": "Von {{min}} bis {{max}}",
"clearDeprecated": "Leeren: zurück zum Standard",
"connect": "",
"consented": "Als root zugestimmt von {{by}}, {{when}}",
"consentedCarried": "Läuft als root, wie schon bevor Zustimmungen gespeichert wurden",
"consentedConverted": "",
Expand Down Expand Up @@ -1207,6 +1209,7 @@
"screenviewOld": "ScreenView wurde auf die alte Weise installiert.",
"screenviewOldHelp": "Wechseln Sie zur ScreenView-App: von remote.it aktuell gehalten, mit ihren Einstellungen hier. Sie läuft als root, daher wird zuerst gefragt.",
"screenviewSwitch": "Zur App wechseln",
"settingAdminHeld": "",
"stable": "",
"starting": "",
"startingDetail": "",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
"searchDevices": "Search devices…",
"service": "Service",
"serviceLine": "{{name}} · port {{port}}",
"serviceLineUdp": "{{name}} · UDP port {{port}}",
"servicePort": "Port people connect to",
"serviceStopped": "Stopped while the app is disabled: enable it to open it",
"sessionAs": "as {{login}}",
Expand Down Expand Up @@ -1174,6 +1175,7 @@
"beta": "Beta",
"between": "From {{min}} to {{max}}",
"clearDeprecated": "Clear: back to its default",
"connect": "Connect",
"consented": "Consented to run as root by {{by}}, {{when}}",
"consentedCarried": "Runs as root, as it did before consents were kept",
"consentedConverted": "Runs as root, as its old install did: switched to the app by remote.it, {{when}}",
Expand Down Expand Up @@ -1207,6 +1209,7 @@
"screenviewOld": "ScreenView was installed the old way.",
"screenviewOldHelp": "Switch to the ScreenView app: kept up to date by remote.it, with its settings here. It runs as root, so it asks first.",
"screenviewSwitch": "Switch to the app",
"settingAdminHeld": "Set by this device’s administrator",
"stable": "Stable",
"starting": "Starting — waiting for the device to say so",
"startingDetail": "Starting — {{detail}}",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/es/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"searchDevices": "",
"service": "",
"serviceLine": "",
"serviceLineUdp": "",
"servicePort": "",
"serviceStopped": "",
"sessionAs": "como {{login}}",
Expand Down Expand Up @@ -1188,6 +1189,7 @@
"beta": "",
"between": "De {{min}} a {{max}}",
"clearDeprecated": "Borrar: volver al valor predeterminado",
"connect": "",
"consented": "Consentimiento para ejecutarse como root de {{by}}, {{when}}",
"consentedCarried": "Se ejecuta como root, como antes de que se guardaran los consentimientos",
"consentedConverted": "",
Expand Down Expand Up @@ -1221,6 +1223,7 @@
"screenviewOld": "ScreenView se instaló de la forma antigua.",
"screenviewOldHelp": "Cambie a la app ScreenView: remote.it la mantiene actualizada, con sus ajustes aquí. Se ejecuta como root, así que primero se le pregunta.",
"screenviewSwitch": "Cambiar a la app",
"settingAdminHeld": "",
"stable": "",
"starting": "",
"startingDetail": "",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/locales/ja/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
"searchDevices": "",
"service": "",
"serviceLine": "",
"serviceLineUdp": "",
"servicePort": "",
"serviceStopped": "",
"sessionAs": "{{login}} として",
Expand Down Expand Up @@ -1160,6 +1161,7 @@
"beta": "",
"between": "{{min}} から {{max}} まで",
"clearDeprecated": "クリア: 既定値に戻す",
"connect": "",
"consented": "{{by}} が root での実行に同意 ({{when}})",
"consentedCarried": "同意が記録される前から root で実行",
"consentedConverted": "",
Expand Down Expand Up @@ -1193,6 +1195,7 @@
"screenviewOld": "ScreenView は旧方式でインストールされています。",
"screenviewOldHelp": "ScreenView アプリに切り替えます: remote.it が最新に保ち、設定はここで行えます。root で実行されるため、最初に確認します。",
"screenviewSwitch": "アプリに切り替え",
"settingAdminHeld": "",
"stable": "",
"starting": "",
"startingDetail": "",
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/pages/DeviceAppPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ describe('its service, settings, root, delivery and problems', () => {
expect(await words('vnc')).toBe('Open screen')
expect(await words('rdp')).toBe('Open screen')
expect(await words('tcp')).toBe('Open')
expect(await words('udp')).toBe('Connect')
})

it('udp: a connection alone — its port, said UDP, for the person’s own UDP client; never a terminal or a page', async () => {
params.appID = 'acme.dns'
// Even one that declares person-certificates: only ssh opens a terminal.
apps.value.apps = [backup({ id: 'acme.dns', name: 'DNS', protocol: 'udp', capabilities: ['person-certificates'] })]
const page = await render()
expect(text(page, 'service')).toContain('Backup · UDP port 30001')
expect(page.querySelector('[data-app-terminal]')).toBeNull()
expect(page.querySelector('[data-app-open]')?.textContent).toBe('Connect')
await click(page.querySelector('[data-app-open]'))
expect(push).toHaveBeenCalledWith({ pathname: '/devices/D1/S7/connect', state: { autoConnect: true } })
})

it('a port its owner chooses is its service’s, edited under Service, not again under Settings', async () => {
Expand Down
Loading
Loading