Recently I got a requirement from a client that wanted to be able to modify the Access Requests Settings of a SharePoint online site to:
- Prevent users from Sharing the site and individual files and folders.
- Prevent users from inviting others to the site members group.
- Prevent non authorized users from sending access requests.
I had to split the logic into two requests. On the first request, I obtained the web and the group of users who had been given contribute permissions to the Web site.
var web = ctx.get_web();
var meGroups = web.get_associatedMemberGroup();
On the second request, I set the configurations over the web and groups objects:
- Prevent users from Sharing the site and individual files and folders by setting the Members Can Share property of the current web to false.
- Prevent non authorized users from sending access requests by setting the Allow Members Edit Membership property of the groups given contribute permission to false.
- Prevent users from inviting others to the site members group by setting the Request Access Email property of the current web to string empty(”).
Finally, after executing the script within the site and opening the Access Requests Settings modal windows, you can see that all of the options are now unchecked.
Hope you like it and find it helpful.