From 8b07548303830c94aebb02c1021aba6abcda73c5 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 09:10:22 -0500 Subject: [PATCH 1/8] Ignore sarif files --- .gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 748f561af..9a30cdc70 100644 --- a/.gitignore +++ b/.gitignore @@ -107,8 +107,6 @@ DatabaseTemplate/* # .Net Tools tools/* -Ed-Fi-Db-Deploy.log -EdFi\.CodeGen\.log downloads/ reports/ @@ -123,3 +121,7 @@ environment.json # Sandbox Admin /**/SandboxAdminLog* + +# Log output +*.sarif +*.log \ No newline at end of file From 99502e8831a9cc5473398653e35dbd5c3f17206c Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 09:10:38 -0500 Subject: [PATCH 2/8] An initial editorconfig --- Application/.editorconfig | 138 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 Application/.editorconfig diff --git a/Application/.editorconfig b/Application/.editorconfig new file mode 100644 index 000000000..ce980e1a7 --- /dev/null +++ b/Application/.editorconfig @@ -0,0 +1,138 @@ +# References +# https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2022 +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ +# https://rules.sonarsource.com/csharp +# https://editorconfig.org/ + +root = true + +[**/*] +# Sensible Defaults +file_header_template = SPDX-License-Identifier: Apache-2.0\nLicensed to the Ed-Fi Alliance under one or more agreements.\nThe Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.\nSee the LICENSE and NOTICES files in the project root for more information. +indent_style=space +indent_size=4 +tab_width=2 +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +max_line_length = 110 + +[**/**.min.js] +# Minified JavaScript files shouldn't be changed +indent_style = ignore +insert_final_newline = ignore + +[**/*.md] +trim_trailing_whitespace = false + +[**/*.{cs,cshtml,csx}] +indent_style = space +indent_size = 4 +tab_width = 4 +end_of_line = crlf +csharp_new_line_before_members_in_object_initializers = false +csharp_preferred_modifier_order = private, public, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion + +dotnet_diagnostic.IDE0073.severity=error # File header template required + +# Formatting rules +dotnet_diagnostic.IDE0055.severity=warning +csharp_new_line_before_open_brace = all # Allman style +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents_when_block = true +csharp_space_after_cast = true +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_parentheses = none +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_after_comma = true +csharp_space_before_comma = false +csharp_space_after_dot = false +csharp_space_before_dot = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_before_semicolon_in_for_statement = false +csharp_space_around_declaration_statements = false +csharp_space_before_open_square_brackets = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_square_brackets = false + +# Naming rules +dotnet_naming_rule.local_constants_rule.severity = warning +dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.severity = warning +dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.severity = warning +dotnet_naming_rule.private_static_readonly_rule.style = lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style.required_prefix = _ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local +dotnet_naming_symbols.local_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly + +# Misc style +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning + +# We *like* var +dotnet_diagnostic.IDE0008.severity=none # IDE0008: Use explicit type +csharp_style_var_elsewhere = false:none +csharp_style_var_for_built_in_types = false:suggestion + +# IDE0065: placement of using statements +csharp_using_directive_placement=outside_namespace:warning +dotnet_diagnostic.IDE0065.severity=warning + +# Lower the priority +dotnet_diagnostic.S4136.severity=suggestion # Method overloads should be grouped together +dotnet_diagnostic.S1135.severity=suggestion # Complete TODO comments + + +[**/tests/**/*.cs] +# Allow our strange test class naming convention +dotnet_naming_symbols.amt_tests.applicable_kinds = class,method +dotnet_naming_symbols.amt_tests.word_separator = "_" +dotnet_naming_symbols.amt_tests.capitalization = first_word_upper +dotnet_diagnostic.IDE1006.severity=none +dotnet_diagnostic.S101.severity=none + +# SonarLint doesn't understand implied assertions from FakeItEasy +dotnet_diagnostic.S2699.severity=none # S2699: Tests should include assertions From 2f44128c46c53bdcd00f20296e4e3486403ce0f1 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 09:10:50 -0500 Subject: [PATCH 3/8] Add code analyzers to entry point projects --- .../EdFi.Ods.SandboxAdmin.csproj | 9 +++++++++ .../EdFi.Ods.SwaggerUI/EdFi.Ods.SwaggerUI.csproj | 9 +++++++++ Application/EdFi.Ods.WebApi/EdFi.Ods.WebApi.csproj | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Application/EdFi.Ods.SandboxAdmin/EdFi.Ods.SandboxAdmin.csproj b/Application/EdFi.Ods.SandboxAdmin/EdFi.Ods.SandboxAdmin.csproj index c03d5d14a..78d311195 100644 --- a/Application/EdFi.Ods.SandboxAdmin/EdFi.Ods.SandboxAdmin.csproj +++ b/Application/EdFi.Ods.SandboxAdmin/EdFi.Ods.SandboxAdmin.csproj @@ -25,6 +25,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -32,6 +37,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Application/EdFi.Ods.SwaggerUI/EdFi.Ods.SwaggerUI.csproj b/Application/EdFi.Ods.SwaggerUI/EdFi.Ods.SwaggerUI.csproj index 8a4f6071f..8d3cbd02a 100644 --- a/Application/EdFi.Ods.SwaggerUI/EdFi.Ods.SwaggerUI.csproj +++ b/Application/EdFi.Ods.SwaggerUI/EdFi.Ods.SwaggerUI.csproj @@ -19,7 +19,16 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Application/EdFi.Ods.WebApi/EdFi.Ods.WebApi.csproj b/Application/EdFi.Ods.WebApi/EdFi.Ods.WebApi.csproj index 01bd02502..896573b70 100644 --- a/Application/EdFi.Ods.WebApi/EdFi.Ods.WebApi.csproj +++ b/Application/EdFi.Ods.WebApi/EdFi.Ods.WebApi.csproj @@ -24,17 +24,26 @@ - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + From 13f4bf6f87a9726911698b43c7ce49d0e883d0b3 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 09:22:06 -0500 Subject: [PATCH 4/8] Tweak: do not want unused imports --- Application/.editorconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Application/.editorconfig b/Application/.editorconfig index ce980e1a7..b1c8fc31b 100644 --- a/Application/.editorconfig +++ b/Application/.editorconfig @@ -117,9 +117,10 @@ dotnet_diagnostic.IDE0008.severity=none # IDE0008: Use explicit type csharp_style_var_elsewhere = false:none csharp_style_var_for_built_in_types = false:suggestion -# IDE0065: placement of using statements +# Using statements csharp_using_directive_placement=outside_namespace:warning -dotnet_diagnostic.IDE0065.severity=warning +dotnet_diagnostic.IDE0065.severity=warning # placement of using statements +dotnet_diagnostic.IDE0005.severity=warning # Remove unnecessary using directives # Lower the priority dotnet_diagnostic.S4136.severity=suggestion # Method overloads should be grouped together From 4cb050507f811060f169d9cf22611ddbf083a177 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 09:24:52 -0500 Subject: [PATCH 5/8] Style fixes in SwaggerUI --- Application/EdFi.Ods.SwaggerUI/Program.cs | 4 +--- Application/EdFi.Ods.SwaggerUI/Startup.cs | 2 +- Application/EdFi.Ods.SwaggerUI/Years.cs | 7 ++++++- Application/EdFi.Ods.WebApi/Program.cs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Application/EdFi.Ods.SwaggerUI/Program.cs b/Application/EdFi.Ods.SwaggerUI/Program.cs index 4c73028f7..a7d450061 100644 --- a/Application/EdFi.Ods.SwaggerUI/Program.cs +++ b/Application/EdFi.Ods.SwaggerUI/Program.cs @@ -3,15 +3,13 @@ // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. -using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; namespace EdFi.Ods.SwaggerUI { - public class Program + public static class Program { public static async Task Main(string[] args) { diff --git a/Application/EdFi.Ods.SwaggerUI/Startup.cs b/Application/EdFi.Ods.SwaggerUI/Startup.cs index 020e4eb7b..f98374aeb 100644 --- a/Application/EdFi.Ods.SwaggerUI/Startup.cs +++ b/Application/EdFi.Ods.SwaggerUI/Startup.cs @@ -22,7 +22,7 @@ public class Startup { private readonly bool _useReverseProxyHeaders; private readonly string _pathBase; - private string _routePrefix; + private readonly string _routePrefix; private const string DefaultRoutePrefix = "swagger"; public Startup(IConfiguration configuration) diff --git a/Application/EdFi.Ods.SwaggerUI/Years.cs b/Application/EdFi.Ods.SwaggerUI/Years.cs index 0958c1d0c..e1f5d43ca 100644 --- a/Application/EdFi.Ods.SwaggerUI/Years.cs +++ b/Application/EdFi.Ods.SwaggerUI/Years.cs @@ -1,4 +1,9 @@ -namespace EdFi.Ods.SwaggerUI +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. + +namespace EdFi.Ods.SwaggerUI { public class Years { diff --git a/Application/EdFi.Ods.WebApi/Program.cs b/Application/EdFi.Ods.WebApi/Program.cs index b7ad33b35..c835a47b8 100644 --- a/Application/EdFi.Ods.WebApi/Program.cs +++ b/Application/EdFi.Ods.WebApi/Program.cs @@ -13,7 +13,7 @@ namespace EdFi.Ods.WebApi { - public class Program + public static class Program { public static async Task Main(string[] args) { From d9965531b1800e7b52fb93ee1daa6cff626ff2d9 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Thu, 7 Jul 2022 10:51:52 -0500 Subject: [PATCH 6/8] Addressing style inconsistencies and code smells --- .../Contexts/DatabaseEngineDbConfiguration.cs | 3 +-- .../Contexts/IdentityContext.cs | 2 +- .../Contexts/PostgresIdentityContext.cs | 4 ++-- .../Contexts/SqlServerIdentityContext.cs | 4 ++-- .../Controllers/AccountController.cs | 10 ++++----- .../Controllers/Api/ClientController.cs | 14 +++++++----- .../Controllers/Api/SandboxController.cs | 6 +++-- .../Controllers/Api/UserProfileController.cs | 22 ++----------------- .../Controllers/ClientController.cs | 4 ++-- .../Controllers/HomeController.cs | 2 +- .../Controllers/SandboxController.cs | 4 ++-- .../Controllers/TestUsersController.cs | 4 ++-- .../Extensions/ExpressionExtensions.cs | 4 ++-- .../HealthCheckServiceExtensions.cs | 2 +- .../Extensions/PasswordExtensions.cs | 4 ++-- .../Extensions/RequestExtensions.cs | 1 - .../Extensions/StringExtensions.cs | 6 ++--- .../Extensions/TempDataExtensions.cs | 6 ++--- .../Filters/SetCurrentUserInfoAttribute.cs | 10 ++++----- .../Initialization/InitializationEngine.cs | 21 +++++++++++++++++- .../Initialization/SandboxOptions.cs | 4 ++-- .../Initialization/UserOptions.cs | 2 +- .../Models/ActivateUserModel.cs | 4 ++-- .../Models/ActivateUserViewModel.cs | 4 ++-- .../Models/ChangePasswordModel.cs | 4 ++-- .../Models/Client/ClientIndexViewModel.cs | 4 ++-- .../Models/Client/SandboxClientCreateModel.cs | 4 ++-- .../Models/CreateLoginModel.cs | 4 ++-- .../Models/ForgotPasswordModel.cs | 4 ++-- .../Models/Home/IndexViewModel.cs | 4 ++-- .../Models/PasswordResetCompletViewModel.cs | 4 ++-- .../Models/PasswordResetModel.cs | 4 ++-- .../Models/PasswordResetViewModel.cs | 4 ++-- .../Models/RegisterModel.cs | 8 +++---- .../Models/Results/AdminActionResult.cs | 16 ++++++++------ .../Models/Results/ChangePasswordResult.cs | 6 ++--- .../Models/Results/ConfirmationResult.cs | 11 +++++----- .../Models/Results/CreateLoginResult.cs | 4 ++-- .../Results/ForgotPasswordResetResult.cs | 6 ++--- .../Models/Results/PasswordResetResult.cs | 19 ++++++++-------- .../Models/Sandbox/SandboxIndexViewModel.cs | 4 ++-- .../Models/UserStatus.cs | 4 ++-- .../Modules/PostgresModule.cs | 2 +- .../Modules/SandboxAdminModule.cs | 2 +- .../Modules/SqlServerModule.cs | 2 +- Application/EdFi.Ods.SandboxAdmin/Program.cs | 2 +- .../Security/IIdentityProvider.cs | 2 +- .../Security/IdentityProvider.cs | 5 ++--- .../Security/SecurityRoles.cs | 4 ++-- .../Services/BackgroundJobService.cs | 18 ++++++++------- .../Services/ClientCreator.cs | 4 ++-- .../Services/EmailService.cs | 10 +++++++-- .../Services/IBackgroundJobService.cs | 7 +++++- .../Services/IClientCreator.cs | 2 +- .../Services/IEmailService.cs | 4 ++-- .../Services/IPasswordService.cs | 4 ++-- .../Services/IRouteService.cs | 4 ++-- .../Services/ISecurityService.cs | 4 ++-- .../Services/ITemplateDatabaseLeaQuery.cs | 4 ++-- .../Services/IUserAccountManager.cs | 4 ++-- .../Services/PasswordService.cs | 12 +++++----- .../PostgresTemplateDatabaseLeaQuery.cs | 2 +- .../Services/RouteService.cs | 2 +- .../Services/SecurityService.cs | 2 +- .../SqlServerTemplateDatabaseLeaQuery.cs | 4 ++-- .../Services/TemplateDatabaseLeaQueryBase.cs | 2 +- .../Services/UserAccountManager.cs | 10 ++++----- Application/EdFi.Ods.SandboxAdmin/Startup.cs | 8 +++++-- 68 files changed, 203 insertions(+), 184 deletions(-) diff --git a/Application/EdFi.Ods.SandboxAdmin/Contexts/DatabaseEngineDbConfiguration.cs b/Application/EdFi.Ods.SandboxAdmin/Contexts/DatabaseEngineDbConfiguration.cs index 6a714f8ae..bfdc31678 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Contexts/DatabaseEngineDbConfiguration.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Contexts/DatabaseEngineDbConfiguration.cs @@ -5,7 +5,6 @@ using System.Data.Entity; using EdFi.Common.Configuration; -using EdFi.Ods.Common.Configuration; using Npgsql; namespace EdFi.Ods.Sandbox.Admin.Contexts @@ -32,4 +31,4 @@ public DatabaseEngineDbConfiguration(DatabaseEngine databaseEngine) SetDefaultConnectionFactory(connectionFactory: new NpgsqlConnectionFactory()); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Contexts/IdentityContext.cs b/Application/EdFi.Ods.SandboxAdmin/Contexts/IdentityContext.cs index db3ba1031..a8632cd8a 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Contexts/IdentityContext.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Contexts/IdentityContext.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Contexts/PostgresIdentityContext.cs b/Application/EdFi.Ods.SandboxAdmin/Contexts/PostgresIdentityContext.cs index 33502a5c3..2b2971496 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Contexts/PostgresIdentityContext.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Contexts/PostgresIdentityContext.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -55,4 +55,4 @@ protected override void ApplyProviderSpecificConnection(DbContextOptionsBuilder optionsBuilder.UseNpgsql(_connectionString); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Contexts/SqlServerIdentityContext.cs b/Application/EdFi.Ods.SandboxAdmin/Contexts/SqlServerIdentityContext.cs index bca2cd788..6d25f2b99 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Contexts/SqlServerIdentityContext.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Contexts/SqlServerIdentityContext.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -21,4 +21,4 @@ protected override void ApplyProviderSpecificConnection(DbContextOptionsBuilder optionsBuilder.UseSqlServer(_connectionString); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/AccountController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/AccountController.cs index e0c0b4c0d..afefc6d0b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/AccountController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/AccountController.cs @@ -64,7 +64,7 @@ public async Task Create(CreateLoginModel model) } // Failed Model Validation - Response.StatusCode = (int)HttpStatusCode.BadRequest; + Response.StatusCode = (int) HttpStatusCode.BadRequest; return Json(BuildJsonResponseFromModelState()); } @@ -245,7 +245,7 @@ public ActionResult PasswordResetSuccessful() return View( new PasswordResetCompletViewModel { - Message = (string)message + Message = (string) message }); } @@ -296,7 +296,7 @@ public async Task Login(LoginModel model) } //Failed Login - Response.StatusCode = (int)HttpStatusCode.Unauthorized; + Response.StatusCode = (int) HttpStatusCode.Unauthorized; return Json( new @@ -307,7 +307,7 @@ public async Task Login(LoginModel model) } // Failed Model Validation - Response.StatusCode = (int)HttpStatusCode.BadRequest; + Response.StatusCode = (int) HttpStatusCode.BadRequest; return Json(BuildJsonResponseFromModelState()); } @@ -360,4 +360,4 @@ private string GetErrorMessageFromModelState() return string.Join("\n", errorMessages); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs index b9530d92e..2c8db9f12 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -18,6 +18,7 @@ using EdFi.Ods.Sandbox.Provisioners; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using System.Text; namespace EdFi.Ods.SandboxAdmin.Controllers.Api { @@ -92,17 +93,18 @@ public async Task GetClients() { var currentException = e; var counter = 0; - var message = string.Empty; + var message = new StringBuilder(); while (currentException != null) { Trace.TraceError("{0}: {1}", currentException.Message, currentException.StackTrace); - message += string.Format("{0}:{1}", counter, currentException.Message); + message.AppendLine($"{counter}:{currentException.Message}"); counter++; currentException = currentException.InnerException; } - throw new Exception(string.Format("Unhandled exception with these messages: {0}", message)); + // This is not an ideal exception type, but it is better than a plain Exception + throw new InvalidOperationException(string.Format("Unhandled exception with these messages: {0}", message)); } } @@ -170,7 +172,7 @@ public async Task PostClient([FromBody] SandboxClientCreateModel } } - return StatusCode((int)HttpStatusCode.NotAcceptable); + return StatusCode((int) HttpStatusCode.NotAcceptable); } [HttpPut("{id}")] @@ -207,4 +209,4 @@ public void DeleteClient([FromRoute] string id) } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/SandboxController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/SandboxController.cs index 6e1a49bad..4d76f83d3 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/SandboxController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/SandboxController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -10,7 +10,9 @@ namespace EdFi.Ods.SandboxAdmin.Controllers.Api { +#pragma warning disable S101 // Types should be named in PascalCase, however, uppercase is preferred for acronyms such as "DTO" public class SandboxDTO +#pragma warning restore S101 // Types should be named in PascalCase { public string Command { get; set; } } @@ -41,4 +43,4 @@ public void Put(SandboxDTO sandboxDTO) } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/UserProfileController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/UserProfileController.cs index 9c4a3d7b0..ee2c38d5d 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/UserProfileController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/UserProfileController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -39,24 +39,6 @@ public IActionResult Get(int id) return Ok(user); } - //// POST api/userprofile - //public void Post([FromBody]UserProfile value) - //{ - //} - - // PUT api/userprofile/5 - /// - /// Used to enable or disable user, nothing else - /// - /// - /// - - //public void Put(int id, [FromBody]UserProfile value) - //{ - // var user = _clientAppRepo.GetUserProfile(id); - // if (user == null) throw new HttpResponseException(HttpStatusCode.NotFound); - //} - // DELETE api/userprofile/5 public void Delete(int id) { @@ -70,4 +52,4 @@ public void Delete(int id) _clientAppRepo.DeleteUser(user); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/ClientController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/ClientController.cs index a54ab5425..2e310d65b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/ClientController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/ClientController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,4 +15,4 @@ public ActionResult Index() return View(); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/HomeController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/HomeController.cs index b8f49e795..98312b079 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/HomeController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/SandboxController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/SandboxController.cs index 845fb1c24..519e94519 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/SandboxController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/SandboxController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -111,4 +111,4 @@ public ActionResult RemoveOrphans() }); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/TestUsersController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/TestUsersController.cs index 2b36b8ab2..96a7b7f28 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/TestUsersController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/TestUsersController.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,4 +15,4 @@ public ActionResult Initialize() return Content("Successfully initialized test users."); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/ExpressionExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/ExpressionExtensions.cs index e10bc7bae..934a19ccc 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/ExpressionExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/ExpressionExtensions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -43,4 +43,4 @@ public static string MemberName(this LambdaExpression expression) throw new ArgumentException(string.Format("Expression '{0}' of type '{1}' is not handled", expression, expression.Body.GetType())); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/HealthCheckServiceExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/HealthCheckServiceExtensions.cs index 4763cc5cc..29d3c6256 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/HealthCheckServiceExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/HealthCheckServiceExtensions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/PasswordExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/PasswordExtensions.cs index bc5d29355..6d5fd051d 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/PasswordExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/PasswordExtensions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -44,4 +44,4 @@ private static bool HasCharacter(string input, string pattern) return Regex.IsMatch(input, string.Format("^.*[{0}].*$", pattern)); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/RequestExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/RequestExtensions.cs index f37df9dd8..d788e6099 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/RequestExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/RequestExtensions.cs @@ -6,7 +6,6 @@ using System; using log4net; using Microsoft.AspNetCore.Http; -using Microsoft.EntityFrameworkCore.Internal; namespace EdFi.Ods.Sandbox.Admin.Extensions { diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/StringExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/StringExtensions.cs index b64081118..cab27c845 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/StringExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/StringExtensions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -14,7 +14,7 @@ public static bool IsValidEmailAddress(this string address) { try { - var ma = new MailAddress(address); + _ = new MailAddress(address); return true; } catch (FormatException) @@ -23,4 +23,4 @@ public static bool IsValidEmailAddress(this string address) } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Extensions/TempDataExtensions.cs b/Application/EdFi.Ods.SandboxAdmin/Extensions/TempDataExtensions.cs index 4e6bf11c0..62ea61601 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Extensions/TempDataExtensions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Extensions/TempDataExtensions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -37,7 +37,7 @@ public static bool HasErrorMessage(this ITempDataDictionary tempData) public static string GetErrorMessage(this ITempDataDictionary tempData) { - return (string)tempData[ErrorKey]; + return (string) tempData[ErrorKey]; } public static void SetFlag(this ITempDataDictionary tempData, string key) @@ -50,4 +50,4 @@ public static bool GetFlag(this ITempDataDictionary tempData, string key) return tempData.ContainsKey(key); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Filters/SetCurrentUserInfoAttribute.cs b/Application/EdFi.Ods.SandboxAdmin/Filters/SetCurrentUserInfoAttribute.cs index a7a03a43a..dd43fcdb3 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Filters/SetCurrentUserInfoAttribute.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Filters/SetCurrentUserInfoAttribute.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -33,16 +33,16 @@ private ISecurityService SecurityService get { return _securityServiceLocator(); } } - public override void OnActionExecuted(ActionExecutedContext filterContext) + public override void OnActionExecuted(ActionExecutedContext context) { - if (filterContext.HttpContext.Request.IsAjaxRequest()) + if (context.HttpContext.Request.IsAjaxRequest()) { return; } string currentUserName = _httpContextAccessor.HttpContext.User?.Identity?.Name; var userLookup = SecurityService.GetCurrentUser(currentUserName); - ((Controller)(filterContext.Controller)).ViewBag.UserLookup = userLookup; + ((Controller) (context.Controller)).ViewBag.UserLookup = userLookup; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Initialization/InitializationEngine.cs b/Application/EdFi.Ods.SandboxAdmin/Initialization/InitializationEngine.cs index e87a9be36..fed2d72fc 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Initialization/InitializationEngine.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Initialization/InitializationEngine.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -163,7 +163,26 @@ public void RebuildSandboxes() List resetSandboxKeys = new List(); try { + // The code analyzer wants to change to the following, which I do not like due to the + // "database style" of Linq. We should decide if we want to disable or keep this rule. + // More info: https://rules.sonarsource.com/csharp/RSPEC-3267 +#pragma warning disable S125 // Sections of code should not be commented out + /* + foreach (var (clientProfile, sandbox) in from user in _users + let clientProfile = _clientAppRepo.GetUser(user.Value.Email) + from sandbox in user.Value.Sandboxes.Where(x => x.Value.Refresh) + select (clientProfile, sandbox)) + { + if (resetSandboxKeys.Contains(sandbox.Key)) + { + continue; + } + */ +#pragma warning restore S125 // Sections of code should not be commented out + +#pragma warning disable S3267 // Loops should be simplified with "LINQ" expressions foreach (var user in _users) +#pragma warning restore S3267 // Loops should be simplified with "LINQ" expressions { var clientProfile = _clientAppRepo.GetUser(user.Value.Email); diff --git a/Application/EdFi.Ods.SandboxAdmin/Initialization/SandboxOptions.cs b/Application/EdFi.Ods.SandboxAdmin/Initialization/SandboxOptions.cs index 2d3355c5a..304541b92 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Initialization/SandboxOptions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Initialization/SandboxOptions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -17,4 +17,4 @@ public class SandboxOptions public bool Refresh { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Initialization/UserOptions.cs b/Application/EdFi.Ods.SandboxAdmin/Initialization/UserOptions.cs index df21c0610..84f5f8dfc 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Initialization/UserOptions.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Initialization/UserOptions.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserModel.cs index e06e79ef8..9ccc8c006 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,4 +15,4 @@ public class ActivateUserModel public string ConfirmPassword { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserViewModel.cs index 8f29ef11e..510e818d2 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/ActivateUserViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -20,4 +20,4 @@ public bool ShowErrorMessage public bool ShowResendEmailLink { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/ChangePasswordModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/ChangePasswordModel.cs index 26d265e0a..ae6e0cbae 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/ChangePasswordModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/ChangePasswordModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,4 +15,4 @@ public class ChangePasswordModel public string UserName { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Client/ClientIndexViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Client/ClientIndexViewModel.cs index 81f98d222..f85d7591b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Client/ClientIndexViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Client/ClientIndexViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -30,4 +30,4 @@ public bool IsLoading get { return Status != ApiClientStatus.Online; } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Client/SandboxClientCreateModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Client/SandboxClientCreateModel.cs index 242c4146b..e2e47a451 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Client/SandboxClientCreateModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Client/SandboxClientCreateModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -13,4 +13,4 @@ public class SandboxClientCreateModel public SandboxType SandboxType { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/CreateLoginModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/CreateLoginModel.cs index ec889ec85..3d092e483 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/CreateLoginModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/CreateLoginModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,4 +15,4 @@ public class CreateLoginModel [Required] public string Name { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/ForgotPasswordModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/ForgotPasswordModel.cs index 08bd95348..da0c38e7d 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/ForgotPasswordModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/ForgotPasswordModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -9,4 +9,4 @@ public class ForgotPasswordModel { public string Email { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Home/IndexViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Home/IndexViewModel.cs index 40dbfc070..176247507 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Home/IndexViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Home/IndexViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -11,4 +11,4 @@ public class IndexViewModel public bool UserIsAdmin { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetCompletViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetCompletViewModel.cs index 398d621b1..d2b3def2c 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetCompletViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetCompletViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -9,4 +9,4 @@ public class PasswordResetCompletViewModel { public string Message { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetModel.cs index 1f04b0ab8..bec563da3 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -18,4 +18,4 @@ public class PasswordResetModel : ResetRequestValidationModel public string ConfirmPassword { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetViewModel.cs index 171b3d71a..587dbb7cc 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/PasswordResetViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -11,4 +11,4 @@ public class PasswordResetViewModel public string Email { get; set; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/RegisterModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/RegisterModel.cs index 18fdfe1fc..8e4c7f5c5 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/RegisterModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/RegisterModel.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. namespace EdFi.Ods.SandboxAdmin.Models { diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs index 4f64d7bca..eab683dfd 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs @@ -23,10 +23,12 @@ public bool HasMessage get { return !string.IsNullOrEmpty(Message); } } - public string[] FailingFields - { - get { return _failingFields.ToArray(); } - } + // SF: I agree with this recommendation from SonarSource. However, I am nervous + // that this isn't being falgged as unused, yet changing to a method isn't + // breaking anything. Would need to test this thoroughly. Might prefer to + // make an exception and leave this alone. For more information, see + // https://rules.sonarsource.com/csharp/RSPEC-2365 + public string[] GetFailingFields() => _failingFields.ToArray(); public bool Success { get; set; } @@ -35,7 +37,7 @@ public string[] FailingFields public TResult WithMessage(string message) { Message = message; - return (TResult)this; + return (TResult) this; } public TResult AddFailingField(Expression> field) @@ -44,7 +46,7 @@ public TResult AddFailingField(Expression> field) field.MemberName() .ToLower()); - return (TResult)this; + return (TResult) this; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ChangePasswordResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ChangePasswordResult.cs index 16a928d51..c5f2f4440 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ChangePasswordResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ChangePasswordResult.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -7,9 +7,9 @@ namespace EdFi.Ods.SandboxAdmin.Models.Results { public class ChangePasswordResult : AdminActionResult { - public static ChangePasswordResult Successful = new ChangePasswordResult + public static ChangePasswordResult Successful { get; private set; } = new ChangePasswordResult { Success = true }; } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ConfirmationResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ConfirmationResult.cs index 5eb213379..81f5eb5b7 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ConfirmationResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ConfirmationResult.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -7,14 +7,13 @@ namespace EdFi.Ods.SandboxAdmin.Models.Results { public class ConfirmationResult : AdminActionResult { - public static ConfirmationResult UserAlreadyConfirmed = new ConfirmationResult + public static ConfirmationResult UserAlreadyConfirmed { get; set; } = new ConfirmationResult { Success = false, - Message = - "This account has already been confirmed. Would you like to reset your password?" + Message = "This account has already been confirmed. Would you like to reset your password?" }; - public static ConfirmationResult Failure = new ConfirmationResult + public static ConfirmationResult Failure { get; set; } = new ConfirmationResult { Success = false, Message = "Your confirmation request is invalid or expired." @@ -34,4 +33,4 @@ public static ConfirmationResult Successful(string userName, string passwordRese }; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/CreateLoginResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/CreateLoginResult.cs index aa2affe40..65641079b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/CreateLoginResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/CreateLoginResult.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -26,4 +26,4 @@ public string UserStatusMessage get { return UserStatus.ToString(); } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ForgotPasswordResetResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ForgotPasswordResetResult.cs index e9b3b0cc6..9bef32b15 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/ForgotPasswordResetResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/ForgotPasswordResetResult.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -7,7 +7,7 @@ namespace EdFi.Ods.SandboxAdmin.Models.Results { public class ForgotPasswordResetResult : AdminActionResult { - public static ForgotPasswordResetResult Successful = new ForgotPasswordResetResult + public static ForgotPasswordResetResult Successful { get; private set; } = new ForgotPasswordResetResult { Success = true }; @@ -23,4 +23,4 @@ public static ForgotPasswordResetResult BadEmail(string email) }; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/PasswordResetResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/PasswordResetResult.cs index 3d3e19744..550bf92f2 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/PasswordResetResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/PasswordResetResult.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -15,25 +15,26 @@ public enum PasswordResetStatus public class PasswordResetResult : AdminActionResult { - public static PasswordResetResult Successful = new PasswordResetResult + public static PasswordResetResult Successful { get; set; } = new PasswordResetResult { Success = true }; - public static PasswordResetResult BadUsername = new PasswordResetResult + + public static PasswordResetResult BadUsername { get; set; } = new PasswordResetResult { Success = false, ResetStatus = PasswordResetStatus.BadUsername, - Message = - "We are having some trouble looking up your account. Please enter your email address to send a verification link." + Message = "We are having some trouble looking up your account. Please enter your email address to send a verification link." }; - public static PasswordResetResult BadPassword = new PasswordResetResult + + public static PasswordResetResult BadPassword { get; set; } = new PasswordResetResult { Success = false, ResetStatus = PasswordResetStatus.BadPassword, Message = "The password you entered is invalid." } - .AddFailingField(x => x.Password) - .AddFailingField(x => x.ConfirmPassword); + .AddFailingField(x => x.Password) + .AddFailingField(x => x.ConfirmPassword); public PasswordResetStatus ResetStatus { get; private set; } @@ -51,4 +52,4 @@ public static PasswordResetResult Expired(string email) }; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Sandbox/SandboxIndexViewModel.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Sandbox/SandboxIndexViewModel.cs index e5bd992af..b4fa5800a 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Sandbox/SandboxIndexViewModel.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Sandbox/SandboxIndexViewModel.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -46,4 +46,4 @@ public bool HasMissing get { return MissingSandboxes.Length > 0; } } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/UserStatus.cs b/Application/EdFi.Ods.SandboxAdmin/Models/UserStatus.cs index dc14f757c..999e6e82f 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/UserStatus.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/UserStatus.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -13,4 +13,4 @@ public enum UserStatus NeedsEmailConfirmation, Failed } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Modules/PostgresModule.cs b/Application/EdFi.Ods.SandboxAdmin/Modules/PostgresModule.cs index 28df28f04..1bbbf3e33 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Modules/PostgresModule.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Modules/PostgresModule.cs @@ -17,4 +17,4 @@ protected override void Load(ContainerBuilder builder) builder.RegisterType().As(); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Modules/SandboxAdminModule.cs b/Application/EdFi.Ods.SandboxAdmin/Modules/SandboxAdminModule.cs index 97bc549c8..4c7491510 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Modules/SandboxAdminModule.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Modules/SandboxAdminModule.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Modules/SqlServerModule.cs b/Application/EdFi.Ods.SandboxAdmin/Modules/SqlServerModule.cs index 2fb7288e6..dda62d3d5 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Modules/SqlServerModule.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Modules/SqlServerModule.cs @@ -17,4 +17,4 @@ protected override void Load(ContainerBuilder builder) builder.RegisterType().As(); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Program.cs b/Application/EdFi.Ods.SandboxAdmin/Program.cs index 10f9de1ce..b53fdffec 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Program.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Program.cs @@ -16,7 +16,7 @@ namespace EdFi.Ods.SandboxAdmin { - public class Program + public static class Program { public static async Task Main(string[] args) { diff --git a/Application/EdFi.Ods.SandboxAdmin/Security/IIdentityProvider.cs b/Application/EdFi.Ods.SandboxAdmin/Security/IIdentityProvider.cs index 787eef2f9..1148369ba 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Security/IIdentityProvider.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Security/IIdentityProvider.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Security/IdentityProvider.cs b/Application/EdFi.Ods.SandboxAdmin/Security/IdentityProvider.cs index c33293582..01237fa08 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Security/IdentityProvider.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Security/IdentityProvider.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Threading.Tasks; using log4net; -using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; namespace EdFi.Ods.SandboxAdmin.Security @@ -63,7 +62,7 @@ public async Task FindUserByEmail(string userEmail) return await _userManager.FindByEmailAsync(userEmail); } - public async Task Login(string userEmail, string password, bool isPersistent = false) + public async Task Login(string userEmail, string password, bool isPersistent) { var identityUser = await _userManager.FindByEmailAsync(userEmail); @@ -163,4 +162,4 @@ public async Task AddToRoles(string userId, IEnumerable roles) } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Security/SecurityRoles.cs b/Application/EdFi.Ods.SandboxAdmin/Security/SecurityRoles.cs index 7f079c9f7..01cc13fd6 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Security/SecurityRoles.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Security/SecurityRoles.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -14,4 +14,4 @@ public static class SecurityRoles Administrator }; } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/BackgroundJobService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/BackgroundJobService.cs index de94b549d..2ea7b0606 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/BackgroundJobService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/BackgroundJobService.cs @@ -1,4 +1,9 @@ -using Hangfire; +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. + +using Hangfire; using Microsoft.Extensions.Options; using System; using System.Linq; @@ -33,14 +38,11 @@ public void Configure() var id3 = BackgroundJob.ContinueJobWith(id2, () => _engine.CreateSandboxes()); BackgroundJob.ContinueJobWith(id3, () => _engine.UpdateClientWithLEAIdsFromPopulatedSandbox()); - foreach (var user in _users) + // refresh existing sandboxes periodically + if (_users.Any(x => x.Value.Sandboxes.Any(s => s.Value.Refresh))) { - // refresh existing sandboxes periodically - if (user.Value.Sandboxes.Any(s => s.Value.Refresh)) - { - // Change the recurrence to suit your needs using Cron functions or a unix CRON expressions (i.e. "* */6 * * *" = every 6 hours) - RecurringJob.AddOrUpdate("RebuildSandboxes", () => _engine.RebuildSandboxes(), Cron.Daily(), TimeZoneInfo.Local); - } + // Change the recurrence to suit your needs using Cron functions or a unix CRON expressions (i.e. "* */6 * * *" = every 6 hours) + RecurringJob.AddOrUpdate("RebuildSandboxes", () => _engine.RebuildSandboxes(), Cron.Daily(), TimeZoneInfo.Local); } } } diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/ClientCreator.cs b/Application/EdFi.Ods.SandboxAdmin/Services/ClientCreator.cs index 68a7e3a39..2982485af 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/ClientCreator.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/ClientCreator.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -109,4 +109,4 @@ private void ProvisionSandbox(ApiClient client) _sandboxProvisioner.AddSandbox(client.Key, client.SandboxType); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/EmailService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/EmailService.cs index 97be669db..a45772300 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/EmailService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/EmailService.cs @@ -117,7 +117,13 @@ private SmtpClient GetSmtpClientWithEnvironmentVariableExpansion() { Directory.CreateDirectory(smtpClient.PickupDirectoryLocation); } - catch { } +#pragma warning disable S2486 // Generic exceptions should not be ignored + catch + { + // TODO ODS-5492: it would be preferable to have a logger and at least record a message that + // the error occurred. + } +#pragma warning restore S2486 // Generic exceptions should not be ignored } return smtpClient; @@ -128,4 +134,4 @@ private MailAddress GetFromAddress() return new MailAddress(_configuration.GetValue("MailSettings:Smtp:From")); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IBackgroundJobService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IBackgroundJobService.cs index 8f13c1256..5061600ec 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IBackgroundJobService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IBackgroundJobService.cs @@ -1,4 +1,9 @@ -namespace EdFi.Ods.Sandbox.Admin.Services +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. + +namespace EdFi.Ods.Sandbox.Admin.Services { public interface IBackgroundJobService { diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IClientCreator.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IClientCreator.cs index 8c8d461e3..eba78048b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IClientCreator.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IClientCreator.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IEmailService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IEmailService.cs index 0de2ce37e..31a2f8568 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IEmailService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IEmailService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -11,4 +11,4 @@ public interface IEmailService void SendForgotPasswordEmail(string emailAddress, string secret); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IPasswordService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IPasswordService.cs index cd0127ebe..c7062f0b1 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IPasswordService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IPasswordService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -18,4 +18,4 @@ public interface IPasswordService bool PasswordIsStrong(string password); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IRouteService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IRouteService.cs index e8d8f078f..d34d46ea1 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IRouteService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IRouteService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -11,4 +11,4 @@ public interface IRouteService string GetRouteForActivation(string email, string marker); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/ISecurityService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/ISecurityService.cs index 50a97ff3c..4f8a55cd6 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/ISecurityService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/ISecurityService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -9,4 +9,4 @@ public interface ISecurityService { UserLookupResult GetCurrentUser(string currentUserName); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/ITemplateDatabaseLeaQuery.cs b/Application/EdFi.Ods.SandboxAdmin/Services/ITemplateDatabaseLeaQuery.cs index 5a5a02850..0236f6e6f 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/ITemplateDatabaseLeaQuery.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/ITemplateDatabaseLeaQuery.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -13,4 +13,4 @@ public interface ITemplateDatabaseLeaQuery Task GetLocalEducationAgencyIdsAsync(string sandboxKey); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/IUserAccountManager.cs b/Application/EdFi.Ods.SandboxAdmin/Services/IUserAccountManager.cs index 3d32c5e97..a561a1f53 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/IUserAccountManager.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/IUserAccountManager.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -23,4 +23,4 @@ public interface IUserAccountManager Task ResendConfirmationAsync(ForgotPasswordModel model); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/PasswordService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/PasswordService.cs index dad3b2b5c..835f3bf04 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/PasswordService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/PasswordService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -48,12 +48,10 @@ public async Task ValidateRequest(string userEmail, string return PasswordResetResult.BadUsername; } - if (!await _identityProvider.VerifyUserEmailConfirmed(userEmail)) + if (!await _identityProvider.VerifyUserEmailConfirmed(userEmail) + && !await _identityProvider.VerifyUserPassword(userEmail, secret)) { - if (!await _identityProvider.VerifyUserPassword(userEmail, secret)) - { - return PasswordResetResult.Expired(userEmail); - } + return PasswordResetResult.Expired(userEmail); } return PasswordResetResult.Successful; @@ -76,4 +74,4 @@ public bool PasswordIsStrong(string password) return password.IsStrongPassword(); } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/PostgresTemplateDatabaseLeaQuery.cs b/Application/EdFi.Ods.SandboxAdmin/Services/PostgresTemplateDatabaseLeaQuery.cs index b96daeac0..f152c8957 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/PostgresTemplateDatabaseLeaQuery.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/PostgresTemplateDatabaseLeaQuery.cs @@ -18,4 +18,4 @@ public PostgresTemplateDatabaseLeaQuery(IConfigConnectionStringsProvider configC protected override DbConnection CreateConnection(string templateDatabaseName) => new NpgsqlConnection(string.Format(_connectionStringTemplate, templateDatabaseName)); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/RouteService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/RouteService.cs index 67befd68f..bdcaa4a2e 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/RouteService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/RouteService.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/SecurityService.cs b/Application/EdFi.Ods.SandboxAdmin/Services/SecurityService.cs index 6a570bb97..357a0567e 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/SecurityService.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/SecurityService.cs @@ -86,4 +86,4 @@ public UserLookupResult GetCurrentUser(string currentUserName) } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/SqlServerTemplateDatabaseLeaQuery.cs b/Application/EdFi.Ods.SandboxAdmin/Services/SqlServerTemplateDatabaseLeaQuery.cs index 8ea5dcb39..fcb351126 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/SqlServerTemplateDatabaseLeaQuery.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/SqlServerTemplateDatabaseLeaQuery.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -18,4 +18,4 @@ public SqlServerTemplateDatabaseLeaQuery(IConfigConnectionStringsProvider config protected override DbConnection CreateConnection(string templateDatabaseName) => new SqlConnection(string.Format(_connectionStringTemplate, templateDatabaseName)); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/TemplateDatabaseLeaQueryBase.cs b/Application/EdFi.Ods.SandboxAdmin/Services/TemplateDatabaseLeaQueryBase.cs index 95ef35bfe..5993c106f 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/TemplateDatabaseLeaQueryBase.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/TemplateDatabaseLeaQueryBase.cs @@ -40,4 +40,4 @@ public async Task GetLocalEducationAgencyIdsAsync(string sandboxKey) protected abstract DbConnection CreateConnection(string templateDatabaseName); } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Services/UserAccountManager.cs b/Application/EdFi.Ods.SandboxAdmin/Services/UserAccountManager.cs index c26379f8d..96367a51b 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Services/UserAccountManager.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Services/UserAccountManager.cs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // Licensed to the Ed-Fi Alliance under one or more agreements. // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. // See the LICENSE and NOTICES files in the project root for more information. @@ -72,9 +72,9 @@ public async Task Create(CreateLoginModel model) .AddFailingField(x => x.Email); } - public async Task Login(string userEmail, string password, bool isPersistent = false) + public async Task Login(string userName, string password, bool isPersistent) { - return await _identityProvider.Login(userEmail, password, isPersistent); + return await _identityProvider.Login(userName, password, isPersistent); } public async Task ResetPassword(PasswordResetModel model) @@ -215,7 +215,7 @@ private async Task CreateNewUser(CreateLoginModel model) try { - bool success = await _identityProvider.CreateUser(model.Name, model.Email, randomPassword); + _ = await _identityProvider.CreateUser(model.Name, model.Email, randomPassword); string confirmationSecret = await _identityProvider.GenerateEmailConfirmationToken(model.Email); @@ -444,4 +444,4 @@ private static TResult EmailDown() return result; } } -} \ No newline at end of file +} diff --git a/Application/EdFi.Ods.SandboxAdmin/Startup.cs b/Application/EdFi.Ods.SandboxAdmin/Startup.cs index 7c755a71e..53ae2a7ee 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Startup.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Startup.cs @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. + using Autofac; using Autofac.Extensions.DependencyInjection; using EdFi.Ods.Common.Configuration; @@ -14,7 +19,6 @@ using System.Collections.Generic; using System.Data.Entity; using EdFi.Common.Configuration; -using EdFi.Common.Extensions; using EdFi.Ods.Sandbox.Admin.Contexts; using EdFi.Ods.SandboxAdmin.Filters; using EdFi.Ods.SandboxAdmin.Services; @@ -216,7 +220,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF if (!string.IsNullOrEmpty(pathBase)) { - app.UsePathBase("/" + pathBase.Trim('/')); + app.UsePathBase($"/{pathBase.Trim('/')}"); } Container = app.ApplicationServices.GetAutofacRoot(); From b72f0a7fb755cb775d67ca088d853bcbe78998dc Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Fri, 8 Jul 2022 17:04:10 -0500 Subject: [PATCH 7/8] Restore property --- .../Models/Results/AdminActionResult.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs b/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs index eab683dfd..57919758c 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Models/Results/AdminActionResult.cs @@ -23,12 +23,10 @@ public bool HasMessage get { return !string.IsNullOrEmpty(Message); } } - // SF: I agree with this recommendation from SonarSource. However, I am nervous - // that this isn't being falgged as unused, yet changing to a method isn't - // breaking anything. Would need to test this thoroughly. Might prefer to - // make an exception and leave this alone. For more information, see - // https://rules.sonarsource.com/csharp/RSPEC-2365 - public string[] GetFailingFields() => _failingFields.ToArray(); + // Properties should not make collection or array copies - cannot change because of downstream impact +#pragma warning disable S2365 + public string[] FailingFields => _failingFields.ToArray(); +#pragma warning restore S2365 // Properties should not make collection or array copies public bool Success { get; set; } From 37e09b30c2f3af64a7e7f0837e089f2d47fb9582 Mon Sep 17 00:00:00 2001 From: "Stephen A. Fuqua" Date: Mon, 11 Jul 2022 13:17:22 -0500 Subject: [PATCH 8/8] Restore throwing of an Exception --- Application/.editorconfig | 1 + .../EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Application/.editorconfig b/Application/.editorconfig index b1c8fc31b..219afecf2 100644 --- a/Application/.editorconfig +++ b/Application/.editorconfig @@ -125,6 +125,7 @@ dotnet_diagnostic.IDE0005.severity=warning # Remove unnecessary using directives # Lower the priority dotnet_diagnostic.S4136.severity=suggestion # Method overloads should be grouped together dotnet_diagnostic.S1135.severity=suggestion # Complete TODO comments +dotnet_diagnostic.S112.severity=suggestion # 'System.Exception' should not be thrown by user code. [**/tests/**/*.cs] diff --git a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs index 2c8db9f12..b7ece3191 100644 --- a/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs +++ b/Application/EdFi.Ods.SandboxAdmin/Controllers/Api/ClientController.cs @@ -103,8 +103,7 @@ public async Task GetClients() currentException = currentException.InnerException; } - // This is not an ideal exception type, but it is better than a plain Exception - throw new InvalidOperationException(string.Format("Unhandled exception with these messages: {0}", message)); + throw new Exception(string.Format("Unhandled exception with these messages: {0}", message)); } }