Skip to content

Commit

Permalink
Moved code from Razor components to code-behind to fix Identity UI sc…
Browse files Browse the repository at this point in the history
…affolding.
  • Loading branch information
bitbound committed Jul 31, 2023
1 parent 57b8676 commit 1a033fb
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 304 deletions.
14 changes: 7 additions & 7 deletions Agent/Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.7" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.3.4" />
<PackageReference Include="Microsoft.WSMan.Management" Version="7.3.4" />
<PackageReference Include="Microsoft.WSMan.Runtime" Version="7.3.4" />
<PackageReference Include="System.Management.Automation" Version="7.3.4" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.3.6" />
<PackageReference Include="Microsoft.WSMan.Management" Version="7.3.6" />
<PackageReference Include="Microsoft.WSMan.Runtime" Version="7.3.6" />
<PackageReference Include="System.Management.Automation" Version="7.3.6" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="7.0.1" />
</ItemGroup>

Expand Down
160 changes: 117 additions & 43 deletions Server/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable disable

namespace Remotely.Server.Areas.Identity.Pages.Account.Manage;
using System;
using Microsoft.AspNetCore.Mvc.Rendering;

public static class ManageNavPages
namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
{
public static string Index => "Index";

public static string Email => "Email";

public static string ChangePassword => "ChangePassword";

public static string DownloadPersonalData => "DownloadPersonalData";

public static string DeletePersonalData => "DeletePersonalData";

public static string ExternalLogins => "ExternalLogins";

public static string PersonalData => "PersonalData";

public static string TwoFactorAuthentication => "TwoFactorAuthentication";

public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);

public static string EmailNavClass(ViewContext viewContext) => PageNavClass(viewContext, Email);

public static string ChangePasswordNavClass(ViewContext viewContext) => PageNavClass(viewContext, ChangePassword);

public static string DownloadPersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DownloadPersonalData);

public static string DeletePersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DeletePersonalData);

public static string ExternalLoginsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ExternalLogins);

public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);

public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication);

private static string PageNavClass(ViewContext viewContext, string page)
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static class ManageNavPages
{
var activePage = viewContext.ViewData["ActivePage"] as string
?? System.IO.Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName);
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : "";
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string Index => "Index";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string Email => "Email";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string ChangePassword => "ChangePassword";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string DownloadPersonalData => "DownloadPersonalData";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string DeletePersonalData => "DeletePersonalData";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string ExternalLogins => "ExternalLogins";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string PersonalData => "PersonalData";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string TwoFactorAuthentication => "TwoFactorAuthentication";

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string EmailNavClass(ViewContext viewContext) => PageNavClass(viewContext, Email);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string ChangePasswordNavClass(ViewContext viewContext) => PageNavClass(viewContext, ChangePassword);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string DownloadPersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DownloadPersonalData);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string DeletePersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DeletePersonalData);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string ExternalLoginsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ExternalLogins);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication);

/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static string PageNavClass(ViewContext viewContext, string page)
{
var activePage = viewContext.ViewData["ActivePage"] as string
?? System.IO.Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName);
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
}
}
}
18 changes: 18 additions & 0 deletions Server/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<environment include="Development">
<script src="~/Identity/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha384-rZfj/ogBloos6wzLGpPkkOr/gpkBNLZ6b6yLy4o+ok+t/SAKlL5mvXLr0OXNi1Hp">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
crossorigin="anonymous"
integrity="sha384-R3vNCHsZ+A2Lo3d5A6XNP7fdQkeswQWTIPfiYwSpEP3YV079R+93YzTeZRah7f/F">
</script>
</environment>
59 changes: 7 additions & 52 deletions Server/Components/ModalContents/EditDeviceGroup.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@attribute [Authorize]
@inherits AuthComponentBase
@inject IDataService DataService
@inject IToastService ToastService
@inherits AuthComponentBase

<h5 class="text-info">
Editing @EditUser?.UserName
Expand All @@ -10,55 +8,12 @@
@foreach (var group in DeviceGroups ?? Array.Empty<DeviceGroup>())
{
<div @key="group.ID">
<input id="@group.ID" type="checkbox" class="align-middle mr-2" checked="@(DoesGroupContainUser(group))" @onchange="ev => GroupCheckChanged(ev, group)" />
<input
id="@group.ID"
type="checkbox"
class="align-middle mr-2"
checked="@(DoesGroupContainUser(group))"
@onchange="ev => GroupCheckChanged(ev, group)" />
<label class="align-middle mb-0" for="@group.ID">@group.Name</label>
</div>
}


@code {
public static string EditUserPropName => nameof(EditUser);
public static string DeviceGroupsPropName => nameof(DeviceGroups);

[Parameter]
public required RemotelyUser EditUser { get; set; }

[Parameter]
public required DeviceGroup[] DeviceGroups { get; set; }


private bool DoesGroupContainUser(DeviceGroup group)
{
return group.Users.Any(x => x.Id == EditUser.Id);
}

private async Task GroupCheckChanged(ChangeEventArgs args, DeviceGroup group)
{
if (!string.IsNullOrWhiteSpace(EditUser.UserName) &&
args.Value is bool boolValue &&
boolValue)
{
if (!DataService.AddUserToDeviceGroup(EditUser.OrganizationID, group.ID, EditUser.UserName, out var result))
{
ToastService.ShowToast(result, classString: "bg-warning");
}
else
{
ToastService.ShowToast("User added to group.");
}

}
else
{
var result = await DataService.RemoveUserFromDeviceGroup(EditUser.OrganizationID, group.ID, EditUser.Id);
if (!result)
{
ToastService.ShowToast("Failed to remove from group.", classString: "bg-warning");
}
else
{
ToastService.ShowToast("Removed user from group.");
}
}
}
}
63 changes: 63 additions & 0 deletions Server/Components/ModalContents/EditDeviceGroup.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Remotely.Server.Services;
using Remotely.Shared.Entities;
using Remotely.Shared.Models;
using System.Linq;
using System.Threading.Tasks;

namespace Remotely.Server.Components.ModalContents;

[Authorize]
public partial class EditDeviceGroup : AuthComponentBase
{
public static string DeviceGroupsPropName => nameof(DeviceGroups);
public static string EditUserPropName => nameof(EditUser);
[Parameter]
public required DeviceGroup[] DeviceGroups { get; set; }

[Parameter]
public required RemotelyUser EditUser { get; set; }

[Inject]
private IDataService DataService { get; init; } = null!;

[Inject]
private IToastService ToastService { get; init; } = null!;


private bool DoesGroupContainUser(DeviceGroup group)
{
return group.Users.Any(x => x.Id == EditUser.Id);
}

private async Task GroupCheckChanged(ChangeEventArgs args, DeviceGroup group)
{
if (!string.IsNullOrWhiteSpace(EditUser.UserName) &&
args.Value is bool boolValue &&
boolValue)
{
if (!DataService.AddUserToDeviceGroup(EditUser.OrganizationID, group.ID, EditUser.UserName, out var result))
{
ToastService.ShowToast(result, classString: "bg-warning");
}
else
{
ToastService.ShowToast("User added to group.");
}

}
else
{
var result = await DataService.RemoveUserFromDeviceGroup(EditUser.OrganizationID, group.ID, EditUser.Id);
if (!result)
{
ToastService.ShowToast("Failed to remove from group.", classString: "bg-warning");
}
else
{
ToastService.ShowToast("Removed user from group.");
}
}
}
}
7 changes: 7 additions & 0 deletions Server/Components/ModalContents/QuickScriptsSelector.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Components;

namespace Remotely.Server.Components.ModalContents;

public partial class QuickScriptsSelector : ComponentBase
{
}
Loading

0 comments on commit 1a033fb

Please sign in to comment.