Francois Gouget : testbot/cgi: Let CollectionBlock operate in read-only mode.
Module: tools Branch: master Commit: babda62efde5ad100101e5506167dc37e38728e6 URL: https://source.winehq.org/git/tools.git/?a=commit;h=babda62efde5ad100101e550... Author: Francois Gouget <fgouget(a)codeweavers.com> Date: Wed Apr 6 14:18:36 2022 +0200 testbot/cgi: Let CollectionBlock operate in read-only mode. When in read-only mode the CollectionBlock does not allow any per-item or global action to be performed. Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- testbot/lib/ObjectModel/CGI/CollectionBlock.pm | 39 ++++++++++++++++++++++---- testbot/lib/ObjectModel/CGI/CollectionPage.pm | 7 +++++ testbot/web/PatchesList.pl | 13 +-------- testbot/web/index.pl | 32 ++------------------- 4 files changed, 43 insertions(+), 48 deletions(-) diff --git a/testbot/lib/ObjectModel/CGI/CollectionBlock.pm b/testbot/lib/ObjectModel/CGI/CollectionBlock.pm index 40ad61b..13c2a62 100644 --- a/testbot/lib/ObjectModel/CGI/CollectionBlock.pm +++ b/testbot/lib/ObjectModel/CGI/CollectionBlock.pm @@ -53,7 +53,7 @@ use URI::Escape; =item C<new()> -Creates a table showing the content of the specified Collection with +Creates a table showing the content of the specified Collection with optional support for performing actions on selected rows, or performing global actions. Parameters: @@ -67,6 +67,8 @@ ObjectModel::CGI::Page interface. =back +Note that by default the table is in read-write mode (see SetReadWrite()). + =back =cut @@ -76,7 +78,9 @@ sub new($$$@) my ($Collection, $EnclosingPage) = @_; my $self = {Collection => $Collection, - EnclosingPage => $EnclosingPage}; + EnclosingPage => $EnclosingPage, + RW => 1, + }; $self = bless $self, $class; $self->_initialize(@_); return $self; @@ -92,6 +96,28 @@ sub Create($$@) return ObjectModel::CGI::CollectionBlock->new(@_); } +=pod +=over 12 + +=item C<SetReadWrite()> + +If set to true, the table allows selecting rows and applying actions to +them (see GetItemActions()), as well as performing global actions (see +GetActions()). + +Otherwise none of this is allowed, regardless of what GetItemActions() and +GetActions() return. + +=back +=cut + +sub SetReadWrite($$) +{ + my ($self, $RW) = @_; + + $self->{RW} = $RW; +} + sub GetDetailsPage($) { my ($self) = @_; @@ -405,7 +431,7 @@ EOF print "<table border='0' cellpadding='5' cellspacing='0' summary='" . "Overview of " . $Collection->GetCollectionName() . "'>\n"; print "<thead>\n"; - my $ItemActions = $self->GetItemActions(); + my $ItemActions = $self->{RW} ? $self->GetItemActions() : []; $self->GenerateHeaderRow($PropertyDescriptors, $ItemActions); print "</thead>\n"; @@ -459,7 +485,7 @@ EOF print "</div>\n"; } - my $Actions = $self->GetActions(); + my $Actions = $self->{RW} ? $self->GetActions() : []; if (@$Actions != 0) { print "<div class='CollectionBlockActions'>\n"; @@ -499,6 +525,7 @@ column of checkboxes is added. sub GetItemActions($) { #my ($self) = @_; + return ["Delete"]; } @@ -523,7 +550,7 @@ sub OnItemAction($$$) { my ($self, $Item, $Action) = @_; - if ($Action eq "Delete") + if ($self->{RW} and $Action eq "Delete") { my $ErrMessage = $self->{Collection}->DeleteItem($Item); if (defined $ErrMessage) @@ -587,7 +614,7 @@ sub OnAction($$) { my ($self, $Action) = @_; - if ($Action eq "Add " . $self->{Collection}->GetItemName()) + if ($self->{RW} and $Action eq "Add ". $self->{Collection}->GetItemName()) { my $Target = $self->GetDetailsPage(); my ($MasterColNames, $MasterColValues) = $self->{Collection}->GetMasterCols(); diff --git a/testbot/lib/ObjectModel/CGI/CollectionPage.pm b/testbot/lib/ObjectModel/CGI/CollectionPage.pm index 2de667b..7bdd27e 100644 --- a/testbot/lib/ObjectModel/CGI/CollectionPage.pm +++ b/testbot/lib/ObjectModel/CGI/CollectionPage.pm @@ -87,6 +87,13 @@ sub _initialize($$$$;$) $self->SUPER::_initialize($Request, $RequiredRole); } +sub SetReadWrite($$) +{ + my ($self, $RW) = @_; + + $self->{CollectionBlock}->SetReadWrite($RW); +} + # # HTML page generation diff --git a/testbot/web/PatchesList.pl b/testbot/web/PatchesList.pl index 49e16d8..854c276 100644 --- a/testbot/web/PatchesList.pl +++ b/testbot/web/PatchesList.pl @@ -64,18 +64,6 @@ sub GenerateDataCell($$$$$) } } -sub GetItemActions($) -{ - #my ($self) = @_; - return []; -} - -sub GetActions($) -{ - #my ($self) = @_; - return []; -} - package main; @@ -84,5 +72,6 @@ use WineTestBot::Patches; my $Request = shift; my $Page = ObjectModel::CGI::CollectionPage->new($Request, "", CreatePatches(), \&PatchesBlock::Create); +$Page->SetReadWrite(0); $Page->SetRefreshInterval(60); $Page->GeneratePage(); diff --git a/testbot/web/index.pl b/testbot/web/index.pl index d2dd2b4..85f8df3 100644 --- a/testbot/web/index.pl +++ b/testbot/web/index.pl @@ -43,18 +43,6 @@ sub SortKeys($$) return \@SortedKeys; } -sub GetItemActions($) -{ - #my ($self) = @_; - return []; -} - -sub GetActions($) -{ - #my ($self) = @_; - return []; -} - sub DisplayProperty($$) { my ($self, $PropertyDescriptor) = @_; @@ -207,18 +195,6 @@ sub SortKeys($$) return $self->{Collection}->SortKeysBySortOrder($Keys); } -sub GetItemActions($) -{ - #my ($self) = @_; - return []; -} - -sub GetActions($) -{ - #my ($self) = @_; - return []; -} - sub DisplayProperty($$) { my ($self, $PropertyDescriptor) = @_; @@ -229,12 +205,6 @@ sub DisplayProperty($$) $PropertyName eq "Description"; } -sub GetDetailsPage($) -{ - #my ($self) = @_; - return undef; -} - package StatusPage; @@ -344,6 +314,7 @@ sub GenerateBody($) my $CutOff = time() - $Days * 24 * 60 * 60; $Jobs->AddFilter("Submitted", [$CutOff], ">="); my $JobsCollectionBlock = new JobStatusBlock($Jobs, $self); + $JobsCollectionBlock->SetReadWrite(0); # We need to collect information about the tasks of all jobs except the # pretty rare queued jobs. But doing so one job at a time is inefficient so @@ -384,6 +355,7 @@ EOF print "<h2><a name='vms'></a>VMs</h2>\n"; my $VMsCollectionBlock = new VMStatusBlock(CreateVMs(), $self); + $VMsCollectionBlock->SetReadWrite(0); $VMsCollectionBlock->GenerateList(); print "</div>\n";
participants (1)
-
Alexandre Julliard