Revert files that shouldn't change back in v11

This commit is contained in:
Sebastiaan Janssen
2022-09-19 16:37:24 +02:00
parent 85147fb5e8
commit db5d05d641
201 changed files with 933 additions and 1859 deletions

View File

@@ -186,11 +186,13 @@ public class AuthenticationController : UmbracoApiControllerBase
[ValidateAngularAntiForgeryToken]
public async Task<IActionResult> PostUnLinkLogin(UnLinkLoginModel unlinkLoginModel)
{
BackOfficeIdentityUser? user = await _userManager.FindByIdAsync(User.Identity?.GetUserId());
if (user == null)
var userId = User.Identity?.GetUserId();
if (userId is null)
{
throw new InvalidOperationException("Could not find user");
throw new InvalidOperationException("Could not find userId");
}
var user = await _userManager.FindByIdAsync(userId);
if (user == null) throw new InvalidOperationException("Could not find user");
AuthenticationScheme? authType = (await _signInManager.GetExternalAuthenticationSchemesAsync())
.FirstOrDefault(x => x.Name == unlinkLoginModel.LoginProvider);
@@ -484,16 +486,19 @@ public class AuthenticationController : UmbracoApiControllerBase
UmbracoUserExtensions.GetUserCulture(user.Culture, _textService, _globalSettings),
new[] { code });
if (provider == "Email")
{
var mailMessage = new EmailMessage(from, user.Email, subject, message, true);
await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.TwoFactorAuth);
}
else if (provider == "Phone")
{
await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
}
if (provider == "Email")
{
var mailMessage = new EmailMessage(from, user.Email, subject, message, true);
await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.TwoFactorAuth);
}
else if (provider == "Phone")
{
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
if (phoneNumber is not null)
{
await _smsSender.SendSmsAsync(phoneNumber, message);
}
}
return Ok();
}
@@ -544,6 +549,10 @@ public class AuthenticationController : UmbracoApiControllerBase
{
BackOfficeIdentityUser? identityUser =
await _userManager.FindByIdAsync(model.UserId.ToString(CultureInfo.InvariantCulture));
if (identityUser is null)
{
return new ValidationErrorResult("Could not find user");
}
IdentityResult result = await _userManager.ResetPasswordAsync(identityUser, model.ResetCode, model.Password);
if (result.Succeeded)

View File

@@ -386,7 +386,7 @@ public class BackOfficeController : UmbracoController
[HttpGet]
public async Task<IActionResult> ExternalLinkLoginCallback()
{
BackOfficeIdentityUser user = await _userManager.GetUserAsync(User);
BackOfficeIdentityUser? user = await _userManager.GetUserAsync(User);
if (user == null)
{
// ... this should really not happen
@@ -504,9 +504,8 @@ public class BackOfficeController : UmbracoController
}
else if (result == SignInResult.TwoFactorRequired)
{
BackOfficeIdentityUser? attemptedUser =
await _userManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey);
if (attemptedUser == null)
BackOfficeIdentityUser? attemptedUser = await _userManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey);
if (attemptedUser?.UserName is null)
{
return new ValidationErrorResult(
$"No local user found for the login provider {loginInfo.LoginProvider} - {loginInfo.ProviderKey}");

View File

@@ -376,7 +376,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"currentUserApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<CurrentUserController>(
controller => controller.PostChangePassword(new ChangingPasswordModel()))
controller => controller.PostSetAvatar(new List<IFormFile>()))
},
{
"entityApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<EntityController>(
@@ -416,7 +416,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"memberTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MemberTypeController>(
controller => controller.GetAllTypes())
controller => controller.GetById(0))
},
{
"memberTypeQueryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MemberTypeQueryController>(

View File

@@ -81,47 +81,15 @@ public class CurrentUserController : UmbracoAuthorizedJsonController
_userDataService = userDataService;
}
[Obsolete("This constructor is obsolete and will be removed in v11, use constructor with all values")]
public CurrentUserController(
MediaFileManager mediaFileManager,
IOptions<ContentSettings> contentSettings,
IHostingEnvironment hostingEnvironment,
IImageUrlGenerator imageUrlGenerator,
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
IUserService userService,
IUmbracoMapper umbracoMapper,
IBackOfficeUserManager backOfficeUserManager,
ILoggerFactory loggerFactory,
ILocalizedTextService localizedTextService,
AppCaches appCaches,
IShortStringHelper shortStringHelper,
IPasswordChanger<BackOfficeIdentityUser> passwordChanger) : this(
mediaFileManager,
StaticServiceProvider.Instance.GetRequiredService<IOptionsSnapshot<ContentSettings>>(),
hostingEnvironment,
imageUrlGenerator,
backofficeSecurityAccessor,
userService,
umbracoMapper,
backOfficeUserManager,
localizedTextService,
appCaches,
shortStringHelper,
passwordChanger,
StaticServiceProvider.Instance.GetRequiredService<IUserDataService>())
{
}
/// <summary>
/// Returns permissions for all nodes passed in for the current user
/// </summary>
/// <param name="nodeIds"></param>
/// <returns></returns>
[HttpPost]
public Dictionary<int, string[]> GetPermissions(int[] nodeIds)
{
EntityPermissionCollection permissions = _userService
/// <summary>
/// Returns permissions for all nodes passed in for the current user
/// </summary>
/// <param name="nodeIds"></param>
/// <returns></returns>
[HttpPost]
public Dictionary<int, string[]> GetPermissions(int[] nodeIds)
{
EntityPermissionCollection permissions = _userService
.GetPermissions(_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, nodeIds);
var permissionsDictionary = new Dictionary<int, string[]>();
@@ -230,12 +198,13 @@ public class CurrentUserController : UmbracoAuthorizedJsonController
[AllowAnonymous]
public async Task<ActionResult<UserDetail?>> PostSetInvitedUserPassword([FromBody] string newPassword)
{
BackOfficeIdentityUser? user = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor
.BackOfficeSecurity?.GetUserId().ResultOr(0).ToString());
if (user == null)
var userId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().ResultOr(0).ToString();
if (userId is null)
{
throw new InvalidOperationException("Could not find user");
throw new InvalidOperationException("Could not find user Id");
}
var user = await _backOfficeUserManager.FindByIdAsync(userId);
if (user == null) throw new InvalidOperationException("Could not find user");
IdentityResult result = await _backOfficeUserManager.AddPasswordAsync(user, newPassword);
@@ -335,8 +304,18 @@ public class CurrentUserController : UmbracoAuthorizedJsonController
[ValidateAngularAntiForgeryToken]
public async Task<Dictionary<string, string>> GetCurrentUserLinkedLogins()
{
BackOfficeIdentityUser identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor
.BackOfficeSecurity?.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture));
var userId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture);
if (userId is null)
{
throw new InvalidOperationException("Could not find user Id");
}
BackOfficeIdentityUser? identityUser = await _backOfficeUserManager.FindByIdAsync(userId);
if (identityUser is null)
{
throw new InvalidOperationException("Could not find user");
}
// deduplicate in case there are duplicates (there shouldn't be now since we have a unique constraint on the external logins
// but there didn't used to be)

View File

@@ -471,46 +471,6 @@ public class EntityController : UmbracoAuthorizedJsonController
.Select(id => new { Id = id, Url = MediaOrDocumentUrl(id) }).ToDictionary(x => x.Id, x => x.Url);
}
/// <summary>
/// Get entity URLs by UDIs
/// </summary>
/// <param name="udis">
/// A list of UDIs to lookup items by
/// </param>
/// <param name="culture">The culture to fetch the URL for</param>
/// <returns>Dictionary mapping Udi -> Url</returns>
/// <remarks>
/// We allow for POST because there could be quite a lot of Ids.
/// </remarks>
[HttpGet]
[HttpPost]
[Obsolete("Use GetUrlsByIds instead.")]
public IDictionary<Udi, string?> GetUrlsByUdis([FromJsonPath] Udi[] udis, string? culture = null)
{
if (udis == null || !udis.Any())
{
return new Dictionary<Udi, string?>();
}
var udiEntityType = udis.First().EntityType;
UmbracoEntityTypes entityType;
switch (udiEntityType)
{
case Constants.UdiEntityType.Document:
entityType = UmbracoEntityTypes.Document;
break;
case Constants.UdiEntityType.Media:
entityType = UmbracoEntityTypes.Media;
break;
default:
entityType = (UmbracoEntityTypes)(-1);
break;
}
return GetUrlsByIds(udis, entityType, culture);
}
/// <summary>
/// Gets the URL of an entity
/// </summary>

View File

@@ -18,12 +18,6 @@ public class HelpController : UmbracoAuthorizedJsonController
private readonly ILogger<HelpController> _logger;
private HelpPageSettings? _helpPageSettings;
[Obsolete("Use constructor that takes IOptions<HelpPageSettings>")]
public HelpController(ILogger<HelpController> logger)
: this(logger, StaticServiceProvider.Instance.GetRequiredService<IOptionsMonitor<HelpPageSettings>>())
{
}
[ActivatorUtilitiesConstructor]
public HelpController(
ILogger<HelpController> logger,

View File

@@ -30,21 +30,13 @@ public class LanguageController : UmbracoAuthorizedJsonController
_umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
}
[Obsolete("Use the constructor without global settings instead, scheduled for removal in V11.")]
public LanguageController(ILocalizationService localizationService, IUmbracoMapper umbracoMapper,
IOptionsSnapshot<GlobalSettings> globalSettings)
: this(localizationService, umbracoMapper)
{
}
/// <summary>
/// Returns all cultures available for creating languages.
/// </summary>
/// <returns></returns>
[HttpGet]
public IDictionary<string, string> GetAllCultures()
=> CultureInfo.GetCultures(CultureTypes.AllCultures).DistinctBy(x => x.Name).OrderBy(x => x.EnglishName)
.ToDictionary(x => x.Name, x => x.EnglishName);
/// <summary>
/// Returns all cultures available for creating languages.
/// </summary>
/// <returns></returns>
[HttpGet]
public IDictionary<string, string> GetAllCultures()
=> CultureInfo.GetCultures(CultureTypes.AllCultures).DistinctBy(x => x.Name).OrderBy(x => x.EnglishName).ToDictionary(x => x.Name, x => x.EnglishName);
/// <summary>
/// Returns all currently configured languages.

View File

@@ -22,12 +22,6 @@ public class LogViewerController : BackOfficeNotificationsController
private readonly ILogLevelLoader _logLevelLoader;
private readonly ILogViewer _logViewer;
[Obsolete]
public LogViewerController(ILogViewer logViewer)
: this(logViewer, StaticServiceProvider.Instance.GetRequiredService<ILogLevelLoader>())
{
}
[ActivatorUtilitiesConstructor]
public LogViewerController(ILogViewer logViewer, ILogLevelLoader logLevelLoader)
{
@@ -147,8 +141,4 @@ public class LogViewerController : BackOfficeNotificationsController
[HttpGet]
public ReadOnlyDictionary<string, LogEventLevel?> GetLogLevels() => _logLevelLoader.GetLogLevelsFromSinks();
[Obsolete("Please use GetLogLevels() instead. Scheduled for removal in V11.")]
[HttpGet]
public string GetLogLevel() => _logViewer.GetLogLevel();
}

View File

@@ -986,37 +986,6 @@ public class MediaController : ContentControllerBase
return new ActionResult<IMedia>(toMove);
}
[Obsolete(
"Please use TrackedReferencesController.GetPagedRelationsForItem() instead. Scheduled for removal in V11.")]
public PagedResult<EntityBasic> GetPagedReferences(int id, string entityType, int pageNumber = 1,
int pageSize = 100)
{
if (pageNumber <= 0 || pageSize <= 0)
{
throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
}
UmbracoObjectTypes objectType = ObjectTypes.GetUmbracoObjectType(entityType);
var udiType = objectType.GetUdiType();
IEnumerable<IUmbracoEntity> relations =
_relationService.GetPagedParentEntitiesByChildId(id, pageNumber - 1, pageSize, out var totalRecords,
objectType);
return new PagedResult<EntityBasic>(totalRecords, pageNumber, pageSize)
{
Items = relations.Cast<ContentEntitySlim>().Select(rel => new EntityBasic
{
Id = rel.Id,
Key = rel.Key,
Udi = Udi.Create(udiType, rel.Key),
Icon = rel.ContentTypeIcon,
Name = rel.Name,
Alias = rel.ContentTypeAlias
})
};
}
#region GetChildren
private int[]? _userStartNodes;

View File

@@ -367,7 +367,7 @@ public class MemberController : ContentControllerBase
contentItem.IsApproved,
contentItem.Name);
IdentityResult created = await _memberManager.CreateAsync(identityMember, contentItem.Password?.NewPassword);
IdentityResult created = await _memberManager.CreateAsync(identityMember, contentItem.Password?.NewPassword!);
if (created.Succeeded == false)
{
@@ -513,8 +513,12 @@ public class MemberController : ContentControllerBase
}
var needsResync = false;
MemberIdentityUser identityMember = await _memberManager.FindByIdAsync(contentItem.Id?.ToString());
var memberId = contentItem.Id?.ToString();
if (memberId is null)
{
return ValidationProblem("Member was not found");
}
MemberIdentityUser? identityMember = await _memberManager.FindByIdAsync(memberId);
if (identityMember == null)
{
return ValidationProblem("Member was not found");

View File

@@ -183,17 +183,6 @@ public class MemberTypeController : ContentTypeControllerBase<IMemberType>
return dto;
}
/// <summary>
/// Returns all member types
/// </summary>
[Obsolete(
"Use MemberTypeQueryController.GetAllTypes instead as it only requires AuthorizationPolicies.TreeAccessMembersOrMemberTypes and not both this and AuthorizationPolicies.TreeAccessMemberTypes")]
[Authorize(Policy = AuthorizationPolicies.TreeAccessMembersOrMemberTypes)]
public IEnumerable<ContentTypeBasic> GetAllTypes() =>
_memberTypeService.GetAll()
.Select(_umbracoMapper.Map<IMemberType, ContentTypeBasic>).WhereNotNull();
public ActionResult<MemberTypeDisplay?> PostSave(MemberTypeSave contentTypeSave)
{
//get the persisted member type

View File

@@ -39,23 +39,14 @@ public class TemplateController : BackOfficeNotificationsController
throw new ArgumentNullException(nameof(defaultViewContentProvider));
}
[Obsolete("Use ctor will all params")]
public TemplateController(
IFileService fileService,
IUmbracoMapper umbracoMapper,
IShortStringHelper shortStringHelper)
: this(fileService, umbracoMapper, shortStringHelper, StaticServiceProvider.Instance.GetRequiredService<IDefaultViewContentProvider>())
{
}
/// <summary>
/// Gets data type by alias
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
public TemplateDisplay? GetByAlias(string alias)
{
ITemplate? template = _fileService.GetTemplate(alias);
/// <summary>
/// Gets data type by alias
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
public TemplateDisplay? GetByAlias(string alias)
{
ITemplate? template = _fileService.GetTemplate(alias);
return template == null ? null : _umbracoMapper.Map<ITemplate, TemplateDisplay>(template);
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -23,7 +23,7 @@ public class TwoFactorLoginController : UmbracoAuthorizedJsonController
private readonly IBackOfficeSignInManager _backOfficeSignInManager;
private readonly IBackOfficeUserManager _backOfficeUserManager;
private readonly ILogger<TwoFactorLoginController> _logger;
private readonly ITwoFactorLoginService2 _twoFactorLoginService;
private readonly ITwoFactorLoginService _twoFactorLoginService;
private readonly IOptionsSnapshot<TwoFactorLoginViewOptions> _twoFactorLoginViewOptions;
public TwoFactorLoginController(
@@ -36,15 +36,7 @@ public class TwoFactorLoginController : UmbracoAuthorizedJsonController
{
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_logger = logger;
if (twoFactorLoginService is not ITwoFactorLoginService2 twoFactorLoginService2)
{
throw new ArgumentException(
"twoFactorLoginService needs to implement ITwoFactorLoginService2 until the interfaces are merged",
nameof(twoFactorLoginService));
}
_twoFactorLoginService = twoFactorLoginService2;
_twoFactorLoginService = twoFactorLoginService;
_backOfficeSignInManager = backOfficeSignInManager;
_backOfficeUserManager = backOfficeUserManager;
_twoFactorLoginViewOptions = twoFactorLoginViewOptions;
@@ -73,7 +65,11 @@ public class TwoFactorLoginController : UmbracoAuthorizedJsonController
[HttpGet]
public async Task<ActionResult<IEnumerable<UserTwoFactorProviderModel>>> Get2FAProvidersForUser(int userId)
{
BackOfficeIdentityUser user = await _backOfficeUserManager.FindByIdAsync(userId.ToString(CultureInfo.InvariantCulture));
BackOfficeIdentityUser? user = await _backOfficeUserManager.FindByIdAsync(userId.ToString(CultureInfo.InvariantCulture));
if (user is null)
{
throw new InvalidOperationException("Could not find user");
}
var enabledProviderNameHashSet =
new HashSet<string>(await _twoFactorLoginService.GetEnabledTwoFactorProviderNamesAsync(user.Key));

View File

@@ -565,10 +565,20 @@ public class UsersController : BackOfficeNotificationsController
return new ActionResult<IUser?>(user);
}
private async Task SendUserInviteEmailAsync(UserBasic? userDisplay, string? from, string? fromEmail, IUser? to,
string? message)
private async Task SendUserInviteEmailAsync(UserBasic? userDisplay, string? from, string? fromEmail, IUser? to, string? message)
{
BackOfficeIdentityUser user = await _userManager.FindByIdAsync(((int?)userDisplay?.Id).ToString());
var userId = userDisplay?.Id?.ToString();
if (userId is null)
{
throw new InvalidOperationException("Could not find user Id");
}
var user = await _userManager.FindByIdAsync(userId);
if (user is null)
{
throw new InvalidOperationException("Could not find user");
}
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
// Use info from SMTP Settings if configured, otherwise set fromEmail as fallback