extending umbraco backoffice - users and permissions to specific features
z
I have created a new section in the back office of umbraco(using v13). Any idea of how to implement permissions to specific users to view specific features on a view page?
a
Copy code
csharp @using Umbraco.Cms.Core.Security
@using Umbraco.Cms.Web.Common.PublishedModels;
@using Umbraco.Docs.PropertyEditors
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<MySuggestionsModel>
@inject IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
@{
    Layout = null;
}


<div>
    @* Check for others properties here and tailor them to your needs *@
    @if (_backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser.IsAdmin())
        @Model.Suggestion
</div>
First from the top of my head is just injecting BackOfficeService to your view and simply check if user is in the permitted group. I guess you can achive the same in the backoffice as well. Somehow access the user context in your angularJs code. Probablly you have to refer to documentation.
https://apidocs.umbraco.com/v13/ui/#/api/umbraco.resources.authResource Look for getCurrentUser() endpoint.
Copy code
authResource.getCurrentUser()
   .then(function(data) {
       //Do stuff for fetching the current logged in Umbraco backoffice user
   });
This should have information about user's groups and roles.
z
Thank you for your reply! This is helpful yes but I would like to be able to control the user groups permissions(something similar to what umbraco has for permissions). Rather than hardcoding the user group+allowed features, i'd like to be able to configure this straight on the system. Any idea on that please? Someone implemented something similar in umbraco v8(https://our.umbraco.com/forum/using-umbraco-and-getting-started/104930-creating-my-custom-iactions)
m
As it's a section, it can be managed within user groups either manually via the UI. Or id suggest looking at Migrations and the user service Here's an example of adding a section by alias to a user group https://github.com/Matthew-Wise/Umbraco-CSP-manager/blob/main/src/Umbraco.Community.CSPManager/Migrations/AddCspManagerSectionToAdminUserGroupMigration.cs There is also the migration plan etc in that repo as well
170 Views