Skip to content

Commit facc139

Browse files
committed
fix cache validation bug, inspection/quickfix viewmodels
1 parent a2deed7 commit facc139

File tree

25 files changed

+104
-107
lines changed

25 files changed

+104
-107
lines changed

rubberduckvba.Server/Api/Admin/AdminController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace rubberduckvba.Server.Api.Admin;
88

9-
109
[ApiController]
1110
public class AdminController(ConfigurationOptions options, HangfireLauncherService hangfire, CacheService cache) : ControllerBase
1211
{
@@ -15,7 +14,7 @@ public class AdminController(ConfigurationOptions options, HangfireLauncherServi
1514
/// </summary>
1615
/// <returns>The unique identifier of the enqueued job.</returns>
1716
[Authorize("github")]
18-
[EnableCors("CorsPolicy")]
17+
[EnableCors(CorsPolicies.AllowAuthenticated)]
1918
[HttpPost("admin/update/xmldoc")]
2019
public IActionResult UpdateXmldocContent()
2120
{
@@ -28,7 +27,7 @@ public IActionResult UpdateXmldocContent()
2827
/// </summary>
2928
/// <returns>The unique identifier of the enqueued job.</returns>
3029
[Authorize("github")]
31-
[EnableCors("CorsPolicy")]
30+
[EnableCors(CorsPolicies.AllowAuthenticated)]
3231
[HttpPost("admin/update/tags")]
3332
public IActionResult UpdateTagMetadata()
3433
{
@@ -37,7 +36,7 @@ public IActionResult UpdateTagMetadata()
3736
}
3837

3938
[Authorize("github")]
40-
[EnableCors("CorsPolicy")]
39+
[EnableCors(CorsPolicies.AllowAuthenticated)]
4140
[HttpPost("admin/cache/clear")]
4241
public IActionResult ClearCache()
4342
{
@@ -46,7 +45,8 @@ public IActionResult ClearCache()
4645
}
4746

4847
#if DEBUG
49-
[EnableCors("CorsPolicy")]
48+
[AllowAnonymous]
49+
[EnableCors(CorsPolicies.AllowAll)]
5050
[HttpGet("admin/config/current")]
5151
public IActionResult Config()
5252
{

rubberduckvba.Server/Api/Admin/WebhookController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public WebhookController(
2222
}
2323

2424
[Authorize("webhook")]
25-
[EnableCors("webhookPolicy")]
25+
[EnableCors(CorsPolicies.AllowAll)]
2626
[HttpPost("webhook/github")]
2727
public async Task<IActionResult> GitHub([FromBody] dynamic body) =>
2828
GuardInternalAction(() =>

rubberduckvba.Server/Api/Auth/AuthController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public AuthController(IOptions<GitHubSettings> configuration, IOptions<ApiSettin
3737
}
3838

3939
[HttpGet("auth")]
40-
[EnableCors("CorsPolicy")]
40+
[EnableCors(CorsPolicies.AllowAll)]
4141
[AllowAnonymous]
4242
public IActionResult Index()
4343
{
@@ -72,7 +72,7 @@ public IActionResult Index()
7272
}
7373

7474
[HttpPost("auth/signin")]
75-
[EnableCors("CorsPolicy")]
75+
[EnableCors(CorsPolicies.AllowAll)]
7676
[AllowAnonymous]
7777
public IActionResult SessionSignIn(SignInViewModel vm)
7878
{
@@ -109,7 +109,7 @@ public IActionResult SessionSignIn(SignInViewModel vm)
109109
}
110110

111111
[HttpPost("auth/github")]
112-
[EnableCors("CorsPolicy")]
112+
[EnableCors(CorsPolicies.AllowAll)]
113113
[AllowAnonymous]
114114
public IActionResult OnGitHubCallback(SignInViewModel vm)
115115
{

rubberduckvba.Server/Api/Downloads/DownloadsController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Cors;
23
using Microsoft.AspNetCore.Mvc;
34
using rubberduckvba.Server.Services;
45
using System.Collections.Immutable;
@@ -7,6 +8,7 @@ namespace rubberduckvba.Server.Api.Downloads;
78

89

910
[AllowAnonymous]
11+
[EnableCors(CorsPolicies.AllowAll)]
1012
public class DownloadsController : RubberduckApiController
1113
{
1214
private readonly CacheService cache;

rubberduckvba.Server/Api/Features/FeatureViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public FeatureViewModel(Feature model, bool summaryOnly = false)
5555

5656
public class InspectionViewModel
5757
{
58-
public InspectionViewModel(Inspection model, IDictionary<int, Tag> tagsByAssetId)
58+
public InspectionViewModel(Inspection model, IEnumerable<QuickFixViewModel> quickFixes, IDictionary<int, Tag> tagsByAssetId)
5959
{
6060
Id = model.Id;
6161
DateTimeInserted = model.DateTimeInserted;
@@ -78,7 +78,7 @@ public InspectionViewModel(Inspection model, IDictionary<int, Tag> tagsByAssetId
7878

7979
InspectionType = model.InspectionType;
8080
DefaultSeverity = model.DefaultSeverity;
81-
QuickFixes = model.QuickFixes;
81+
QuickFixes = quickFixes.Where(e => model.QuickFixes.Any(name => string.Equals(e.Name, name, StringComparison.InvariantCultureIgnoreCase))).ToArray();
8282

8383
Reasoning = model.Reasoning;
8484
HostApp = model.HostApp;
@@ -110,7 +110,7 @@ public InspectionViewModel(Inspection model, IDictionary<int, Tag> tagsByAssetId
110110
public string? Remarks { get; init; }
111111
public string? HostApp { get; init; }
112112
public string[] References { get; init; } = [];
113-
public string[] QuickFixes { get; init; } = [];
113+
public QuickFixViewModel[] QuickFixes { get; init; } = [];
114114
public InspectionExample[] Examples { get; init; } = [];
115115
}
116116

@@ -239,11 +239,11 @@ public record class QuickFixInspectionLinkViewModel
239239

240240
public class InspectionsFeatureViewModel : FeatureViewModel
241241
{
242-
public InspectionsFeatureViewModel(FeatureGraph model, IDictionary<int, Tag> tagsByAssetId, bool summaryOnly = false)
242+
public InspectionsFeatureViewModel(FeatureGraph model, IEnumerable<QuickFixViewModel> quickFixes, IDictionary<int, Tag> tagsByAssetId, bool summaryOnly = false)
243243
: base(model, summaryOnly)
244244
{
245245

246-
Inspections = model.Inspections.OrderBy(e => e.Name).Select(e => new InspectionViewModel(e, tagsByAssetId)).ToArray();
246+
Inspections = model.Inspections.OrderBy(e => e.Name).Select(e => new InspectionViewModel(e, quickFixes, tagsByAssetId)).ToArray();
247247
}
248248

249249
public InspectionViewModel[] Inspections { get; init; } = [];

rubberduckvba.Server/Api/Features/FeaturesController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Cors;
23
using Microsoft.AspNetCore.Mvc;
34
using rubberduckvba.Server.Data;
45
using rubberduckvba.Server.Model;
@@ -37,6 +38,7 @@ await db.GetTopLevelFeatures(repositoryId)
3738
.ContinueWith(t => t.Result.Select(e => new FeatureOptionViewModel { Id = e.Id, Name = e.Name, Title = e.Title }).ToArray());
3839

3940
[HttpGet("features")]
41+
[EnableCors(CorsPolicies.AllowAll)]
4042
[AllowAnonymous]
4143
public IActionResult Index()
4244
{
@@ -66,6 +68,7 @@ public IActionResult Index()
6668
}
6769

6870
[HttpGet("features/{name}")]
71+
[EnableCors(CorsPolicies.AllowAll)]
6972
[AllowAnonymous]
7073
public IActionResult Info([FromRoute] string name)
7174
{
@@ -82,6 +85,7 @@ public IActionResult Info([FromRoute] string name)
8285
}
8386

8487
[HttpGet("inspections/{name}")]
88+
[EnableCors(CorsPolicies.AllowAll)]
8589
[AllowAnonymous]
8690
public IActionResult Inspection([FromRoute] string name)
8791
{
@@ -103,6 +107,7 @@ public IActionResult Inspection([FromRoute] string name)
103107
}
104108

105109
[HttpGet("annotations/{name}")]
110+
[EnableCors(CorsPolicies.AllowAll)]
106111
[AllowAnonymous]
107112
public IActionResult Annotation([FromRoute] string name)
108113
{
@@ -124,6 +129,7 @@ public IActionResult Annotation([FromRoute] string name)
124129
}
125130

126131
[HttpGet("quickfixes/{name}")]
132+
[EnableCors(CorsPolicies.AllowAll)]
127133
[AllowAnonymous]
128134
public IActionResult QuickFix([FromRoute] string name)
129135
{
@@ -145,6 +151,7 @@ public IActionResult QuickFix([FromRoute] string name)
145151
}
146152

147153
[HttpGet("features/create")]
154+
[EnableCors(CorsPolicies.AllowAuthenticated)]
148155
[Authorize("github")]
149156
public async Task<ActionResult<FeatureEditViewModel>> Create([FromQuery] RepositoryId repository = RepositoryId.Rubberduck, [FromQuery] int? parentId = default)
150157
{
@@ -156,6 +163,7 @@ public async Task<ActionResult<FeatureEditViewModel>> Create([FromQuery] Reposit
156163
}
157164

158165
[HttpPost("create")]
166+
[EnableCors(CorsPolicies.AllowAuthenticated)]
159167
[Authorize("github")]
160168
public async Task<ActionResult<FeatureEditViewModel>> Create([FromBody] FeatureEditViewModel model)
161169
{
@@ -178,6 +186,7 @@ public async Task<ActionResult<FeatureEditViewModel>> Create([FromBody] FeatureE
178186
}
179187

180188
[HttpPost("features/update")]
189+
[EnableCors(CorsPolicies.AllowAuthenticated)]
181190
[Authorize("github")]
182191
public async Task<ActionResult<FeatureEditViewModel>> Update([FromBody] FeatureEditViewModel model)
183192
{
@@ -203,8 +212,10 @@ private InspectionsFeatureViewModel GetInspections()
203212
InspectionsFeatureViewModel result;
204213
if (!cache.TryGetInspections(out result!))
205214
{
215+
var quickfixesModel = GetQuickFixes();
216+
206217
var feature = features.Get("Inspections") as FeatureGraph;
207-
result = new InspectionsFeatureViewModel(feature,
218+
result = new InspectionsFeatureViewModel(feature, quickfixesModel.QuickFixes,
208219
feature.Inspections
209220
.Select(e => e.TagAssetId).Distinct()
210221
.ToDictionary(id => id, id => new Tag(tagsRepository.GetById(assetsRepository.GetById(id).TagId))));

rubberduckvba.Server/Api/Indenter/IndenterController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Cors;
23
using Microsoft.AspNetCore.Mvc;
34
using RubberduckServices;
45

56
namespace rubberduckvba.Server.Api.Indenter;
67

78
[AllowAnonymous]
9+
[EnableCors(CorsPolicies.AllowAll)]
810
public class IndenterController : RubberduckApiController
911
{
1012
private readonly IIndenterService service;

rubberduckvba.Server/Api/Tags/TagsController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Cors;
23
using Microsoft.AspNetCore.Mvc;
34
using rubberduckvba.Server.Services;
45

56
namespace rubberduckvba.Server.Api.Tags;
67

78

89
[AllowAnonymous]
10+
[EnableCors(CorsPolicies.AllowAll)]
911
public class TagsController : RubberduckApiController
1012
{
1113
private readonly CacheService cache;
@@ -23,7 +25,6 @@ public TagsController(CacheService cache, IRubberduckDbService db, ILogger<TagsC
2325
/// </summary>
2426
[HttpGet("api/v1/public/tags")] // legacy route
2527
[HttpGet("tags/latest")]
26-
[AllowAnonymous]
2728
public IActionResult Latest()
2829
{
2930
return GuardInternalAction(() =>

rubberduckvba.Server/ContentSynchronization/Pipeline/Sections/Context/SyncContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public SyncContext(IRequestParameters parameters)
2121
IRequestParameters IPipelineContext.Parameters => Parameters;
2222
public void LoadParameters(SyncRequestParameters parameters)
2323
{
24-
InvalidContextParameterException.ThrowIfNull(nameof(parameters), parameters);
2524
_parameters = parameters;
2625
_staging = new StagingContext(parameters);
2726
}

rubberduckvba.Server/GitHubAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected async override Task<AuthenticateResult> HandleAuthenticateAsync()
2525
var token = Context.Request.Headers["X-ACCESS-TOKEN"].SingleOrDefault();
2626
if (string.IsNullOrWhiteSpace(token))
2727
{
28-
return AuthenticateResult.NoResult();
28+
return AuthenticateResult.Fail("Access token was not provided");
2929
}
3030

3131
var principal = await _github.ValidateTokenAsync(token);
@@ -36,7 +36,7 @@ protected async override Task<AuthenticateResult> HandleAuthenticateAsync()
3636
return AuthenticateResult.Success(new AuthenticationTicket(principal, "github"));
3737
}
3838

39-
return AuthenticateResult.NoResult();
39+
return AuthenticateResult.Fail("An invalid access token was provided");
4040
}
4141
catch (InvalidOperationException e)
4242
{

0 commit comments

Comments
 (0)