Jump to content
Graham Quince

Removing share permissions from multiple sites

Recommended Posts

Here's an interesting snippet should anyone need it.

A school deleted a collection, but kept the ePortfolios as sites, not realising that this meant the sharing would be transferred to each site.  They were faced with manually altering 1000 sites, so I helped them with this:

<div class="btn btn-danger shareChange">Change Teacher Comments share</div>
<div class="shareStatus"></div>

<script>
var SEARCH_TERM = "old sites";
function getSites() {
       
    Frog.Model.api('sites.search', {
        exclude_sources: ["temporary"],
        filter: {is_eportfolio: "0"},
        include_associations: "true",
        limit: "1000",
        offset: "0",
        order: {updated: "desc"},
        query: SEARCH_TERM,
        requires: {columns: "false"},
        scope: "global"
    }).done(function(response) {
        
        var sites = response.data.sites;
        $('.shareStatus').text("Found: "+sites.length);
        onebyone(sites,0);


     }).fail(function(e) {
         console.log("FAILED");
     });
}
function onebyone(allSites,i) {
    console.log(i);
    if (i < allSites.length) {
        if (i == 100 || i == 200 || i == 300 || i == 400 || i == 500 || i == 600 || i == 700 || i == 800 || i == 900 || i == 1000) {
           $('.shareStatus').html('Pausing for 1 minute to prevent maxing out API requests');
           setTimeout(function(){ changeshare(allSites,i); }, 60000);
        } else {
            $('.shareStatus').html('Running '+i+' of '+ allSites.length);
            changeshare(allSites,i);
        }
    }
}
    
function changeshare(allSites,i) {
            Frog.Model.api('sites.sharing.set', {
                associations: {template: "0"},
                external_url: allSites[i].external_url,
                is_external: "false",
                site: allSites[i].uuid
            },{
                type: 'POST'
            }).done(function(response) {
            }).fail(function(e) {
                console.log("FAILED to share :"+i+" - "+allSites[i].uuid);
            });
            Frog.Model.api('share.set', {
                permissions: 'none',
                target: allSites[i].uuid
            },{
                type: 'POST'
            }).done(function(response) {
            }).fail(function(e) {
                console.log("FAILED to share :"+i+" - "+allSites[i].uuid);
            });
    i = i+1;
    onebyone(allSites,i);
}
		
$('.shareChange').click(function(){
    getSites();
});		

</script>

This removed the individual shares, although I had to go back over it and remove the profile shares.  To do that, I removed the shares from one site and observed the API call.  The permissions for share.set were stored as an object.

The search term is what was a searched for in FrogDrive > Sites to identify the sites to change.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...