Restrict access to Guide "submit a request" button

Answered

9 Comments

  • Ryan McGrew
    Zendesk Product Manager

    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!

    0
  • Sean Bonner

    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!

    0
  • Sean Bonner

    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
    }

     

    2
  • David

    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? 

     

    0
  • Sean Bonner

    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

    }

     

    1
  • David

    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 :) 

    1
  • Jean-Michel WEISS

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

    0
  • Brett Bowser
    Zendesk Community Team

    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!

    0
  • Jean-Michel WEISS

    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

     

    0

Post is closed for comments.

Powered by Zendesk