Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Trevor Husseini 15 posts 105 karma points
    Jan 28, 2021 @ 03:08
    Trevor Husseini
    0

    How do you get the current instance of the DashboardService?

    Aloha,

    I have a controller from a v7 solution that inherits from DashboardController that is being used to hide Umbraco's sections if the user's password is older than our business rules allow.

    I'm trying to create similar logic in a v8 solution, however, by inheriting from DashboardController, I realize I don't have a "handle" on any of the services or parameters that the controller's constructor requires. I know DI is somehow relevant here but I don't know how. From here, I decided to inherit from UmbracoApiController with the intent of trying to get a handle of the current DashboardService because I found this: https://github.com/umbraco/Umbraco-CMS/issues/4390. Unfortunately, DashboardService isn't something that it's Umbraco.Core.Services.

    Is there a way to get the current DashboardService? If not, how can I properly inherit from DashboardController? See below for the pertinent code snippet:

    using Custom.Umbraco.v8.Security.Factories;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Core.Dashboards;
    using Umbraco.Web.Editors;
    using Umbraco.Web.Models.ContentEditing;
    using Umbraco.Web.Mvc;
    using Umbraco.Web.WebApi;
    
    namespace Custom.Umbraco.v8.Security.Controllers
    {
        [PluginController("UmbracoApi")]
        public class CustomDashboardController : UmbracoApiController
        {
            public IEnumerable<Tab<IDashboardSlim>> GetAuthorizedDashboard(string section)
            {
                var service = PasswordServiceFactory.Create();
                List<Tab<IDashboardSlim>> tabs = new List<Tab<IDashboardSlim>>();
    
                if (!service.passwordAge(Security.CurrentUser.Username))
                {
                    if (section != "password")
                    {
                        section = "password";
                    }
                }
    
                var blah = Services.DashboardService.GetDashboard(section).ToList();
    
                tabs = DashboardController.GetDashboard(section).ToList();
    
                return tabs;
            }
        }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies