Skip to content

Instantly share code, notes, and snippets.

@Shazwazza
Created May 18, 2017 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shazwazza/54495ea48742272225ed2b49d85012b2 to your computer and use it in GitHub Desktop.
Save Shazwazza/54495ea48742272225ed2b49d85012b2 to your computer and use it in GitHub Desktop.
For Umbraco, the ability to not render any user permissions tree nodes based on the current user
using System.Threading;
using umbraco.cms.presentation.Trees;
using Umbraco.Core;
using Umbraco.Core.Security;
namespace Test
{
public class MyStartup : ApplicationEventHandler
{
/// <summary>
/// Bind to umbraco events when the application is ready
/// </summary>
/// <param name="umbracoApplication"></param>
/// <param name="applicationContext"></param>
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
BaseTree.BeforeNodeRender += UserGroupPermissions_BeforeNodeRender;
}
private void UserGroupPermissions_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, System.EventArgs e)
{
if (node.TreeType != "userPermissions") return;
//get the current user
var backOfficeIdentity = Thread.CurrentPrincipal.Identity as UmbracoBackOfficeIdentity;
if (backOfficeIdentity == null) return;
//check if it's the 'special' user
if (backOfficeIdentity.Username == "UserAdmin")
{
node = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment