Francois Gouget : testbot/web: Simplify the users deletion code.
Module: tools Branch: master Commit: 75be651535ede96432dce018d4027e9240be39c7 URL: https://source.winehq.org/git/tools.git/?a=commit;h=75be651535ede96432dce018... Author: Francois Gouget <fgouget(a)codeweavers.com> Date: Wed Mar 2 17:05:49 2022 +0100 testbot/web: Simplify the users deletion code. Use CollectionPage's per-item action methods. Also make sure the actions report all failures. Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- testbot/web/admin/UsersList.pl | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/testbot/web/admin/UsersList.pl b/testbot/web/admin/UsersList.pl index 2799070..3621702 100644 --- a/testbot/web/admin/UsersList.pl +++ b/testbot/web/admin/UsersList.pl @@ -102,43 +102,30 @@ sub GenerateDataCell($$$$$) } } -sub GetActions($$) +sub GetItemActions($$) { my ($self, $CollectionBlock) = @_; - if (defined($LDAPServer)) - { - # LDAP accounts cannot be deleted - return []; - } - - return $self->SUPER::GetActions($CollectionBlock); + # LDAP accounts cannot be deleted + return defined $LDAPServer ? [] : ["Delete"]; } -sub OnAction($$$) +sub OnItemAction($$$$) { - my ($self, $CollectionBlock, $Action) = @_; + my ($self, $CollectionBlock, $Item, $Action) = @_; if ($Action eq "Delete") { - foreach my $UserName (@{$self->{Collection}->GetKeys()}) - { - next if (!defined $self->GetParam($CollectionBlock->SelName($UserName))); - my $User = $self->{Collection}->GetItem($UserName); - $User->Status('deleted'); - my ($ErrProperty, $ErrMessage) = $User->Save(); - if (defined $ErrMessage) - { - $self->{ErrMessage} = $ErrMessage; - return !1; - } - # Forcefully log out that user by deleting his web sessions - DeleteSessions($User); - } + $Item->Status('deleted'); + (my $ErrProperty, $self->{ErrMessage}) = $Item->Save(); + return 0 if (defined $self->{ErrMessage}); + + # Forcefully log out that user by deleting the web sessions + DeleteSessions($Item); return 1; } - return $self->SUPER::OnAction($CollectionBlock, $Action); + return $self->SUPER::OnItemAction($CollectionBlock, $Item, $Action); }
participants (1)
-
Alexandre Julliard