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 = @( Scopes = @(
"Files.ReadWrite.All" "Files.ReadWrite.All"
"Sites.ReadWrite.All" "Sites.ReadWrite.All"
"Sites.Read.All"
"Sites.Selected"
) )
} }

View File

@ -113,25 +113,18 @@ function Get-FolderBrowser {
# Get site ID first # Get site ID first
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/') $siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
# Extract hostname and site path from URL # Get site directly using the URL
if ($siteUrl -match "https://([^/]+)(/.*)") { $encodedUrl = [System.Web.HttpUtility]::UrlEncode($siteUrl)
$hostname = $matches[1] $site = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/sites/sutterhill.sharepoint.com:/sites/tax" -ErrorAction Stop
$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
if (-not $site) { if (-not $site) {
throw "Site not found at $siteUrl" 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) # Get drive (document library)
$drives = Get-MgSiteDrive -SiteId $site.Id $drives = Get-MgSiteDrive -SiteId $site.id
# Handle "Shared Documents" special case # Handle "Shared Documents" special case
$libraryName = if ($script:txtProdLib.Text -eq "Shared Documents") { $libraryName = if ($script:txtProdLib.Text -eq "Shared Documents") {
"Documents" "Documents"