Skip to content

Commit 32954d5

Browse files
refactor: Replace WebFileTransportType with FileTransportType across controllers and view models
1 parent e278593 commit 32954d5

14 files changed

Lines changed: 36 additions & 48 deletions

src/XtremeIdiots.Portal.Web.Tests/Controllers/GameServersControllerTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using XtremeIdiots.Portal.Web.Controllers;
2222
using XtremeIdiots.Portal.Web.Models;
2323
using XtremeIdiots.Portal.Web.ViewModels;
24-
using WebFileTransportType = XtremeIdiots.Portal.Web.Models.FileTransportType;
2524

2625
namespace XtremeIdiots.Portal.Web.Tests.Controllers;
2726

@@ -257,7 +256,7 @@ public async Task Edit_WhenUserCannotEditFileTransport_PreservesExistingFileTran
257256
QueryPort = existingServer.QueryPort,
258257
AgentEnabled = existingServer.AgentEnabled,
259258
FileTransportEnabled = true,
260-
FileTransportType = WebFileTransportType.Sftp,
259+
FileTransportType = FileTransportType.Sftp,
261260
RconEnabled = existingServer.RconEnabled,
262261
BanFileSyncEnabled = existingServer.BanFileSyncEnabled,
263262
BanFileRootPath = existingServer.BanFileRootPath,
@@ -318,7 +317,7 @@ public async Task Edit_WhenUserSelectsSftp_PersistsTransportEnabledAndType()
318317
QueryPort = existingServer.QueryPort,
319318
AgentEnabled = false,
320319
FileTransportEnabled = true,
321-
FileTransportType = WebFileTransportType.Sftp,
320+
FileTransportType = FileTransportType.Sftp,
322321
RconEnabled = false,
323322
BanFileSyncEnabled = false,
324323
BanFileRootPath = "/",

src/XtremeIdiots.Portal.Web.Tests/Extensions/FileTransportCompatibilityExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using XtremeIdiots.Portal.Web.Extensions;
2-
using XtremeIdiots.Portal.Web.Models;
2+
using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1;
33

44
namespace XtremeIdiots.Portal.Web.Tests.Extensions;
55

src/XtremeIdiots.Portal.Web.Tests/Extensions/GameServerDtoExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void ToViewModel_WhenLegacyFtpEnabledWithoutFileTransportType_InfersFtp()
8989
var viewModel = dto.ToViewModel();
9090

9191
// Assert
92-
Assert.Equal(XtremeIdiots.Portal.Web.Models.FileTransportType.Ftp, viewModel.FileTransportType);
92+
Assert.Equal(FileTransportType.Ftp, viewModel.FileTransportType);
9393
}
9494

9595
[Fact]
@@ -102,6 +102,6 @@ public void ToViewModel_WhenFileTransportDisabledAndFtpDisabledWithoutFileTransp
102102
var viewModel = dto.ToViewModel();
103103

104104
// Assert
105-
Assert.Equal(XtremeIdiots.Portal.Web.Models.FileTransportType.Unknown, viewModel.FileTransportType);
105+
Assert.Equal(FileTransportType.Unknown, viewModel.FileTransportType);
106106
}
107107
}

src/XtremeIdiots.Portal.Web/Controllers/GameServersController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using MX.Observability.ApplicationInsights.Auditing;
1414
using XtremeIdiots.Portal.Web.Models;
1515
using XtremeIdiots.Portal.Web.ViewModels;
16-
using WebFileTransportType = XtremeIdiots.Portal.Web.Models.FileTransportType;
1716

1817
namespace XtremeIdiots.Portal.Web.Controllers;
1918

@@ -152,7 +151,7 @@ public async Task<IActionResult> Create(GameServerViewModel model, CancellationT
152151

153152
createGameServerDto.AgentEnabled = model.AgentEnabled;
154153
createGameServerDto.SetFileTransportProperties(model.FileTransportEnabled, model.FileTransportType);
155-
createGameServerDto.FtpEnabled = model.FileTransportEnabled && model.FileTransportType == WebFileTransportType.Ftp;
154+
createGameServerDto.FtpEnabled = model.FileTransportEnabled && model.FileTransportType == FileTransportType.Ftp;
156155
createGameServerDto.RconEnabled = model.RconEnabled;
157156
createGameServerDto.BanFileSyncEnabled = model.BanFileSyncEnabled;
158157
createGameServerDto.BanFileRootPath = string.IsNullOrWhiteSpace(model.BanFileRootPath) ? "/" : model.BanFileRootPath;
@@ -243,12 +242,12 @@ public async Task<IActionResult> Details(Guid id, CancellationToken cancellation
243242
{
244243
case "ftp":
245244
case "sftp":
246-
var expectedNamespace = fileTransportType == WebFileTransportType.Sftp ? "sftp" : "ftp";
245+
var expectedNamespace = fileTransportType == FileTransportType.Sftp ? "sftp" : "ftp";
247246
if (!string.Equals(config.Namespace, expectedNamespace, StringComparison.OrdinalIgnoreCase))
248247
break;
249248

250249
ViewBag.FtpHostname = GetStringProperty(root, "hostname");
251-
ViewBag.FtpPort = GetIntProperty(root, "port", fileTransportType == WebFileTransportType.Sftp ? 22 : 21);
250+
ViewBag.FtpPort = GetIntProperty(root, "port", fileTransportType == FileTransportType.Sftp ? 22 : 21);
252251
ViewBag.FtpUsername = GetStringProperty(root, "username");
253252
ViewBag.FtpPassword = GetStringProperty(root, "password");
254253
ViewBag.FileTransportType = fileTransportType;
@@ -444,7 +443,7 @@ public async Task<IActionResult> Edit(GameServerEditViewModel model, Cancellatio
444443
: existingFileTransportType;
445444

446445
editGameServerDto.SetFileTransportProperties(selectedFileTransportEnabled, selectedFileTransportType);
447-
editGameServerDto.FtpEnabled = selectedFileTransportEnabled && selectedFileTransportType == WebFileTransportType.Ftp;
446+
editGameServerDto.FtpEnabled = selectedFileTransportEnabled && selectedFileTransportType == FileTransportType.Ftp;
448447
editGameServerDto.RconEnabled = model.GameServer.RconEnabled;
449448
editGameServerDto.BanFileSyncEnabled = model.GameServer.BanFileSyncEnabled;
450449
editGameServerDto.BanFileRootPath = string.IsNullOrWhiteSpace(model.GameServer.BanFileRootPath) ? "/" : model.GameServer.BanFileRootPath;

src/XtremeIdiots.Portal.Web/Controllers/MapRotationsController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using MX.Observability.ApplicationInsights.Auditing;
1717
using XtremeIdiots.Portal.Web.Models;
1818
using XtremeIdiots.Portal.Web.ViewModels;
19-
using WebFileTransportType = XtremeIdiots.Portal.Web.Models.FileTransportType;
2019

2120
namespace XtremeIdiots.Portal.Web.Controllers;
2221

@@ -606,7 +605,7 @@ public async Task<IActionResult> EditAssignment(Guid id, CancellationToken cance
606605
var canBrowseFileTransport = await authorizationService.AuthorizeAsync(User, rotation.GameType, AuthPolicies.GameServers_Credentials_FileTransport_Write).ConfigureAwait(false);
607606

608607
var fileTransportEnabled = server?.GetFileTransportEnabled(server.FtpEnabled) ?? false;
609-
var fileTransportType = server?.GetFileTransportType(fileTransportEnabled, server.FtpEnabled) ?? WebFileTransportType.Unknown;
608+
var fileTransportType = server?.GetFileTransportType(fileTransportEnabled, server.FtpEnabled) ?? FileTransportType.Unknown;
610609

611610
ViewData["RotationTitle"] = rotation.Title;
612611

src/XtremeIdiots.Portal.Web/Extensions/FileTransportCompatibilityExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Reflection;
22

3-
using XtremeIdiots.Portal.Web.Models;
3+
using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1;
44

55
namespace XtremeIdiots.Portal.Web.Extensions;
66

src/XtremeIdiots.Portal.Web/Models/FileTransportType.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/XtremeIdiots.Portal.Web/ViewModels/EditMapRotationAssignmentViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel;
22
using System.ComponentModel.DataAnnotations;
33
using GameType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.GameType;
4-
using XtremeIdiots.Portal.Web.Models;
4+
using RepoFileTransportType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.FileTransportType;
55

66
namespace XtremeIdiots.Portal.Web.ViewModels;
77

@@ -28,5 +28,5 @@ public class EditMapRotationAssignmentViewModel
2828
public int? PlayerCountMax { get; set; }
2929

3030
public bool CanBrowseFileTransport { get; set; }
31-
public FileTransportType FileTransportType { get; set; } = FileTransportType.Unknown;
31+
public RepoFileTransportType FileTransportType { get; set; } = RepoFileTransportType.Unknown;
3232
}

src/XtremeIdiots.Portal.Web/ViewModels/GameServerEditViewModel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel;
22
using System.ComponentModel.DataAnnotations;
33
using GameType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.GameType;
4-
using XtremeIdiots.Portal.Web.Models;
4+
using RepoFileTransportType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.FileTransportType;
55

66
namespace XtremeIdiots.Portal.Web.ViewModels;
77

@@ -134,24 +134,24 @@ public class GameServerEditViewModel : IValidatableObject
134134
public string? FtpConfigUsername { get => FileTransportConfigUsername; set => FileTransportConfigUsername = value; }
135135
public string? FtpConfigPassword { get => FileTransportConfigPassword; set => FileTransportConfigPassword = value; }
136136

137-
public static string GetFileTransportNamespace(FileTransportType fileTransportType)
137+
public static string GetFileTransportNamespace(RepoFileTransportType fileTransportType)
138138
{
139-
return fileTransportType == FileTransportType.Sftp ? "sftp" : "ftp";
139+
return fileTransportType == RepoFileTransportType.Sftp ? "sftp" : "ftp";
140140
}
141141

142-
public static string GetFileTransportScheme(FileTransportType fileTransportType)
142+
public static string GetFileTransportScheme(RepoFileTransportType fileTransportType)
143143
{
144-
return fileTransportType == FileTransportType.Sftp ? "sftp" : "ftp";
144+
return fileTransportType == RepoFileTransportType.Sftp ? "sftp" : "ftp";
145145
}
146146

147-
public static string GetFileTransportLabel(FileTransportType fileTransportType)
147+
public static string GetFileTransportLabel(RepoFileTransportType fileTransportType)
148148
{
149-
return fileTransportType == FileTransportType.Sftp ? "SFTP" : "FTP";
149+
return fileTransportType == RepoFileTransportType.Sftp ? "SFTP" : "FTP";
150150
}
151151

152-
public static int GetDefaultPort(FileTransportType fileTransportType)
152+
public static int GetDefaultPort(RepoFileTransportType fileTransportType)
153153
{
154-
return fileTransportType == FileTransportType.Sftp ? 22 : 21;
154+
return fileTransportType == RepoFileTransportType.Sftp ? 22 : 21;
155155
}
156156

157157
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)

src/XtremeIdiots.Portal.Web/ViewModels/GameServerViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel;
22
using System.ComponentModel.DataAnnotations;
33
using GameType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.GameType;
4-
using XtremeIdiots.Portal.Web.Models;
4+
using RepoFileTransportType = XtremeIdiots.Portal.Repository.Abstractions.Constants.V1.FileTransportType;
55

66
namespace XtremeIdiots.Portal.Web.ViewModels;
77

@@ -58,7 +58,7 @@ public class GameServerViewModel
5858
/// Gets or sets the file transport type used by this server
5959
/// </summary>
6060
[DisplayName("File Transport Type")]
61-
public FileTransportType FileTransportType { get; set; } = FileTransportType.Ftp;
61+
public RepoFileTransportType FileTransportType { get; set; } = RepoFileTransportType.Ftp;
6262

6363
/// <summary>
6464
/// Gets or sets whether FTP integration is enabled for this server

0 commit comments

Comments
 (0)