Restrict access to Guide "submit a request" button | Community
Skip to main content

Restrict access to Guide "submit a request" button

  • May 28, 2018
  • 9 replies
  • 0 views

Hello

I was looking at this article and I wonder could you give me a bit more info or some guidance on how to achieve restricting help-desk users from creating tickets via the Guide "submit a ticket" button.

https://support.zendesk.com/hc/en-us/articles/224926148-Restricting-ticket-submission-to-specific-users-within-an-organization

Our use case is that we would like restrict access to raise a ticket to only a subset of users or a user tag maybe. We do not want this available to everyone who is signed in, only to selected users (or a single group of users).

So for example, in our case we will have standard users and super-users. Only super-users can have the ability to raise tickets via that Guide button. All users, regardless of type should still be able to log in and post comments/post replies in the community or on Guide articles. Perhaps an option might be the hide the 'submit a request' button from everyone (both signed in and non-signed in users), and only show the button to a particular user-group/user-tag/set of users

I saw this example of code in a different topic which seems to provide this functionality, but at an organisation level. I would like to do this but at a user level (e.g. any user tagged with 'superuser'). Is this possible?

https://support.zendesk.com/hc/en-us/articles/203661076-Hide-and-show-My-Activities-and-Submit-a-Request-Help-Center-

 

CSS:

 

/* ====================================================
   things to hide at start up
   ==================================================== */  
   a[href$='requests/new'], a.submit-a-request, .my-activities, #user-menu .my-activities {
     display: none;
   }

Javascript:

 (function() {
    var isCust;
    // find the tag in the array
    function isCustomer(element, index, array) {
      return (element === 'my_tag');
    }
//go through the HelpCenter object and look for org tags HelpCenter.user.organizations.forEach(function(x) { isCust = x.tags.some(isCustomer); return (isCust === true); });
//is this a customer and show them if (isCust === true) { $('a[href$="requests/new"]').show(); $('.my-activities').show(); $('#user-menu .my-activities').show();
$('a.submit-a-request').show(); } }());

Can you provide some guidance on how to achieve this use case?.

Thanks and Regards
Sean

This topic has been closed for replies.

9 replies

Ryan48
  • May 29, 2018

Hey Sean,

The script you've pasted iterates over the HelpCenter.user.organizations array to find the organization, so I think you'd just change that to iterate over the HelpCenter.user.tags array instead.

Thanks!


  • Author
  • May 29, 2018

Hi Ryan

 

Thanks for the reply. 

I had also tried what you suggested, but this does not have the desired effect. I tried it like this by amending the line to 'tags' instead of 'organisation'. Is that correct?


//go through the HelpCenter object and look for org tags
HelpCenter.user.tags.forEach(function(x) {
isCust = x.tags.some(isCustomer);
return (isCust === true);
});

 

This not only does not have the desired effect (show the submit ticket button to only users with the tag), but it also stops the menu button from working (i.e. when click on the menu in the top right, it does not open)

Is there any documentation on how this java script works, in particular, the helpdesk.user.X part....what are the available options here. I couldn't find it on the developer site (maybe i didnt look in the right place :) )

 

Thanks!


  • Author
  • June 1, 2018

Hello

 

So i figured out how to achieve my use case. Below is the Javascript code and CSS

First, hide any elements you want using the CSS code below. 

Then, use the below Javascript code to unhide those html elements when the tagged user logs in. 

 

So for example, if an anonymus user or a user tagged as "standard" logs in, keep the submit a ticket button hidden. 

If the user has the tag "premium", unhide the submit ticket button.

 

 CSS:

/* ====================================================
things to hide at start up
==================================================== */
a[href$='requests/new'], a.submit-a-request{
display: none;
}

 

Javascript:

//show submit ticket only to if a user has a particular tag and is an end user

//first check if the user is an end user. If not, do something else
if(HelpCenter.user.role==="end_user")
   {
      //get user takes
      var userTags=HelpCenter.user.tags;
      //check if any tags are returned. If no tags defined, print to console.
      if (userTags.length!=0)
         {
         //if tags are found, start iterating through using a for loop.

         for(var i = 0; i < userTags.length; i++ )
            {
              //check for the require tag. If found, do XYZ. In my case, it is to unhide  the submit a request button
               if (userTags[i] === '<insert tag here>')
            
                  //unhide submit request button
                  $('a[href$="requests/new"]').show();
                  $('a.submit-a-request').show();
                  //break loop. We found the required tag, so no longer need to proceed any further
                  break;
               }
               //could do checks for other tags here if needed or something else if the required tag isn't found
               // else if (userTags[i] === '<other tag>'){
               // //do something here
               // }
               }
       } else {
        //do something if no tags found
       }
} else {
//do something if user is not an end user
}

 


  • June 5, 2018

Hi Sean,

Can you direct me how and where to paste this in the JS?

In the meantime (before I put in the JS), the css is not hiding the .submit-a-request class. I even tried removing the "a", but no luck. 

 

EDIT: The css was being overridden by the nav-wrapper "display:inline-block" rule. i disabled that, seemingly with no damage done, and now the submit a request link is hidden.

But the java script doesn't work. I replaced '<insert tag here>' with 'partner', and it does not appear for a user with that tag. I don't know JS. Am i missing something? 

 


  • Author
  • June 12, 2018

Apologies for not getting back to you sooner David. You probably already figured it out at this stage. Perhaps the JavaScript might need some adjustment for you on account of your CSS being a bit different. I'm not using the default theme. 

 Good to hear you figured out the CSS bit though!

 

I put the JavaScript  within this function as below: $(document).ready(function()

Do you have it in here? or elsewhere. Give it a try and see.

 

 

 

$(document).ready(function() {
//show submit ticket only to if a user has a particular tag and is an end user

//first check if the user is an end user. If not, do something else
if(HelpCenter.user.role==="end_user")
   {
      //get user takes
      var userTags=HelpCenter.user.tags;
      //check if any tags are returned. If no tags defined, print to console.
      if (userTags.length!=0)
         {
         //if tags are found, start iterating through using a for loop.

         for(var i = 0; i < userTags.length; i++ )
            {
              //check for the require tag. If found, do XYZ. In my case, it is to unhide  the submit a request button
               if (userTags[i] === '<insert tag here>')
            
                  //unhide submit request button
                  $('a[href$="requests/new"]').show();
                  $('a.submit-a-request').show();
                  //break loop. We found the required tag, so no longer need to proceed any further
                  break;
               }
               //could do checks for other tags here if needed or something else if the required tag isn't found
               // else if (userTags[i] === '<other tag>'){
               // //do something here
               // }
               }
       } else {
        //do something if no tags found
       }
} else {
//do something if user is not an end user
}
.
.
.
.
.
.
rest of code

}

 


  • June 13, 2018

Thanks Sean for your concern and your help, I got it to work!

But then i ran into another problem - turns out my users are hardly tagged, because I manage them by organization. I have no problems with them viewing sections in the HC that are restricted to certain tags, but something here isn't working the same.

Is there a way to have this JS check the user's organization tags? What would I have to substitute?

(Sean or anyone else)

Thanks :) 


i'm also interested by the user's organization tags,; could you give us the appropriate HelpCenter object


Brett13
  • Community Manager
  • December 19, 2019

Hi Jean,

I did some digging in our documentation and I could only find user tags within the user segments endpoint. More information in the following link: User Segments

I'm not sure if this will get you what you're looking for but I hope this helps!


thx, but unfortunately no, since i'm following this topic. with the this .JS code, i can limit the access trough the user tag (better than nothing), plus ( there is an issue with the brackets), but on my support side, i have only "premium" tag on the organisation, and i pretty sure that those exist, I saw a thread, where @Jennifer Rowe gave a link, that i don't have access. maybe it will make my day.

ps: i attach the corrected code

$(document).ready(function() {

//show submit ticket only to if a user has a particular tag and is an end user

//first check if the user is an end user. If not, do something else
 if(HelpCenter.user.role==="end_user") {
//get user takes
var userTags=HelpCenter.user.tags;
//check if any tags are returned. If no tags defined, print to console.
if (userTags.length!=0) {
//if tags are found, start iterating through using a for loop.
for(var i = 0; i < userTags.length; i++ ) {
//check for the require tag. If found, do XYZ. In my case, it is to unhide the submit a request button
if (userTags[i] === 'your_tag') {

//unhide submit request button
$('a[href$="new_request"]').show();
$('a.submit-a-request').show();
//break loop. We found the required tag, so no longer need to proceed any further
break;
}
}
//could do checks for other tags here if needed or something else if the required tag isn't found
// else if (userTags[i] === '<other tag>'){
// //do something here
// }
}
else {
//do something if no tags found
}
}
else {
//do something if user is not an end user