Skip to content

Add section to admin group using package migration #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions samples/Umbraco14.Website/Umbraco14.Website.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Umbraco.Cms" Version="14.2.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Umbraco.Cms" Version="14.2.0" />
<ProjectReference Include="..\..\src\Our.Umbraco.UiExamples.v14\Our.Umbraco.UiExamples.v14.csproj" />
</ItemGroup>

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

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

<PropertyGroup>
<!-- Razor files are needed for the backoffice to work correctly -->
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>

<PropertyGroup>
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
<RazorCompileOnBuild>false</RazorCompileOnBuild>
<RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>
<PropertyGroup>
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
<RazorCompileOnBuild>false</RazorCompileOnBuild>
<RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations;
using Umbraco.Cms.Infrastructure.Scoping;

namespace Our.Umbraco.UiExamples.Migrations;

internal sealed class AddSectionToAdminsMigration : MigrationBase
{
private readonly IScopeProvider _scopeProvider;
private readonly IUserService _userService;

public AddSectionToAdminsMigration(IMigrationContext context, IScopeProvider scopeProvider, IUserService userService)
: base(context)
{
_userService = userService;
_scopeProvider = scopeProvider;
}

protected override void Migrate()
{
using var scope = _scopeProvider.CreateScope();

var adminGroup = _userService.GetUserGroupByAlias(Constants.Security.AdminGroupAlias);
adminGroup.AddAllowedSection("example.ui.section");

_userService.Save(adminGroup);

scope.Complete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Umbraco.Cms.Core.Packaging;

namespace Our.Umbraco.UiExamples.Migrations;

internal sealed class UiExamplesMigrationPlan : PackageMigrationPlan
{
public UiExamplesMigrationPlan()
: base("Our.Umbraco.UiExamples", "UI Examples", "UiExamples")
{ }

public override bool IgnoreCurrentState => false;

protected override void DefinePlan()
=> To<AddSectionToAdminsMigration>("AddedSectionForAdmins-Ran");
}
21 changes: 8 additions & 13 deletions src/Our.Umbraco.UiExamples.v14/Our.Umbraco.UiExamples.v14.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="App_Plugins\**" />
<EmbeddedResource Remove="App_Plugins\**" />
<None Remove="App_Plugins\**" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Umbraco.Cms.Web.Common" Version="14.2.0" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/Our.Umbraco.UiExamples.v14/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "our-umbraco-uiexamples-v14",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "tsc && vite build --watch",
Expand Down
Loading