Can Protect-UDSection be used in Navigation UDListItem?

Product: PowerShell Universal
Version: 3.6.4

It seems, the way I have my dashboard written now (below), nobody can see the third section, regardless of role. Is there a way to protect a list item based on role.

I am attempting to use this methodology since each dashboard seems to consume about a GB or less of memory - which is not a big deal; However, I would think the below methodology could be advantageous in saving memory as we scale? Is that thinking sound? Otherwise, I will just spin up a new dashboard :slight_smile:


$pages = Get-ChildItem (Join-Path -Path $PSScriptRoot -ChildPath pages) -Recurse -File | ForEach-Object {
    & $PSItem.FullName
}

$Navigation = @(
    New-UDListItem -Label 'Home' -Icon (New-UDIcon -Icon Home -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/home'
    }
    New-UDListItem -Label 'Start Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/accessreviews'
    }
    Protect-UDSection -Content {
        New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
            Invoke-UDRedirect -Url '/createaccessreview'
        }
    } -Role @('Dash-AppOwners')

)

$splat = @{
    Title            = 'data'
    Pages            = $pages
    Navigation       = $Navigation
    NavigationLayout = 'Permanent'
}

New-UDDashboard @splat

# dashboard.ps1
New-PSUDashboard -Name "data" -FilePath "dashboards\data\data.ps1" -BaseUrl "/" -Environment "7.3.1" -Authenticated -Role @('Administrator') -AutoDeploy 
New-PSUDashboard -Name "accessreviews" -FilePath "dashboards\accessreviews\ar.ps1" -BaseUrl "/ar" -Authenticated -Role @('Administrator','Dash-AccessReviews','Dash-AppOwners') -AutoDeploy 
New-PSUDashboard -Name "extra" -FilePath "dashboards\extra\extra.ps1" -BaseUrl "/extra" -Authenticated -Role @('Administrator') -AutoDeploy

@adam also a separate topic, 3.6.4 and it’s Git/SQL integration has been tremendous. Thank you for that feature!

The problem is that navigation is static when defined in that way. If you use -LoadNavigation, it is dynamic and will honor the Protect-UDSection.

And glad you’re digging SQL and Git!

Hmm having a bit of a time converting to that methodology. This is what I have so far:

# ar.ps1
$Navigation = {
    New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/createaccessreview'
    }
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages += New-UDPage -Name 'Create Access Review' -Content {
    . "$UDScriptRoot\pages\createaccessreview.ps1"
} -NavigationLayout permanent -LoadNavigation $Navigation

New-UDDashboard -Title "Access Reviews" -Pages $Pages
# dashboards.ps1
New-PSUDashboard -Name "data" -FilePath "dashboards\data\data.ps1" -BaseUrl "/" -Environment "7.3.1" -Authenticated -Role @('Administrator') -AutoDeploy
New-PSUDashboard -Name "accessreviews" -FilePath "dashboards\accessreviews\ar.ps1" -BaseUrl "/ar" -Authenticated -Role @('Administrator', 'Dash-AccessReviews', 'Dash-AppOwners') -AutoDeploy
New-PSUDashboard -Name "extra" -FilePath "dashboards\extra\extra.ps1" -BaseUrl "/extra" -Authenticated -Role @('Administrator') -AutoDeploy
# top of createaccessreview.ps1
New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content {....}

@adam how would i handle this instead? thanks!

Basically I am getting Page not found

You’re calling New-UDPage inside New-UDPage. You could just remove the one from the dashboard.ps1 and put the URL on the one in createaccessreview.ps1

# top of createaccessreview.ps1
New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content {....}

You can also just set the navigation on the dashboard rather than pass to each page.

$Navigation = {
    New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/createaccessreview'
    }
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages +=     . "$UDScriptRoot\pages\createaccessreview.ps1"
New-UDDashboard -Title "Access Reviews" -Pages $Pages NavigationLayout permanent -LoadNavigation $Navigation

thanks @adam

This is what I now have but I am getting Error with dashboard script

# ar.ps1
$Navigation = {
    New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/createaccessreview'
    }
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages += . "$UDScriptRoot\pages\createaccessreview.ps1"
New-UDDashboard -Title "Access Reviews" -Pages $Pages NavigationLayout permanent -LoadNavigation $Navigation

I also tried to comment out line 2 but got the same error

Any idea what I am doing wrong?

You need at least one New-UDPage command. Try this:

# ar.ps1
$Navigation = {
    New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/createaccessreview'
    }
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages += New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content { 
. "$UDScriptRoot\pages\createaccessreview.ps1"
}
New-UDDashboard -Title "Access Reviews" -Pages $Pages NavigationLayout permanent -LoadNavigation $Navigation

And then leave New-UDPage out of createaccessreview.ps1

I have that verbatim now but still getting same error:

# ar.ps1
$Navigation = {
    New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/createaccessreview'
    }
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages += New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content {
    . "$UDScriptRoot\pages\createaccessreview.ps1"
}
New-UDDashboard -Title "Access Reviews" -Pages $Pages NavigationLayout permanent -LoadNavigation $Navigation

createaccessreviews.ps1 still has no New-UDPage:

Should my dashboards.ps1 be different than this?

New-PSUDashboard -Name "data" -FilePath "dashboards\data\data.ps1" -BaseUrl "/" -Environment "7.3.1" -Authenticated -Role @('Administrator') -AutoDeploy
New-PSUDashboard -Name "accessreviews" -FilePath "dashboards\accessreviews\ar.ps1" -BaseUrl "/ar" -Authenticated -Role @('Administrator', 'Dash-AccessReviews', 'Dash-AppOwners') -AutoDeploy
New-PSUDashboard -Name "extra" -FilePath "dashboards\extra\extra.ps1" -BaseUrl "/extra" -Authenticated -Role @('Administrator') -AutoDeploy

thank you @adam

I have also tried commenting out:

New-PSUDashboard -Name "accessreviews" -FilePath "dashboards\accessreviews\ar.ps1" -BaseUrl "/ar" -Authenticated -Role @('Administrator', 'Dash-AccessReviews', 'Dash-AppOwners') -AutoDeploy

We get the same error

Ah! You’re missing a hyphen in front of NavigationLayout

New-UDDashboard -Title "Access Reviews" -Pages $Pages -NavigationLayout permanent -LoadNavigation $Navigation

If you run into this “Error with dashboard script” thing, you should see a syntax error in the Log tab of the dashboard editor.

1 Like

Thank you @adam - to revisit my original question, I now have the following:


$Navigation = {
    New-UDListItem -Label 'Access Reviews' -Icon (New-UDIcon -Icon Home -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/home'
    }
    New-UDListItem -Label 'Start Access Review' -Icon (New-UDIcon -Icon glasses -Size 1x) -OnClick {
        Invoke-UDRedirect -Url '/accessreviews'
    }
    Protect-UDSection -Content {
        New-UDListItem -Label 'Create Access Review' -Icon (New-UDIcon -Icon Clock -Size 1x) -OnClick {
            Invoke-UDRedirect -Url '/createaccessreview'
        }
    } -Role @('Administrator')
}

$UDScriptRoot = $PSScriptRoot
$Pages = @()
$Pages += New-UDPage -Name 'Access Reviews' -Url '/home' -Content {
    . "$UDScriptRoot\pages\home.ps1"
}
$Pages += New-UDPage -Name 'Start Access Review' -Url '/accessreviews' -Content {
    . "$UDScriptRoot\pages\accessreviews.ps1"
}

$Pages += New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content {
    . "$UDScriptRoot\pages\createaccessreview.ps1"
}

New-UDDashboard -Title "Access Reviews" -Pages $Pages -NavigationLayout permanent -LoadNavigation $Navigation

Currently, regardless of the role I add (in this example, Administrator), the link is…

  1. Hidden from everyone
  2. Available to everyone if they type the full URL, in this case https://<redacted>.azurewebsites.net/aar/createaccessreview

Any guidance would be greatly appreciated. Thanks!
Kevin

Ok. If you want to prevent going directly to the URL, do this:

$Pages += New-UDPage -Name 'Create Access Review' -Url '/createaccessreview' -Content {
    . "$UDScriptRoot\pages\createaccessreview.ps1"
} -Role @('Administrator')

Let me throw together an example to see about the issue with the link. That should be working. I wanna verify that something isn’t wrong.