Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ddff760c41 |
|||
|
344c38704b |
|||
|
af1a0e0bf9 |
|||
|
c665a3e95d |
|||
|
91fc7f168b |
19 changed files with 567 additions and 41 deletions
|
|
@ -52,4 +52,4 @@ jobs:
|
|||
--verbosity normal \
|
||||
--filter="Category!=Platform-Android" \
|
||||
--logger "xunit;LogFileName=test-results.xml" \
|
||||
&& echo "✅ Success !" || echo "❌ Fail ($?)!"
|
||||
&& echo "✅ Success !" || { echo "❌ Fail ($?)!"; exit 1; }
|
||||
|
|
|
|||
|
|
@ -175,6 +175,12 @@ jobs:
|
|||
run: |
|
||||
cd /src/_src
|
||||
dotnet restore
|
||||
- name: Test
|
||||
run: |
|
||||
cd /src/_src && dotnet test \
|
||||
--verbosity normal \
|
||||
--filter="Category!=Platform-Android" \
|
||||
--logger "xunit;LogFileName=test-results.xml"
|
||||
|
||||
- name: Build de PostIt.Android ARM64
|
||||
run: |
|
||||
|
|
@ -200,6 +206,7 @@ jobs:
|
|||
RELEASE_BODY: ${{ env.RELEASE_BODY }}
|
||||
IS_PRERELEASE: ${{ env.IS_PRERELEASE }}
|
||||
run: |
|
||||
set -e
|
||||
if [[ -z "$TAG" ]]; then
|
||||
echo "::error::No tag resolved for the API call."
|
||||
exit 1
|
||||
|
|
|
|||
|
|
@ -45,10 +45,8 @@ public class BillingQueriesPageViewModelTests
|
|||
Assert.Equal(2, vm.Queries.Count);
|
||||
Assert.All(vm.Queries, q => Assert.DoesNotContain("Rejected", q.StatusLabel, StringComparison.OrdinalIgnoreCase));
|
||||
Assert.Contains("lecture seule", vm.StatusMessage, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.False(vm.CanOpenDetails);
|
||||
|
||||
vm.SelectedQuery = vm.Queries[0];
|
||||
Assert.False(vm.OpenSelectedQueryCommand.CanExecute(null));
|
||||
Assert.True(vm.Queries.Count > 0);
|
||||
}
|
||||
|
||||
private sealed class StubBillingApi : IYavscApiClient
|
||||
|
|
|
|||
15
src/PostIt/PostIt.Tests/HomePageProviderFlowTests.cs
Normal file
15
src/PostIt/PostIt.Tests/HomePageProviderFlowTests.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using PostIt.ViewModels;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
public class HomePageProviderFlowTests
|
||||
{
|
||||
[Fact]
|
||||
public void HomePage_exposes_provider_requests_command()
|
||||
{
|
||||
var vm = new HomePageViewModel();
|
||||
|
||||
Assert.NotNull(vm.OpenProviderRequests);
|
||||
Assert.True(vm.OpenProviderRequests.CanExecute(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ using PostIt.Services;
|
|||
using PostIt.ViewModels;
|
||||
using PostIt.Views;
|
||||
using PostIt.Views.Blogs;
|
||||
using PostIt.Helpers;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
|
|
@ -115,8 +116,12 @@ public class MainPageButtonsTests
|
|||
var window = new MainView();
|
||||
var page = new BlogsPage { DataContext = vm };
|
||||
var app = (PostIt.App)Application.Current!;
|
||||
|
||||
app.AttachMainWindow(window);
|
||||
|
||||
window.NavRoot.PushAsync(page).GetAwaiter().GetResult();
|
||||
var mainWindow = new Window { Content = window };
|
||||
mainWindow.Show();
|
||||
return (window, page);
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +151,7 @@ public class MainPageButtonsTests
|
|||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Acl_button_click_pushes_a_page_onto_nav_stack()
|
||||
public async Task Acl_button_click_pushes_a_page_onto_nav_stack()
|
||||
{
|
||||
// Arrange: a VM whose SelectedPost is non-null so
|
||||
// CanManageAcl evaluates to true and the button is
|
||||
|
|
@ -179,7 +184,7 @@ public class MainPageButtonsTests
|
|||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Circles_button_click_pushes_a_page_onto_nav_stack()
|
||||
public async Task Circles_button_click_pushes_a_page_onto_nav_stack()
|
||||
{
|
||||
// Arrange: OpenCircles has no CanExecute guard today —
|
||||
// any click should fire it and push the page.
|
||||
|
|
|
|||
|
|
@ -64,9 +64,7 @@ public class MainPageSaveTests
|
|||
const string typed = "Mon premier billet";
|
||||
titleBox.Text = typed;
|
||||
|
||||
var saveButton = window.GetVisualDescendants()
|
||||
.OfType<Button>()
|
||||
.Single(b => b.Content as string == "Save");
|
||||
var saveButton = page.SaveButton;
|
||||
saveButton.Command!.Execute(null);
|
||||
|
||||
// The Save command is async (RelayCommand over Task) but
|
||||
|
|
|
|||
|
|
@ -46,35 +46,48 @@ public partial class App : Application
|
|||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var window = ServiceProvider.GetRequiredService<MainWindow>();
|
||||
desktop.MainWindow = window;
|
||||
View = window.MainView;
|
||||
this.ConfigureRootView(window.MainView);
|
||||
|
||||
ApplyDarkMode(settings);
|
||||
InitializeClassicDesktopLifetime(settings, desktop);
|
||||
}
|
||||
else if (ApplicationLifetime is IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
|
||||
{
|
||||
singleViewFactoryApplicationLifetime.MainViewFactory =
|
||||
() =>
|
||||
{
|
||||
View = ServiceProvider.GetRequiredService<MainView>();
|
||||
this.ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
return View;
|
||||
};
|
||||
InitializeActivityLifetime(settings, singleViewFactoryApplicationLifetime);
|
||||
}
|
||||
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
|
||||
{
|
||||
singleViewPlatform.MainView = View = ServiceProvider.GetRequiredService<MainView>();
|
||||
ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
InitializeSingleViewLifetime(settings, singleViewPlatform);
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private void ConfigureRootView(MainView rootView)
|
||||
public void InitializeSingleViewLifetime(Settings settings, ISingleViewApplicationLifetime singleViewPlatform)
|
||||
{
|
||||
singleViewPlatform.MainView = View = ServiceProvider!.GetRequiredService<MainView>();
|
||||
ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
}
|
||||
|
||||
public void InitializeActivityLifetime(Settings settings, IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
|
||||
{
|
||||
singleViewFactoryApplicationLifetime.MainViewFactory =
|
||||
() =>
|
||||
{
|
||||
this.ConfigureRootView(ServiceProvider!.GetRequiredService<MainView>());
|
||||
ApplyDarkMode(settings);
|
||||
return View!;
|
||||
};
|
||||
}
|
||||
|
||||
public void InitializeClassicDesktopLifetime(Settings settings, IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var window = ServiceProvider!.GetRequiredService<MainWindow>();
|
||||
desktop.MainWindow = window;
|
||||
this.ConfigureRootView(window.MainView);
|
||||
|
||||
ApplyDarkMode(settings);
|
||||
}
|
||||
|
||||
public void ConfigureRootView(MainView rootView)
|
||||
{
|
||||
// Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran.
|
||||
rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync();
|
||||
|
|
@ -87,6 +100,7 @@ private void ConfigureRootView(MainView rootView)
|
|||
};
|
||||
|
||||
rootView.SessionBanner.DataContext = sessionStatus;
|
||||
this.View = rootView;
|
||||
}
|
||||
|
||||
private async Task BootOnceAsync()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace PostIt.Helpers;
|
|||
|
||||
public static class ViewModelBaseHelpers
|
||||
{
|
||||
public static async Task PushPageAsync(this App app, ViewModelBase vm)
|
||||
public static async Task<Page> PushPageAsync(this App app, ViewModelBase vm)
|
||||
{
|
||||
var window = app.View;
|
||||
if (window is null)
|
||||
|
|
@ -43,9 +43,11 @@ public static class ViewModelBaseHelpers
|
|||
var stack = window.NavRoot.NavigationStack;
|
||||
if (stack.Count > 0 && ReferenceEquals(stack[stack.Count - 1], page))
|
||||
{
|
||||
return;
|
||||
return page;
|
||||
}
|
||||
|
||||
await window.NavRoot.PushAsync(page);
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,12 @@ public class HomePageViewModel : ViewModelBase
|
|||
SessionStatus = sessionStatus;
|
||||
|
||||
OpenActivities = new AsyncRelayCommand(OpenActivitiesAsync);
|
||||
|
||||
OpenProviderRequests = new AsyncRelayCommand(OpenProviderRequestsAsync);
|
||||
OpenBlogs = new AsyncRelayCommand(App.PushBlogsPageAsync);
|
||||
}
|
||||
public IAsyncRelayCommand OpenBlogs { get; } = new AsyncRelayCommand(App.PushBlogsPageAsync);
|
||||
public IAsyncRelayCommand OpenBlogs { get; }
|
||||
public IAsyncRelayCommand OpenActivities { get; }
|
||||
public IAsyncRelayCommand OpenProviderRequests { get; }
|
||||
|
||||
private async Task OpenActivitiesAsync()
|
||||
{
|
||||
|
|
@ -48,6 +50,8 @@ public class HomePageViewModel : ViewModelBase
|
|||
await app.PushPageAsync(vm);
|
||||
}
|
||||
|
||||
private Task OpenProviderRequestsAsync() => OpenActivitiesAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Avalonia designer constructor. Builds a self-contained VM
|
||||
/// with a freshly-constructed Settings so the XAML preview can
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@
|
|||
|
||||
<Grid Grid.Row="3" Margin="0,12,0,0" ColumnDefinitions="Auto,8,Auto,8,Auto,12,*">
|
||||
<Button Grid.Column="0"
|
||||
Content="Ouvrir le formulaire"
|
||||
Content="Ouvrir le formulaire de demande"
|
||||
Command="{Binding OpenSelectedFormCommand}" />
|
||||
<Button Grid.Column="2"
|
||||
Content="Voir les commandes"
|
||||
Content="Voir les demandes non validées"
|
||||
Command="{Binding OpenQueriesCommand}" />
|
||||
<Button Grid.Column="4"
|
||||
Content="Demandes en cours (lecture seule)"
|
||||
Content="Demandes en cours (validées, en lecture seule)"
|
||||
Command="{Binding OpenOngoingQueriesCommand}" />
|
||||
<postitControls:StatusBar Grid.Column="6"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
<TextBox Text="{Binding SearchText, Mode=TwoWay}" PlaceholderText="Filter by title or author..." />
|
||||
<CommandBar IsDynamicOverflowEnabled="True">
|
||||
<CommandBar.PrimaryCommands>
|
||||
|
||||
|
||||
<CommandBarButton Label="Filter" Command="{Binding SearchAsync}">
|
||||
<CommandBarButton.Icon>
|
||||
<PathIcon Data="{StaticResource FilterIcon}" />
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
<PathIcon Data="{StaticResource RefreshIcon}" />
|
||||
</CommandBarButton.Icon>
|
||||
</CommandBarButton>
|
||||
<CommandBarButton Label="Save" Command="{Binding SaveAsync}">
|
||||
<CommandBarButton x:Name="SaveButton" Label="Save" Command="{Binding SaveAsync}">
|
||||
<CommandBarButton.Icon>
|
||||
<PathIcon Data="{StaticResource SaveIcon}" />
|
||||
</CommandBarButton.Icon>
|
||||
|
|
@ -57,7 +57,8 @@
|
|||
</CommandBarButton.Icon>
|
||||
</CommandBarButton>
|
||||
<CommandBarButton x:Name="ManageAclButton"
|
||||
Label="ACL" Command="{Binding ManageAclAsync}">
|
||||
Label="ACL"
|
||||
Command="{Binding ManageAclAsync}">
|
||||
<CommandBarButton.Icon>
|
||||
<PathIcon Data="{StaticResource AclIcon}" />
|
||||
</CommandBarButton.Icon>
|
||||
|
|
@ -114,7 +115,8 @@
|
|||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Text="Post detail" FontWeight="SemiBold" />
|
||||
<TextBox Grid.Row="1" Text="{Binding DraftTitle, Mode=TwoWay}" PlaceholderText="Title" />
|
||||
<TextBox x:Name="DraftTitleTextBox"
|
||||
Grid.Row="1" Text="{Binding DraftTitle, Mode=TwoWay}" PlaceholderText="Title" />
|
||||
<TextBox Grid.Row="2" PlaceholderText="Write something here !"
|
||||
Text="{Binding DraftArticle, Mode=TwoWay}"
|
||||
MinHeight="320"
|
||||
|
|
@ -22,5 +22,9 @@
|
|||
Command="{Binding OpenActivities}"
|
||||
HorizontalAlignment="Center"
|
||||
IsEnabled="{Binding SessionStatus.IsLoggedIn}"/>
|
||||
<Button Content="Mes demandes en cours"
|
||||
Command="{Binding OpenProviderRequests}"
|
||||
HorizontalAlignment="Center"
|
||||
IsEnabled="{Binding SessionStatus.IsLoggedIn}"/>
|
||||
</StackPanel>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public sealed class BlogApiClient
|
|||
=> _api.CallAsync(HttpMethod.Put, $"{_pathPrefix}/{id}/publish",
|
||||
body: new { publish }, ct: ct);
|
||||
|
||||
private Task<BlogPostDto?> SendPostAsync(
|
||||
private async Task<BlogPostDto?> SendPostAsync(
|
||||
HttpMethod method,
|
||||
string path,
|
||||
BlogPostDto post,
|
||||
|
|
@ -99,9 +99,9 @@ public sealed class BlogApiClient
|
|||
CancellationToken ct)
|
||||
{
|
||||
if (files is null || files.Count == 0)
|
||||
return _api.CallAsync<BlogPostDto?>(method, path, body: post, ct: ct);
|
||||
return await _api.CallAsync<BlogPostDto?>(method, path, body: post, ct: ct);
|
||||
|
||||
return _api.CallAsync<BlogPostDto?>(method, path, () => CreateMultipartContent(post, files), ct: ct);
|
||||
return await _api.CallAsync<BlogPostDto?>(method, path, () => CreateMultipartContent(post, files), ct: ct);
|
||||
}
|
||||
|
||||
private static HttpContent CreateMultipartContent(BlogPostDto post, IReadOnlyCollection<BlogUploadFile> files)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
using Yavsc.Server.Helpers;
|
||||
using Yavsc.Server.Services;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route(Constants.APIPrefix + "/dictionnaire-metier")]
|
||||
public class DictionnaireMetierController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly DictionnaireMetierModerationService _moderationService;
|
||||
|
||||
public DictionnaireMetierController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
_moderationService = new DictionnaireMetierModerationService(context);
|
||||
}
|
||||
|
||||
[HttpGet("{activityCode}")]
|
||||
public async Task<ActionResult<IEnumerable<TermeMetier>>> GetTerms(
|
||||
[FromRoute] string activityCode,
|
||||
[FromQuery] string langue = "fr",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(activityCode))
|
||||
{
|
||||
return BadRequest("Activity code is required.");
|
||||
}
|
||||
|
||||
var activityCodes = await ResolveActivityCodesAsync(activityCode, cancellationToken);
|
||||
if (activityCodes.Count == 0)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var dictionaryIds = await _context.DictionnaireMetier
|
||||
.AsNoTracking()
|
||||
.Where(d => activityCodes.Contains(d.DomaineActiviteCode) && d.Langue == langue)
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
if (dictionaryIds.Count == 0)
|
||||
{
|
||||
return Ok(new List<TermeMetier>());
|
||||
}
|
||||
|
||||
var terms = await _context.TermeMetier
|
||||
.AsNoTracking()
|
||||
.Where(t => dictionaryIds.Contains(t.DictionnaireMetierId)
|
||||
&& t.StatutValidation == StatutValidationTerme.Valide)
|
||||
.OrderBy(t => t.Mot)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return Ok(terms);
|
||||
}
|
||||
|
||||
[HttpGet("dictionnaires/{activityCode}")]
|
||||
public async Task<ActionResult<IEnumerable<DictionnaireMetier>>> GetDictionaries(
|
||||
[FromRoute] string activityCode,
|
||||
[FromQuery] string langue = "fr",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(activityCode))
|
||||
{
|
||||
return BadRequest("Activity code is required.");
|
||||
}
|
||||
|
||||
var activityCodes = await ResolveActivityCodesAsync(activityCode, cancellationToken);
|
||||
if (activityCodes.Count == 0)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var dictionaries = await _context.DictionnaireMetier
|
||||
.AsNoTracking()
|
||||
.Where(d => activityCodes.Contains(d.DomaineActiviteCode) && d.Langue == langue)
|
||||
.OrderBy(d => d.Nom)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return Ok(dictionaries);
|
||||
}
|
||||
|
||||
[HttpPost("proposer")]
|
||||
public async Task<ActionResult<TermeMetier>> ProposeTerm(
|
||||
[FromBody] TermeMetier term,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(term.Mot) || string.IsNullOrWhiteSpace(term.Definition))
|
||||
{
|
||||
return BadRequest("Le terme et sa définition sont requis.");
|
||||
}
|
||||
|
||||
var dictionary = await _context.DictionnaireMetier
|
||||
.SingleOrDefaultAsync(d => d.Id == term.DictionnaireMetierId, cancellationToken);
|
||||
|
||||
if (dictionary is null)
|
||||
{
|
||||
return NotFound("Dictionary not found.");
|
||||
}
|
||||
|
||||
var proposerId = User.GetUserId();
|
||||
var result = await _moderationService.ProposerTermAsync(
|
||||
term.DictionnaireMetierId,
|
||||
term.Mot,
|
||||
term.Definition,
|
||||
term.Langue,
|
||||
proposerId);
|
||||
|
||||
return CreatedAtAction(nameof(GetTerms), new { activityCode = dictionary.DomaineActiviteCode }, result);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/valider")]
|
||||
[Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> ValidateTerm(
|
||||
[FromRoute] long id,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var term = await _moderationService.ValiderTermAsync(id, User.GetUserId());
|
||||
return Ok(term);
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{id}/rejeter")]
|
||||
[Authorize("AdministratorOnly")]
|
||||
public async Task<IActionResult> RejectTerm(
|
||||
[FromRoute] long id,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var term = await _moderationService.RejeterTermAsync(id, User.GetUserId());
|
||||
return Ok(term);
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<string>> ResolveActivityCodesAsync(string activityCode, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new HashSet<string>();
|
||||
var currentCode = activityCode;
|
||||
|
||||
while (!string.IsNullOrWhiteSpace(currentCode))
|
||||
{
|
||||
result.Add(currentCode);
|
||||
|
||||
var current = await _context.Activities
|
||||
.AsNoTracking()
|
||||
.SingleOrDefaultAsync(a => a.Code == currentCode, cancellationToken);
|
||||
|
||||
if (current is null || string.IsNullOrWhiteSpace(current.ParentCode))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
currentCode = current.ParentCode;
|
||||
}
|
||||
|
||||
return result.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
76
src/Yavsc.Org.Tests/DictionnaireMetierTests.cs
Normal file
76
src/Yavsc.Org.Tests/DictionnaireMetierTests.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
using Yavsc.Server.Services;
|
||||
|
||||
namespace Yavsc.Org.Tests;
|
||||
|
||||
public class DictionnaireMetierTests
|
||||
{
|
||||
[Fact]
|
||||
public void DictionnaireMetier_and_TermeMetier_can_be_constructed()
|
||||
{
|
||||
var dictionary = new DictionnaireMetier
|
||||
{
|
||||
Id = 1,
|
||||
Nom = "Droit",
|
||||
Langue = "fr",
|
||||
DomaineActiviteCode = "Droit"
|
||||
};
|
||||
|
||||
var term = new TermeMetier
|
||||
{
|
||||
Id = 2,
|
||||
DictionnaireMetierId = dictionary.Id,
|
||||
DictionnaireMetier = dictionary,
|
||||
Mot = "contrat",
|
||||
Definition = "Accord de volontés",
|
||||
Langue = "fr",
|
||||
StatutValidation = StatutValidationTerme.Propose,
|
||||
ProposeParId = "user-1"
|
||||
};
|
||||
|
||||
Assert.Equal("Droit", dictionary.DomaineActiviteCode);
|
||||
Assert.Equal("contrat", term.Mot);
|
||||
Assert.Equal(StatutValidationTerme.Propose, term.StatutValidation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DictionnaireMetier_moderation_flow_allows_propose_validate_and_reject()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
|
||||
await using var context = new ApplicationDbContext(options);
|
||||
context.Activities.Add(new Activity
|
||||
{
|
||||
Code = "Droit",
|
||||
Name = "Droit",
|
||||
ParentCode = null,
|
||||
Description = "Domaine de référence",
|
||||
Hidden = false,
|
||||
Forms = new List<CommandForm>()
|
||||
});
|
||||
|
||||
context.DictionnaireMetier.Add(new DictionnaireMetier
|
||||
{
|
||||
Nom = "Droit civil",
|
||||
Langue = "fr",
|
||||
DomaineActiviteCode = "Droit"
|
||||
});
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
var service = new DictionnaireMetierModerationService(context);
|
||||
|
||||
var proposed = await service.ProposerTermAsync(1, "contrat", "Accord de volontés", "fr", "user-proposer");
|
||||
Assert.Equal(StatutValidationTerme.Propose, proposed.StatutValidation);
|
||||
|
||||
var validated = await service.ValiderTermAsync(proposed.Id, "user-moderator");
|
||||
Assert.Equal(StatutValidationTerme.Valide, validated.StatutValidation);
|
||||
Assert.Equal("user-moderator", validated.ValideParId);
|
||||
|
||||
var rejected = await service.RejeterTermAsync(1, "user-moderator");
|
||||
Assert.Equal(StatutValidationTerme.Rejete, rejected.StatutValidation);
|
||||
}
|
||||
}
|
||||
|
|
@ -126,6 +126,27 @@ namespace Yavsc.Models
|
|||
builder.Entity<Activity>().Property(a => a.ParentCode).IsRequired(false);
|
||||
builder.Entity<Activity>().Property(a => a.Description).IsRequired(false);
|
||||
|
||||
builder.Entity<DictionnaireMetier>()
|
||||
.HasOne(d => d.DomaineActivite)
|
||||
.WithMany()
|
||||
.HasForeignKey(d => d.DomaineActiviteCode)
|
||||
.HasPrincipalKey(a => a.Code)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.Entity<DictionnaireMetier>()
|
||||
.HasIndex(d => new { d.DomaineActiviteCode, d.Langue, d.Nom })
|
||||
.IsUnique();
|
||||
|
||||
builder.Entity<TermeMetier>()
|
||||
.HasOne(t => t.DictionnaireMetier)
|
||||
.WithMany(d => d.Termes)
|
||||
.HasForeignKey(t => t.DictionnaireMetierId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Entity<TermeMetier>()
|
||||
.HasIndex(t => new { t.DictionnaireMetierId, t.Langue, t.Mot })
|
||||
.IsUnique();
|
||||
|
||||
builder.Entity<Country>().HasKey(c => c.Code);
|
||||
builder.Entity<PerformerCodeInputValidation>()
|
||||
.HasOne(v => v.Country)
|
||||
|
|
@ -263,6 +284,10 @@ namespace Yavsc.Models
|
|||
/// <returns></returns>
|
||||
public DbSet<Activity> Activities { get; set; }
|
||||
|
||||
public DbSet<DictionnaireMetier> DictionnaireMetier { get; set; }
|
||||
|
||||
public DbSet<TermeMetier> TermeMetier { get; set; }
|
||||
|
||||
public DbSet<UserActivity> UserActivities { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
79
src/Yavsc.Server/Models/Workflow/DictionnaireMetier.cs
Normal file
79
src/Yavsc.Server/Models/Workflow/DictionnaireMetier.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#nullable enable annotations
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Yavsc.Models.Workflow
|
||||
{
|
||||
public enum StatutValidationTerme
|
||||
{
|
||||
Propose,
|
||||
Valide,
|
||||
Rejete
|
||||
}
|
||||
|
||||
public class DictionnaireMetier
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required, MaxLength(200)]
|
||||
public string Nom { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(20)]
|
||||
public string Langue { get; set; } = "fr";
|
||||
|
||||
[Required, MaxLength(128)]
|
||||
[ForeignKey(nameof(DomaineActivite))]
|
||||
public string DomaineActiviteCode { get; set; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual Activity? DomaineActivite { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<TermeMetier> Termes { get; set; } = new List<TermeMetier>();
|
||||
}
|
||||
|
||||
public class TermeMetier
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public long DictionnaireMetierId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(DictionnaireMetierId))]
|
||||
[JsonIgnore]
|
||||
public virtual DictionnaireMetier? DictionnaireMetier { get; set; }
|
||||
|
||||
[Required, MaxLength(200)]
|
||||
public string Mot { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(2000)]
|
||||
public string Definition { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(20)]
|
||||
public string Langue { get; set; } = "fr";
|
||||
|
||||
public StatutValidationTerme StatutValidation { get; set; } = StatutValidationTerme.Propose;
|
||||
|
||||
[MaxLength(450)]
|
||||
public string? ProposeParId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ProposeParId))]
|
||||
[JsonIgnore]
|
||||
public virtual ApplicationUser? ProposePar { get; set; }
|
||||
|
||||
[MaxLength(450)]
|
||||
public string? ValideParId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ValideParId))]
|
||||
[JsonIgnore]
|
||||
public virtual ApplicationUser? ValidePar { get; set; }
|
||||
|
||||
public DateTime DateSoumission { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime? DateValidation { get; set; }
|
||||
}
|
||||
}
|
||||
116
src/Yavsc.Server/Services/DictionnaireMetierModerationService.cs
Normal file
116
src/Yavsc.Server/Services/DictionnaireMetierModerationService.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
|
||||
namespace Yavsc.Server.Services
|
||||
{
|
||||
public class DictionnaireMetierModerationService
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public DictionnaireMetierModerationService(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> ProposerTermAsync(
|
||||
long dictionnaireId,
|
||||
string mot,
|
||||
string definition,
|
||||
string langue,
|
||||
string userId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mot))
|
||||
{
|
||||
throw new ArgumentException("Le terme est requis.", nameof(mot));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(definition))
|
||||
{
|
||||
throw new ArgumentException("La définition est requise.", nameof(definition));
|
||||
}
|
||||
|
||||
var dictionary = await _context.DictionnaireMetier
|
||||
.SingleOrDefaultAsync(d => d.Id == dictionnaireId);
|
||||
|
||||
if (dictionary is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Dictionnaire {dictionnaireId} introuvable.");
|
||||
}
|
||||
|
||||
var normalizedMot = mot.Trim();
|
||||
var exists = await _context.TermeMetier
|
||||
.AnyAsync(t => t.DictionnaireMetierId == dictionnaireId
|
||||
&& t.Langue == langue
|
||||
&& t.Mot == normalizedMot);
|
||||
|
||||
if (exists)
|
||||
{
|
||||
throw new InvalidOperationException($"Le terme '{normalizedMot}' existe déjà dans ce dictionnaire.");
|
||||
}
|
||||
|
||||
var term = new TermeMetier
|
||||
{
|
||||
DictionnaireMetierId = dictionnaireId,
|
||||
DictionnaireMetier = dictionary,
|
||||
Mot = normalizedMot,
|
||||
Definition = definition.Trim(),
|
||||
Langue = string.IsNullOrWhiteSpace(langue) ? "fr" : langue,
|
||||
StatutValidation = StatutValidationTerme.Propose,
|
||||
ProposeParId = userId,
|
||||
ValideParId = null,
|
||||
DateSoumission = DateTime.UtcNow,
|
||||
DateValidation = null
|
||||
};
|
||||
|
||||
_context.TermeMetier.Add(term);
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> ValiderTermAsync(long termeId, string moderatorId)
|
||||
{
|
||||
var term = await _context.TermeMetier
|
||||
.SingleOrDefaultAsync(t => t.Id == termeId);
|
||||
|
||||
if (term is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Terme {termeId} introuvable.");
|
||||
}
|
||||
|
||||
term.StatutValidation = StatutValidationTerme.Valide;
|
||||
term.ValideParId = moderatorId;
|
||||
term.DateValidation = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> RejeterTermAsync(long termeId, string moderatorId)
|
||||
{
|
||||
var term = await _context.TermeMetier
|
||||
.SingleOrDefaultAsync(t => t.Id == termeId);
|
||||
|
||||
if (term is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Terme {termeId} introuvable.");
|
||||
}
|
||||
|
||||
term.StatutValidation = StatutValidationTerme.Rejete;
|
||||
term.ValideParId = moderatorId;
|
||||
term.DateValidation = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<List<TermeMetier>> GetPendingAsync(long dictionnaireId)
|
||||
{
|
||||
return await _context.TermeMetier
|
||||
.Where(t => t.DictionnaireMetierId == dictionnaireId
|
||||
&& t.StatutValidation == StatutValidationTerme.Propose)
|
||||
.OrderBy(t => t.DateSoumission)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue