This simplifies adding a role to a user, particularly with regards to making sure the user's Roles collection is up to date.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/Users.pm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/testbot/lib/WineTestBot/Users.pm b/testbot/lib/WineTestBot/Users.pm index bd9cf358b..f2f2a199d 100644 --- a/testbot/lib/WineTestBot/Users.pm +++ b/testbot/lib/WineTestBot/Users.pm @@ -106,22 +106,25 @@ sub GenerateResetCode($) } }
+sub AddRole($$) +{ + my ($self, $Role) = @_; + + my $UserRole = $self->Roles->Add(); + my $OldKey = $UserRole->GetKey(); + $UserRole->Role($Role); + $self->Roles->KeyChanged($OldKey, $Role->GetKey()); +} + sub AddDefaultRoles($) { my ($self) = @_;
- my $UserRoles = $self->Roles; my $DefaultRoles = CreateRoles(); $DefaultRoles->AddFilter("IsDefaultRole", [1]); - foreach my $RoleKey (@{$DefaultRoles->GetKeys()}) + foreach my $Role (@{$DefaultRoles->GetItems()}) { - if (! defined($UserRoles->GetItem($RoleKey))) - { - my $NewRole = $UserRoles->Add(); - my $OldKey = $NewRole->GetKey(); - $NewRole->Role($DefaultRoles->GetItem($RoleKey)); - $UserRoles->KeyChanged($OldKey, $RoleKey); - } + $self->AddRole($Role) if (!$self->Roles->GetItem($Role->Name)); } }