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 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());
});
});
function getQueryStringParameter(param) {
var params = document.URL.split('?')[1].split('&');
var strParams = '';
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split('=');
if (singleParam[0] == param) {
return singleParam[1];
}
}
}
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 have tried SharePoint Hosted model and Autohosted model with a same luck.
So the question is - why the behaviour is different and how can I really set Full Control level of permissions to my App?
0 commentaires:
Enregistrer un commentaire