This commit is contained in:
Paul Schneider 2026-02-16 00:14:33 +00:00
commit ca03b496db
19 changed files with 45 additions and 106 deletions

View file

@ -37,8 +37,8 @@
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.7" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />

View file

@ -19,13 +19,13 @@ namespace Yavsc.Controllers
// GET: HyperLink
public async Task<IActionResult> Index()
{
return View(await _context.HyperLink.ToListAsync());
return Ok(await _context.HyperLink.ToListAsync());
}
// GET: HyperLink/Details/5
public async Task<IActionResult> Details(string href, string method)
{
if (href == null || method ==null)
if (href == null || method == null)
{
return NotFound();
}
@ -36,14 +36,9 @@ namespace Yavsc.Controllers
return NotFound();
}
return View(hyperLink);
return Ok(hyperLink);
}
// GET: HyperLink/Create
public IActionResult Create()
{
return View();
}
// POST: HyperLink/Create
[HttpPost]
@ -54,15 +49,15 @@ namespace Yavsc.Controllers
{
_context.HyperLink.Add(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok(hyperLink);
}
return View(hyperLink);
return BadRequest(ModelState);
}
// GET: HyperLink/Edit/5
public async Task<IActionResult> Edit(string href, string method)
{
if (href == null || method ==null)
if (href == null || method == null)
{
return NotFound();
}
@ -72,7 +67,7 @@ namespace Yavsc.Controllers
{
return NotFound();
}
return View(hyperLink);
return Ok(hyperLink);
}
// POST: HyperLink/Edit/5
@ -84,36 +79,17 @@ namespace Yavsc.Controllers
{
_context.Update(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok(hyperLink);
}
return View(hyperLink);
}
// GET: HyperLink/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string href, string method)
{
if (href == null || method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
if (hyperLink == null)
{
return NotFound();
}
return View(hyperLink);
return BadRequest(ModelState);
}
// POST: HyperLink/Delete/5
[HttpPost, ActionName("Delete")]
[HttpDelete, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string HRef, string Method)
{
if (HRef == null || Method ==null)
if (HRef == null || Method == null)
{
return NotFound();
}
@ -122,7 +98,7 @@ namespace Yavsc.Controllers
_context.HyperLink.Remove(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok();
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

View file

@ -30,6 +30,8 @@ namespace Yavsc.Controllers
this._dbContext = context;
}
[Authorize("AdministratorOnly")]
public async Task<IActionResult> Role(string id)
{
var role = await _roleManager.FindByIdAsync(id);
@ -39,7 +41,7 @@ namespace Yavsc.Controllers
Id = id,
Name = role.Name,
Users = (await this._userManager.GetUsersInRoleAsync(role.Name))
.Select(u => new UserInfo (id, u.UserName, u.Email, u.Avatar)).ToArray()
.Select(u => new UserInfo(id, u.UserName, u.Email, u.Avatar)).ToArray()
};
return View(roleUserCollection);
}
@ -62,17 +64,16 @@ namespace Yavsc.Controllers
if (!resultCreate.Succeeded)
{
AddErrors(resultCreate);
return false;
}
}
if (ModelState.ErrorCount > 0) return false;
return true;
}
/// <summary>
/// Gives the (new if was not existing) administrator role
/// to current authenticated user, when no existing
/// administrator was found.
/// When nothing is to do, it returns a 404.
/// Gives the new, when not existing, administrator role
/// to current authenticated user.
/// If nothing is to do, it returns a 404.
/// </summary>
/// <returns></returns>
[Produces("application/json")]
@ -110,7 +111,6 @@ namespace Yavsc.Controllers
}
[Authorize("AdministratorOnly")]
[Produces("application/json")]
public async Task<IActionResult> Index()
{
var adminCount = await _userManager.GetUsersInRoleAsync(
@ -197,6 +197,7 @@ namespace Yavsc.Controllers
ViewBag.UserId = new SelectList(_dbContext.Users, "Id", "UserName");
return View(model);
}
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)

View file

@ -7,7 +7,7 @@ using Yavsc.Models;
namespace Yavsc.Controllers
{
[Authorize()]
[Authorize("AdministratorOnly")]
public class DatabaseController : Controller
{
private readonly ILogger<DatabaseController> logger;

View file

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Attributes.Validation;
namespace Yavsc.Models.Musical
@ -17,7 +18,10 @@ namespace Yavsc.Models.Musical
public int Rate { get; set; }
[YaRequired]
public long TendencyId {get; set; }
public long TendencyId { get; set; }
[ForeignKey("TendencyId")]
public virtual MusicalTendency MusicalTendency { get; set; }
}
}

View file

@ -15,6 +15,7 @@ namespace Yavsc.Models.Payment {
[YaRequired]
public string ExecutorId { get; set; }
[ForeignKey("ExecutorId")]
public virtual ApplicationUser Executor { get; set; }

View file

@ -3,7 +3,6 @@ using Microsoft.Extensions.DependencyInjection;
using Yavsc.Models;
using Xunit.Abstractions;
using Yavsc.Server.Models.IT.SourceCode;
using yavscTests.Settings;
using Microsoft.EntityFrameworkCore;
using isnd.tests;
@ -14,13 +13,11 @@ namespace yavscTests
public class BaseTestContext: IClassFixture<WebServerFixture>, IDisposable
{
public readonly WebServerFixture _serverFixture;
private readonly TestingSetup _testingOptions;
private readonly ITestOutputHelper _output;
public BaseTestContext(ITestOutputHelper output, WebServerFixture fixture)
{
this._serverFixture = fixture;
_testingOptions = fixture.TestingSetup;
this._output = output;
}

View file

@ -1,6 +1,4 @@
using System;
using isnd.tests;
using Xunit;
using Xunit.Abstractions;
namespace yavscTests.Mandatory
@ -18,7 +16,6 @@ namespace yavscTests.Mandatory
this.output = output;
_serverFixture = serverFixture;
output.WriteLine($"Testing connection string is {_serverFixture?.TestingSetup?.ConnectionStrings.DefaultConnection}");
}
/// <summary>

View file

@ -1,12 +1,8 @@
using isnd.tests;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
using Yavsc.Abstract.Manage;
using Yavsc.Interface;
using Yavsc.Models;
namespace yavscTests
{

View file

@ -1,7 +0,0 @@
namespace yavscTests.Settings
{
public class DbConnectionSettings
{
public string? DefaultConnection { get; set; }
}
}

View file

@ -1,23 +0,0 @@
namespace yavscTests.Settings
{
public class PasswordCreds
{
public string UserName { get; set; }
public string Password { get; set; }
}
public class TestingSetup
{
public DbConnectionSettings ConnectionStrings { get; set; }
public PasswordCreds ValidCreds
{
get; set;
}
public PasswordCreds InvalidCreds
{
get; set;
}
public string YavscWebPath {get; set; }
}
}

View file

@ -1,7 +1,4 @@
using System.Net;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Identity;
@ -9,15 +6,10 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Xunit;
using Yavsc;
using Yavsc.Models;
using Yavsc.Services;
using yavscTests.Settings;
using Yavsc.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Yavsc.Models.Auth;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
@ -46,7 +38,6 @@ namespace isnd.tests
public ApplicationUser TestingUser { get; private set; }
public bool DbCreated { get; internal set; }
public SiteSettings SiteSettings { get => siteSettings; set => siteSettings = value; }
public TestingSetup? TestingSetup { get; internal set; }
public string TestClientSecret { get; private set; } = "TestClientSecret";
public WebServerFixture()
@ -119,9 +110,6 @@ namespace isnd.tests
}
SiteSettings = app.Services.GetRequiredService<IOptions<SiteSettings>>().Value;
}
public void EnsureUser(string testingUserName, string password)

View file

@ -24,9 +24,9 @@
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Yavsc\Yavsc.csproj" />
<ProjectReference Include="..\..\src\Yavsc.Abstract\Yavsc.Abstract.csproj" />
<ProjectReference Include="..\..\src\Yavsc.Server\Yavsc.Server.csproj" />
<ProjectReference Include="..\..\src\Org\Org.csproj" />
<ProjectReference Include="..\..\src\Abstract\Abstract.csproj" />
<ProjectReference Include="..\..\src\Server\Server.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />

View file

@ -17,6 +17,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "src\Api\Api.csproj",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cli", "src\cli\cli.csproj", "{27DA6CEC-4266-4F78-BB32-8388F9A401D0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{76A7FBA6-B7EC-4864-85C0-1F470794BA0F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "yavscTests", "test\yavscTests\yavscTests.csproj", "{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -50,6 +54,10 @@ Global
{27DA6CEC-4266-4F78-BB32-8388F9A401D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27DA6CEC-4266-4F78-BB32-8388F9A401D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27DA6CEC-4266-4F78-BB32-8388F9A401D0}.Release|Any CPU.Build.0 = Release|Any CPU
{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8AD551DA-AFB7-4C2A-BB33-9418E38659BC} = {CDB1BDB5-53F9-4B43-864F-60F2E74F44E2}
@ -58,5 +66,6 @@ Global
{1F594222-C5CB-4D4A-94A1-C5AEB4990B59} = {CDB1BDB5-53F9-4B43-864F-60F2E74F44E2}
{95DAD2B5-4324-4E89-A337-5703E45CFBE8} = {CDB1BDB5-53F9-4B43-864F-60F2E74F44E2}
{27DA6CEC-4266-4F78-BB32-8388F9A401D0} = {CDB1BDB5-53F9-4B43-864F-60F2E74F44E2}
{CDCF676A-2037-472E-8C8B-67C5E4FDFEA1} = {76A7FBA6-B7EC-4864-85C0-1F470794BA0F}
EndGlobalSection
EndGlobal