Created
August 1, 2014 22:38
-
-
Save dpawluk/151763ba381c34e91f3d to your computer and use it in GitHub Desktop.
Snippet for Zendesk Help Center - permission for ticket submission based on user tag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var req_link = $('.submit-a-request'); // class selector for submit request link, now we can req_link.hide() and req_link.show() | |
| var sub_tag = 'tix_sub_approved'; // sub_tag variable essentially holds the 'approved tag' value, whatever you decide | |
| var hc_user = HelpCenter.user; // Just a shortcut to type less later | |
| var user_path = window.location.pathname; // user's current path (everything after the tld, HC home pathname is "/hc/en-us/") | |
| var is_approved = false; | |
| if (hc_user.hasOwnProperty('tags')) { // anonymous user objects don't have a 'tags' property, first check if it exists...no? then no link | |
| if(hc_user.tags.indexOf(sub_tag) > -1) { | |
| req_link.show(); // if tags[] exists and one of them matches approved tag, show link | |
| is_approved = true; // since this is the only case where we approve a user, lets make a shortcut for future checking... | |
| } | |
| } else { | |
| req_link.hide(); // else just always hide the link. | |
| } | |
| if (user_path == "/hc/en-us/requests/new" && is_approved === false) { | |
| window.location.replace("/hc/en-us"); // if you shouldn't be here, lets kick you out. | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be added to Zendesk HelpCenter to allow only users with a certain tag to submit tickets. Users without that tag will be kicked back to the home page if they somehow make it to the requests page. To use your own tag, simply change the value of
var sub_tag = 'to_whatever_you_want';