Skip to content

Commit fa542ef

Browse files
committed
Improves admin actions and validation
Enhances the admin controller by implementing improved validation for organization IDs and providing more descriptive error messages. The changes introduce model validation for the `SetBonusAsync` action, ensuring that the organization ID is valid before proceeding. This prevents unexpected errors and provides better feedback to the user. Additionally, it adds API documentation to the SetBonusAsync method. The change also fixes an issue in the `AuthController` where the change password method was not returning a validation error when the current password was incorrect.
1 parent 4d680d9 commit fa542ef

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Exceptionless.Web/Controllers/AdminController.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public ActionResult<IEnumerable<AssemblyDetail>> Assemblies()
8181
return Ok(details);
8282
}
8383

84-
[Consumes("application/json")]
8584
[HttpPost("change-plan")]
8685
public async Task<IActionResult> ChangePlanAsync(string organizationId, string planId)
8786
{
@@ -109,21 +108,33 @@ await _messagePublisher.PublishAsync(new PlanChanged
109108
return Ok(new { Success = true });
110109
}
111110

112-
[Consumes("application/json")]
111+
/// <summary>
112+
/// Applies a bonus event count to the specified organization, optionally with an expiration date.
113+
/// </summary>
114+
/// <param name="organizationId">The unique identifier of the organization to receive the bonus.</param>
115+
/// <param name="bonusEvents">The number of bonus events to apply.</param>
116+
/// <param name="expires">The optional expiration date for the bonus events.</param>
117+
/// <response code="200">Bonus was applied successfully.</response>
118+
/// <response code="422">Validation error occurred.</response>
113119
[HttpPost("set-bonus")]
114120
public async Task<IActionResult> SetBonusAsync(string organizationId, int bonusEvents, DateTime? expires = null)
115121
{
116122
if (String.IsNullOrEmpty(organizationId) || !CanAccessOrganization(organizationId))
117-
return Ok(new { Success = false, Message = "Invalid Organization Id." });
123+
{
124+
ModelState.AddModelError(nameof(organizationId), "Invalid Organization Id");
125+
return ValidationProblem(ModelState);
126+
}
118127

119128
var organization = await _organizationRepository.GetByIdAsync(organizationId);
120-
if (organization is null)
121-
return Ok(new { Success = false, Message = "Invalid Organization Id." });
129+
if (organization is null) {
130+
ModelState.AddModelError(nameof(organizationId), "Invalid Organization Id");
131+
return ValidationProblem(ModelState);
132+
}
122133

123134
_billingManager.ApplyBonus(organization, bonusEvents, expires);
124135
await _organizationRepository.SaveAsync(organization, o => o.Cache().Originals());
125136

126-
return Ok(new { Success = true });
137+
return Ok();
127138
}
128139

129140
[HttpGet("requeue")]

src/Exceptionless.Web/Controllers/AuthController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ public async Task<ActionResult<TokenResult>> ChangePasswordAsync(ChangePasswordM
435435
_logger.LogError("Change password failed for {EmailAddress}: The current password is incorrect", user.EmailAddress);
436436
ModelState.AddModelError<ChangePasswordModel>(m => m.CurrentPassword, "The current password is incorrect.");
437437
return ValidationProblem(ModelState);
438-
439438
}
440439

441440
string newPasswordHash = model.Password!.ToSaltedHash(user.Salt!);

0 commit comments

Comments
 (0)