Jump to Section
Prerequisites#
- A working Umbraco CMS v8 setup.
- Basic understanding of Umbraco's back office.
- Familiarity with C# and Umbraco's APIs.
Role-Based Customization of Umbraco CMS Back-Office Interface#
The purpose is to provide content managers, writers, and technical teams with a simplified and clutter-free back office interface by showing or hiding specific fields and tabs.
To ensure that they only see content types and fields relevant to their role.
Include these essential namespaces#
Create the Composer and Component#
The custom composer will append our component to Umbraco's component collection during the application's startup.
Now, create the component that will handle the logic for showing or hiding content based on the user role.
Register SendingContentModel event#
Secondly, go to HideContentPartsComponent and set the SendingContentModel event for EditorModelEventManager as follows:
Finding user groups for logged-in Umbraco user#
To get user roles in Umbraco, you need to refer to the CurrentUser object inside UmbracoContext as follows:
Showing content fields only for the role#
For example, to display the 'google manager' field exclusively for administrators, use the following method:
Showing content tabs only for the role#
To show the ‘SEO Settings’ tab only for the admin role execute the method as follows:
Show content tab only for specific roles#
To make ‘SEO Settings’ tab visible only for both admin and editor roles, execute the method as follows:
Show list of tabs only for specific roles #
To make ‘SEO Settings’ and “Content” tab visible only for both admin and editor user groups, execute the method as follows:
Helper Extensions#
We'll include an extension method to streamline the code.
Working HideContentPartsComponent implementation#
Common pitfall and workaround when hiding properties/tabs in Umbraco#
However, not everything works beautifully, as the Umbraco documentation says.
Wojciech Tengler noticed a bug.
When submitting content, hidden properties might unexpectedly save as empty values.
To prevent this, instead of just hiding the properties, consider changing the view.
Here's an example in pseudo-code:
Conclusion#
Umbraco's extensible nature means it can be tailored to specific requirements, as demonstrated by this role-based visibility control.
By understanding and leveraging Umbraco's events and APIs, you can create an intricate content control system that enhances productivity, security, and user experience.
You can modify or extend the above code as needed, and I recommend exploring the Umbraco events if you need more advanced back-office workflows.
📚 For more tips and updates, don't forget to browse our blog. 👩💻👨💻