Skip to content
Merged
Changes from 2 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
84 changes: 59 additions & 25 deletions src/Umbraco.Core/Services/ElementEditingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,48 @@ protected override string RelateParentOnDeleteAlias
public async Task<Attempt<ContentValidationResult, ContentEditingOperationStatus>> ValidateUpdateAsync(Guid key, ValidateElementUpdateModel updateModel, Guid userKey)
{
IElement? content = _elementService.GetById(key);
return content is not null
? await ValidateCulturesAndPropertiesAsync(
updateModel,
content.ContentType.Key,
updateModel.Cultures,
userKey)
: Attempt.FailWithStatus(ContentEditingOperationStatus.NotFound, new ContentValidationResult());
if (content is null)
{
return Attempt.FailWithStatus(ContentEditingOperationStatus.NotFound, new ContentValidationResult());
}

ContentEditingOperationStatus contentTypeStatus = ValidateContentTypeForUpdate(content.ContentType.Key);
if (contentTypeStatus is not ContentEditingOperationStatus.Success)
{
return Attempt.FailWithStatus(contentTypeStatus, new ContentValidationResult());
}

return await ValidateCulturesAndPropertiesAsync(
updateModel,
content.ContentType.Key,
updateModel.Cultures,
userKey);
}

/// <inheritdoc />
public async Task<Attempt<ContentValidationResult, ContentEditingOperationStatus>> ValidateCreateAsync(ElementCreateModel createModel, Guid userKey)
=> await ValidateCulturesAndPropertiesAsync(
{
ContentEditingOperationStatus contentTypeStatus = ValidateContentTypeForCreate(createModel.ContentTypeKey);
if (contentTypeStatus is not ContentEditingOperationStatus.Success)
{
return Attempt.FailWithStatus(contentTypeStatus, new ContentValidationResult());
}

return await ValidateCulturesAndPropertiesAsync(
createModel,
createModel.ContentTypeKey,
createModel.Variants.Select(variant => variant.Culture),
userKey);
}

protected override IContentType? TryGetAndValidateContentType(
Guid contentTypeKey, ContentEditingModelBase contentEditingModelBase,
out ContentEditingOperationStatus operationStatus)
public async Task<Attempt<ElementCreateResult, ContentEditingOperationStatus>> CreateAsync(ElementCreateModel createModel, Guid userKey)
{
IContentType? contentType = base.TryGetAndValidateContentType(contentTypeKey, contentEditingModelBase, out operationStatus);
if (contentType is null)
{
return null;
}

if (contentType.IsElement is false || contentType.AllowedInLibrary is false)
ContentEditingOperationStatus contentTypeStatus = ValidateContentTypeForCreate(createModel.ContentTypeKey);
if (contentTypeStatus is not ContentEditingOperationStatus.Success)
{
operationStatus = ContentEditingOperationStatus.NotAllowed;
return null;
return Attempt.FailWithStatus(contentTypeStatus, new ElementCreateResult());
}
Comment thread
lauraneto marked this conversation as resolved.
Outdated

return contentType;
}

public async Task<Attempt<ElementCreateResult, ContentEditingOperationStatus>> CreateAsync(ElementCreateModel createModel, Guid userKey)
{
if (await ValidateCulturesAsync(createModel) is false)
{
return Attempt.FailWithStatus(ContentEditingOperationStatus.InvalidCulture, new ElementCreateResult());
Expand Down Expand Up @@ -158,6 +162,12 @@ public async Task<Attempt<ElementUpdateResult, ContentEditingOperationStatus>> U
return Attempt.FailWithStatus(ContentEditingOperationStatus.NotFound, new ElementUpdateResult());
}

ContentEditingOperationStatus contentTypeStatus = ValidateContentTypeForUpdate(element.ContentType.Key);
if (contentTypeStatus is not ContentEditingOperationStatus.Success)
{
return Attempt.FailWithStatus(contentTypeStatus, new ElementUpdateResult { Content = element });
}

Comment thread
lauraneto marked this conversation as resolved.
Outdated
if (await ValidateCulturesAsync(updateModel) is false)
{
return Attempt.FailWithStatus(ContentEditingOperationStatus.InvalidCulture, new ElementUpdateResult { Content = element });
Expand Down Expand Up @@ -475,6 +485,30 @@ private async Task<Attempt<ContentEditingOperationStatus>> MoveLockedAsync<TNoti
// NOTE: We have a custom implementation for Move because ContentEditingServiceBase has no concept of Containers.
protected override OperationResult? Move(IElement element, int newParentId, int userId) => throw new NotImplementedException();

private ContentEditingOperationStatus ValidateContentTypeForCreate(Guid contentTypeKey)
{
IContentType? contentType = ContentTypeService.Get(contentTypeKey);
if (contentType is null)
{
Comment thread
lauraneto marked this conversation as resolved.
Outdated
return ContentEditingOperationStatus.ContentTypeNotFound;
}

if (contentType.IsElement is false || contentType.AllowedInLibrary is false)
{
return ContentEditingOperationStatus.NotAllowed;
}

return ContentEditingOperationStatus.Success;
}

private ContentEditingOperationStatus ValidateContentTypeForUpdate(Guid contentTypeKey)
{
IContentType? contentType = ContentTypeService.Get(contentTypeKey);
return contentType is null
? ContentEditingOperationStatus.ContentTypeNotFound
: ContentEditingOperationStatus.Success;
}

private async Task<ContentEditingOperationStatus> SaveAsync(IElement content, Guid userKey)
{
try
Expand Down
Loading