Skip to content

Commit

Permalink
#84 - Notes Property Management on KPGroup Objects
Browse files Browse the repository at this point in the history
New/Update commands now support Notes parameter
Added tests
Added Notes to ConvertTo-KPPSObject function for groups
updated docs and function parameter help text
  • Loading branch information
jkdba committed Mar 22, 2019
1 parent b545c3e commit e3aa808
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 14 deletions.
Binary file modified PoShKeePass.psd1
Binary file not shown.
27 changes: 26 additions & 1 deletion Test/PSKeePassUsage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,12 @@ InModuleScope "PoShKeePass" {

It "Example 1.3: Creates a New KeePass Group - Valid - PassThru" {

$PassThruResult = New-KeePassGroup -KeePassGroupParentPath 'PSKeePassTestDatabase' -KeePassGroupName 'test2PassThru' -DatabaseProfileName 'SampleProfile' -PassThru
$PassThruResult = New-KeePassGroup -KeePassGroupParentPath 'PSKeePassTestDatabase' -KeePassGroupName 'test2PassThru' -DatabaseProfileName 'SampleProfile' -Notes 'testnotes' -PassThru

$PassThruResult.psobject.TypeNames -icontains 'PSKeePass.Group' | Should Be $true
$PassThruResult.ParentGroup | Should Be 'PSKeePassTestDatabase'
$PassThruResult.Name | Should Be 'test2PassThru'
$PassThruResult.Notes | Should Be 'testnotes'
}

It "Example 1.4: Creates a New KeePass Entry - Invalid - Group Path does not Exist" {
Expand Down Expand Up @@ -926,6 +927,30 @@ InModuleScope "PoShKeePass" {
$KeePassGroup.Expires | Should be $true
$KeePassGroup.ExpireTime | Should be $expiryTime.ToUniversalTime()
}

It "Example 1.9: Updates a KeePass Group - Valid - Notes" {
New-KeePassGroup -KeePassGroupParentPath 'PSKeePassTestDatabase' -KeePassGroupName 'test8' -DatabaseProfileName 'SampleProfile' -Notes 'meh' | Should Be $null
$KeePassGroup = Get-KeePassGroup -DatabaseProfileName SampleProfile -KeePassGroupPath 'PSKeePassTestDatabase/test8'
$KeePassGroup.Name | Should Be 'test8'
$KeePassGroup.Notes | Should Be 'meh'
$KeePassGroup = Update-KeePassGroup -KeePassGroup $KeePassGroup -GroupName 'Test8Update' -DatabaseProfileName 'SampleProfile' -Notes 'bye' -Force -PassThru
$KeePassGroup.Name | Should Be 'Test8Update'
$KeePassGroup.psobject.TypeNames -icontains 'PSKeePass.Group' | Should Be $true
$KeePassGroup.ParentGroup | Should be 'PSKeePassTestDatabase'
$KeePassGroup.Notes | Should Be 'bye'
}

It "Example 2.0: Updates a KeePass Group - Valid - Notes Not Passed" {
New-KeePassGroup -KeePassGroupParentPath 'PSKeePassTestDatabase' -KeePassGroupName 'test9' -DatabaseProfileName 'SampleProfile' -Notes 'meh' | Should Be $null
$KeePassGroup = Get-KeePassGroup -DatabaseProfileName SampleProfile -KeePassGroupPath 'PSKeePassTestDatabase/test9'
$KeePassGroup.Name | Should Be 'test9'
$KeePassGroup.Notes | Should Be 'meh'
$KeePassGroup = Update-KeePassGroup -KeePassGroup $KeePassGroup -GroupName 'Test9Update' -DatabaseProfileName 'SampleProfile' -Force -PassThru
$KeePassGroup.Name | Should Be 'Test9Update'
$KeePassGroup.psobject.TypeNames -icontains 'PSKeePass.Group' | Should Be $true
$KeePassGroup.ParentGroup | Should be 'PSKeePassTestDatabase'
$KeePassGroup.Notes | Should Be 'meh'
}
}

New-KPConfigurationFile -Force
Expand Down
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## v.2.1.2.6
## v.2.1.2.8

* [#158](https://github.com/PSKeePass/PoShKeePass/issues/158) - Added Update-KeePassDatabaseConfiguration function and tests.
* Added - [#84](https://github.com/PSKeePass/PoShKeePass/issues/84) - Manage Notes properties on KPGroup Objects.

* v.2.1.2.6 - Added - [#158](https://github.com/PSKeePass/PoShKeePass/issues/158) - Added Update-KeePassDatabaseConfiguration function and tests.

* v.2.1.2.5 - Fix - [#157](https://github.com/PSKeePass/PoShKeePass/issues/157) - Set New-KPConnection function back to internal function and no longer exports.

Expand Down
1 change: 1 addition & 0 deletions functions/ConvertTo-KPPSObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function ConvertTo-KPPSObject
'LastAccessTimeUtc' = $_keepassItem.LastAccessTime;
'LastModificationTimeUtc' = $_keepassItem.LastModificationTime;
'LocationChanged' = $_keepassItem.LocationChanged;
'Notes' = $_keepassItem.Notes;
'Touched' = $_keepassItem.Touched;
'UsageCount' = $_keepassItem.UsageCount;
'ParentGroup' = $_keepassItem.ParentGroup.Name;
Expand Down
16 changes: 12 additions & 4 deletions functions/New-KeePassGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function New-KeePassGroup
This parameter was created with scripting in mind.
.PARAMETER IconName
Specify the Name of the Icon for the Group to display in the KeePass UI.
.PARAMETER Notes
Specify group notes
.PARAMETER Expires
Specify if you want the KeePass Object to Expire, default is to not expire.
.PARAMETER ExpiryTime
Expand Down Expand Up @@ -51,20 +53,24 @@ function New-KeePassGroup
[string] $IconName = 'Folder',

[Parameter(Position = 3)]
[switch] $Expires,
[ValidateNotNullOrEmpty()]
[String] $Notes,

[Parameter(Position = 4)]
[switch] $Expires,

[Parameter(Position = 5)]
[DateTime] $ExpiryTime,

[Parameter(Position = 5, Mandatory, ValueFromPipelineByPropertyName)]
[Parameter(Position = 6, Mandatory, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[string] $DatabaseProfileName,

[Parameter(Position = 6)]
[Parameter(Position = 7)]
[ValidateNotNullOrEmpty()]
[PSobject] $MasterKey,

[Parameter(Position = 7)]
[Parameter(Position = 8)]
[Switch] $PassThru
)
begin
Expand All @@ -83,8 +89,10 @@ function New-KeePassGroup
IconName = $IconName
PassThru = $PassThru
KeePassParentGroup = $KeePassParentGroup
Notes = $Notes
}

# if($Notes){ $addKPGroupSplat.Notes = $Notes }
if(Test-Bound -ParameterName 'Expires'){ $addKPGroupSplat.Expires = $Expires }
if($ExpiryTime){ $addKPGroupSplat.ExpiryTime = $ExpiryTime }

Expand Down
7 changes: 7 additions & 0 deletions functions/Update-KeePassGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function Update-KeePassGroup
This parameter was created with scripting in mind.
.PARAMETER IconName
Specify the Name of the Icon for the Group to display in the KeePass UI.
.PARAMETER Notes
Specify group notes
.PARAMETER Expires
Specify if you want the KeePass Object to Expire, default is to not expire.
.PARAMETER ExpiryTime
Expand Down Expand Up @@ -67,6 +69,10 @@ function Update-KeePassGroup
[ValidateNotNullOrEmpty()]
[string] $IconName,

[Parameter(Position = 5)]
[ValidateNotNullOrEmpty()]
[String] $Notes,

[Parameter(Position = 3)]
[switch] $Expires,

Expand Down Expand Up @@ -118,6 +124,7 @@ function Update-KeePassGroup
Force = $true
GroupName = $GroupName
Confirm = $false
Notes = $Notes
}

if($IconName){ $setKPGroupSplat.IconName = $IconName }
Expand Down
14 changes: 12 additions & 2 deletions internal/Add-KPGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function Add-KPGroup
Sepcify the KeePassParentGroup(s) for the new Group(s).
.PARAMETER IconName
Specify the Name of the Icon for the Group to display in the KeePass UI.
.PARAMETER Notes
Specify group notes
.PARAMETER PassThru
Specify to return the new keepass group object.
.PARAMETER Expires
Expand Down Expand Up @@ -47,12 +49,15 @@ function Add-KPGroup
[KeePassLib.PwIcon] $IconName,

[Parameter(Position = 4)]
[bool] $Expires,
[String] $Notes,

[Parameter(Position = 5)]
[DateTime] $ExpiryTime,
[bool] $Expires,

[Parameter(Position = 6)]
[DateTime] $ExpiryTime,

[Parameter(Position = 7)]
[Switch] $PassThru
)
begin
Expand All @@ -78,6 +83,11 @@ function Add-KPGroup
$KeePassGroup.IconId = $IconName
}

if($Notes)
{
$KeePassGroup.Notes = $Notes
}

if(Test-Bound -ParameterName 'Expires')
{
$KeePassGroup.Expires = $Expires
Expand Down
17 changes: 14 additions & 3 deletions internal/Set-KPGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function Set-KPGroup
Sepcify the KeePassParentGroup(s) for the new Group(s).
.PARAMETER IconName
Specify the Name of the Icon for the Entry to display in the KeePass UI.
.PARAMETER Notes
Specify group notes
.PARAMETER PassThru
Specify to return the updated group object.
.PARAMETER Force
Expand Down Expand Up @@ -52,15 +54,18 @@ function Set-KPGroup
[KeePassLib.PwIcon] $IconName,

[Parameter(Position = 5)]
[bool] $Expires,
[String] $Notes,

[Parameter(Position = 6)]
[DateTime] $ExpiryTime,
[bool] $Expires,

[Parameter(Position = 7)]
[Switch] $PassThru,
[DateTime] $ExpiryTime,

[Parameter(Position = 8)]
[Switch] $PassThru,

[Parameter(Position = 9)]
[Switch] $Force
)
process
Expand All @@ -79,6 +84,11 @@ function Set-KPGroup
$KeePassGroup.IconId = $IconName
}

if($Notes)
{
$KeePassGroup.Notes = $Notes
}

if(Test-Bound -ParameterName 'Expires')
{
$KeePassGroup.Expires = $Expires
Expand All @@ -102,6 +112,7 @@ function Set-KPGroup
$KeePassGroup = $UpdatedKeePassGroup
}
}

$KeePassConnection.Save($null)

if($PassThru)
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ Please check out our [Getting Started](https://github.com/PSKeePass/PoShKeePass/

Please review the [changelog document](https://github.com/PSKeePass/PoShKeePass/blob/master/changelog.md) for a full history.

## v.2.1.2.6
## v.2.1.2.8

* [#158](https://github.com/PSKeePass/PoShKeePass/issues/158) - Added Update-KeePassDatabaseConfiguration function and tests.
* Added - [#84](https://github.com/PSKeePass/PoShKeePass/issues/84) - Manage Notes properties on KPGroup Objects.

* v.2.1.2.6 - Added - [#158](https://github.com/PSKeePass/PoShKeePass/issues/158) - Added Update-KeePassDatabaseConfiguration function and tests.

* v.2.1.2.5 - Fix - [#157](https://github.com/PSKeePass/PoShKeePass/issues/157) - Set New-KPConnection function back to internal function and no longer exports.

Expand Down

0 comments on commit e3aa808

Please sign in to comment.