Polulate dropdown box with list of all subsites current user has access to

Aug 16, 2010 at 8:33 PM


Thanks for providing this library, it is such a lifesaver.

I'm trying to add a drop-down box on the home that will contain all sub-sites that the current user has access to. I was able to use GetWebCollection; howver it displays all sub-sites. Howver, i want to filter the options so that only subsites user have access to should be listed as option. Any help with be sooo welcome. See below for the script.

<script type="text/javascript" src="/Utilities/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/Utilities/jquery.SPServices-0.4.6.js"></script>
<script type="text/javascript">
Console.log($(document).ready(function() {
         completefunc: function (xData, status) {$(xData.responseXML).find("Web").each(function() {
         // var weburlvar = $(this).attr("Url");


function checkwebaccess(weburl)
         operation: "GetRolesAndPermissionsForCurrentUser",
         webURL: weburl,
         async: false,
         completefunc: function(xData, Status) {
        // var userPerm = $(xData.responseXML).find("[nodeName=Permissions]").attr("Value");
//alert("userPerm = " + userPerm);

if($(xData.responseXML).find("[nodeName=Permissions]").attr("Value") != "undefined")
         {return true;  }
         {return false;}           
<select id="urlOptions" onchange="window.open(this.options[this.selectedIndex].value,'_top')">
   <option value="">Select an ER project...</option>

Aug 18, 2010 at 1:38 AM

This is one of those things that I always thought SPServices would come in really useful for, but honestly have never done it.

I'm going to assume that you're seeing your select populate with all of the sites/subsites, and the permission trimming is the piece that's not working. If you're getting any errors along the way, please post them...

The user permissions that get returned aren't "pretty", they're enumerated values, which then correspond back to the permissions the user actually has. Your if statement [if(checkwebaccess($(this).attr("Url")))] is only going to look to see if there's a value returned, what you probably want to be doing is look for a specific permission, can they open it for example, and check for the enumerated value of the open permission.

There's a post on my blog with a comparison chart of enumerated value to permission type, which may be helpful (http://mike-greene.com/?p=309).

There's also a post by Jim Bob Howard on displaying/hiding content based on permissions, which will probably also be helpful (http://spservices.codeplex.com/Thread/View.aspx?ThreadId=80847).

Again, if you're seeing any specific errors, could you post them; it's a bit hard to debug code with no idea of what it's actually doing for you.