This commit is contained in:
Paul Schneider 2026-07-04 19:49:48 +01:00
commit 34b4203cd1
10 changed files with 152 additions and 6 deletions

View file

@ -0,0 +1,38 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;
namespace Yavsc.Org.Tests.Controllers;
public class CommandFormsControllerTests : IClassFixture<TestWebApplicationFactory>
{
private readonly TestWebApplicationFactory _factory;
public CommandFormsControllerTests(TestWebApplicationFactory factory)
{
_factory = factory;
}
private HttpClient CreateAdminClient()
{
var http = _factory.CreateClient(new WebApplicationFactoryClientOptions
{
HandleCookies = true,
});
http.DefaultRequestHeaders.Add(TestAuthPolicyProvider.HeaderName, TestAuthPolicyProvider.AdminRole);
return http;
}
[Fact]
public async Task Create_GET_returns_200_for_admin()
{
var http = CreateAdminClient();
var response = await http.GetAsync("/CommandForms/Create", TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
Assert.Contains("Create", body);
}
}

View file

@ -50,7 +50,7 @@ namespace Yavsc.Controllers
private void SetViewBag(CommandForm commandForm = null)
{
ViewBag.ActivityCode = new SelectList(_context.Activities, "Code", "Name", commandForm?.ActivityCode);
ViewBag.ActionName = _context.CommandForm.Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Title, Selected = commandForm.Id == c.Id });
ViewBag.ActionName = new SelectList(_context.CommandForm, nameof(CommandForm.Id), nameof(CommandForm.Title), commandForm?.Id);
}
// POST: CommandForms/Create
[HttpPost]

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<!--
route name for the api controller used to tag the 'BlogPost' entity
-->
<data name="CommandForms"><value>Formulaires de commandes</value></data>
</root>

View file

@ -21,7 +21,19 @@
@foreach (var user in Model.Users) {
<tr>
<td>
<img src="~/avatars/@(user.UserName).xs.png" alt="avatar"/>
@if (user.UserId==User.GetUserId()) {
<span class="badge badge-warning">You</span>
}
@if (SiteSettings.Value.Admin.EMail == user.Email) {
<span class="badge badge-success">Admin</span>
}
@if (SiteSettings.Value.Owner.EMail == user.Email) {
<span class="badge badge-success">Owner</span>
}
@if (!String.IsNullOrWhiteSpace(user.Avatar))
{
<img src="@user.Avatar" alt="avatar" class="user-icon"/>
}
<span> @user.UserName &lt;@(user.Email)&gt; </span>
</td>
<td>

View file

@ -1,10 +1,10 @@
@model IEnumerable<CommandForm>
@{
ViewBag.Title = "Index";
ViewBag.Title = Localizer["CommandForms"];
}
<h2>Index</h2>
<h2>@ViewBag.Title</h2>
<p>
<a asp-action="Create">Create New</a>
@ -22,7 +22,7 @@
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr class="@(item.Context.Hidden?"disabled":null)">
<td>

View file

@ -14,6 +14,7 @@
<script src="~/lib/jquery-ui/jquery-ui.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<title>@ViewBag.Title - Yavsc</title>
@await RenderSectionAsync("header", false)
</head>
<body>

View file

@ -0,0 +1,4 @@
.user-icon {
max-width: 1.5em;
max-height: 1.5em;
}

View file

@ -0,0 +1,4 @@
user-icon {
max-width: 1.5em;
max-height: 1.5em;
}