Skip to content

Commit

Permalink
Fix create/edit for ReferenceSourceLibraries,ReferenceAssemblies,Embe…
Browse files Browse the repository at this point in the history
…ddedResources
  • Loading branch information
cobbr committed Jul 31, 2020
1 parent 720aa18 commit 7d64880
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed POST /api/users API endpoint authentication issue
- Fixed profiles using Cookie header
- Fixed profile using curly brace character
- Fix create/edit for ReferenceSourceLibraries,ReferenceAssemblies,EmbeddedResources

## [v0.5] - 2020-06-04
### Added
Expand Down
36 changes: 36 additions & 0 deletions Covenant/Components/EmbeddedResources/CreateEmbeddedResource.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/embeddedresource/create"
@attribute [Authorize(Roles = "User, Administrator")]
@inherits OwningComponentBase<ICovenantService>

@using Covenant.Core
@using Covenant.Models.Grunts
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
<h1 class="h2">Create EmbeddedResource</h1>
</div>

<EmbeddedResourceForm EmbeddedResource="EmbeddedResource" OnSubmit="OnCreate" SubmitIcon="plus" SubmitLabel="Create" />

@code {
[Parameter]
public EmbeddedResource EmbeddedResource { get; set; }

protected override void OnInitialized()
{
this.EmbeddedResource = this.EmbeddedResource ?? new EmbeddedResource();
}

public async Task OnCreate(EmbeddedResource resource)
{
try
{
this.EmbeddedResource = await Service.CreateEmbeddedResource(resource);
NavigationManager.NavigateTo("/grunttask");
}
catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
{
// return RedirectToAction(nameof(Edit), new { id = libraryModel.Id });
}
}
}
39 changes: 39 additions & 0 deletions Covenant/Components/EmbeddedResources/EditEmbeddedResource.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@page "/embeddedresource/edit/{EmbeddedResourceId:int}"
@attribute [Authorize(Roles = "User, Administrator")]
@inherits OwningComponentBase<ICovenantService>

@using Covenant.Core
@using Covenant.Models.Grunts
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
<h1 class="h2">EmbeddedResource: <span class="primary-color">@EmbeddedResource.Name</span></h1>
</div>

<EmbeddedResourceForm EmbeddedResource="EmbeddedResource" OnSubmit="OnEdit" SubmitIcon="edit" SubmitLabel="Edit" />

@code {
[Parameter]
public int EmbeddedResourceId { get; set; }

[Parameter]
public EmbeddedResource EmbeddedResource { get; set; }

protected override async Task OnInitializedAsync()
{
this.EmbeddedResource = this.EmbeddedResource ?? await Service.GetEmbeddedResource(this.EmbeddedResourceId);
}

public async Task OnEdit(EmbeddedResource resource)
{
try
{
await Service.EditEmbeddedResource(resource);
NavigationManager.NavigateTo("/grunttask");
}
catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
{
// return RedirectToAction(nameof(Edit), new { id = resource.Id });
}
}
}
39 changes: 39 additions & 0 deletions Covenant/Components/EmbeddedResources/EmbeddedResourceForm.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Forms
@using Covenant.Core
@using Covenant.Models.Grunts
@inject IJSRuntime IJSRuntime

<EditForm Model="EmbeddedResource" OnValidSubmit="(e => this.OnSubmit.InvokeAsync(EmbeddedResource))">
<div class="form-row">
<div class="form-group col-md-4">
<label for="Name">Name</label>
<input id="Name" name="Name" @bind="EmbeddedResource.Name" class="form-control">
<div class="text-danger"><ValidationMessage For="() => EmbeddedResource.Name" /></div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="Location">Location</label>
<input id="Location" name="Location" @bind="EmbeddedResource.Location" class="form-control">
<div class="text-danger"><ValidationMessage For="() => EmbeddedResource.Location" /></div>
</div>
</div>
<button type="submit" class="btn btn-primary">
<span class="fe fe-@SubmitIcon"></span> @SubmitLabel
</button>
</EditForm>

@code {
[Parameter]
public EmbeddedResource EmbeddedResource { get; set; }

[Parameter]
public string SubmitIcon { get; set; }

[Parameter]
public string SubmitLabel { get; set; }

[Parameter]
public EventCallback<EmbeddedResource> OnSubmit { get; set; }
}
1 change: 0 additions & 1 deletion Covenant/Components/GruntTasks/CreateGruntTask.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
{
await Service.CreateGruntTask(task);
NavigationManager.NavigateTo("/grunttask");
this.StateHasChanged();
}
catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
{
Expand Down
2 changes: 1 addition & 1 deletion Covenant/Components/GruntTasks/EditGruntTask.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
<h1 class="h2">GruntTask: <span id="task-name" class="primary-color">@GruntTask.Name</span></h1>
<h1 class="h2">GruntTask: <span class="primary-color">@GruntTask.Name</span></h1>
</div>

<GruntTaskForm GruntTask="GruntTask" OnSubmit="OnEdit" SubmitIcon="edit" SubmitLabel="Edit">
Expand Down
12 changes: 6 additions & 6 deletions Covenant/Components/GruntTasks/GruntTaskIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@
</div>
<div class="tab-pane fade" id="libraries" role="tabpanel" aria-labelledby="libraries-tab">
<ReferenceSourceLibraryTable ReferenceSourceLibraries="ReferenceSourceLibraries" />
<button href="/referencesourcelibrary/create" class="btn btn-primary">
<a href="/referencesourcelibrary/create" class="btn btn-primary">
<span class="fe fe-plus"></span>
Create
</button>
</a>
</div>
<div class="tab-pane fade" id="assemblies" role="tabpanel" aria-labelledby="assemblies-tab">
<ReferenceAssemblyTable ReferenceAssemblies="ReferenceAssemblies" />
<button href="/referenceassembly/create" class="btn btn-primary">
<a href="/referenceassembly/create" class="btn btn-primary">
<span class="fe fe-plus"></span>
Create
</button>
</a>
</div>
<div class="tab-pane fade" id="resources" role="tabpanel" aria-labelledby="resources-tab">
<EmbeddedResourceTable EmbeddedResources="EmbeddedResources" />
<button href="/embeddedresource/create" class="btn btn-primary">
<a href="/embeddedresource/create" class="btn btn-primary">
<span class="fe fe-plus"></span>
Create
</button>
</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
[Parameter]
public ReferenceAssembly ReferenceAssembly { get; set; }

protected override void OnInitialized()
{
this.ReferenceAssembly = this.ReferenceAssembly ?? new ReferenceAssembly();
}

public async Task OnCreate(ReferenceAssembly assembly)
{
try
{
await Service.CreateReferenceAssembly(assembly);
NavigationManager.NavigateTo("/referenceassembly");
NavigationManager.NavigateTo("/grunttask");
}
catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
<h1 class="h2">ReferenceAssembly: <span id="task-name" class="primary-color">@ReferenceAssembly.Name</span></h1>
<h1 class="h2">ReferenceAssembly: <span class="primary-color">@ReferenceAssembly.Name</span></h1>
</div>

<ReferenceAssemblyForm ReferenceAssembly="ReferenceAssembly" OnSubmit="OnEdit" SubmitIcon="edit" SubmitLabel="Edit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="text-danger"><ValidationMessage For="() => ReferenceAssembly.Location" /></div>
</div>
</div>
<button type="button" class="btn btn-primary">
<button type="submit" class="btn btn-primary">
<span class="fe fe-@SubmitIcon"></span> @SubmitLabel
</button>
</EditForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@using Covenant.Core
@using Covenant.Models.Grunts
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
<h1 class="h2">Create ReferenceSourceLibrary</h1>
Expand All @@ -15,17 +16,21 @@
[Parameter]
public ReferenceSourceLibrary ReferenceSourceLibrary { get; set; }

protected override void OnInitialized()
{
this.ReferenceSourceLibrary = this.ReferenceSourceLibrary ?? new ReferenceSourceLibrary();
}

public async Task OnCreate(ReferenceSourceLibrary library)
{
try
{
this.ReferenceSourceLibrary = await Service.CreateReferenceSourceLibrary(library);
this.StateHasChanged();
// return View(await _context.EditReferenceSourceLibrary(library));
NavigationManager.NavigateTo("/grunttask");
}
catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
{
// return RedirectToAction(nameof(Edit), new { id = libraryModel.Id });
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@inject IJSRuntime IJSRuntime

<EditForm Model="ReferenceSourceLibrary" OnValidSubmit="Submit">
<DataAnnotationsValidator />
<div class="form-row">
<div class="form-group col-md-4">
<label for="Name">Name</label>
Expand Down Expand Up @@ -118,7 +119,7 @@
}
set
{
if (value.Id > 0)
if (value != null && value.Id > 0)
{
_ReferenceSourceLibrary = Service.GetReferenceSourceLibrary(value.Id).WaitResult();
}
Expand Down
2 changes: 1 addition & 1 deletion Covenant/Models/Grunts/GruntTaskComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class ReferenceSourceLibrary : ISerializable<ReferenceSourceLibrary>
public string Description { get; set; }
public string Location { get; set; }
public ImplantLanguage Language { get; set; } = ImplantLanguage.CSharp;
public List<Common.DotNetVersion> CompatibleDotNetVersions { get; set; }
public List<Common.DotNetVersion> CompatibleDotNetVersions { get; set; } = new List<Common.DotNetVersion> { Common.DotNetVersion.Net35, Common.DotNetVersion.Net40 };

private List<ReferenceSourceLibraryReferenceAssembly> ReferenceSourceLibraryReferenceAssemblies { get; set; } = new List<ReferenceSourceLibraryReferenceAssembly>();
private List<ReferenceSourceLibraryEmbeddedResource> ReferenceSourceLibraryEmbeddedResources { get; set; } = new List<ReferenceSourceLibraryEmbeddedResource>();
Expand Down

0 comments on commit 7d64880

Please sign in to comment.