Skip to content

Commit 1541d01

Browse files
committed
Stack Controller Improvements
1 parent d807d70 commit 1541d01

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

src/Exceptionless.Web/Controllers/StackController.cs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task<ActionResult<Stack>> GetAsync(string id, string? offset = null
9999
/// <summary>
100100
/// Mark fixed
101101
/// </summary>
102-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
102+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
103103
/// <param name="version">A version number that the stack was fixed in.</param>
104104
/// <response code="404">One or more stacks could not be found.</response>
105105
[HttpPost("{ids:objectids}/mark-fixed")]
@@ -121,13 +121,10 @@ public async Task<ActionResult> MarkFixedAsync(string ids, string? version = nul
121121
if (stacks.Count is 0)
122122
return NotFound();
123123

124-
if (stacks.Count > 0)
125-
{
126-
foreach (var stack in stacks)
127-
stack.MarkFixed(semanticVersion, _timeProvider);
124+
foreach (var stack in stacks)
125+
stack.MarkFixed(semanticVersion, _timeProvider);
128126

129-
await _stackRepository.SaveAsync(stacks);
130-
}
127+
await _stackRepository.SaveAsync(stacks);
131128

132129
return Ok();
133130
}
@@ -160,7 +157,7 @@ public async Task<ActionResult> MarkFixedAsync(JObject data)
160157
/// <summary>
161158
/// Mark the selected stacks as snoozed
162159
/// </summary>
163-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
160+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
164161
/// <param name="snoozeUntilUtc">A time that the stack should be snoozed until.</param>
165162
/// <response code="404">One or more stacks could not be found.</response>
166163
[HttpPost("{ids:objectids}/mark-snoozed")]
@@ -176,19 +173,16 @@ public async Task<ActionResult<WorkInProgressResult>> SnoozeAsync(string ids, Da
176173
if (stacks.Count is 0)
177174
return NotFound();
178175

179-
if (stacks.Count > 0)
176+
foreach (var stack in stacks)
180177
{
181-
foreach (var stack in stacks)
182-
{
183-
stack.Status = StackStatus.Snoozed;
184-
stack.SnoozeUntilUtc = snoozeUntilUtc;
185-
stack.FixedInVersion = null;
186-
stack.DateFixed = null;
187-
}
188-
189-
await _stackRepository.SaveAsync(stacks);
178+
stack.Status = StackStatus.Snoozed;
179+
stack.SnoozeUntilUtc = snoozeUntilUtc;
180+
stack.FixedInVersion = null;
181+
stack.DateFixed = null;
190182
}
191183

184+
await _stackRepository.SaveAsync(stacks);
185+
192186
return Ok();
193187
}
194188

@@ -279,7 +273,7 @@ public async Task<IActionResult> RemoveLinkAsync(string id, ValueFromBody<string
279273
/// <summary>
280274
/// Mark future occurrences as critical
281275
/// </summary>
282-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
276+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
283277
/// <response code="404">One or more stacks could not be found.</response>
284278
[HttpPost("{ids:objectids}/mark-critical")]
285279
[Authorize(Policy = AuthorizationRoles.UserPolicy)]
@@ -304,7 +298,7 @@ public async Task<IActionResult> MarkCriticalAsync(string ids)
304298
/// <summary>
305299
/// Mark future occurrences as not critical
306300
/// </summary>
307-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
301+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
308302
/// <response code="204">The stacks were marked as not critical.</response>
309303
/// <response code="404">One or more stacks could not be found.</response>
310304
[HttpDelete("{ids:objectids}/mark-critical")]
@@ -331,14 +325,14 @@ public async Task<IActionResult> MarkNotCriticalAsync(string ids)
331325
/// <summary>
332326
/// Change stack status
333327
/// </summary>
334-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
328+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
335329
/// <param name="status">The status that the stack should be changed to.</param>
336330
/// <response code="404">One or more stacks could not be found.</response>
337331
[HttpPost("{ids:objectids}/change-status")]
338332
[Authorize(Policy = AuthorizationRoles.UserPolicy)]
339333
public async Task<IActionResult> ChangeStatusAsync(string ids, StackStatus status)
340334
{
341-
if (status == StackStatus.Regressed || status == StackStatus.Snoozed)
335+
if (status is StackStatus.Regressed or StackStatus.Snoozed)
342336
return BadRequest("Can't set stack status to regressed or snoozed.");
343337

344338
var stacks = await GetModelsAsync(ids.FromDelimitedString(), false);
@@ -361,8 +355,7 @@ public async Task<IActionResult> ChangeStatusAsync(string ids, StackStatus statu
361355
stack.FixedInVersion = null;
362356
}
363357

364-
if (status != StackStatus.Snoozed)
365-
stack.SnoozeUntilUtc = null;
358+
stack.SnoozeUntilUtc = null;
366359
}
367360

368361
await _stackRepository.SaveAsync(stacks);
@@ -377,7 +370,7 @@ public async Task<IActionResult> ChangeStatusAsync(string ids, StackStatus statu
377370
/// <param name="id">The identifier of the stack.</param>
378371
/// <response code="404">The stack could not be found.</response>
379372
/// <response code="426">Promote to External is a premium feature used to promote an error stack to an external system.</response>
380-
/// <response code="501">"No promoted web hooks are configured for this project.</response>
373+
/// <response code="501">No promoted web hooks are configured for this project.</response>
381374
[HttpPost("{id:objectid}/promote")]
382375
[Authorize(Policy = AuthorizationRoles.UserPolicy)]
383376
public async Task<IActionResult> PromoteAsync(string id)
@@ -389,7 +382,11 @@ public async Task<IActionResult> PromoteAsync(string id)
389382
if (stack is null || !CanAccessOrganization(stack.OrganizationId))
390383
return NotFound();
391384

392-
if (!await _billingManager.HasPremiumFeaturesAsync(stack.OrganizationId))
385+
var organization = await GetOrganizationAsync(stack.OrganizationId);
386+
if (organization is null)
387+
return NotFound();
388+
389+
if (!organization.HasPremiumFeatures)
393390
return PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature.");
394391

395392
var promotedProjectHooks = (await _webHookRepository.GetByProjectIdAsync(stack.ProjectId)).Documents.Where(p => p.EventTypes.Contains(WebHook.KnownEventTypes.StackPromoted)).ToList();
@@ -404,9 +401,6 @@ public async Task<IActionResult> PromoteAsync(string id)
404401
.Property("User", CurrentUser)
405402
.SetHttpContext(HttpContext));
406403

407-
var organization = await GetOrganizationAsync(stack.OrganizationId);
408-
if (organization is null)
409-
return NotFound();
410404
var project = await GetProjectAsync(stack.ProjectId);
411405
if (project is null)
412406
return NotFound();
@@ -444,7 +438,7 @@ await _webHookNotificationQueue.EnqueueAsync(new WebHookNotification
444438
/// <summary>
445439
/// Remove
446440
/// </summary>
447-
/// <param name="ids">A comma delimited list of stack identifiers.</param>
441+
/// <param name="ids">A comma-delimited list of stack identifiers.</param>
448442
/// <response code="204">No Content.</response>
449443
/// <response code="400">One or more validation errors occurred.</response>
450444
/// <response code="404">One or more stacks were not found.</response>

0 commit comments

Comments
 (0)