Signed-off-by: Francois Gouget fgouget@codeweavers.com --- I don't forsee a need to add / remove roles but it is useful to at least be able to see which ones exist. In that it's similar to the Branches pages and fills a hole in the website administration interface. These pages are also little more than a 's/Branch/Role/g' of the Branches pages and should not require much maintenance. --- v1 failed to apply because the context had a bit from a patch in my worktree adding a copy of the "Special Jobs" page (I guess that patch should not be part of my "configuration tweaks for my copy of the TestBot" patches). --- testbot/lib/WineTestBot/CGI/PageBase.pm | 2 ++ testbot/web/admin/RoleDetails.pl | 42 +++++++++++++++++++++++++ testbot/web/admin/RolesList.pl | 30 ++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 testbot/web/admin/RoleDetails.pl create mode 100644 testbot/web/admin/RolesList.pl
diff --git a/testbot/lib/WineTestBot/CGI/PageBase.pm b/testbot/lib/WineTestBot/CGI/PageBase.pm index c42a4f2b4..40f519737 100644 --- a/testbot/lib/WineTestBot/CGI/PageBase.pm +++ b/testbot/lib/WineTestBot/CGI/PageBase.pm @@ -559,6 +559,8 @@ EOF "'>Special Jobs</a></p></li>\n"; print " <li><p><a href='", MakeSecureURL("/admin/UsersList.pl"), "'>Users</a></p></li>\n"; + print " <li><p><a href='", MakeSecureURL("/admin/RolesList.pl"), + "'>Roles</a></p></li>\n"; print " <li class='divider'> </li>\n"; print " <li><p><a href='", MakeSecureURL("/admin/VMsList.pl"), "'>VMs</a></p></li>\n"; diff --git a/testbot/web/admin/RoleDetails.pl b/testbot/web/admin/RoleDetails.pl new file mode 100644 index 000000000..3f6d02eb8 --- /dev/null +++ b/testbot/web/admin/RoleDetails.pl @@ -0,0 +1,42 @@ +# -*- Mode: Perl; perl-indent-level: 2; indent-tabs-mode: nil -*- +# Role details page +# +# Copyright 2010 VMware, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +use strict; + +package RoleDetailsPage; + +use ObjectModel::CGI::ItemPage; +our @ISA = qw(ObjectModel::CGI::ItemPage); + +use WineTestBot::Roles; + + +sub _initialize($$$) +{ + my ($self, $Request, $RequiredRole) = @_; + + $self->SUPER::_initialize($Request, $RequiredRole, CreateRoles()); +} + + +package main; + +my $Request = shift; +my $Page = RoleDetailsPage->new($Request, "admin"); +$Page->GeneratePage(); diff --git a/testbot/web/admin/RolesList.pl b/testbot/web/admin/RolesList.pl new file mode 100644 index 000000000..3fb765b0a --- /dev/null +++ b/testbot/web/admin/RolesList.pl @@ -0,0 +1,30 @@ +# -*- Mode: Perl; perl-indent-level: 2; indent-tabs-mode: nil -*- +# Role list page +# +# Copyright 2009 Ge van Geldorp +# Copyright 2022 Francois Gouget +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +use strict; + +package main; + +use ObjectModel::CGI::CollectionPage; +use WineTestBot::Roles; + +my $Request = shift; +my $Page = ObjectModel::CGI::CollectionPage->new($Request, "admin", CreateRoles()); +$Page->GeneratePage();
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/Roles.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/testbot/lib/WineTestBot/Roles.pm b/testbot/lib/WineTestBot/Roles.pm index c37de63a9..182538ceb 100644 --- a/testbot/lib/WineTestBot/Roles.pm +++ b/testbot/lib/WineTestBot/Roles.pm @@ -60,8 +60,8 @@ sub CreateItem($) }
my @PropertyDescriptors = ( - CreateBasicPropertyDescriptor("Name", "Role name", 1, 1, "A", 20), - CreateBasicPropertyDescriptor("IsDefaultRole", "Should new users get this role by default", !1, 1, "B", 1), + CreateBasicPropertyDescriptor("Name", "Role", 1, 1, "A", 20), + CreateBasicPropertyDescriptor("IsDefaultRole", "Default role", !1, 1, "B", 1), );
=pod
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/admin/UserDetails.pl | 129 ++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-)
diff --git a/testbot/web/admin/UserDetails.pl b/testbot/web/admin/UserDetails.pl index f11d127ad..798063dd7 100644 --- a/testbot/web/admin/UserDetails.pl +++ b/testbot/web/admin/UserDetails.pl @@ -2,7 +2,7 @@ # User details page # # Copyright 2009 Ge van Geldorp -# Copyright 2013 Francois Gouget +# Copyright 2013-2014, 2017-2018, 2022 Francois Gouget # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,111 @@
use strict;
+ +package RolesBlock; + +use ObjectModel::CGI::CollectionBlock; +our @ISA = qw(ObjectModel::CGI::CollectionBlock); + +use URI::Escape; + +use ObjectModel::BasicPropertyDescriptor; +use WineTestBot::Utils; + + +sub _initialize($$$) +{ + my ($self, $Collection, $EnclosingPage) = @_; + + $self->SUPER::_initialize($self, $Collection, $EnclosingPage); + $self->{User} = $self->{EnclosingPage}->{Item}; + $self->{UserName} = $self->{User}->Name; +} + +sub GetPropertyDescriptors($) +{ + my ($self) = @_; + + my %Props; + map { $Props{$_->GetName()} = $_ } @{$self->{Collection}->GetPropertyDescriptors()}; + return [ + CreateBasicPropertyDescriptor($self->{UserName}, $self->{UserName}, !1, !1, "B", 1), + $Props{IsDefaultRole}, + $Props{Name}, + ]; +} + +sub GetPropertyValue($$$) +{ + my ($self, $Row, $Col) = @_; + + return $Col->{Descriptor}->GetName() eq $self->{UserName} ? + $self->{User}->Roles->HasItem($Row->{Item}->Name) : + $self->SUPER::GetPropertyValue($Row, $Col); +} + +sub GenerateFormStart($) +{ + my ($self) = @_; + + $self->SUPER::GenerateFormStart(); + print "<input type='hidden' name='Key' value='", + uri_escape($self->{User}->GetKey()), "'>\n"; +} + +sub GetItemActions($) +{ + #my ($self) = @_; + + return ["Add role", "Remove role"]; +} + +sub OnItemAction($$$) +{ + my ($self, $Item, $Action) = @_; + + if ($self->{RW} and $Action eq "Add role") + { + return 1 if ($self->{User}->Roles->HasItem($Item->Name)); + + $self->{User}->AddRole($Item); + my $ErrMessage = $self->{User}->Roles->Save(); + if (defined $ErrMessage) + { + $self->{EnclosingPage}->SetError(undef, $ErrMessage); + return 0; + } + NotifyAdministrator("New administrator user: $self->{UserName}", + "$self->{UserName} now is an administrator.\n"); + return 1; + } + if ($self->{RW} and $Action eq "Remove role") + { + my $UserRole = $self->{User}->Roles->GetItem($Item->Name); + return 1 if (!$UserRole); + + my $ErrMessage = $self->{User}->Roles->DeleteItem($UserRole); + if (defined $ErrMessage) + { + $self->{EnclosingPage}->SetError(undef, $ErrMessage); + return 0; + } + NotifyAdministrator("Removed an administrator: $self->{UserName}", + "$self->{UserName} is no longer an administrator.\n"); + return 1; + } + + $self->{EnclosingPage}->SetError(undef, "No per-Item action defined for $Action"); + return 0; +} + +sub GetActions($) +{ + #my ($self) = @_; + return []; +} + + package UserDetailsPage;
use ObjectModel::CGI::ItemPage; @@ -27,6 +132,7 @@ our @ISA = qw(ObjectModel::CGI::ItemPage);
use WineTestBot::CGI::Sessions; use WineTestBot::Config; +use WineTestBot::Roles; use WineTestBot::Users;
@@ -35,6 +141,10 @@ sub _initialize($$$) my ($self, $Request, $RequiredRole) = @_;
$self->SUPER::_initialize($Request, $RequiredRole, CreateUsers()); + if (!$self->{Item}->GetIsNew()) + { + $self->{RolesBlock} = new RolesBlock(CreateRoles(), $self); + } }
sub DisplayProperty($$) @@ -51,6 +161,18 @@ sub DisplayProperty($$) return $self->SUPER::DisplayProperty($PropertyDescriptor); }
+sub GenerateBody($) +{ + my ($self) = @_; + + $self->SUPER::GenerateBody(); + if ($self->{RolesBlock}) + { + print "<h2><a name='Roles'></a>Roles</h2>\n"; + $self->{RolesBlock}->GenerateList(); + } +} + sub GetActions($) { my ($self) = @_; @@ -118,6 +240,11 @@ sub OnAction($$) { return $self->OnSave(); } + elsif ($self->{RolesBlock} and + grep { $_ eq $Action } @{$self->{RolesBlock}->GetItemActions()}) + { + return $self->{RolesBlock}->OnAction($self->GetParam("Action")); + }
return $self->SUPER::OnAction($Action); }