I have created a very simple SharePoint Online App. It has a manifest and a website. There is a simple script on a Default aspx. It is trying to deploy the file to a Library and getting "Access denied. You do not have permission to perform this action or access this resource." exception when saving to "Style Library", but it saves OK to "SiteAssets".
Here is a code of Default.aspx of my website:
$(document).ready(function () {
var fileContents = "alert('Hello World');";
var context = SP.ClientContext.get_current();
var hostContext = new SP.AppContextSite(context, decodeURIComponent(getQueryStringParameter('SPHostUrl')));
var web = hostContext.get_web();
context.load(web);
var createInfo = new SP.FileCreationInformation();
createInfo.set_content(new SP.Base64EncodedByteArray());
for (var i = 0; i < fileContents.length; i++) {
createInfo.get_content().append(fileContents.charCodeAt(i));
}
createInfo.set_overwrite(true);
createInfo.set_url("test.js");
// !!! magic starts here
// !!! Style Library doesn't work (Access Denied)
// !!! but SiteAssets does
var targetFolder = "Style Library";
// var targetFolder = "SiteAssets";
var files = hostContext.get_web().getFolderByServerRelativeUrl(targetFolder).get_files();
files.add(createInfo);
context.executeQueryAsync(function () {
alert("Saved successfully");
}, function (_, args) {
alert("Well, it's SharePoint. Error message: " + args.get_message());
});
});
And here is my paranoid AppPermissionRequests section of AppManifest.xml file:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="FullControl" />
</AppPermissionRequests>
I am using SharePoint Hosted model.
So the question is - why the behaviour is different and how can I really set Full Control level of permissions to my App?