Found via S1192 triage. ArtStudioController repeated the exact same token-user-id auth check in 27 endpoints:
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (string.IsNullOrEmpty(userId))
{
return Unauthorized("User ID not found in token");
}
That is 27 copies of the same auth logic + error message (SonarQube flagged the 'User ID not found in token' literal as duplicated 27x under S1192). It is a DRY/maintainability smell: the claim type, the null handling, and the 401 message can only be changed consistently by editing 27 places.
Fix: extract a private TryGetUserId(out string userId, out ActionResult? error) helper (returns false + a 401 result when the id claim is absent) and replace all 27 blocks with if (!TryGetUserId(out var userId, out var authError)) return authError;. Behavior is byte-for-byte identical — same claim, same message, same 401. All 49 ArtStudioController tests pass; build clean. Net ~80 lines of duplication removed.
Follow-up: ArtStudioPresetsController has the same pattern x4 (deferred to keep this change scoped to one controller). SonarQube rule csharpsquid:S1192.
Found via S1192 triage. ArtStudioController repeated the exact same token-user-id auth check in 27 endpoints:
```
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (string.IsNullOrEmpty(userId))
{
return Unauthorized("User ID not found in token");
}
```
That is 27 copies of the same auth logic + error message (SonarQube flagged the 'User ID not found in token' literal as duplicated 27x under S1192). It is a DRY/maintainability smell: the claim type, the null handling, and the 401 message can only be changed consistently by editing 27 places.
**Fix:** extract a private `TryGetUserId(out string userId, out ActionResult? error)` helper (returns false + a 401 result when the id claim is absent) and replace all 27 blocks with `if (!TryGetUserId(out var userId, out var authError)) return authError;`. Behavior is byte-for-byte identical — same claim, same message, same 401. All 49 ArtStudioController tests pass; build clean. Net ~80 lines of duplication removed.
Follow-up: ArtStudioPresetsController has the same pattern x4 (deferred to keep this change scoped to one controller). SonarQube rule csharpsquid:S1192.
Resolved in spikersoft-backend PR #376 (merged to master). Consolidated the 27 duplicated token-user-id auth checks into a TryGetUserId helper; behavior identical, all 49 controller tests pass. Closing.
Resolved in spikersoft-backend PR #376 (merged to master). Consolidated the 27 duplicated token-user-id auth checks into a TryGetUserId helper; behavior identical, all 49 controller tests pass. Closing.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Found via S1192 triage. ArtStudioController repeated the exact same token-user-id auth check in 27 endpoints:
That is 27 copies of the same auth logic + error message (SonarQube flagged the 'User ID not found in token' literal as duplicated 27x under S1192). It is a DRY/maintainability smell: the claim type, the null handling, and the 401 message can only be changed consistently by editing 27 places.
Fix: extract a private
TryGetUserId(out string userId, out ActionResult? error)helper (returns false + a 401 result when the id claim is absent) and replace all 27 blocks withif (!TryGetUserId(out var userId, out var authError)) return authError;. Behavior is byte-for-byte identical — same claim, same message, same 401. All 49 ArtStudioController tests pass; build clean. Net ~80 lines of duplication removed.Follow-up: ArtStudioPresetsController has the same pattern x4 (deferred to keep this change scoped to one controller). SonarQube rule csharpsquid:S1192.
Resolved in spikersoft-backend PR #376 (merged to master). Consolidated the 27 duplicated token-user-id auth checks into a TryGetUserId helper; behavior identical, all 49 controller tests pass. Closing.