[tools resend] testbot/orm: Make the Itemref columns read-only.

Francois Gouget fgouget at codeweavers.com
Mon Jun 13 10:14:50 CDT 2022


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>
---
Same as before, just out of the patch series since the other two are 
deferred.
---
 testbot/lib/ObjectModel/CGI/FormPage.pm       |  3 +-
 testbot/lib/ObjectModel/Item.pm               |  8 ++++++
 .../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 224bf3687..6f3449b5b 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 b07b76066..11d09be67 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 6895e801a..171d00a9e 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 f13a4b248..2f9411aa2 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 5ca84e734..8594cfcdf 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 140bd572b..7f15a9c57 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 f4768b823..32a6af44f 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 2533c6a01..87146b277 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 5c5813cd9..0360e4ebc 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 90c4332c3..900f41fc5 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
-- 
2.30.2



More information about the wine-devel mailing list