Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UserModelMapperTests.cs
Bjarke Berg 2494d8c5aa Granular permissions in Management API (#15734)
* It builds..

* Added granular permissions

* Added granular permissions

* Rename content to document

* Added migration

* Fixed issues causing the migration from v13 was not possible.

* Merged Permissions and Granular Permissions in viewmodel

* Prepared the viewmodel to a future where permissions can be more types.

* OpenApi

* Allow to translate a single char to many strings

* Use frontend friendly values for known permissions

* Validate the documents exist

* Allow setting non-document settings

* Add "$type" when required

* Rename to presentation model and update OpenApi.json

* OpenApi.json

* Fix tests

* OpenAPI

* Fixed issues with upgrades

* Add the discriminator name

* Fixed issues that only happended on SqlServer

* Fixed queries for SqlServer

* Clean up

* More cleanup

* Fix issue when migrating sqlserver

* Split fallback permissions into own concept in view model

* Also split on current user

* Added a extenable pattern for mappers between DTO => Granular Permission => ViewModel and ViewModel => Granular Permission

* Fixed issue with new exists method, that did not take duplicate keys into account.

* Added sections to current user response model

* Formatting fixes

* Move class to its own file

* xml comment

---------

Co-authored-by: Zeegaan <skrivdetud@gmail.com>
2024-02-27 21:57:02 +01:00

43 lines
1.7 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Mapping;
[TestFixture]
[UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class UserModelMapperTests : UmbracoIntegrationTest
{
[SetUp]
public void Setup() => _sut = Services.GetRequiredService<IUmbracoMapper>();
private IUmbracoMapper _sut;
[Test]
public void Map_UserGroupSave_To_IUserGroup()
{
IUserGroup userGroup =
new UserGroup(ShortStringHelper, 0, "alias", "name", "icon") { Id = 42 };
userGroup.Permissions = new HashSet<string>() { "c" };
const string json =
"{\"id\":@@@ID@@@,\"alias\":\"perm1\",\"name\":\"Perm1\",\"icon\":\"icon-users\",\"sections\":[\"content\"],\"users\":[],\"defaultPermissions\":[\"F\",\"C\",\"A\"],\"assignedPermissions\":{},\"startContentId\":-1,\"startMediaId\":-1,\"action\":\"save\",\"parentId\":-1}";
var userGroupSave =
JsonConvert.DeserializeObject<UserGroupSave>(json.Replace("@@@ID@@@", userGroup.Id.ToString()));
// failed, AutoMapper complained, "Unable to cast object of type 'WhereSelectArrayIterator`2[System.Char,System.String]' to type 'System.Collections.IList'".
// TODO: added ToList() in UserGroupFactory
_sut.Map(userGroupSave, userGroup);
}
}