Skip to content

Commit

Permalink
Merge pull request #375 from Kentico/kentico-13
Browse files Browse the repository at this point in the history
Add support for Kentico 13
  • Loading branch information
JosefDvorak authored Nov 13, 2023
2 parents 6b21ae1 + a4c5e6b commit e6d687d
Show file tree
Hide file tree
Showing 205 changed files with 23,270 additions and 10,973 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# See https://help.github.com/articles/about-code-owners/

* @JosefDvorak
* @kentico-ericd
15 changes: 10 additions & 5 deletions KInspector.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F3EF3619-F312-4B17-B5BE-5764A8010D38}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -27,9 +26,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KenticoInspector.Reports",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KenticoInspector.Reports.Tests", "KenticoInspector.Reports.Tests\KenticoInspector.Reports.Tests.csproj", "{3F359210-5970-4CAA-B442-338F2EC51729}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KenticoInspector.Infrastructure.Tests", "KenticoInspector.Infrastructure.Tests\KenticoInspector.Infrastructure.Tests.csproj", "{7C8E2AC5-5ED5-45D7-8EB4-39F3BEECCFDA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KenticoInspector.Infrastructure.Tests", "KenticoInspector.Infrastructure.Tests\KenticoInspector.Infrastructure.Tests.csproj", "{7C8E2AC5-5ED5-45D7-8EB4-39F3BEECCFDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KenticoInspector.Core.Tests", "KenticoInspector.Core.Tests\KenticoInspector.Core.Tests.csproj", "{46F38A42-61A3-4FA9-9FB0-32B343CFA6A2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KenticoInspector.Core.Tests", "KenticoInspector.Core.Tests\KenticoInspector.Core.Tests.csproj", "{46F38A42-61A3-4FA9-9FB0-32B343CFA6A2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KenticoInspector.Actions", "KenticoInspector.Actions\KenticoInspector.Actions.csproj", "{29948680-57BC-487A-A8E5-F68674CEB694}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -65,6 +66,10 @@ Global
{46F38A42-61A3-4FA9-9FB0-32B343CFA6A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46F38A42-61A3-4FA9-9FB0-32B343CFA6A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46F38A42-61A3-4FA9-9FB0-32B343CFA6A2}.Release|Any CPU.Build.0 = Release|Any CPU
{29948680-57BC-487A-A8E5-F68674CEB694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29948680-57BC-487A-A8E5-F68674CEB694}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29948680-57BC-487A-A8E5-F68674CEB694}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29948680-57BC-487A-A8E5-F68674CEB694}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
23 changes: 23 additions & 0 deletions KenticoInspector.Actions/ActionsModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Autofac;

using KenticoInspector.Core.Modules;

using System.Reflection;

namespace KenticoInspector.Reports
{
public class ActionsModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
var assemblies = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.IsClass
&& !t.IsAbstract
&& typeof(IAction).IsAssignableFrom(t)
)
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
}
}
}
27 changes: 27 additions & 0 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KenticoInspector.Core\KenticoInspector.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="ResetCmsUserLogin\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ResetCmsUserLogin\Scripts\GetAdministrators.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ResetCmsUserLogin\Scripts\ResetAndEnableUser.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
78 changes: 78 additions & 0 deletions KenticoInspector.Actions/ResetCmsUserLogin/Action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using KenticoInspector.Actions.ResetCmsUserLogin.Models;
using KenticoInspector.Core;
using KenticoInspector.Core.Constants;
using KenticoInspector.Core.Helpers;
using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;

using System;
using System.Collections.Generic;

namespace KenticoInspector.Actions.ResetCmsUserLogin
{
public class Action : AbstractAction<Terms,Options>
{
private IDatabaseService databaseService;

public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("10", "11", "12", "13");

public override IList<string> Tags => new List<string> {
ActionTags.Reset,
ActionTags.User
};

public Action(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService)
{
this.databaseService = databaseService;
}

public override ActionResults Execute(Options options)
{
if (options.UserId < 0)
{
return GetInvalidOptionsResult();
}

// No user provided, list users
if (options.UserId == 0)
{
return GetListingResult();
}

// Reset provided user
databaseService.ExecuteSqlFromFileGeneric(Scripts.ResetAndEnableUser, new { UserID = options.UserId });
var result = GetListingResult();
result.Summary = Metadata.Terms.UserReset.With(new {
userId = options.UserId
});

return result;
}

public override ActionResults GetInvalidOptionsResult()
{
return new ActionResults {
Status = ResultsStatus.Error,
Summary = Metadata.Terms.InvalidOptions
};
}

private ActionResults GetListingResult()
{
var administratorUsers = databaseService.ExecuteSqlFromFile<CmsUser>(Scripts.GetAdministrators);
var data = new TableResult<CmsUser>()
{
Name = Metadata.Terms.TableTitle,
Rows = administratorUsers
};

return new ActionResults
{
Type = ResultsType.Table,
Status = ResultsStatus.Information,
Summary = Metadata.Terms.ListSummary,
Data = data
};
}
}
}
12 changes: 12 additions & 0 deletions KenticoInspector.Actions/ResetCmsUserLogin/Metadata/en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
details:
name: Global Administrator Summary
shortDescription: Reset a global administrator so that you can login with an empty password.
longDescription: |
This action ensures that the global administrator user is enabled, their password is blank, and their last changed date is reset to today.
Run the action without options to view the global administrator accounts. To reset a user account, re-run the action with their user ID below.
terms:
tableTitle: Global administrators
invalidOptions: The user ID must be an integer greater than zero.
listSummary: Set the user ID you wish to reset and re-run
userReset: User ID <userId> was reset
7 changes: 7 additions & 0 deletions KenticoInspector.Actions/ResetCmsUserLogin/Models/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace KenticoInspector.Actions.ResetCmsUserLogin.Models
{
public class Options
{
public int UserId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KenticoInspector.Actions.ResetCmsUserLogin.Models
{
public class CmsUser
{
public int UserID { get; set; }

public string UserName { get; set; }

public string Password { get; set; }

public bool Enabled { get; set; }
}
}
15 changes: 15 additions & 0 deletions KenticoInspector.Actions/ResetCmsUserLogin/Models/Terms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using KenticoInspector.Core.Models;

namespace KenticoInspector.Actions.ResetCmsUserLogin.Models
{
public class Terms
{
public Term InvalidOptions { get; internal set; }

public Term TableTitle { get; internal set; }

public Term ListSummary { get; internal set; }

public Term UserReset { get; internal set; }
}
}
11 changes: 11 additions & 0 deletions KenticoInspector.Actions/ResetCmsUserLogin/Scripts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace KenticoInspector.Actions.ResetCmsUserLogin
{
public static class Scripts
{
public static string BaseDirectory = $"{nameof(ResetCmsUserLogin)}/Scripts";

public static string GetAdministrators => $"{BaseDirectory}/{nameof(GetAdministrators)}.sql";

public static string ResetAndEnableUser => $"{BaseDirectory}/{nameof(ResetAndEnableUser)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT UserID, UserName, UserPassword AS 'Password', UserEnabled AS 'Enabled' FROM CMS_User WHERE UserPrivilegeLevel = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPDATE CMS_User
SET UserPassword = '', UserEnabled = 1
WHERE UserID = @UserID

UPDATE CMS_UserSettings
SET UserPasswordLastChanged = GETDATE()
WHERE UserSettingsUserID = @UserID
8 changes: 8 additions & 0 deletions KenticoInspector.Core.Tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<ItemGroup Label="StaticCodeAnalysis">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.41.0.50478">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions KenticoInspector.Core.Tests/SimpleTokenExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Should_Throw_When_ExpressionIsInvalid(string termString, object toke
}
}

public class TokenValues
public static class TokenValues
{
public static object IsUndefined => new { };

Expand Down Expand Up @@ -73,7 +73,7 @@ public class TokenValues
// TODO: Add valid expressions with contains url case
// TODO: Add valid expressions with multiple tokens

public class TokenExpressionTestCases
public static class TokenExpressionTestCases
{
private static string category;
private static string tokenExpression;
Expand Down
Loading

0 comments on commit e6d687d

Please sign in to comment.