Convert Tourdata into a more generic concept (#15923)
* Added UserData and migrated tours data into it * Remove tourdata from user * Removed tour definition/manipulation classes Fixed a userData error typo * Removed toursettings * Update openapi spec * V13: Align database schemas of migrated and new database (#15934) * Drop default constraint umbracoCacheInstruction table * Align umbracoContentVersion table * Update indexes on external login table * Align node table * Make relation type index unique * Remove user-group default constraint * Re-order methods * Make webhook url not nullable * Cleanup * Cleanup * Update OpenApi.json * Update src/Umbraco.Cms.Api.Management/Controllers/UserData/UserDataControllerBase.cs * Remove tour settings from schema * Add cancelation tokens * Dont inject, but take as parameter * Remove some from injection * Update schema --------- Co-authored-by: Sven Geusens <sge@umbraco.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Co-authored-by: Zeegaan <skrivdetud@gmail.com>
This commit is contained in:
@@ -1,38 +1,102 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Querying;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
[Obsolete($"Use {nameof(ISystemTroubleshootingInformationService)} instead. Will be removed in V16.")]
|
||||
public class UserDataService : IUserDataService
|
||||
public class UserDataService : RepositoryService, IUserDataService
|
||||
{
|
||||
private readonly ISystemTroubleshootingInformationService _systemTroubleshootingInformationService;
|
||||
private readonly IUserDataRepository _userDataRepository;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
[Obsolete($"Use the constructor that accepts {nameof(ISystemTroubleshootingInformationService)}")]
|
||||
public UserDataService(IUmbracoVersion version, ILocalizationService localizationService)
|
||||
: this(version, localizationService, StaticServiceProvider.Instance.GetRequiredService<ISystemTroubleshootingInformationService>())
|
||||
public UserDataService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IUserDataRepository userDataRepository,
|
||||
IUserService userService)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
_userDataRepository = userDataRepository;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public UserDataService(IUmbracoVersion version, ILocalizationService localizationService, ISystemTroubleshootingInformationService systemTroubleshootingInformationService)
|
||||
=> _systemTroubleshootingInformationService = systemTroubleshootingInformationService;
|
||||
|
||||
[Obsolete($"Use {nameof(ISystemTroubleshootingInformationService)} instead. Will be removed in V16.")]
|
||||
public IEnumerable<UserData> GetUserData() =>
|
||||
_systemTroubleshootingInformationService.GetTroubleshootingInformation().Select(kvp => new UserData(kvp.Key, kvp.Value)).ToArray();
|
||||
|
||||
public bool IsRunningInProcessIIS()
|
||||
public async Task<IUserData?> GetAsync(Guid key)
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
IUserData? userData = await _userDataRepository.GetAsync(key);
|
||||
scope.Complete();
|
||||
return userData;
|
||||
}
|
||||
|
||||
public async Task<PagedModel<IUserData>> GetAsync(int skip, int take, IUserDataFilter? filter = null)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
PagedModel<IUserData> pagedUserData = await _userDataRepository.GetAsync(skip, take, filter);
|
||||
scope.Complete();
|
||||
return pagedUserData;
|
||||
}
|
||||
|
||||
public async Task<Attempt<IUserData, UserDataOperationStatus>> CreateAsync(IUserData userData)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
IUserData? existingUserData = await _userDataRepository.GetAsync(userData.Key);
|
||||
if (existingUserData is not null)
|
||||
{
|
||||
return false;
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Fail(UserDataOperationStatus.AlreadyExists, userData);
|
||||
}
|
||||
|
||||
var processName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
|
||||
return processName.Contains("w3wp") || processName.Contains("iisexpress");
|
||||
if (await ReferencedUserExits(userData) is false)
|
||||
{
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Fail(UserDataOperationStatus.UserNotFound, userData);
|
||||
}
|
||||
|
||||
await _userDataRepository.Save(userData);
|
||||
|
||||
scope.Complete();
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Succeed(UserDataOperationStatus.Success, userData);
|
||||
}
|
||||
|
||||
public async Task<Attempt<IUserData, UserDataOperationStatus>> UpdateAsync(IUserData userData)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
IUserData? existingUserData = await _userDataRepository.GetAsync(userData.Key);
|
||||
if (existingUserData is null)
|
||||
{
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Fail(UserDataOperationStatus.NotFound, userData);
|
||||
}
|
||||
|
||||
if (await ReferencedUserExits(userData) is false)
|
||||
{
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Fail(UserDataOperationStatus.UserNotFound, userData);
|
||||
}
|
||||
|
||||
await _userDataRepository.Update(userData);
|
||||
|
||||
scope.Complete();
|
||||
return Attempt<IUserData, UserDataOperationStatus>.Succeed(UserDataOperationStatus.Success, userData);
|
||||
}
|
||||
|
||||
public async Task<Attempt<UserDataOperationStatus>> DeleteAsync(Guid key)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
IUserData? existingUserData = await _userDataRepository.GetAsync(key);
|
||||
if (existingUserData is null)
|
||||
{
|
||||
return Attempt<UserDataOperationStatus>.Fail(UserDataOperationStatus.NotFound);
|
||||
}
|
||||
|
||||
await _userDataRepository.Delete(existingUserData);
|
||||
|
||||
scope.Complete();
|
||||
return Attempt<UserDataOperationStatus>.Succeed(UserDataOperationStatus.Success);
|
||||
}
|
||||
|
||||
private async Task<bool> ReferencedUserExits(IUserData userData)
|
||||
=> await _userService.GetAsync(userData.UserKey) is not null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user