1

When I am trying to get the all subwebs under the site collection in Sharepoint online using jsom, if the logged in user doesn't have permissions on a site collection I am unable to retrieve the all subsites.

But I am able to get all the subsites under the site collection if the logged in user have permissions on site collection.

I want, even if the user have permissions on site collection retrieve the all subsites under a site collection in Sharepoint online using JavaScript.

halfer
  • 19,824
  • 17
  • 99
  • 186
Deepu
  • 13
  • 4

2 Answers2

1

That's not possible because the data is what's security trimmed to what the user has access to. Having the ability to escalate privileges client side would be a huge security breach. What people usually end up doing usually is either giving very small permissions everywhere to the all users group or using a relay custom API and a service account that has permissions.

baywet
  • 4,377
  • 4
  • 20
  • 49
  • Is there any out of box solution to get subsites? – Deepu Jan 12 '17 at 04:21
  • Everything airways executes within the context of the user and his permissions. Unless you're doing custom server side code. So the data will always be trimmed to only what the current user has access to – baywet Jan 12 '17 at 04:26
  • please tell me how to get the subsites by passing custom credentials who have permissions on site collection using jsom. – Deepu Jan 12 '17 at 06:03
  • please tell me how to get the subsites by passing specific user who have permissions on site collection using jsom. – Deepu Jan 12 '17 at 08:57
0
getAllWebs: function (siteUrl, success, error) {
    var ctx = new SP.ClientContext(siteUrl);
    var web = ctx.get_site().get_rootWeb();
    var result = [];
    var level = 0;
    var getAllWebsInner = function (web, result, success, error, isChild, siteUrl) {
        level++;
        var ctx = web.get_context();
        var webs = web.get_webs();

        ctx.load(webs, 'Include(Title,Url,Webs)');
        ctx.executeQueryAsync(
            function () {

                for (var i = 0; i < webs.get_count(); i++) {
                    var web = webs.getItemAtIndex(i);
                    if (isChild)
                        siteHierarchy.subSiteInfo.push({ Title: web.get_title(), SiteUrl: web.get_url(), ParentUrl: siteUrl });
                    else
                        siteHierarchy.siteInfo.push({ Title: web.get_title(), SiteUrl: web.get_url(), Subsite: [] });
                    result.push(web);
                    if (web.get_webs().get_count() > 0) {
                        getAllWebsInner(web, result, success, error, true, web.get_url());
                    }
                }

                level--;
                if (level == 0 && success) {
                    success(result);
                }
            },
            error);
    };
    getAllWebsInner(web, result, success, error, false, siteUrl);
}

Based on the asnwer from "Vadim Gremyachev" at https://sharepoint.stackexchange.com/questions/130403/most-efficient-way-to-get-all-sub-sites-under-a-site-collection-sub-site-using-j .

Vainktesh Kumar
  • 113
  • 1
  • 11