Skip to content

Commit a96af29

Browse files
committed
Add ability to disable dangerous config warning from OB settings
Closes #888
1 parent 110ba86 commit a96af29

10 files changed

Lines changed: 62 additions & 5 deletions

File tree

OpenBullet2.Core/Models/Settings/GeneralSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public class GeneralSettings
8787
/// </summary>
8888
public bool WarnConfigNotSaved { get; set; } = true;
8989

90+
/// <summary>
91+
/// Whether to output a warning when selecting a config that might contain
92+
/// custom C# code or external program calls.
93+
/// </summary>
94+
public bool WarnDangerousConfig { get; set; } = true;
95+
9096
/// <summary>
9197
/// The default author to use when creating new configs.
9298
/// </summary>

OpenBullet2.Native/ViewModels/OBSettingsViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public bool WarnConfigNotSaved
5454
}
5555
}
5656

57+
public bool WarnDangerousConfig
58+
{
59+
get => General.WarnDangerousConfig;
60+
set
61+
{
62+
General.WarnDangerousConfig = value;
63+
OnPropertyChanged();
64+
}
65+
}
66+
5767
public string DefaultAuthor
5868
{
5969
get => General.DefaultAuthor;

OpenBullet2.Native/Views/Dialogs/MultiRunJobOptionsDialog.xaml.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ namespace OpenBullet2.Native.Views.Dialogs;
3434
public partial class MultiRunJobOptionsDialog : Page
3535
{
3636
private readonly IUiFactory uiFactory;
37+
private readonly OpenBulletSettingsService obSettingsService;
3738
private readonly Func<JobOptions, Task>? onAccept;
3839
private readonly MultiRunJobOptionsViewModel vm;
3940

4041
public MultiRunJobOptionsDialog(
4142
IUiFactory uiFactory,
43+
OpenBulletSettingsService obSettingsService,
4244
MultiRunJobOptionsViewModel vm,
4345
Func<JobOptions, Task>? onAccept)
44-
: this(uiFactory, vm, null, onAccept)
46+
: this(uiFactory, obSettingsService, vm, null, onAccept)
4547
{
4648
}
4749

4850
public MultiRunJobOptionsDialog(
4951
IUiFactory uiFactory,
52+
OpenBulletSettingsService obSettingsService,
5053
MultiRunJobOptionsViewModel vm,
5154
MultiRunJobOptions? options,
5255
Func<JobOptions, Task>? onAccept)
5356
{
5457
this.uiFactory = uiFactory;
58+
this.obSettingsService = obSettingsService;
5559
this.onAccept = onAccept;
5660
this.vm = vm;
5761
vm.Initialize(options);
@@ -127,7 +131,9 @@ private async void Accept(object sender, RoutedEventArgs e)
127131
return;
128132
}
129133

130-
if (vm.SelectedConfig is not null && vm.SelectedConfig.HasCSharpCode())
134+
if (obSettingsService.Settings.GeneralSettings.WarnDangerousConfig
135+
&& vm.SelectedConfig is not null
136+
&& vm.SelectedConfig.HasCSharpCode())
131137
{
132138
Alert.Warning("Potentially dangerous config", "The Config you selected might have some C# code in it" +
133139
" (or blocks that call external programs). Although C# can be helpful for config makers who want to" +

OpenBullet2.Native/Views/Pages/OBSettings.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
IsChecked="{Binding WarnConfigNotSaved}"
4444
VerticalContentAlignment="Center"
4545
Margin="5 10 0 0"/>
46+
<CheckBox Content="View warning when selecting a potentially dangerous config"
47+
IsChecked="{Binding WarnDangerousConfig}"
48+
VerticalContentAlignment="Center"
49+
Margin="5 10 0 0"/>
4650
<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
4751
<Label>Default author for new configs</Label>
4852
<TextBox Text="{Binding DefaultAuthor}"

OpenBullet2.Web.Tests/Integration/SettingsIntegrationTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public async Task GetSettings_Admin_Success()
150150
using var client = Factory.CreateClient();
151151
var openBulletSettings = GetRequiredService<OpenBulletSettingsService>();
152152
openBulletSettings.Settings.GeneralSettings.DefaultAuthor = "test";
153+
openBulletSettings.Settings.GeneralSettings.WarnDangerousConfig = false;
153154
await openBulletSettings.SaveAsync();
154155

155156
// Act
@@ -160,6 +161,7 @@ public async Task GetSettings_Admin_Success()
160161
Assert.True(result.IsSuccess);
161162
Assert.NotNull(result.Value);
162163
Assert.Equal("test", result.Value.GeneralSettings.DefaultAuthor);
164+
Assert.False(result.Value.GeneralSettings.WarnDangerousConfig);
163165
}
164166

165167
[Fact]
@@ -207,11 +209,16 @@ public async Task UpdateSettings_Admin_Success()
207209
using var client = Factory.CreateClient();
208210
var openBulletSettings = GetRequiredService<OpenBulletSettingsService>();
209211
openBulletSettings.Settings.GeneralSettings.DefaultAuthor = "test";
212+
openBulletSettings.Settings.GeneralSettings.WarnDangerousConfig = true;
210213
await openBulletSettings.SaveAsync();
211214

212215
var newSettings = new OpenBulletSettingsDto
213216
{
214-
GeneralSettings = new OBGeneralSettingsDto { DefaultAuthor = "test2" }
217+
GeneralSettings = new OBGeneralSettingsDto
218+
{
219+
DefaultAuthor = "test2",
220+
WarnDangerousConfig = false
221+
}
215222
};
216223

217224
// Act
@@ -221,7 +228,9 @@ public async Task UpdateSettings_Admin_Success()
221228
// Assert
222229
Assert.True(result.IsSuccess);
223230
Assert.Equal("test2", result.Value.GeneralSettings.DefaultAuthor);
231+
Assert.False(result.Value.GeneralSettings.WarnDangerousConfig);
224232
Assert.Equal("test2", openBulletSettings.Settings.GeneralSettings.DefaultAuthor);
233+
Assert.False(openBulletSettings.Settings.GeneralSettings.WarnDangerousConfig);
225234
}
226235

227236
[Fact]

OpenBullet2.Web/Dtos/Settings/OBGeneralSettingsDto.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class OBGeneralSettingsDto
2828
/// </summary>
2929
public bool WarnConfigNotSaved { get; set; } = true;
3030

31+
/// <summary>
32+
/// Whether to output a warning when selecting a config that might contain
33+
/// custom C# code or external program calls.
34+
/// </summary>
35+
public bool WarnDangerousConfig { get; set; } = true;
36+
3137
/// <summary>
3238
/// The default author to use when creating new configs.
3339
/// </summary>

openbullet2-web-client/src/app/main/components/configs/configs.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class ConfigsComponent implements OnInit {
171171
summary: 'Selected',
172172
detail: `Selected config ${resp.metadata.name}`,
173173
});
174-
if (config.dangerous) {
174+
if (config.dangerous && this.obSettings?.generalSettings.warnDangerousConfig !== false) {
175175
this.messageService.add({
176176
key: 'br',
177177
severity: 'warn',

openbullet2-web-client/src/app/main/components/jobs/edit-multi-run-job/edit-multi-run-job.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { DeactivatableComponent } from 'src/app/shared/guards/can-deactivate-for
3333
import { parseTimeSpan } from 'src/app/shared/utils/dates';
3434
import { FieldValidity } from 'src/app/shared/utils/forms';
3535
import { TimeSpan } from 'src/app/shared/utils/timespan';
36+
import { OBSettingsDto } from 'src/app/main/dtos/settings/ob-settings.dto';
3637
import { AddWordlistComponent } from '../../wordlists/add-wordlist/add-wordlist.component';
3738
import { UploadWordlistComponent } from '../../wordlists/upload-wordlist/upload-wordlist.component';
3839
import { SelectConfigComponent } from '../select-config/select-config.component';
@@ -102,6 +103,7 @@ export class EditMultiRunJobComponent implements DeactivatableComponent {
102103
mode: EditMode = EditMode.Edit;
103104
jobId: number | null = null;
104105
options: MultiRunJobOptionsDto | null = null;
106+
obSettings: OBSettingsDto | null = null;
105107
proxyGroups: ProxyGroupDto[] | null = null;
106108
wordlistTypes: string[] = [];
107109
botLimit = 200;
@@ -181,6 +183,10 @@ export class EditMultiRunJobComponent implements DeactivatableComponent {
181183
this.dataPoolWordlistType = settings.wordlistTypes[0].name;
182184
});
183185

186+
settingsService.getSettings().subscribe((settings) => {
187+
this.obSettings = settings;
188+
});
189+
184190
settingsService.getSystemSettings().subscribe((settings) => {
185191
this.botLimit = settings.botLimit;
186192
});
@@ -444,7 +450,7 @@ export class EditMultiRunJobComponent implements DeactivatableComponent {
444450
}
445451

446452
selectConfig(config: ConfigInfoDto) {
447-
if (config.dangerous) {
453+
if (config.dangerous && this.obSettings?.generalSettings.warnDangerousConfig !== false) {
448454
this.messageService.add({
449455
key: 'br',
450456
severity: 'warn',

openbullet2-web-client/src/app/main/components/ob-settings/ob-settings.component.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ <h3>General</h3>
6161
label="Show a warning when the currently loaded config was not saved and another one is loaded" />
6262
</div>
6363
</div>
64+
<div class="row my-3">
65+
<div class="col-12">
66+
<p-checkbox
67+
(onChange)="touched = true" ngDefaultControl
68+
[(ngModel)]="settings.generalSettings.warnDangerousConfig"
69+
[binary]="true" inputId="warnDangerousConfig"
70+
label="Show a warning when selecting a potentially dangerous config" />
71+
</div>
72+
</div>
6473
<div class="row my-3">
6574
<div class="col-12">
6675
<span class="mr-2">Default author on newly created configs</span>

openbullet2-web-client/src/app/main/dtos/settings/ob-settings.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface GeneralOBSettings {
2424
configSectionOnLoad: ConfigSection;
2525
autoSetRecommendedBots: boolean;
2626
warnConfigNotSaved: boolean;
27+
warnDangerousConfig: boolean;
2728
defaultAuthor: string;
2829
enableJobLogging: boolean;
2930
logBufferSize: number;

0 commit comments

Comments
 (0)