Has anyone worked out how to do this in Umbraco v14+ ?
Especially if the same admin manages multiple domain names.
”This” being: work out if the current user is a backoffice user in order to show them an edit button on each page that will allow them to jump direclty to the umbraco edit page for the current page.
Hiya
In the TagHelpers project there is an our-user-include and our-user-exclude to apply to the razor markup to show or hide markup to the users on the frontend razor rendering.
Interesting to see @kjac approach. This is probably the RIGHT way to do it, considering he’s one of the smart chaps at Umbraco HQ core team.
Project
Usage
<h2>our-user-include and our-user-exclude</h2>
<p>
This is a tag helper attribute that can be applied to any DOM element in the razor template or partial. It will show or hide its element and children on the page when passing a comma seperated string of user groups that the current logged in Umbraco backoffice user is in, for the exclude or include variants.
</p>
<p>
There are two special User Groups you can use:
</p>
<ul>
<li> * - All anonymous users</li>
<li>? - All authenticated users</li>
<li>Use the alias of the User Group</li>
</ul>
<h4>Include</h4>
<div our-user-include="admin">Only users in the <strong>✅ Admin</strong> group will see this.</div>
<div our-user-include="admin,editor">Only users in the <strong>✅ Admin</strong> or <strong>✅ Editor</strong> user group will see this.</div>
<div our-user-include="?">Only <strong>✅ Anonymous</strong> users will see this.</div>
<div our-user-include="*">Only <strong>✅ logged in</strong> users will see this.</div>
<h4>Exclude</h4>
<div our-user-exclude="editor">Everyone except <strong>❌ Editor</strong> users can see this.</div>
<div our-user-exclude="editor">Everyone except <strong>❌ Admin</strong> or <strong>❌ Editor</strong> users can see this.</div>
<div our-user-exclude="?">Everyone except <strong>❌ Anonymous</strong> users will see this.</div>
<div our-user-exclude="*">Everyone except <strong>❌ logged in</strong> users will see this.</div>
Source Code
TL:DR
Use the taghelper project above or directly inject & use IBackofficeUserAccessor as needed
Ah apologies, you could lift & shift the source code from the project into your own code in the meantime whilst you wait on me trying to get a v17 release sorted.
Or perhaps create your own logic or approach of a taghelper using the IBackofficeUserAccessor or perhaps the more correct way from Kenn ?