We have certain roles in our community that can view topics but can’t participate in them or add new ones. Is there a way to completely remove the Create Topic button for these roles altogether? Right now they can still click on it, and they get an error when trying to make a post.
Solved
Any way to hide the Create Topic button for certain roles?
Best answer by ahamburg9
Hey Daniel -
You can add a third party script to achieve this.
Here is example code:
<script>
document.addEventListener('DOMContentLoaded', function () {
console.log('Document is ready.');
// Ensure the inSidedData object exists
if (window.inSidedData && window.inSidedData.user && window.inSidedData.user.role) {
console.log('inSidedData object found:', window.inSidedData.user.role);
// Check if the user role includes "Chat Beta"
if (window.inSidedData.user.role.includes('Chat Beta')) {
console.log('User has the Chat Beta role.');
// Observe DOM changes to detect when the "Create topic" element is added
const observer = new MutationObserver(function (mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
const createTopicElement = document.querySelector(
'li.is-hidden-S a.menu-create-topic.qa-menu-create-topic[title="Create topic"]'
);
if (createTopicElement) {
console.log('Create topic element found via MutationObserver:', createTopicElement);
createTopicElement.parentElement.style.display = 'none';
console.log('Create topic element hidden.');
// Stop observing once the element is found
observer.disconnect();
break;
}
}
}
});
// Start observing the body for added nodes
observer.observe(document.body, { childList: true, subtree: true });
} else {
console.log('User does not have the Chat Beta role.');
}
} else {
console.error('inSidedData object or roles not found.');
}
});
</script>
in this case we using the role = “Chat Beta”, so you would have to change it based on your role.
Thanks,
Anthony
Reply
Sign up
If you ever had a profile with us, there's no need to create another one.
Don't worry if your email address has since changed, or you can't remember your login, just let us know at community@gainsight.com and we'll help you get started from where you left.
Else, please continue with the registration below.
Welcome to the Gainsight Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.