fix: Update SharePoint authentication and folder browser with proper permissions
This commit is contained in:
parent
ffdbb56aa3
commit
21bc01e3cc
@ -37,7 +37,6 @@ function Save-Config {
|
|||||||
|
|
||||||
function Connect-SharePoint {
|
function Connect-SharePoint {
|
||||||
try {
|
try {
|
||||||
# Use current form values instead of saved config
|
|
||||||
$siteUrl = $script:txtSiteUrl.Text
|
$siteUrl = $script:txtSiteUrl.Text
|
||||||
$clientId = $config.ClientId
|
$clientId = $config.ClientId
|
||||||
$clientSecret = $config.ClientSecret
|
$clientSecret = $config.ClientSecret
|
||||||
@ -46,11 +45,15 @@ function Connect-SharePoint {
|
|||||||
throw "Please enter a Site URL"
|
throw "Please enter a Site URL"
|
||||||
}
|
}
|
||||||
|
|
||||||
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret -WarningAction SilentlyContinue
|
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret `
|
||||||
|
-WarningAction SilentlyContinue `
|
||||||
|
-Tenant "sutterhill" ` # Match your tenant name
|
||||||
|
-Scopes @("AllSites.FullControl") # Required for folder browsing
|
||||||
|
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$script:txtStatus.Text += "Error connecting: $_`n"
|
$script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n"
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,29 +134,28 @@ function Move-Files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function Get-FolderBrowser {
|
function Get-FolderBrowser {
|
||||||
param($context)
|
|
||||||
try {
|
try {
|
||||||
if (-not (Connect-SharePoint)) {
|
if (-not (Connect-SharePoint)) {
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
$libraryName = $script:txtProdLib.Text
|
# Verify library exists and is accessible
|
||||||
if (-not $libraryName) {
|
$library = Get-PnPList -Identity $script:txtProdLib.Text -Includes RootFolder,HasUniqueRoleAssignments
|
||||||
throw "Production Library name is required"
|
if ($library.HasUniqueRoleAssignments) {
|
||||||
|
throw "This library has unique permissions - verify app has access"
|
||||||
}
|
}
|
||||||
|
|
||||||
$ctx = Get-PnPConnection
|
# Get folders with elevated permissions
|
||||||
$web = Get-PnPWeb
|
$ctx = Get-PnPContext
|
||||||
$library = Get-PnPList -Identity $libraryName
|
$ctx.Load($library.RootFolder.Folders)
|
||||||
|
$ctx.ExecuteQuery()
|
||||||
|
|
||||||
$folders = Get-PnPFolder -Url $library.RootFolder.ServerRelativeUrl -Includes Folders |
|
return $library.RootFolder.Folders |
|
||||||
Select-Object -ExpandProperty Folders |
|
Select-Object Name, ServerRelativeUrl |
|
||||||
Select-Object Name, ServerRelativeUrl
|
Out-GridView -Title "Select Folder" -PassThru
|
||||||
|
|
||||||
return $folders | Out-GridView -Title "Select Folder (Double-click to select)" -PassThru
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$script:txtStatus.Text += "Error browsing folders: $_`n"
|
$script:txtStatus.Text += "Folder Error: $($_.Exception.Message)`n"
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,5 +3,6 @@
|
|||||||
"ClientId": "dcb744a3-96ee-4521-bb35-9909146d3a13",
|
"ClientId": "dcb744a3-96ee-4521-bb35-9909146d3a13",
|
||||||
"SiteUrl": "https://sutterhill.sharepoint.com/sites/tax",
|
"SiteUrl": "https://sutterhill.sharepoint.com/sites/tax",
|
||||||
"ProductionLibrary": "Documents",
|
"ProductionLibrary": "Documents",
|
||||||
"ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso"
|
"ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso",
|
||||||
|
"TenantId": "sutterhill"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user