Skip to content

V14: Add missing action parameters mapping#16557

Merged
Zeegaan merged 4 commits intov14/devfrom
v14/bugfix/add-missing-actionParameters-mappnig
Jun 7, 2024
Merged

V14: Add missing action parameters mapping#16557
Zeegaan merged 4 commits intov14/devfrom
v14/bugfix/add-missing-actionParameters-mappnig

Conversation

@Zeegaan
Copy link
Copy Markdown
Member

@Zeegaan Zeegaan commented Jun 5, 2024

Fixes #16477

Notes

  • Adds missing mapping for ActionParameter, I suspect this mapping was missing, because we had trouble mapping Dictionary<string, object> earlier on in the development process.

How to test

  • Implement the following healthcheck:
using Umbraco.Cms.Core.Extensions;
using Umbraco.Cms.Core.HealthChecks;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI;

[HealthCheck("3A482719-3D90-4BC1-B9F8-910CD9CF5B32", "Tests the healthchecks",
    Description = "Runs a tests of the healthchecks for a PR", Group = "TestingGroup")]
public class HealthCheckNotifier : HealthCheck
{
    private readonly IHostEnvironment _hostEnvironment;
    private readonly ILogger<HealthCheckNotifier> _logger;
    private readonly ILocalizedTextService _textService;

    public HealthCheckNotifier(ILocalizedTextService textService, IHostEnvironment hostEnvironment,
        ILogger<HealthCheckNotifier> logger)
    {
        _textService = textService;
        _hostEnvironment = hostEnvironment;
        _logger = logger;
    }

    public override Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
        Task.FromResult((IEnumerable<HealthCheckStatus>)new[] {GetHealthCheckStatus()});

    private HealthCheckStatus GetHealthCheckStatus()
    {
        var actions = new List<HealthCheckAction>();

        actions.Add(new HealthCheckAction($"action 1", Id)
        {
            Name = $"This will be action #1",
            ActionParameters = new Dictionary<string, object>()
            {
                { "folder", "my" },
            },
            Description = $"This is action number 1, it does awesome stuff",
        });

        actions.Add(new HealthCheckAction($"action 2", Id)
        {
            Name = $"This will be action #2",
            ActionParameters = new Dictionary<string, object>()
            {
                { "folder", "my" },
            },
            Description = $"This is action number 2, it does awesome stuff",
        });

        return
            new HealthCheckStatus("Wow that was awesome")
            {
                ResultType = StatusResultType.Success, Actions = actions
            };
    }

    public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
    {
        switch (action.Alias)
        {
            case "removeFolders":
                if (action.ActionParameters?.ContainsKey("folder") is true)
                {
                    string? folder = action.ActionParameters["folder"].ToString();
                    return
                        new HealthCheckStatus("It worked )")
                        {
                            ResultType = StatusResultType.Success, Actions = new List<HealthCheckAction>()
                        };
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(action), $"No Folder for {action.Alias}");
                }
            default:
                throw new ArgumentOutOfRangeException(nameof(action));
        }
    }
}
  • Set a breakpoint in the ExecuteAction method
  • Run umbraco
  • Go to Settings -> Health Check -> TestingGroup and click Run checks
  • 2 actions should show, click either one
  • You should now hit your breakpoint
  • Assert that ActionParameters is no longer null

@Zeegaan Zeegaan changed the title V14: Add missing action parameters mappnig V14: Add missing action parameters mapping Jun 5, 2024
Copy link
Copy Markdown
Contributor

@elit0451 elit0451 left a comment

Choose a reason for hiding this comment

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

Looks good 💪 Will merge on ✅

@Zeegaan Zeegaan merged commit b04e4d7 into v14/dev Jun 7, 2024
@Zeegaan Zeegaan deleted the v14/bugfix/add-missing-actionParameters-mappnig branch June 7, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants