Created
May 18, 2017 02:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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