Skip to content

Commit 8f46ac1

Browse files
authored
Add tenant-level setting for instance ID handling in agent installations. (#96)
1 parent 7b1c7b5 commit 8f46ac1

39 files changed

+1251
-172
lines changed

ControlR.Web.Client/Components/Dashboard.razor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public partial class Dashboard : IDisposable
4040
[Inject]
4141
public required NavigationManager NavMan { get; init; }
4242
[Inject]
43-
public required IUserSettingsProvider Settings { get; init; }
44-
[Inject]
4543
public required ISnackbar Snackbar { get; init; }
4644
[Inject]
45+
public required IUserPreferencesProvider UserPreferences { get; init; }
46+
[Inject]
4747
public required IUserTagStore UserTagStore { get; init; }
4848
[Inject]
4949
public required IDeviceContentWindowStore WindowStore { get; init; }
@@ -61,8 +61,8 @@ protected override async Task OnInitializedAsync()
6161
{
6262
await base.OnInitializedAsync();
6363

64-
_hideOfflineDevices = await Settings.GetHideOfflineDevices();
65-
_openDeviceInNewTab = await Settings.GetOpenDeviceInNewTab();
64+
_hideOfflineDevices = await UserPreferences.GetHideOfflineDevices();
65+
_openDeviceInNewTab = await UserPreferences.GetOpenDeviceInNewTab();
6666

6767
_disposables.AddRange(
6868
Messenger.Register<HubConnectionStateChangedMessage>(this, HandleHubConnectionStateChangedMessage),
@@ -100,7 +100,7 @@ private async Task HandleRefreshClicked()
100100
private async Task HideOfflineDevicesChanged(bool isChecked)
101101
{
102102
_hideOfflineDevices = isChecked;
103-
await Settings.SetHideOfflineDevices(isChecked);
103+
await UserPreferences.SetHideOfflineDevices(isChecked);
104104
await ReloadGridData();
105105
}
106106

@@ -218,7 +218,7 @@ private async Task OnSelectedTagsChanged(ImmutableArray<TagViewModel> tags)
218218
private async Task OpenDeviceInNewTabChanged(bool isChecked)
219219
{
220220
_openDeviceInNewTab = isChecked;
221-
await Settings.SetOpenDeviceInNewTab(isChecked);
221+
await UserPreferences.SetOpenDeviceInNewTab(isChecked);
222222
}
223223

224224
private async Task RefreshDeviceInfo(DeviceViewModel device)

ControlR.Web.Client/Components/Layout/BaseLayout.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class BaseLayout : LayoutComponentBase, IAsyncDisposable
2424
[Inject]
2525
public required ILazyInjector<ISnackbar> Snackbar { get; set; }
2626
[Inject]
27-
public required IUserSettingsProvider UserSettings { get; set; }
27+
public required IUserPreferencesProvider UserPreferences { get; set; }
2828

2929
protected Palette CurrentPalette => IsDarkMode
3030
? CustomTheme.PaletteDark
@@ -96,7 +96,7 @@ protected override async Task OnInitializedAsync()
9696
// No persisted state, this is SSR or first load
9797
if (IsAuthenticated)
9898
{
99-
CurrentThemeMode = await UserSettings.GetThemeMode();
99+
CurrentThemeMode = await UserPreferences.GetThemeMode();
100100
}
101101
await UpdateIsDarkMode();
102102

@@ -111,7 +111,7 @@ protected override async Task OnInitializedAsync()
111111
// Still need to load theme mode
112112
if (IsAuthenticated)
113113
{
114-
CurrentThemeMode = await UserSettings.GetThemeMode();
114+
CurrentThemeMode = await UserPreferences.GetThemeMode();
115115
}
116116
}
117117

ControlR.Web.Client/Components/Pages/Deploy.razor.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace ControlR.Web.Client.Components.Pages;
77
public partial class Deploy
88
{
99
private bool _addTags;
10+
private bool _appendInstanceId = true;
1011
private string? _deviceId;
1112
private IEnumerable<AgentInstallerKeyDto> _existingKeys = [];
1213
private string? _existingKeySecretInput;
@@ -16,6 +17,7 @@ public partial class Deploy
1617
private Guid? _installerKeyId;
1718
private string? _installerKeySecret;
1819
private InstallerKeyType _installerKeyType;
20+
private string? _instanceId;
1921
private string? _keyExpiration;
2022
private AgentInstallerKeyDto? _selectedExistingKey;
2123
private IEnumerable<TagResponseDto>? _selectedTags;
@@ -35,6 +37,8 @@ public partial class Deploy
3537
[Inject]
3638
public required ISnackbar Snackbar { get; init; }
3739
[Inject]
40+
public required ITenantSettingsProvider TenantSettingsProvider { get; init; }
41+
[Inject]
3842
public required TimeProvider TimeProvider { get; init; }
3943

4044
private static Func<string?, string?> DeviceIdValidator => deviceId =>
@@ -122,6 +126,9 @@ protected override async Task OnInitializedAsync()
122126
_tenantId = tenantId;
123127
}
124128

129+
_appendInstanceId = await TenantSettingsProvider.GetAppendInstanceId();
130+
_instanceId = await TenantSettingsProvider.GetInstanceId();
131+
125132
var result = await ControlrApi.UserTags.GetAllowedTags();
126133
if (result.IsSuccess)
127134
{
@@ -294,7 +301,12 @@ private async Task GenerateUsageBasedKey()
294301
private string GetCommonArgs()
295302
{
296303
var serverUri = GetServerUri();
297-
var args = $"-s {serverUri} -i {serverUri.Authority} -t {_tenantId} -ks {_installerKeySecret}";
304+
var args = $"-s {serverUri} -t {_tenantId} -ks {_installerKeySecret}";
305+
306+
if (GetEffectiveInstanceId() is { } instanceId)
307+
{
308+
args += $" -i {instanceId}";
309+
}
298310

299311
if (_installerKeyId.HasValue)
300312
{
@@ -317,6 +329,21 @@ private string GetCommonArgs()
317329
return args;
318330
}
319331

332+
private string? GetEffectiveInstanceId()
333+
{
334+
if (!_appendInstanceId)
335+
{
336+
return null;
337+
}
338+
339+
if (!string.IsNullOrWhiteSpace(_instanceId))
340+
{
341+
return _instanceId;
342+
}
343+
344+
return GetServerUri().Host;
345+
}
346+
320347
private string GetInstallerKeyDisplay(AgentInstallerKeyDto? key)
321348
{
322349
if (key is null)

ControlR.Web.Client/Components/Pages/DeviceAccess/RemoteControl.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public partial class RemoteControl : ViewportAwareComponent
2222
[Inject]
2323
public required IDialogService DialogService { get; init; }
2424
[Inject]
25+
public required IEffectiveUserPreferences EffectiveUserPreferences { get; init; }
26+
[Inject]
2527
public required ILogger<RemoteControl> Logger { get; init; }
2628
[Inject]
2729
public required NavigationManager NavManager { get; init; }
@@ -34,8 +36,6 @@ public partial class RemoteControl : ViewportAwareComponent
3436
[Inject]
3537
public required ISnackbar Snackbar { get; init; }
3638
[Inject]
37-
public required IUserSettingsProvider UserSettings { get; init; }
38-
[Inject]
3939
public required IHubConnection<IViewerHub> ViewerHub { get; init; }
4040
[Inject]
4141
public required IWebAssemblyHostEnvironment WebAssemblyEnv { get; init; }
@@ -352,14 +352,14 @@ private async Task<bool> StartRemoteControl(DesktopSession desktopSession, bool
352352
Snackbar.Add($"Starting remote control in system session {desktopSession.SystemSessionId}", Severity.Info);
353353
}
354354

355-
var notifyUser = await UserSettings.GetNotifyUserOnSessionStart();
355+
var notifyUserPreference = await EffectiveUserPreferences.GetNotifyUserOnSessionStart();
356356
var requestDto = new RemoteControlSessionRequestDto(
357357
session.SessionId,
358358
desktopRelayUri,
359359
session.TargetSystemSession,
360360
session.TargetProcessId,
361361
session.Device.Id,
362-
notifyUser,
362+
notifyUserPreference.Value,
363363
RequireConsent: false);
364364

365365
var remoteControlSessionResult = await ViewerHub.Server.RequestRemoteControlSession(session.Device.Id, requestDto);

ControlR.Web.Client/Components/Pages/DeviceAccess/VncRelay.razor.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ControlR.Libraries.Api.Contracts.Dtos.RemoteControlDtos;
2+
using ControlR.Web.Client.Models;
23
using ControlR.Libraries.Viewer.Common.State;
34
using ControlR.Libraries.WebSocketRelay.Client;
45
using Microsoft.AspNetCore.Components;
@@ -15,16 +16,14 @@ public partial class VncRelay
1516
[Inject]
1617
public required IDeviceState DeviceAccessState { get; init; }
1718
[Inject]
19+
public required IEffectiveUserPreferences EffectiveUserPreferences { get; init; }
20+
[Inject]
1821
public required ILogger<VncRelay> Logger { get; init; }
1922
[Inject]
2023
public required NavigationManager NavManager { get; init; }
2124
[Inject]
2225
public required ISnackbar Snackbar { get; init; }
2326
[Inject]
24-
public required ITenantSettingsProvider TenantSettings { get; init; }
25-
[Inject]
26-
public required IUserSettingsProvider UserSettings { get; init; }
27-
[Inject]
2827
public required IHubConnection<IViewerHub> ViewerHub { get; init; }
2928

3029
[JSInvokable]
@@ -83,8 +82,7 @@ private async Task RequestStreamingSessionFromAgent()
8382
Logger.LogInformation("Resolved NoVNC relay URI: {NoVncUri}", _noVncUri);
8483
Logger.LogInformation("Creating streaming session.");
8584

86-
var tenantNotifyUser = await TenantSettings.GetNotifyUserOnSessionStart();
87-
var notifyUser = tenantNotifyUser ?? await UserSettings.GetNotifyUserOnSessionStart();
85+
var notifyUserPreference = await EffectiveUserPreferences.GetNotifyUserOnSessionStart();
8886

8987
var deviceRelayUri = RelayUriBuilder.Build(
9088
baseUri: serverUri.ToWebsocketUri(),
@@ -101,7 +99,7 @@ private async Task RequestStreamingSessionFromAgent()
10199
deviceRelayUri,
102100
ViewerHub.ConnectionId ?? string.Empty,
103101
device.Id,
104-
notifyUser,
102+
notifyUserPreference.Value,
105103
_port);
106104

107105
var sessionResult = await ViewerHub.Server.RequestVncSession(device.Id, requestDto);

ControlR.Web.Client/Components/Pages/Settings.razor

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
@attribute [Authorize]
55

66
@inject ISnackbar Snackbar
7-
@inject IUserSettingsProvider UserSettings
8-
@inject ITenantSettingsProvider TenantSettings
7+
@inject IEffectiveUserPreferences EffectiveUserPreferences
8+
@inject IUserPreferencesProvider UserPreferences
99
@inject IClipboardManager ClipboardManager
1010
@inject AuthenticationStateProvider AuthState
1111
@inject IMessenger Messenger
@@ -65,11 +65,11 @@
6565
Show Notification to User
6666
</MudText>
6767

68-
@if (_tenantNotifySetting.HasValue)
68+
@if (_isNotifyUserEnforced)
6969
{
7070
<MudAlert Severity="Severity.Info" Class="mb-3">
7171
This setting is being enforced by your tenant administrator.
72-
@if (_tenantNotifySetting.Value)
72+
@if (_notifyUser)
7373
{
7474
<text>Users will always be notified when remote control sessions start.</text>
7575
}
@@ -83,7 +83,7 @@
8383
<MudCheckBox T="bool"
8484
@bind-Value:get="_notifyUser"
8585
@bind-Value:set="SetNotifyUser"
86-
Disabled="_tenantNotifySetting.HasValue"
86+
Disabled="_isNotifyUserEnforced"
8787
Label="Notify users when a remote control session starts" />
8888
</div>
8989

@@ -162,10 +162,10 @@
162162
@code {
163163

164164
private bool _notifyUser;
165+
private bool _isNotifyUserEnforced;
165166
private string _userDisplayName = "";
166167
private Guid? _tenantId;
167168
private Guid? _userId;
168-
private bool? _tenantNotifySetting;
169169
private ThemeMode _themeMode = ThemeMode.Auto;
170170
private KeyboardInputMode _keyboardInputMode = KeyboardInputMode.Auto;
171171
private ViewMode _viewMode = ViewMode.Fit;
@@ -183,20 +183,13 @@
183183
_userId = userId;
184184
}
185185

186-
// Check if tenant has enforced the notify user setting
187-
_tenantNotifySetting = await TenantSettings.GetNotifyUserOnSessionStart();
188-
189-
_notifyUser = await UserSettings.GetNotifyUserOnSessionStart();
190-
_userDisplayName = await UserSettings.GetUserDisplayName();
191-
_themeMode = await UserSettings.GetThemeMode();
192-
_keyboardInputMode = await UserSettings.GetKeyboardInputMode();
193-
_viewMode = await UserSettings.GetViewMode();
194-
195-
// If tenant setting is enforced, override the user setting display
196-
if (_tenantNotifySetting.HasValue)
197-
{
198-
_notifyUser = _tenantNotifySetting.Value;
199-
}
186+
var notifyUserPreference = await EffectiveUserPreferences.GetNotifyUserOnSessionStart();
187+
_notifyUser = notifyUserPreference.Value;
188+
_isNotifyUserEnforced = notifyUserPreference.IsTenantEnforced;
189+
_userDisplayName = await UserPreferences.GetUserDisplayName();
190+
_themeMode = await UserPreferences.GetThemeMode();
191+
_keyboardInputMode = await UserPreferences.GetKeyboardInputMode();
192+
_viewMode = await UserPreferences.GetViewMode();
200193

201194
await base.OnInitializedAsync();
202195
}
@@ -215,42 +208,41 @@
215208

216209
private async Task SetNotifyUser(bool value)
217210
{
218-
// Don't allow changes if tenant setting is enforced
219-
if (_tenantNotifySetting.HasValue)
211+
if (_isNotifyUserEnforced)
220212
{
221213
return;
222214
}
223215

224216
_notifyUser = value;
225-
await UserSettings.SetNotifyUserOnSessionStart(value);
217+
await UserPreferences.SetNotifyUserOnSessionStart(value);
226218
}
227219

228220
private async Task SetThemeMode(ThemeMode value)
229221
{
230222
_themeMode = value;
231-
await UserSettings.SetThemeMode(value);
223+
await UserPreferences.SetThemeMode(value);
232224
await Messenger.Send(new ThemeChangedMessage(value));
233225
Snackbar.Add("Theme updated", Severity.Success);
234226
}
235227

236228
private async Task SetKeyboardInputMode(KeyboardInputMode value)
237229
{
238230
_keyboardInputMode = value;
239-
await UserSettings.SetKeyboardInputMode(value);
231+
await UserPreferences.SetKeyboardInputMode(value);
240232
Snackbar.Add("Keyboard input mode updated", Severity.Success);
241233
}
242234

243235
private async Task SetUserDisplayName(string value)
244236
{
245237
_userDisplayName = value;
246-
await UserSettings.SetUserDisplayName(value);
238+
await UserPreferences.SetUserDisplayName(value);
247239
Snackbar.Add("Display name updated", Severity.Success);
248240
}
249241

250242
private async Task SetViewMode(ViewMode value)
251243
{
252244
_viewMode = value;
253-
await UserSettings.SetViewMode(value);
245+
await UserPreferences.SetViewMode(value);
254246
Snackbar.Add("View mode updated", Severity.Success);
255247
}
256248

0 commit comments

Comments
 (0)