DEV Community

Cover image for Using conventions to fine tune the editor experience in Umbraco v8
Tim Geyssens
Tim Geyssens

Posted on

4

Using conventions to fine tune the editor experience in Umbraco v8

The Umbraco backend allows you to set a start node per backend user (in both content and media) but in some cases this isn't sufficient to hide certain properties that are only of interest for power users...

Say you have the following "admin" group/tab (yes I'm using Matryoshka )

Admin tab

Where you can set that you don't want this page to be unpublished... it makes sense to have this setting as an admin but the content editors shouldn't see this one...

So with some event magic and some simple conventions we can add a bit of code that will hide the admin group/tab on all docs (if you aren't part of the admin usergroup)

using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using System.Linq;
using System;
using Umbraco.Core.Security;
using Umbraco.Web.Editors;
using Umbraco.Web;
using Umbraco.Web.Dashboards;
using Umbraco.Web.PublishedModels;
namespace MySite.Custom
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class CustomEventComposer : ComponentComposer<CustomEventComponent>
{ }
public class CustomEventComponent : IComponent
{
public void Initialize()
{
EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
}
private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Umbraco.Web.Models.ContentEditing.ContentItemDisplay> e)
{
var identity = (UmbracoBackOfficeIdentity)System.Web.HttpContext.Current.User.Identity;
var currentUSer = Current.Services.UserService.GetByProviderKey(identity.Id);
if (!currentUSer.Groups.Any(x => x.Alias == "admin"))
{
foreach (var variant in e.Model.Variants)
variant.Tabs = variant.Tabs.Where(x => x.Label != "Admin");
}
}
public void Terminate()
{
}
}
}

Main bit here is hooking into EditorModelEventManager.SendingContentModel and removing the admin tab when the current user isn't in the admin user group...

et voilà ! all admin tabs will be hidden from editors not in the admin user group.

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute and it's free.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay