Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcludeSystemUser correct logic in Get-DbaDbUser #9415

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

pollusb
Copy link
Contributor

@pollusb pollusb commented Jul 3, 2024

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (affects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Purpose

Correct a logical error in Get-DbaDbUser

Approach

Commands to test

# Actual logic:
PS> (Get-DbaDbUser @splat).Count
15
PS> (Get-DbaDbUser @splat -ExcludeSystemUser).Count 
11
PS> (Get-DbaDbUser @splat -ExcludeSystemUser:$false).Count 
11 # logical error here
PS> (Get-DbaDbUser @splat -ExcludeSystemUser:$true).Count 
11

# Revised logic:
PS> (Get-DbaDbUser @splat).Count
15
PS> (Get-DbaDbUser @splat -ExcludeSystemUser).Count 
11
PS> (Get-DbaDbUser @splat -ExcludeSystemUser:$false).Count 
15
PS> (Get-DbaDbUser @splat -ExcludeSystemUser:$true).Count 
11

Screenshots

Learning

Actual logic:
PS> (Get-DbaDbUser @Splat).Count
15
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser).Count
11
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser:$false).Count
11
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser:$true).Count
11 # logical error here

Revised logic:
PS> (Get-DbaDbUser @Splat).Count
15
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser).Count
11
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser:$false).Count
15
PS> (Get-DbaDbUser @Splat -ExcludeSystemUser:$true).Count
11
@niphlod niphlod requested a review from andreasjordan July 3, 2024 21:46
@niphlod niphlod added the feature internal Feature for the internal handling and structur (AppVayor, test, etc.) and nofor dbatools as a module label Jul 3, 2024
@niphlod
Copy link
Contributor

niphlod commented Jul 3, 2024

LGTM, @andreasjordan ?

Copy link
Contributor

@andreasjordan andreasjordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Maybe we have the same problem in other commands as well.

@pollusb
Copy link
Contributor Author

pollusb commented Jul 4, 2024

Good catch. Maybe we have the same problem in other commands as well.

We do. Testing the presence of a switch parameter does not provide the right logic. Here's a list of a similar pattern:

PS C:\Users\me\Code\Repo\dbatools.fork.git\public> dir *.ps1|sls 'Test-Bound -ParameterName Exclude'

Get-DbaDbCheckConstraint.ps1:105:                    if ( (Test-Bound -ParameterName ExcludeSystemTable) -and
$tbl.IsSystemObject ) {
Get-DbaDbForeignKey.ps1:105:                    if ( (Test-Bound -ParameterName ExcludeSystemTable) -and
$tbl.IsSystemObject ) {
Get-DbaDbServiceBrokerQueue.ps1:92:                if ( (Test-Bound -ParameterName ExcludeSystemQueue) -and
$queue.IsSystemObject ) {
Get-DbaDbServiceBrokerService.ps1:92:                if ( (Test-Bound -ParameterName ExcludeSystemService) -and
$service.IsSystemObject ) {
Get-DbaDbStoredProcedure.ps1:185:                if ( (Test-Bound -ParameterName ExcludeSystemSp) -and
$proc.IsSystemObject ) {
Get-DbaDbUdf.ps1:122:                if (Test-Bound -ParameterName ExcludeSystemUdf) {
Get-DbaDbUser.ps1:124:                if (Test-Bound -ParameterName ExcludeSystemUser) {
Get-DbaDbView.ps1:170:            if (Test-Bound -ParameterName ExcludeSystemView) {
Get-DbaInstanceAudit.ps1:76:            if (Test-Bound -ParameterName ExcludeAudit) {
Set-DbaMaxDop.ps1:153:                    } elseif ((Test-Bound -Not -ParameterName AllDatabases) -and (Test-Bound
-ParameterName ExcludeDatabase)) {

I would probably send PR in the same ways for these. I mean with a testing scenario. Would that be OK?

@andreasjordan
Copy link
Contributor

andreasjordan commented Jul 11, 2024

I would probably send PR in the same ways for these. I mean with a testing scenario. Would that be OK?

Sure.

@potatoqualitee
Copy link
Member

Thanks everyone! 🏆

@potatoqualitee potatoqualitee merged commit 61eed4d into dataplat:development Jul 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature internal Feature for the internal handling and structur (AppVayor, test, etc.) and nofor dbatools as a module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants