Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow editing read-only properties #17915

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Jan 8, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #16615 (and #17889 and #17906)

Description

As described in the linked issues, read-only properties (e.g. labels) are reset upon save.

It should not be possible to edit read-only properties, so that's what this PR ensures 😄

Testing this PR

Create some content with a label property, and add a value to that label property .... for example, use this controller to update exiting content:

using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI.Custom;

[ApiController]
[Route("api/[controller]")]
public class Issue16615Controller : ControllerBase
{
    private readonly IContentService _contentService;

    public Issue16615Controller(IContentService contentService)
        => _contentService = contentService;

    [HttpPost]
    public IActionResult Post(UpdateRequest updateRequest)
    {
        IContent? content = _contentService.GetById(updateRequest.Id);
        if (content is null)
        {
            return NotFound();
        }

        content.SetValue("myLabel", 123);
        _contentService.Save(content);
        return Ok();
    }

    public class UpdateRequest
    {
        public Guid Id { get; init; }
    }
}

image

Edit the content and save it. Verify that the label property value is retained after the save 👍

Copy link
Member

@Zeegaan Zeegaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm 🚀
image

@kjac kjac merged commit 0565eee into v15/dev Jan 9, 2025
28 checks passed
@kjac kjac deleted the v15/fix/16615-readonly-property-editing branch January 9, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants