@@ -25,6 +25,14 @@ function Set-ROUser {
2525 Hashtable of ActionName=Weight pairs to upsert.
2626 . PARAMETER RandomPassword
2727 Generate a random password and set it in both AD and SQLite.
28+ . PARAMETER EnableCategory
29+ Enable all actions in a category (Core, Management, Advanced) by restoring default weights.
30+ . PARAMETER DisableCategory
31+ Disable all actions in a category by setting their weights to 0.
32+ . PARAMETER EnableAction
33+ Enable a specific action by restoring its default weight.
34+ . PARAMETER DisableAction
35+ Disable a specific action by setting its weight to 0.
2836 . EXAMPLE
2937 Set-ROUser -Username 'svc.sim01' -ActiveHourEnd '19:00'
3038 . EXAMPLE
@@ -35,6 +43,15 @@ function Set-ROUser {
3543 . EXAMPLE
3644 Set-ROUser -Username 'svc.sim01' -IsEnabled $false
3745 Disable the user.
46+ . EXAMPLE
47+ Set-ROUser -Username 'svc.sim01' -DisableCategory 'Management'
48+ Disable all Management actions for the user.
49+ . EXAMPLE
50+ Set-ROUser -Username 'svc.sim01' -EnableCategory 'Management'
51+ Restore default weights for all Management actions.
52+ . EXAMPLE
53+ Set-ROUser -Username 'svc.sim01' -DisableAction 'CreateSecret'
54+ Disable a single action for the user.
3855 . OUTPUTS
3956 PSCustomObject - the updated user record
4057 . LINK
@@ -57,7 +74,17 @@ function Set-ROUser {
5774
5875 [hashtable ]$ActionWeights ,
5976
60- [switch ]$RandomPassword
77+ [switch ]$RandomPassword ,
78+
79+ [ValidateSet (' Core' , ' Management' , ' Advanced' )]
80+ [string ]$EnableCategory ,
81+
82+ [ValidateSet (' Core' , ' Management' , ' Advanced' )]
83+ [string ]$DisableCategory ,
84+
85+ [string ]$EnableAction ,
86+
87+ [string ]$DisableAction
6188 )
6289
6390 $user = Invoke-ROQuery - Query " SELECT * FROM ROUser WHERE Username = @Username COLLATE NOCASE" - SqlParameters @ { Username = $Username }
@@ -130,5 +157,67 @@ ON CONFLICT(UserId, ActionName) DO UPDATE SET Weight = @Weight
130157 Write-ROLog - Message " Updated action weights for '$Username '" - Component ' UserMgmt'
131158 }
132159
160+ # Category-level enable/disable
161+ if ($EnableCategory -or $DisableCategory ) {
162+ $registry = Get-ROActionRegistry
163+ $seedPath = Join-Path $PSScriptRoot ' ..\Data\SeedActionWeights.psd1'
164+ $seedPath = [System.IO.Path ]::GetFullPath($seedPath )
165+ $seedWeights = if (Test-Path $seedPath ) { Invoke-Expression (Get-Content - Path $seedPath - Raw) } else { @ {} }
166+
167+ $targetCategory = if ($EnableCategory ) { $EnableCategory } else { $DisableCategory }
168+ $actionsInCategory = $registry.GetEnumerator () | Where-Object { $_.Value.Category -eq $targetCategory }
169+
170+ foreach ($entry in $actionsInCategory ) {
171+ $newWeight = if ($EnableCategory ) {
172+ if ($seedWeights [$entry.Key ]) { $seedWeights [$entry.Key ] } else { 10 }
173+ } else { 0 }
174+
175+ Invoke-ROQuery - Query @"
176+ INSERT INTO ActionWeight (UserId, ActionName, Weight) VALUES (@UserId, @ActionName, @Weight)
177+ ON CONFLICT(UserId, ActionName) DO UPDATE SET Weight = @Weight
178+ "@ - SqlParameters @ {
179+ UserId = $user.UserId
180+ ActionName = $entry.Key
181+ Weight = $newWeight
182+ }
183+ }
184+
185+ $verb = if ($EnableCategory ) { ' Enabled' } else { ' Disabled' }
186+ Write-ROLog - Message " $verb category '$targetCategory ' for '$Username '" - Component ' UserMgmt'
187+ }
188+
189+ # Granular action enable/disable
190+ if ($EnableAction -or $DisableAction ) {
191+ $targetAction = if ($EnableAction ) { $EnableAction } else { $DisableAction }
192+ $registry = Get-ROActionRegistry
193+
194+ if (-not $registry.ContainsKey ($targetAction )) {
195+ Write-Error " Unknown action '$targetAction '. Valid actions: $ ( $registry.Keys -join ' , ' ) "
196+ return
197+ }
198+
199+ $newWeight = 0
200+ if ($EnableAction ) {
201+ $seedPath = Join-Path $PSScriptRoot ' ..\Data\SeedActionWeights.psd1'
202+ $seedPath = [System.IO.Path ]::GetFullPath($seedPath )
203+ if (Test-Path $seedPath ) {
204+ $seedWeights = Invoke-Expression (Get-Content - Path $seedPath - Raw)
205+ $newWeight = if ($seedWeights [$targetAction ]) { $seedWeights [$targetAction ] } else { 10 }
206+ } else { $newWeight = 10 }
207+ }
208+
209+ Invoke-ROQuery - Query @"
210+ INSERT INTO ActionWeight (UserId, ActionName, Weight) VALUES (@UserId, @ActionName, @Weight)
211+ ON CONFLICT(UserId, ActionName) DO UPDATE SET Weight = @Weight
212+ "@ - SqlParameters @ {
213+ UserId = $user.UserId
214+ ActionName = $targetAction
215+ Weight = $newWeight
216+ }
217+
218+ $verb = if ($EnableAction ) { ' Enabled' } else { ' Disabled' }
219+ Write-ROLog - Message " $verb action '$targetAction ' for '$Username '" - Component ' UserMgmt'
220+ }
221+
133222 Get-ROUser - Username $Username
134223}
0 commit comments