Skip to main content
Solved

Any way to hide the Create Topic button for certain roles?

  • December 20, 2024
  • 1 reply
  • 13 views

daniel.truman

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.

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

View original
Did you find this topic helpful?

1 reply

Forum|alt.badge.img+1
  • Helper ⭐️⭐️
  • 35 replies
  • Answer
  • December 21, 2024

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings