Allow amateur performer profiles

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-08 02:29:09 +00:00
commit 0728d2a3f7
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
20 changed files with 217 additions and 29 deletions

View file

@ -608,6 +608,7 @@ namespace Yavsc.Controllers
var uid = user.Id;
var postedCountryCode = model.ExerciseCountryCode;
model.ExerciseCountryCode = NormalizeCountryCodeOrDefault(model.ExerciseCountryCode);
model.SIREN = model.SIREN?.Trim() ?? string.Empty;
// Model binding validated the raw posted payload before entering
// the action. If country was empty, we fallback to "fr" above,
@ -622,7 +623,7 @@ namespace Yavsc.Controllers
if (ModelState.IsValid)
{
var isFrenchPerformerCode = string.Equals(model.ExerciseCountryCode, "fr", StringComparison.Ordinal);
if (isFrenchPerformerCode)
if (isFrenchPerformerCode && !string.IsNullOrWhiteSpace(model.SIREN))
{
var exSiren = await _dbContext.ExceptionsSIREN.FirstOrDefaultAsync(
ex => ex.SIREN == model.SIREN

View file

@ -29,9 +29,10 @@ namespace Yavsc.Controllers
// GET: Estimate
public IActionResult Index()
public async Task<IActionResult> Index()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
ViewBag.CanIssueEstimates = await CanIssueEstimatesAsync(uid);
return View(_context.Estimates.Include(e=>e.Query)
.Include(e=>e.Query.PerformerProfile)
.Include(e=>e.Query.PerformerProfile.Performer)
@ -73,9 +74,14 @@ namespace Yavsc.Controllers
// GET: Estimate/Create
[Authorize]
public IActionResult Create()
public async Task<IActionResult> Create()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (!await CanIssueEstimatesAsync(uid))
{
return RedirectToAction("SetActivity", "Manage");
}
IQueryable<RdvQuery> queries = _context.RdvQueries.Include(q=>q.Location).Where(bq=>bq.PerformerId == uid);
//.Select(bq=>new SelectListItem{ Text = bq.Client.UserName, Value = bq.Client.Id });
ViewBag.Clients = queries.Select(q=>q.Client).Distinct();
@ -93,6 +99,11 @@ namespace Yavsc.Controllers
)
{
estimate.OwnerId = User.GetUserId();
if (!await CanIssueEstimatesAsync(estimate.OwnerId))
{
return RedirectToAction("SetActivity", "Manage");
}
if (ModelState.IsValid)
{
_context.Estimates
@ -138,7 +149,7 @@ namespace Yavsc.Controllers
// GET: Estimate/Edit/5
public IActionResult Edit(long? id)
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
@ -152,6 +163,10 @@ namespace Yavsc.Controllers
{
return NotFound();
}
if (!await CanIssueEstimatesAsync(estimate.OwnerId))
{
return RedirectToAction("SetActivity", "Manage");
}
return View(estimate);
}
@ -159,11 +174,15 @@ namespace Yavsc.Controllers
// POST: Estimate/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(Estimate estimate)
public async Task<IActionResult> Edit(Estimate estimate)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (estimate.OwnerId!=uid&&estimate.ClientId!=uid
) return NotFound();
if (!await CanIssueEstimatesAsync(estimate.OwnerId))
{
return RedirectToAction("SetActivity", "Manage");
}
if (ModelState.IsValid)
{
_context.Update(estimate);
@ -203,5 +222,19 @@ namespace Yavsc.Controllers
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
private Task<bool> CanIssueEstimatesAsync(string? performerId)
{
if (string.IsNullOrWhiteSpace(performerId))
{
return Task.FromResult(false);
}
return _context.Performers
.AsNoTracking()
.AnyAsync(profile => profile.PerformerId == performerId
&& profile.SIREN != null
&& profile.SIREN.Trim() != "");
}
}
}

View file

@ -7,7 +7,14 @@
<h2>Index</h2>
<p>
<a asp-action="Create">Create New</a>
@if ((bool?)ViewBag.CanIssueEstimates == true)
{
<a asp-action="Create">Create New</a>
}
else
{
<span>Un identifiant d'entreprise est nécessaire pour émettre ou modifier des devis.</span>
}
</p>
<table class="table">
<tr>

View file

@ -84,10 +84,10 @@
</div>
<div class="form-group">
<label asp-for="SIREN" class="col-md-2 control-label">SIREN</label>
<label asp-for="SIREN" class="col-md-2 control-label">Identifiant d'entreprise (SIREN/SIRET, facultatif)</label>
<div class="col-md-10">
<input asp-for="SIREN" class="form-control" />
<small class="form-text text-muted">Sans identifiant, votre profil reste utilisable comme amateur, mais l'émission de devis et la facturation sont désactivées.</small>
<span asp-validation-for="SIREN" class="text-danger"></span>
</div>
</div>