start work on controllers
This commit is contained in:
@@ -56,9 +56,9 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
/// <param name="currentUser"></param>
|
||||
/// <param name="groupAliases"></param>
|
||||
/// <returns></returns>
|
||||
public Attempt<string?> AuthorizeGroupAccess(IUser currentUser, params string[] groupAliases)
|
||||
public Attempt<string?> AuthorizeGroupAccess(IUser? currentUser, params string[] groupAliases)
|
||||
{
|
||||
if (currentUser.IsAdmin())
|
||||
if (currentUser?.IsAdmin() ?? false)
|
||||
return Attempt<string?>.Succeed();
|
||||
|
||||
var existingGroups = _userService.GetUserGroupsByAlias(groupAliases);
|
||||
@@ -67,12 +67,12 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
{
|
||||
// We're dealing with new groups,
|
||||
// so authorization should be given to any user with access to Users section
|
||||
if (currentUser.AllowedSections.Contains(Constants.Applications.Users))
|
||||
if (currentUser?.AllowedSections.Contains(Constants.Applications.Users) ?? false)
|
||||
return Attempt<string?>.Succeed();
|
||||
}
|
||||
|
||||
var userGroups = currentUser.Groups.Select(x => x.Alias).ToArray();
|
||||
var missingAccess = groupAliases.Except(userGroups).ToArray();
|
||||
var userGroups = currentUser?.Groups.Select(x => x.Alias).ToArray();
|
||||
var missingAccess = groupAliases.Except(userGroups ?? Array.Empty<string>()).ToArray();
|
||||
return missingAccess.Length == 0
|
||||
? Attempt<string?>.Succeed()
|
||||
: Attempt.Fail("User is not a member of " + string.Join(", ", missingAccess));
|
||||
@@ -82,16 +82,16 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
/// Authorize that the user is not adding a section to the group that they don't have access to
|
||||
/// </summary>
|
||||
public Attempt<string?> AuthorizeSectionChanges(
|
||||
IUser currentUser,
|
||||
IEnumerable<string> existingSections,
|
||||
IEnumerable<string> proposedAllowedSections)
|
||||
IUser? currentUser,
|
||||
IEnumerable<string>? existingSections,
|
||||
IEnumerable<string>? proposedAllowedSections)
|
||||
{
|
||||
if (currentUser.IsAdmin())
|
||||
if (currentUser?.IsAdmin() ?? false)
|
||||
return Attempt<string?>.Succeed();
|
||||
|
||||
var sectionsAdded = proposedAllowedSections.Except(existingSections).ToArray();
|
||||
var sectionAccessMissing = sectionsAdded.Except(currentUser.AllowedSections).ToArray();
|
||||
return sectionAccessMissing.Length > 0
|
||||
var sectionsAdded = proposedAllowedSections?.Except(existingSections ?? Enumerable.Empty<string>()).ToArray();
|
||||
var sectionAccessMissing = sectionsAdded?.Except(currentUser?.AllowedSections ?? Enumerable.Empty<string>()).ToArray();
|
||||
return sectionAccessMissing?.Length > 0
|
||||
? Attempt.Fail("Current user doesn't have access to add these sections " + string.Join(", ", sectionAccessMissing))
|
||||
: Attempt<string?>.Succeed();
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
/// <param name="currentMediaStartId"></param>
|
||||
/// <param name="proposedMediaStartId"></param>
|
||||
/// <returns></returns>
|
||||
public Attempt<string?> AuthorizeStartNodeChanges(IUser currentUser,
|
||||
public Attempt<string?> AuthorizeStartNodeChanges(IUser? currentUser,
|
||||
int? currentContentStartId,
|
||||
int? proposedContentStartId,
|
||||
int? currentMediaStartId,
|
||||
@@ -116,7 +116,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
var content = _contentService.GetById(proposedContentStartId.Value);
|
||||
if (content != null)
|
||||
{
|
||||
if (currentUser.HasPathAccess(content, _entityService, _appCaches) == false)
|
||||
if (currentUser?.HasPathAccess(content, _entityService, _appCaches) == false)
|
||||
return Attempt.Fail("Current user doesn't have access to the content path " + content.Path);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
var media = _mediaService.GetById(proposedMediaStartId.Value);
|
||||
if (media != null)
|
||||
{
|
||||
if (currentUser.HasPathAccess(media, _entityService, _appCaches) == false)
|
||||
if (currentUser?.HasPathAccess(media, _entityService, _appCaches) == false)
|
||||
return Attempt.Fail("Current user doesn't have access to the media path " + media.Path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user