fix: Update Graph API permissions and site access method in folder browser

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:46:33 -08:00
parent d3ffe1098a
commit d3e21955da
2 changed files with 7 additions and 12 deletions

View File

@ -5,6 +5,8 @@ $script:graphConfig = @{
Scopes = @(
"Files.ReadWrite.All"
"Sites.ReadWrite.All"
"Sites.Read.All"
"Sites.Selected"
)
}

View File

@ -113,25 +113,18 @@ function Get-FolderBrowser {
# Get site ID first
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
# Extract hostname and site path from URL
if ($siteUrl -match "https://([^/]+)(/.*)") {
$hostname = $matches[1]
$sitePath = $matches[2]
} else {
throw "Invalid SharePoint URL format"
}
# Get the site using hostname and path
$site = Get-MgSite -Filter "siteCollection/hostname eq '$hostname' and startsWith(webUrl, '$siteUrl')" -ErrorAction Stop
# Get site directly using the URL
$encodedUrl = [System.Web.HttpUtility]::UrlEncode($siteUrl)
$site = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/sites/sutterhill.sharepoint.com:/sites/tax" -ErrorAction Stop
if (-not $site) {
throw "Site not found at $siteUrl"
}
$script:txtStatus.Text += "Found site: $($site.WebUrl)`n"
$script:txtStatus.Text += "Found site: $($site.webUrl)`n"
# Get drive (document library)
$drives = Get-MgSiteDrive -SiteId $site.Id
$drives = Get-MgSiteDrive -SiteId $site.id
# Handle "Shared Documents" special case
$libraryName = if ($script:txtProdLib.Text -eq "Shared Documents") {
"Documents"