Update Office365 / SharePoint site search query (#1006)

* Update Office 365 / SharePoint site search query and response if query return zero match
This commit is contained in:
abraunegg 2020-08-04 11:03:52 +10:00 committed by GitHub
parent 928ad9512f
commit 2fe0574bcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -633,10 +633,10 @@ final class OneDriveApi
}
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/site_search?view=odsp-graph-online
JSONValue o365SiteSearch(string o365SharedLibraryName){
JSONValue o365SiteSearch(){
checkAccessTokenExpired();
const(char)[] url;
url = siteSearchUrl ~ "=" ~ o365SharedLibraryName;
url = siteSearchUrl ~ "=*";
return get(url);
}

View file

@ -4896,7 +4896,7 @@ final class SyncEngine
log.log("Office 365 Library Name Query: ", o365SharedLibraryName);
try {
siteQuery = onedrive.o365SiteSearch(encodeComponent(o365SharedLibraryName));
siteQuery = onedrive.o365SiteSearch();
} catch (OneDriveException e) {
log.error("ERROR: Query of OneDrive for Office 365 Library Name failed");
if (e.httpStatusCode == 403) {
@ -4913,6 +4913,8 @@ final class SyncEngine
// is siteQuery a valid JSON object & contain data we can use?
if ((siteQuery.type() == JSONType.object) && ("value" in siteQuery)) {
// valid JSON object
log.vdebug("O365 Query Response: ", siteQuery);
foreach (searchResult; siteQuery["value"].array) {
// Need an 'exclusive' match here with o365SharedLibraryName as entered
log.vdebug("Found O365 Site: ", searchResult);
@ -4951,7 +4953,13 @@ final class SyncEngine
}
if(!found) {
log.error("ERROR: This site could not be found. Please check it's name and your permissions to access the site.");
log.error("ERROR: The requested SharePoint site could not be found. Please check it's name and your permissions to access the site.");
// List all sites returned to assist user
log.log("\nThe following SharePoint site names were returned:");
foreach (searchResult; siteQuery["value"].array) {
// list the display name that we use to match against the user query
log.log(" * ", searchResult["displayName"].str);
}
}
} else {
// not a valid JSON object