Francois Gouget : testbot/orm: Make the Itemref columns read-only.

Alexandre Julliard julliard at winehq.org
Mon Jun 13 15:58:31 CDT 2022


Module: tools
Branch: master
Commit: d14084c1c2f78b5a140987e9ccc9adfe9b66972a
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=d14084c1c2f78b5a140987e9ccc9adfe9b66972a

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Mon Jun 13 17:14:50 2022 +0200

testbot/orm: Make the Itemref columns read-only.

The columns used by an Itemref should be modified through the Itemref
property to ensure that they remain in sync with it.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/lib/ObjectModel/CGI/FormPage.pm            |  3 ++-
 testbot/lib/ObjectModel/Item.pm                    |  8 +++++++
 .../lib/ObjectModel/ItemrefPropertyDescriptor.pm   | 28 +++++++++++++++++++++-
 testbot/lib/ObjectModel/PropertyDescriptor.pm      |  7 ++++++
 testbot/lib/WineTestBot/CGI/Sessions.pm            |  1 +
 testbot/lib/WineTestBot/Jobs.pm                    |  1 +
 testbot/lib/WineTestBot/PendingPatches.pm          |  1 +
 testbot/lib/WineTestBot/StepsTasks.pm              |  1 +
 testbot/lib/WineTestBot/Tasks.pm                   |  1 +
 testbot/lib/WineTestBot/UserRoles.pm               |  1 +
 10 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/testbot/lib/ObjectModel/CGI/FormPage.pm b/testbot/lib/ObjectModel/CGI/FormPage.pm
index 224bf36..6f3449b 100644
--- a/testbot/lib/ObjectModel/CGI/FormPage.pm
+++ b/testbot/lib/ObjectModel/CGI/FormPage.pm
@@ -198,7 +198,8 @@ sub DisplayProperty($$)
          # type the appropriate key value would also be cumbersome so this is
          # currently not supported. But they can be displayed.
          $PropertyDescriptor->GetClass() eq "Itemref" ? "ro" :
-         # All other properties can displayed,
+         $PropertyDescriptor->GetIsReadOnly() ? "ro" :
+         # All other properties can be displayed,
          !$self->{RW} ? "ro" :
          # and even edited if in read-write mode...
          $PropertyDescriptor->GetClass() ne "Basic" ? "rw" :
diff --git a/testbot/lib/ObjectModel/Item.pm b/testbot/lib/ObjectModel/Item.pm
index b07b760..11d09be 100644
--- a/testbot/lib/ObjectModel/Item.pm
+++ b/testbot/lib/ObjectModel/Item.pm
@@ -270,6 +270,10 @@ sub AUTOLOAD
       {
         if (@_)
         {
+          if ($PropertyDescriptor->GetIsReadOnly())
+          {
+            die "$PropertyName is read-only";
+          }
           my $Value = shift;
           if ($self->ValuesDiffer($Value, $self->{ColValues}{$PropertyName}))
           {
@@ -283,6 +287,10 @@ sub AUTOLOAD
       {
         if (@_)
         {
+          if ($PropertyDescriptor->GetIsReadOnly())
+          {
+            die "$PropertyName is read-only";
+          }
           my $Item = shift;
           if (!$Item and !$self->{Itemrefs}{$PropertyName})
           {
diff --git a/testbot/lib/ObjectModel/ItemrefPropertyDescriptor.pm b/testbot/lib/ObjectModel/ItemrefPropertyDescriptor.pm
index 6895e80..171d00a 100644
--- a/testbot/lib/ObjectModel/ItemrefPropertyDescriptor.pm
+++ b/testbot/lib/ObjectModel/ItemrefPropertyDescriptor.pm
@@ -28,7 +28,7 @@ ObjectModel::ItemrefPropertyDescriptor - A property referencing an ObjectModel::
 use Exporter 'import';
 use ObjectModel::PropertyDescriptor;
 our @ISA = qw(ObjectModel::PropertyDescriptor);
-our @EXPORT = qw(CreateItemrefPropertyDescriptor);
+our @EXPORT = qw(CreateItemrefPropertyDescriptor SetupItemrefColumns);
 
 sub _initialize($$$)
 {
@@ -78,4 +78,30 @@ sub CreateItemrefPropertyDescriptor($$$$$)
   return ObjectModel::ItemrefPropertyDescriptor->new($Name, $DisplayName, !1, $IsRequired, $Creator, $RefColNames);
 }
 
+sub SetupItemrefColumns($)
+{
+  my ($PropertyDescriptors) = @_;
+
+  my (@Itemrefs, %Properties);
+  foreach my $PropertyDescriptor (@$PropertyDescriptors)
+  {
+    $Properties{$PropertyDescriptor->GetName()} = $PropertyDescriptor;
+    if ($PropertyDescriptor->GetClass() eq "Itemref")
+    {
+      push @Itemrefs, $PropertyDescriptor;
+    }
+  }
+
+  # Mark the Itemref columns as read-only so they are only modified
+  # through the Itemref.
+  foreach my $Itemref (@Itemrefs)
+  {
+    foreach my $ColName (@{$Itemref->GetRefColNames()})
+    {
+      my $ColDescriptor = $Properties{$ColName};
+      $ColDescriptor->{IsReadOnly} = 1;
+    }
+  }
+}
+
 1;
diff --git a/testbot/lib/ObjectModel/PropertyDescriptor.pm b/testbot/lib/ObjectModel/PropertyDescriptor.pm
index f13a4b2..2f9411a 100644
--- a/testbot/lib/ObjectModel/PropertyDescriptor.pm
+++ b/testbot/lib/ObjectModel/PropertyDescriptor.pm
@@ -86,6 +86,13 @@ sub GetIsRequired($)
   return $self->{IsRequired};
 }
 
+sub GetIsReadOnly($)
+{
+  my ($self) = @_;
+
+  return $self->{IsReadOnly};
+}
+
 sub GetClass($)
 {
   my ($self) = @_;
diff --git a/testbot/lib/WineTestBot/CGI/Sessions.pm b/testbot/lib/WineTestBot/CGI/Sessions.pm
index 5ca84e7..8594cfc 100644
--- a/testbot/lib/WineTestBot/CGI/Sessions.pm
+++ b/testbot/lib/WineTestBot/CGI/Sessions.pm
@@ -75,6 +75,7 @@ my @PropertyDescriptors = (
   CreateItemrefPropertyDescriptor("User",    "User",                   1, \&CreateUsers, ["UserName"]),
   CreateBasicPropertyDescriptor("Permanent", "Permanent session", !1,  1, "B",  1),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 
 =pod
 =over 12
diff --git a/testbot/lib/WineTestBot/Jobs.pm b/testbot/lib/WineTestBot/Jobs.pm
index 140bd57..7f15a9c 100644
--- a/testbot/lib/WineTestBot/Jobs.pm
+++ b/testbot/lib/WineTestBot/Jobs.pm
@@ -524,6 +524,7 @@ my @PropertyDescriptors = (
   CreateItemrefPropertyDescriptor("Patch", "Submitted from patch", !1, \&WineTestBot::Patches::CreatePatches, ["PatchId"]),
   CreateDetailrefPropertyDescriptor("Steps", "Steps", \&CreateSteps),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 SetDetailrefKeyPrefix("Job", @PropertyDescriptors);
 
 =pod
diff --git a/testbot/lib/WineTestBot/PendingPatches.pm b/testbot/lib/WineTestBot/PendingPatches.pm
index f4768b8..32a6af4 100644
--- a/testbot/lib/WineTestBot/PendingPatches.pm
+++ b/testbot/lib/WineTestBot/PendingPatches.pm
@@ -68,6 +68,7 @@ my @PropertyDescriptors = (
   CreateBasicPropertyDescriptor("PatchId", "Patch id", !1, 1, "N",  10),
   CreateItemrefPropertyDescriptor("Patch", "Submitted via patch", 1, \&CreatePatches, ["PatchId"]),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 my @FlatPropertyDescriptors = (
   CreateBasicPropertyDescriptor("PendingPatchSetEMail", "EMail of series author", 1, 1, "A", 40),
   CreateBasicPropertyDescriptor("PendingPatchSetVersion", "Expected version of the series", 1, 1, "N", 2),
diff --git a/testbot/lib/WineTestBot/StepsTasks.pm b/testbot/lib/WineTestBot/StepsTasks.pm
index 2533c6a..87146b2 100644
--- a/testbot/lib/WineTestBot/StepsTasks.pm
+++ b/testbot/lib/WineTestBot/StepsTasks.pm
@@ -192,6 +192,7 @@ my @PropertyDescriptors = (
   CreateBasicPropertyDescriptor("Ended", "Ended", !1, !1, "DT", 19),
   CreateBasicPropertyDescriptor("TestFailures", "Failures", !1, !1, "N", 6),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 
 sub CreateStepsTasks(;$$)
 {
diff --git a/testbot/lib/WineTestBot/Tasks.pm b/testbot/lib/WineTestBot/Tasks.pm
index 5c5813c..0360e4e 100644
--- a/testbot/lib/WineTestBot/Tasks.pm
+++ b/testbot/lib/WineTestBot/Tasks.pm
@@ -363,6 +363,7 @@ my @PropertyDescriptors = (
   CreateBasicPropertyDescriptor("Ended", "Ended", !1, !1, "DT", 19),
   CreateBasicPropertyDescriptor("TestFailures", "Failures", !1, !1, "N", 6),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 my @FlatPropertyDescriptors = (
   CreateBasicPropertyDescriptor("JobId", "Job id", 1, 1, "N", 10),
   CreateBasicPropertyDescriptor("StepNo", "Step no",  1,  1, "N", 2),
diff --git a/testbot/lib/WineTestBot/UserRoles.pm b/testbot/lib/WineTestBot/UserRoles.pm
index 90c4332..900f41f 100644
--- a/testbot/lib/WineTestBot/UserRoles.pm
+++ b/testbot/lib/WineTestBot/UserRoles.pm
@@ -61,6 +61,7 @@ my @PropertyDescriptors = (
   CreateBasicPropertyDescriptor("RoleName", "Role", 1,  1, "A", 20),
   CreateItemrefPropertyDescriptor("Role", "Role", 1, \&CreateRoles, ["RoleName"]),
 );
+SetupItemrefColumns(\@PropertyDescriptors);
 my @FlatPropertyDescriptors = (
   CreateBasicPropertyDescriptor("UserName", "Username",  1,  1, "A", 40),
   @PropertyDescriptors




More information about the wine-cvs mailing list