I’m wondering if it’s possible to add an option to user groups settings.
Ideally, I would like to add an option to the user group settings somewhere so that when selected, it adds a class to the of the admin panel. From there, I would be adding CSS to show specific widgets to those user groups that have this option selected and hide the widgets from all others.
I’m hoping it’s possible to do this since the only other option I can think of would require me to update the LW CSS every time a new user group begins using Sitecore.
Thanks for writing – I have a few ideas, but I think a little more info would be useful. Are you talking about certain Saved Widgets that you’re trying to show/hide from specific users inside of a group so they can’t use/edit them, but they can others? Or are you talking about differentiating per-Group rather than per-User?
Maybe an example or two of “I want X to be able to do Y, but not Z” would help me understand and we could offer some suggestions then. Thanks!
I want to be able to go into a user group, such as “Intranet” or “IT Services” and click a box that shows something like “Sitecore site”. If this box is checked/clicked, then users within that group who can manage the widgets, would see additional widget templates such as “Sitecore 1 column” or “Sitecore full width”.
Any user group (such as “Accounting Deadlines”, “BSD”, “Center in Paris”, etc.) that does not have the checkbox selected would not be able to see those specific widget templates.
Ah I see, restricting widget templates to specific groups, thanks for explaining.
There’s not a built-in way to do this in LiveWhale (currently Widget Templates are available to everyone who has permission to edit widgets) but it may be a case where some simple backend.js could do the trick.
For instance, here’s a sample script that could go in /_ingredients/backend/backend.js that seems to work in my tests, provided you swap in the group IDs you want to allow your certain templates for into the allowed_gids array and then put your template names in restricted_templates. Hope this may help!
(function ($, LW) {
// Edit these two configuration lines for your use case:
const restricted_templates = ['special_template_1', 'special_template_2']; // templates to restrict
const allowed_gids = [2, 3]; // gids allowed to see them
livewhale.eventHub.bind('widgetEditorLoad', function() {
// do nothing if this gid is allowed
if (allowed_gids.includes(parseInt(livewhale.gid, 10))) return;
const $select = $('#lw_widget_template');
if ($select.length) {
restricted_templates.forEach(function(name) {
$select.find('option[value="' + name + '"]').remove();
});
// reset to default if a restricted template was already selected/loaded
if (restricted_templates.includes($select.val())) {
$select.val('default').trigger('change');
}
}
});
}(livewhale.jQuery, livewhale));
If this doesn’t do the trick, it should definitely be possible with a bit of customization (or via another approach altogether, plenty of ways to get there I’m sure — for instance, removing the Widget Templates altogether and just making a few saved widgets with your special formatting that can get reused with &id=123&group=my-group in the data-options).
I can see this working. My suggestion for the checkbox, I was thinking, would be more simple as then any one of us would be able to go into the admin panel, and click this checkbox so it can just do what it needs to. If we go with something like this, or even a CSS-based approach, then it would require one of us developers to make the change manually though code pushes each time one of our user groups starts using Sitecore. It’s not really a big deal to do it, but was hoping there was some other way we could achieve something similar to what I had in mind initially.
Oh, sure – it could definitely be done with a checkbox on the group editor. I don’t see that being something we necessarily roadmap for core, but it’d still be a relative straightforward customization if you wanted to go that route. A bit more complex than some copy-and-paste code like I offered above, but you’re right it would allow future customizing without needing to push updated _ingredients files.
In that approach, the checkbox could be added to the Edit Group page using a Custom Field, and then in the example code I gave, rather than the static JS array allowed_gids = [2, 3] being defined in the script file, it could pull from some sort of LW.json.sitecore_widget_template_gids that you’d define in PHP based on the custom field (items assigned to $_LW->json in LiveWhale modules get loaded in the editor views as part of the global livewhale object). Feel free to reach out to support if you’d like our help building this kind of thing out.
Thanks Karl. I’ll discuss it further with my team and see if we want to continue to explore that as an option or just stick with doing something through CSS or the method you provided originally. Right now it was just a question on if it would be possible to do something like that. Appreciate it!