Skip to content

Commit 794b563

Browse files
authored
Merge pull request #44 from umbraco/feature/admins-add-section
Add section to admin group using package migration
2 parents eceb9a8 + 15335a1 commit 794b563

File tree

6 files changed

+2069
-45
lines changed

6 files changed

+2069
-45
lines changed
Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
4-
<ImplicitUsings>enable</ImplicitUsings>
5-
<Nullable>enable</Nullable>
6-
</PropertyGroup>
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
77

8-
<ItemGroup>
9-
<PackageReference Include="Umbraco.Cms" Version="14.2.0" />
10-
</ItemGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Umbraco.Cms" Version="14.2.0" />
10+
<ProjectReference Include="..\..\src\Our.Umbraco.UiExamples.v14\Our.Umbraco.UiExamples.v14.csproj" />
11+
</ItemGroup>
1112

12-
<ItemGroup>
13-
<!-- Opt-in to app-local ICU to ensure consistent globalization APIs across different platforms -->
14-
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="72.1.0.3" />
15-
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="72.1.0.3" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))" />
16-
</ItemGroup>
13+
<ItemGroup>
14+
<!-- Opt-in to app-local ICU to ensure consistent globalization APIs across different platforms -->
15+
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="72.1.0.3" />
16+
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="72.1.0.3" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))" />
17+
</ItemGroup>
1718

18-
<ItemGroup>
19-
<Folder Include="App_Plugins\Example.UI\" />
20-
</ItemGroup>
19+
<PropertyGroup>
20+
<!-- Razor files are needed for the backoffice to work correctly -->
21+
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
22+
</PropertyGroup>
2123

22-
<PropertyGroup>
23-
<!-- Razor files are needed for the backoffice to work correctly -->
24-
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
25-
</PropertyGroup>
26-
27-
<PropertyGroup>
28-
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
29-
<RazorCompileOnBuild>false</RazorCompileOnBuild>
30-
<RazorCompileOnPublish>false</RazorCompileOnPublish>
31-
</PropertyGroup>
24+
<PropertyGroup>
25+
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
26+
<RazorCompileOnBuild>false</RazorCompileOnBuild>
27+
<RazorCompileOnPublish>false</RazorCompileOnPublish>
28+
</PropertyGroup>
3229

3330
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Umbraco.Cms.Core;
2+
using Umbraco.Cms.Core.Services;
3+
using Umbraco.Cms.Infrastructure.Migrations;
4+
using Umbraco.Cms.Infrastructure.Scoping;
5+
6+
namespace Our.Umbraco.UiExamples.Migrations;
7+
8+
internal sealed class AddSectionToAdminsMigration : MigrationBase
9+
{
10+
private readonly IScopeProvider _scopeProvider;
11+
private readonly IUserService _userService;
12+
13+
public AddSectionToAdminsMigration(IMigrationContext context, IScopeProvider scopeProvider, IUserService userService)
14+
: base(context)
15+
{
16+
_userService = userService;
17+
_scopeProvider = scopeProvider;
18+
}
19+
20+
protected override void Migrate()
21+
{
22+
using var scope = _scopeProvider.CreateScope();
23+
24+
var adminGroup = _userService.GetUserGroupByAlias(Constants.Security.AdminGroupAlias);
25+
adminGroup.AddAllowedSection("example.ui.section");
26+
27+
_userService.Save(adminGroup);
28+
29+
scope.Complete();
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Umbraco.Cms.Core.Packaging;
2+
3+
namespace Our.Umbraco.UiExamples.Migrations;
4+
5+
internal sealed class UiExamplesMigrationPlan : PackageMigrationPlan
6+
{
7+
public UiExamplesMigrationPlan()
8+
: base("Our.Umbraco.UiExamples", "UI Examples", "UiExamples")
9+
{ }
10+
11+
public override bool IgnoreCurrentState => false;
12+
13+
protected override void DefinePlan()
14+
=> To<AddSectionToAdminsMigration>("AddedSectionForAdmins-Ran");
15+
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<Compile Remove="App_Plugins\**" />
11-
<EmbeddedResource Remove="App_Plugins\**" />
12-
<None Remove="App_Plugins\**" />
13-
</ItemGroup>
14-
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="Umbraco.Cms.Web.Common" Version="14.2.0" />
9+
</ItemGroup>
1510
</Project>

src/Our.Umbraco.UiExamples.v14/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"name": "our-umbraco-uiexamples-v14",
32
"private": true,
4-
"version": "0.0.0",
53
"type": "module",
64
"scripts": {
75
"dev": "tsc && vite build --watch",

0 commit comments

Comments
 (0)