1

The objective is to have a landing page where every user can see what team sites exist and who to contact to request access (which is either someone who has full control to the site or someone who is in an office 365 owners group attached to the site).

Does anyone know a straight forward way of doing this that would list all the sites in the site collection with full control users in a list to display on the home page?

Thanks, Clare

2

We can use jQuery and REST API to get subsites base on current user permission. Add the code below into a script editor web part into home page.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
    ExecuteOrDelayUntilScriptLoaded(function(){
        if(IsAdminUser()){
            GetAllSubSites();
        }
    }, "sp.js");
});
function IsAdminUser() {
    var isAdmin=false;
    //Permission for admin to show or hide the entries on memory board using ShowOnHomePage Field
    var perm = new SP.BasePermissions();
    perm.set(SP.PermissionKind.manageWeb);
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/doesuserhavepermissions(@v)?@v={'High':'" + perm.$E_1.toString() + "', 'Low':'" + perm.$D_1.toString() + "'}",
        type: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        async:false,
        success: function (data) {
            var d = data.d.DoesUserHavePermissions;
            isAdmin=d;
        },
        error: function (err) {
            console.log(JSON.stringify(err));
        }
    });
    return isAdmin;
}
function GetAllSubSites(){
    $.ajax({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetSubwebsFilteredForCurrentUser(nWebTemplateFilter=-1)?$filter=WebTemplate ne 'APP'",  
        method: "GET",
        headers: {  
            "Accept": "application/json; odata=verbose"  
        },  
        success: function(data) {  
            var subSites = data.d.results;          
            var tempValue = "<h2>Sub sites</h2><br/>";  
            subSites.forEach(function(site) {  
                tempValue += "<p><a href='"+site.ServerRelativeUrl+"'>"+site.Title+"</a></p>";  
            });  
            $("#AllSubSites").html(tempValue);  
        },  
        error: function(data) {  
            console.log(data);  
        }  
    });  
}
</script>
<div id="AllSubSites"/>

enter image description here

  • Hi, Thanks for the code however I need to get a list of all the site collections subsites and any users (not just current) that has full control permission to the and any users who have full control that are in office 365 groups. eg Team Site Title Owners (not the official owners of the URL - just the users who have full control on the site – clare Aug 23 '18 at 2:17
  • In the code above, it works for all the users who have full control permission in the site collection, if the user not have permission, it will not see the this web part content. – LZ_MSFT Aug 23 '18 at 8:49
  • Hi, thanks for replying. That's the issue - all users (no matter what permission level) need to see this list. It's a list to display all the url's and all the people who have full control access (including office 365 groups) so the user can then contact these people to request access. It needs to be two columns - one for the site title and one for displaying any users who has full control access to the site. It's basically just looking up info to display. – clare Aug 24 '18 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.